problems sending big numbers via RS232
nomad
Posts: 276
Ref: problems send big numbers via RS232
hallo,
i have a Propeller Professional Development Board aka PPDB
with a RS232-Port.
the communications from a LinuxSystem via RS232 to the board and back is OK.
in the moment i can only send smallNumbers aka <1>
to the board with:
linux send <1>
board receive <49> as ascii (1)
board if input == 49 then make LED ON
board send "5" back to linux
this is ok
The Problem:
i will send a big decimal-Numbers to the Board
bigNumber <12345>
my first idea, is
on the linux system i cut the bigNumber into single bytes aka 12345 = <1><2><3><4><5>
and send this 5 times to the board
the board receive 5 x the single numbers
the code:
is this a correct code?
is this possible?
when i running the whole stuff
- connections ok
- but no led-blinking ???
- and when i send the output aka inputsInt to the linuxSystem
with Serial.dec(inputsInt)
- the linuxSystem receive grumble stuff not <12345>
the second idea is:
on the Extended_FDSerial object gives a functions
x := Serial.rxDec
this functions should be ok, for receive bigNumbers
but, as per the doku " String must end in a carriage return (ASCII 13) <CR>
under linux i can send : "12345\r"
"\r" is the CR
but when experiment with this stuff, nothing is ok
Thanks for help, trick, tipps and hints
regards
nomad
hallo,
i have a Propeller Professional Development Board aka PPDB
with a RS232-Port.
the communications from a LinuxSystem via RS232 to the board and back is OK.
in the moment i can only send smallNumbers aka <1>
to the board with:
linux send <1>
board receive <49> as ascii (1)
board if input == 49 then make LED ON
board send "5" back to linux
this is ok
The Problem:
i will send a big decimal-Numbers to the Board
bigNumber <12345>
my first idea, is
on the linux system i cut the bigNumber into single bytes aka 12345 = <1><2><3><4><5>
and send this 5 times to the board
the board receive 5 x the single numbers
the code:
Con _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 Rx = 31 Tx = 30 baud = 9600 OBJ ' Ser : "FullDuplexSerial" Ser : "Extended_FDSerial" Var byte input0, input1,input2, input3, input4 byte output long inputInt0, inputInt1, inputInt2, inputInt3, inputInt4 long inputsInt byte asciiBase Pub Main dira[noparse][[/noparse]0]~~ ' Pin05 set output leds outa[noparse][[/noparse]0]~ ' Pin05 set low asciiBase := 48 Ser.Start(Rx,Tx,0,baud) repeat input0 := Ser.RxTime(100) ' byte as ascii input1 := Ser.RxTime(100) ' byte as ascii input2 := Ser.RxTime(100) ' byte as ascii input3 := Ser.RxTime(100) ' byte as ascii input4 := Ser.RxTime(100) ' byte as ascii waitcnt(clkfreq / 10 + cnt) convertToInt if inputsInt == 12345 !outa[noparse][[/noparse]0] Ser.str(string("5")) waitcnt(clkfreq / 10 + cnt) PUB convertToInt inputInt0 := (input0 - asciiBase) * 100000 inputInt1 := (input1 - asciiBase) * 1000 inputInt2 := (input2 - asciiBase) * 100 inputInt3 := (input3 - asciiBase) * 10 inputInt4 := input4 - asciiBase inputsInt := inputInt0 + inputInt1 + inputInt2 + inputInt3 + inputInt4
is this a correct code?
is this possible?
when i running the whole stuff
- connections ok
- but no led-blinking ???
- and when i send the output aka inputsInt to the linuxSystem
with Serial.dec(inputsInt)
- the linuxSystem receive grumble stuff not <12345>
the second idea is:
on the Extended_FDSerial object gives a functions
x := Serial.rxDec
this functions should be ok, for receive bigNumbers
but, as per the doku " String must end in a carriage return (ASCII 13) <CR>
under linux i can send : "12345\r"
"\r" is the CR
but when experiment with this stuff, nothing is ok
Thanks for help, trick, tipps and hints
regards
nomad
Comments
for debugging this
first step: write a small testprogramm than can send a byte as a hexadecimal value
that the PC receives short strings like "$FF", "$0D", "$30" etc.
This means send a "$" and then use the .Hex.-method from ExFDS (Extended_FDSerial)
I HIGHLY recommend testing this FIRST step until it works 101% properly !
second step: then send your big number from the PC to the propeller
send BACK - ALL the received bytes as hexadecimal strings "$30" etc.
to see what you really receive
If you need more support on this post CONCRETE questions
best regards
Stefan
excuse me:
with this spin-programm all stuff running:
1) linux send a string as "12345\r" // \r is CR
2) board receive the BigNumber with: inputInt := Ser.rxDec
3) if inputInt == 12345
then blueLed ON
4) send back a) <5> for it's ok
or
send back b) Ser.dec(inputInt) // for debuging
Thanks for your verry good help.
Regards
nomad
the running code:
What your Prop' is receiving is the ASCII character (byte) representation of the string 12345. I see (from your original post) that you've tried to convert this to an integer, but I can't immediately see why your conversion's not working. However, I'm in the process of writing a "Guide to Propeller Communications", so I've attached a modified version of one of my tutorial app's that will do what you're after - I hope it helps (and thank you for giving me the opportunity to give something back to this forum!).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheers,
Simon
www.norfolkhelicopterclub.com
You'll always have as many take-offs as landings, the trick is to be sure you can take-off again
BTW: I type as I'm thinking, so please don't take any offence at my writing style
To convert the input string (e.g. inputStr) to a numeric value (e.g. inputVal), you would call the "FromStr" method:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheers,
Simon
www.norfolkhelicopterclub.com
You'll always have as many take-offs as landings, the trick is to be sure you can take-off again
BTW: I type as I'm thinking, so please don't take any offence at my writing style
Thanks for your Help.
i am happy that the stuff running...
cheers
nomad