rxStr use in Extended_FDSerial.spin
Rsadeika
Posts: 3,837
Below is a snippet of code where I am trying to receive (rx) and work with a short string (less than 15 characters). I am trying to capture (rxStr) the words "gofore", and "stop", and then have an action performed. I got the ser.rx to work, but the string part is not working out for me. Anybody see what I am doing wrong?
Thanks
Ray
PS How do you get the code to appear in a code block. I do not see any instructions for doing it.
PUB BTdev | rx_byte, new_byte
'' rx,tx,0,baud
ser.start(6,5,0,57600)
new_byte := ser.rx
if new_byte == " "
ser.str(string(13,10,"This is Robot ONE!",13,10))
misc.waitms(50)
repeat
''new_byte := ser.rxDec
''if new_byte == 1
''Pwr_btn
''if new_byte == 2
''Ch_up
new_byte := ser.rxStr(rx_byte)
if new_byte == @stop
Pwr_btn
if new_byte == @gofore
Ch_up
DAT
stop byte "stop",0
gofore byte "gofore",0
Thanks
Ray
PS How do you get the code to appear in a code block. I do not see any instructions for doing it.
PUB BTdev | rx_byte, new_byte
'' rx,tx,0,baud
ser.start(6,5,0,57600)
new_byte := ser.rx
if new_byte == " "
ser.str(string(13,10,"This is Robot ONE!",13,10))
misc.waitms(50)
repeat
''new_byte := ser.rxDec
''if new_byte == 1
''Pwr_btn
''if new_byte == 2
''Ch_up
new_byte := ser.rxStr(rx_byte)
if new_byte == @stop
Pwr_btn
if new_byte == @gofore
Ch_up
DAT
stop byte "stop",0
gofore byte "gofore",0
Comments
Ray
Here's a snippet of spin that uses the Strcomp spin instruction to control program flow depending on your C# commands.
Note: take a look at the code of Extended_FDSerial.spin , it has a "Delimiter" variable which is used as a string terminator in RxStr. When I checked the snippet out I set the delimiter to 10 (newline) but thats down to your C# code.
Jeff T.
I am doing a small robot simulation program using the C3, that has a bluetooth module, and an IR detector attached to the C3. On the computer side, I am using the C# program that has access to a bluetooth COM PORT. I wanted to be able to control the simulation with the remote or the computer program.
Ray