PDA

View Full Version : serin2 read until?



eoasap
- 17th January 2006, 13:46
is there a way to perform a serin2 read until CR or a defined char is received?

Dwayne
- 17th January 2006, 16:14
You can loop the Serin2 or the Serin until the predetermined "Flag" is found.

Loop:
serin datapin....variable.
Process by storing data in Eprom or whatever
if variable <> CR (or flag) goto Loop:

This is assuming you are reading 1 char at a time.

I don't know how your data is being sent... but you can read a string of char and check for the "Flag" before looping back.

Dwayne

eoasap
- 19th January 2006, 17:36
Thanks Dwayne, i'll work on that first thing saturday morning. do you think there will be any dataloss doing a loop for the read?

so pseudo code something like this?

loop:
SERIN2 one byte
check that byte for Carriage return (when to stop)
if CR, exit_loop
goto loop

exit_loop:

Dwayne
- 19th January 2006, 21:22
Hello eoasap,

e>>so pseudo code something like this?

loop:
SERIN2 one byte
check that byte for Carriage return (when to stop)
if CR, exit_loop
....
process data
.....
goto loop

exit_loop;
<<

yes this is a good pseudo code example.

Now to answer your other question:


do you think there will be any dataloss doing a loop for the read?


This depends on how your data is being sent. If it is a non-stop 40 characters, yes, you will lose some data. You will have to change your read to a different method... like reading in a string of characters or something before processing.

If your data is coming in spurts, you can use a "control" character to "flag the receiver that the following character is the one you want read.

If I were you, I would *FIRST* find out HOW the data is being sent to you. Then program your PIC for this format of sending. *IF* you can chose the way the data is being sent to you, then you have many many available options!...

Dwayne

Dave
- 20th January 2006, 11:52
eoasap, to answer your original question, use the "WAITSTR" modifier to finish loading your array of characters or variables. This is covered in your manual under "SERIN2".

Dave Purola,
N8NTA

eoasap
- 20th January 2006, 14:25
I through about that, but doesn't WAITSTR wait for that string before reading in bytes? i want to read in bytes until a certain byte is received (carriage return),

The length of the string being received is unknown, but terminated with the carriage return

Dave
- 20th January 2006, 16:56
eoasap, I'm Sorry, What I meant was to use the optional ending character to finish the array load. I usually use the carriage return character $0D to end my input strings. Sorry for the confusion.....

Dave Purola,
N8NTA

eoasap
- 23rd January 2006, 12:11
Thanks Dave, I'll give that a try ;)