Shop OBEX P1 Docs P2 Docs Learn Events
Any code for bs2 using serial data? — Parallax Forums

Any code for bs2 using serial data?

boonboyboonboy Posts: 10
edited 2007-03-02 16:04 in BASIC Stamp
Hi guys got a web site with php sending data to the /dev/ttyusb0, a character c for centigrade & an f for farenheit. I want the bs2 board to use this value from its serial port to respond with one section of code for f & another for C. I know you use an If statement & the serin & serout commands but cant get my head round the bs2 help files. Some code doing a similar type of thing would be greatly appreciated.

thanks for your patience with me guys.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-02 16:04
    If <pin> is the input pin # and <Baud> is the constant for the Baud (see SERIN), you could do:
    x  var  byte
    
    do                                       ' loop forever
      serin <pin>,<baud>,[noparse][[/noparse] x]   ' wait for a single byte
      select x
        case = "f"                       ' is it "f"
        case = "C"                      ' is it "C"
      endselect
    loop                                    ' ignore if neither
    
    


    Check the SELECT statement for other CASE formats and an "other" clause. Note that the SERIN
    will wait for a character. If you need some kind of timeout, the SERIN statement has an optional
    timeout.
Sign In or Register to comment.