PDA

View Full Version : For Next Loops and Serin2?



scottl
- 10th November 2007, 17:43
I am trying to use SERIN2 and get 1 byte at a time! The data being received could be any lenght up to 32 bytes. I have tried the following but it seems to fail. Can anyone tell me if this will work? K will be to send the characters out another port.



mainloop:
for i = 0 to 31
serin2 GPIO.1,84,1000,mainloop,[str receive\1]
command[i] = receive
k = k + 1
if (command[i] == 13) then goto process
next i

process:
SEROUT2 GPIO.0,84,["packet len", dec k, " ", str command\k,13]
goto mainloop


Thanks in advance,

Scott

BrianT
- 10th November 2007, 20:28
Here is what I do to parse an unknown length GPS message.

GetData:
ProcessRMC:
serin2 rx232, 188, 2000, nogps,[WAIT("$GPRMC")] ' find start
for i = 0 to 84 ' plenty of length - can be cut back
serin2 rx232, 188, [a[i]]
next i

Here I bring in 84 characters after first finding the $GPRMC header. Having made the 84 character array I then go through it and count commas to find the particular fields I am looking for.

The complete code was posted to the GPS section of this forum a couple of years back.

HTH
Brian