How to Serial comm. wait for a string?


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: How to Serial comm. wait for a string?

    Because you are typing, there will always be an enter character to terminate the string,
    so you only need to fill a buffer, and check each byte for the enter character,
    then you have all the time in the world for the program to look at the string
    rather than trying to figure out what is going on in-between each byte being sent.

    Same with GPS, I prefer to fill a buffer with the entire command, and count two bytes after the * char is received,
    then look into the content after the entire sentence is received.

  2. #2
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default WAITing to read from serail com GPS receiver example

    Hi,

    This is the way time can be read "on the fly" from a serial GPS receiver module like this one
    Name:  imageedit_2_6240927308.jpg
Views: 463
Size:  5.8 KB
    Code:
    GPGGA_Time:
       SERIN2 GPSfrom,GPSbps,[WAIT("$GPGGA,"),STR GPS_D\6]
       LCDOUT $FE,2,GPS_D(0),GPS_D(1),":",GPS_D(2),GPS_D(3),":",GPS_D(4),GPS_D(5)
    GOTO MAIN:
    The PIC is waiting for the string $GPGGA, from the GPS module to arrive, then it fills an array with the 6 next incoming characters and displays them.
    Last edited by flotulopex; - 28th December 2015 at 11:10.
    Roger

  3. #3
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: WAITing to read from serail com GPS receiver example

    Oh my, you’ll have a bunch of unneeded checking when the sentence could have been discarded for no fix or bad checksum.
    Some GPS modules also put out a bad but valid time from their battery clocks until a position fix is acquired.
    Not good if you were logging for a security system or something like that.

    The thread isn’t necessarily about GPS, but it’s more or less the same thing.
    You might has well make use of the UART if it’s present.

    set a character counter to zero
    Code:
    charbuffer var byte[60]
    character var byte
    charcount var byte
    charcount = 0
    receive the serial with hserin with the smallest possible timeout so it will only give you a character if one is present in the buffer

    Code:
    ‘pseudocode
    
    hserin [character,lowesttimeout,timeoutlabel]
    charbuffer[charcount] = character
    charcount = charcount + 1
    
    if character = enter or linefeed, etc. then
    gosub investigate’ investigate the complete sentence and reset charcount
    endif
    
    timeoutlabel:

Similar Threads

  1. wait for a string
    By sahin5002 in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 2nd April 2009, 23:27
  2. Serial Comm startup
    By ruijc in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 9th January 2008, 15:20
  3. serial comm problem
    By win_832001 in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 29th June 2006, 13:57
  4. Whats going on? serial comm
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 2nd June 2005, 11:57
  5. Serial comm Problems
    By Fossil in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 7th January 2004, 02:29

Members who have read this thread : 2

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