Parsing Strings...


Closed Thread
Results 1 to 24 of 24

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I still think separating the numbers on the way in is the way to go. Although Jerson's code is pretty slick.

    Here is what I was thinking. Just tested it using SERIN2 as the chip I have on the bench is not set up for HSERIN right now.

    The first WAIT is to keep garbage out.
    Code:
    N1	VAR	LONG
    N2	VAR	LONG
    LOOP:
    SERIN2 PORTD.2, 16416, [WAIT("X"),DEC N1,WAIT(","),DEC N2]
    GOTO DISPLAY
    
    DISPLAY:
    Serout2 PORTC.6, 16416, [ DEC N1, $d, $a]
    Serout2 PORTC.6, 16416, [ DEC N2, $d, $a]
    GOTO LOOP
    If you need the data in an array just modify the above with STR...
    Last edited by mackrackit; - 11th February 2009 at 15:09.
    Dave
    Always wear safety glasses while programming.

  2. #2
    Join Date
    Feb 2009
    Posts
    41


    Did you find this post helpful? Yes | No

    Default Hmmm...

    Both great suggestions for which I appreciate!!! I'm pondering....

  3. #3
    Join Date
    Feb 2009
    Posts
    41


    Did you find this post helpful? Yes | No

    Default No success...

    I've tried dozens of ideas along those lines and no solution works....

    Like:
    hserIN 65535, oops, [STR smallp\5, WAIT(","), STR largep\5\13]

    problem here is the string size I expect to receive is variable, but the STR forces you to put in the string length. If it's shorter the function doesn't return anything, yet it doesn't time out. I'm ending up with the comma in my first string, even though I'm only looking for it as a seperator and after I receive the first serial data, every time thereafter there is a non-acsii character in the first byte of smallp.

    If the data was always the same length it would be a breeze...

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    From the manual:
    STR followed by a byte array variable, count and optional ending
    character will receive a string of characters. The string length is
    determined by the count or when the optional character is
    encountered in the input.
    [STR smallp\10\,]
    See if that will get the first part correctly.

    Does the data comming in have a qualifying character before the data you want? If so then the first example I gave will work. If it does not have a qualifying character then leave that part out.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Feb 2009
    Posts
    41


    Did you find this post helpful? Yes | No

    Default

    I appreciate your help! Very confused

    hserIN 65535, oops, [STR smallp\10\","]

    The first time thru I get the correct first part of the string. the device was sent 777,53 and smallp received 777.

    The second time and every time thereafter the data is skewed. For example if the next packet that comes in is 766,59 smallp receives a 53766. The 53 from the last packet sent....

  6. #6
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    It would seem to be a lot easier to capture the whole sequence, then later scan the array for any commas and deal with it that way, especially since when you are using SERIN you have very little processing time available between characters.
    Charles Linquist

  7. #7
    Join Date
    Feb 2009
    Posts
    41


    Did you find this post helpful? Yes | No

    Default

    I think that's a great suggestion and I agree. I have been unable to successfully parse it after the fact.

Similar Threads

  1. Parsing serial data
    By Heckler in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 4th March 2010, 14:25
  2. Please help with storing strings in codespace
    By g-hoot in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 16th May 2008, 01:02
  3. How to write/read strings EEPROM/LCD
    By g-hoot in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 11th February 2007, 06:26
  4. Processing lengthy strings
    By sougata in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 21st March 2006, 05:27
  5. I2CWRITE writing Strings to EEPROM
    By NavMicroSystems in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 27th March 2005, 19:45

Members who have read this thread : 0

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

Tags for this Thread

Posting Permissions

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