Shop OBEX P1 Docs P2 Docs Learn Events
Decoding serial data — Parallax Forums

Decoding serial data

VernonVernon Posts: 1
edited 2012-10-05 12:35 in Propeller 1
Hi

I have no previous programming experience and new to the prop & spin code.
I have been working through the PE kit labs and have the basic understanding of the
fndamentals.

I would like some help, to decode the ASCII code, when using the simple_serial.spn
This is a sample of the data:

DA00002.85 m
DB00002.85 m
BC00.0dB
*
This is coming from a Deso echo sounder to P0 on Prop, I have the output on P1 and have it plugged in to Hyperterminal, on PC, and can see the data (through a MAX232 IC).

How can I write a routine to decode the DA00002.85 string, compare it to a pre difined CON
i.e. DA00005.00 and set a pin high, if condition is equeal?
Sounds simple, I just don't know where to start!

Any help will be great,
Regards
Vernon

Comments

  • AribaAriba Posts: 2,690
    edited 2012-10-05 12:35
    You need to collect the received characters into a string, and then compare this string with the one you want test.
    The following code fragment shows a subroutine (methode) that waits until a certain startcharacter is received and writes then the characters to the string until the endcharacter is received, the result is the string without the endcharacter.
    This string is then compared to a fixed string.
    OBJ
     ser : "SimpleSerial"
    VAR
     byte inpstr[16] 
    
    PUB main
     ...
     getStr(@inpstr,"D","m")
     if strcomp(@inpstr, string("DA00005.00 "))
       outa[pin] := 1   'equal
     else
       outa[pin] := 0   'not equal
     ... 
    
    
    PUB getStr(strptr,startchar,endchar) : c
     repeat
       c := ser.rx
     until c == startchar
     repeat
       byte[strptr++] := c 
       c := ser.rx
     until c == endchar
     byte[strptr] := 0
    
    Andy
Sign In or Register to comment.