serin2 read until?


Closed Thread
Results 1 to 8 of 8
  1. #1
    eoasap's Avatar
    eoasap Guest

    Default serin2 read until?

    is there a way to perform a serin2 read until CR or a defined char is received?

  2. #2
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    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...

  3. #3
    eoasap's Avatar
    eoasap Guest


    Did you find this post helpful? Yes | No

    Default

    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:

  4. #4
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    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
    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...

  5. #5
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    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

  6. #6
    eoasap's Avatar
    eoasap Guest


    Did you find this post helpful? Yes | No

    Default

    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

  7. #7
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    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

  8. #8
    eoasap's Avatar
    eoasap Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks Dave, I'll give that a try

Similar Threads

  1. Cleaning up code
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd December 2009, 07:14
  2. SEROUT WORD variable problem
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th April 2009, 11:20
  3. Q: using MCLR for Input on 12F683
    By picster in forum mel PIC BASIC Pro
    Replies: 46
    Last Post: - 31st January 2009, 15:25
  4. Changing declared variables names on the fly
    By jessey in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th December 2006, 06:34
  5. Serin2 - All I Need Is 8 Numbers....
    By SOMRU in forum Serial
    Replies: 4
    Last Post: - 14th December 2006, 13:50

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts