Shop OBEX P1 Docs P2 Docs Learn Events
rxStr use in Extended_FDSerial.spin — Parallax Forums

rxStr use in Extended_FDSerial.spin

RsadeikaRsadeika Posts: 3,837
edited 2011-01-30 06:46 in Propeller 1
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

Comments

  • RsadeikaRsadeika Posts: 3,837
    edited 2011-01-29 11:49
    I created a terminal program with C#, which I am using to communicate with the spin program. After further investigation I noticed that the C# terminal program is sending (tx) text in unicode characters. Is their a spin serial program that can deal with a string in unicode characters? I think that the best spin serial program is only able to deal with byte, hex, and decimal values, no unicode. Anybody have some work around code?

    Ray
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2011-01-29 18:10
    Hi Ray , your C# app should be transmitting ASCII characters , I would like to see the line you are using to transmit your strings.

    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.
  • RsadeikaRsadeika Posts: 3,837
    edited 2011-01-30 06:46
    Thanks Jeff T. Your example code works! I was just getting ready to give up on using that. Now I can use short commands, plus digits. I thought it was a problem on the C# side, but, it wasn'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
Sign In or Register to comment.