Where to store incoming data ?
Ok imagine this set of non standard basic statements..........
dim a$ as char(50)
for x=1 to 50
mid$(a$,x,1)=serin(port something)
next x
I end up with at least 50 chars from the serial port in a$
Now that I have them, I can parse them.
Imagine I am looking for keywords in that string.....
(say 'feed the' 'dog' 'cat' 'bones' 'meat' 'water' 'milk')
So I parse for valid instructions, otherwise I would forget and starve them...
So an incoming data stream of
''ghdfkghkdFEED THElkjgdjfCATjdflgjMILKjsdfjfjsdljfl"
would mean to milk the cat, sorry give milk to the cat...
But...........
''ghdfkghkdFEED THElkjgdjfMILKjdflgjCATjsdfjfjsdljfl"
would be the same, 'feed the milk cat' while out of context is valid
'Feed the' is just a qualifier and once I have that I can look at the rest of the burst of data I'm getting........
I have used
SERIN portb.7,t1200,1000,comserr3,["FEED THE"]
and it works a treat but........
I cant follow it with
SERIN portb.7,t1200,1000,comserr3,["CAT"]
because it may be time to feed the dog....
If I time out waiting for the cat, the dog may have run past, IYSWIM..........
I bet lots of newbies ask ones like this.............
Pic control was so much easier when I could just wire a switch to a pin!
Store your data in an Array
Quote:
dim a$ as char(50)
for x=1 to 50
mid$(a$,x,1)=serin(port something)
next x
I end up with at least 50 chars from the serial port in a$
Try something like:
Code:
Comm_Buffer VAR BYTE[50]
cnt VAR BYTE
FOR cnt = 0 TO 49
SERIN portb.7,t1200, Comm_Buffer[cnt]
NEXT cnt
Now that you have the data in the array, you can parse it out with whatever logic will ensure none of your pets go hungry :D.
You could try using SERIN portb.7,t1200,1000,comserr3,["FEED THE"] to initiate the capture of the data stream. Once found, use the array to capture the rest of the command and parse accordingly.
One issue you may run into is if the data stream is continuous. If it is, you may need to get bit more sophisticated (like using the hardware serial port, interrupts, a FIFO buffer, and continuously parsing the buffer). Or not, if the data is slow enough and the parsing loop is tight enough.
Additionally, what about the device sending all these instructions? Any way you can modify the data stream? Such as sending a special character proir to any key word?
Steve