is there a way to perform a serin2 read until CR or a defined char is received?
is there a way to perform a serin2 read until CR or a defined char is received?
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
Ability to Fly:
Hurling yourself towards the ground, and missing.
Engineers that Contribute to flying:
Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute
Pilots that are Flying:
Those who know their limitations, and respect the green side of the grass...
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:
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:
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.do you think there will be any dataloss doing a loop for the read?
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
Ability to Fly:
Hurling yourself towards the ground, and missing.
Engineers that Contribute to flying:
Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute
Pilots that are Flying:
Those who know their limitations, and respect the green side of the grass...
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
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
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
Bookmarks