SERIN2 digit parsing


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

    Default SERIN2 digit parsing

    Using SERIN2 command, manual isn't very specific on this....
    I'm receiving a string of data from OBD2 input...looks like this:
    (all responses are in ASCII)
    49 02 01 00 00 00 31
    49 02 02 44 34 47 50
    49 02 03 30 30 52 35
    ....and so on....

    Here's the SERIN2 command I want to use:
    SERIN2 inport , 84 , [ WAIT ( "49 02 01 " ) , HEX2 vin[0] , HEX2 vin[1] , HEX2 vin[2] , HEX2 vin[3] and so on until I get all the char's I want....

    Will SERIN2 skip the spaces between the hex digits & CR's & LF's at the end of the lines, or will SERIN2 kick out when a non-ASCII hex digit is encountered...

    Here's the SERIN2 command I'm afraid I'll have to use:
    SERIN2 inport , 84 , [ WAIT ( "49 02 01 " ) , SKIP 1 , HEX2 vin[0] , SKIP 1 , HEX2 vin[1] , SKIP 1 , HEX2 vin[2] , SKIP 1 , HEX2 vin[3] , SKIP 1 , HEX2 vin[4] ]
    SERIN2 inport , 84 , [ WAIT ("49 02 02 " ) , SKIP 1 , HEX2 vin[5] , SKIP 1 , HEX2 vin[6] , SKIP 1 , HEX2 vin[7] , SKIP 1 , HEX2 vin[8] , SKIP 1 , HEX2 vin[9] ].............and so on until all the data gets received.......

    The first solution is a bit more elegant; the 2nd-not so much.
    Thoughts?

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    Here's the SERIN2 command I want to use:
    SERIN2 inport , 84 , [ WAIT ( "49 02 01 " ) , HEX2 vin[0] , HEX2 vin[1] , HEX2 vin[2] , HEX2 vin[3] and so on until I get all the char's I want....

    Will SERIN2 skip the spaces between the hex digits & CR's & LF's at the end of the lines, or will SERIN2 kick out when a non-ASCII hex digit is encountered...
    Well, right there in the manual on page 135

    If variable is preceded by BIN, DEC or HEX, then SERIN2
    converts a binary, decimal or hexadecimal value in ASCII and stores the
    result in that variable. All non-digits received prior to the first digit of the
    decimal value are ignored and discarded. The non-digit character which
    terminates the value is also discarded.
    HTH,
    DT

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Well, right there in the manual on page 135



    HTH,
    Right, Pg.135 says "the non digit character which terminates the value is also discarded".
    Now maybe I'm reading too much into it, but it sounds to me like SERIN2 will kick out when it comes upon a non digit character (not 0-9 or A-F).

    I'd go out and try it out right now on the vehicle, but it's like 15F outside, a bit cold to be testing hardware...oh, and it's snowing, and like 30 mph winds...

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Talking

    Quote Originally Posted by Darrel Taylor View Post
    Well, right there in the manual on page 135



    HTH,
    _____ Touche'

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Joe S. View Post
    _____ Touche'
    I copy that! Over and out....


    But ya know, it's not all that clear...and again, I'm probably reading too much into the manual (or maybe not enough). If it wasn't so stinkin' cold out, I would've had the answer myself...

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Dude!! Move to southern California.

    At the Worst, we get maybe 1 or 2 days that might freeze a thin layer of ice on the puddles from the overnight drizzle.

    As a kid, I lived for a short time in Cedar Rapids Iowa. I've seen -80 degree wind chill factor. NEVER, I mean NEVER again. I'll jump in a volcano first. Never!

    OK, so back to the serin....

    Yup, you're reading too much into it. And I should also mention that on page 135 it says...
    "BIN, DEC and HEX may be followed by a number. Normally, these modifiers receive as many digits as are in the input. However, if a number follows the modifier, SERIN2 will always receive that number of digits, skipping additional digits as necessary.
    Don't take me too seriously here.

    So, You have the data...

    49 02 01 00 00 00 31

    and you've waited for "49 02 01 " (note: includes a space)

    That means the first thing that HEX2 sees is "00 ", and since the HEX2 stops after receiving the first 2 digits, the next parameter will start with a space, and another "00". The space will be discarded, and the following 2 digits will be parsed. Continuing the process unabated.

    Even if you used the HEX without the 2, it would still work, as the terminating character (space) would be discarded, leaving the next parameter to start with a hex digit, instead of a space. Again proceeding on without error.

    So it all boils down to, YES, what you've shown, should work.
    <br>
    DT

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Dude!! Move to southern California.

    At the Worst, we get maybe 1 or 2 days that might freeze a thin layer of ice on the puddles from the overnight drizzle.

    As a kid, I lived for a short time in Cedar Rapids Iowa. I've seen -80 degree wind chill factor. NEVER, I mean NEVER again. I'll jump in a volcano first. Never!

    OK, so back to the serin....

    Yup, you're reading too much into it. And I should also mention that on page 135 it says...
    Don't take me too seriously here.

    So, You have the data...

    49 02 01 00 00 00 31

    and you've waited for "49 02 01 " (note: includes a space)

    That means the first thing that HEX2 sees is "00 ", and since the HEX2 stops after receiving the first 2 digits, the next parameter will start with a space, and another "00". The space will be discarded, and the following 2 digits will be parsed. Continuing the process unabated.

    Even if you used the HEX without the 2, it would still work, as the terminating character (space) would be discarded, leaving the next parameter to start with a hex digit, instead of a space. Again proceeding on without error.

    So it all boils down to, YES, what you've shown, should work.
    <br>
    So-CAL - What?! And pay silly amounts of cha-ching for practically nothing?
    The way I figure it, you can always light something on fire to stay warm. When was the last time a person lit something on fire to stay cool? And I got 1.5acres & 2400sq.ft., 30ft x 80ft garage, 20x50 bldg w/basement that's about to become my PIC-Shop, 'bout a hundred trees, a burn pit (great for keggars), deer, turkeys, eagles, etc. all over the place, I can drive my junker '94 Geo Metro like an idiot (and I do!) all day almost anywhere, neighbors are great, and I don't have to lock my door when I leave if I don't want to...and I don't worry at all about being shot for no reason...all for $80K. I've been to SoCal for a time (Long Beach/LA, ok, haven't been to Northern end, can't judge that)...I'll pass...thank you...please drive thru...

    And now back to our regularly scheduled program....

    I kinda figured I was reading too much into it, but, you know how it is...just when you think you know how something works, and it ain't workin', it's probably because you didn't know how it really worked in the first place . I guess it goes back to that updated manual thread, adding in a couple more examples and things like that.
    We'll find out how well it works when I get the nerve up to hook the OBD up to my truck and chance burning out the ECU.

  8. #8
    Join Date
    Mar 2005
    Location
    Iowa, USA
    Posts
    216


    Did you find this post helpful? Yes | No

    Default O.t.

    Quote Originally Posted by Darrel Taylor
    As a kid, I lived for a short time in Cedar Rapids Iowa. I've seen -80 degree wind chill factor. NEVER, I mean NEVER again. I'll jump in a volcano first. Never!
    Aw 'cmon Darrel... Iowa isn't so bad.
    Quote Originally Posted by Skimask
    The way I figure it, you can always light something on fire to stay warm.
    I broke down and bought a corn burner this year. Never thought I would be burning corn to heat my house! Ofcourse, as soon as I do, the corn prices start climbing... damn ethanol plants!
    Wisdom is knowing what path to take next... Integrity is taking it.
    Ryan Miller

Similar Threads

  1. GPS $GPRMC to PIC16F684. Need help with SERIN2
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 27th November 2009, 09:47
  2. Getting SERIN2 to work?
    By BobPigford in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 22nd July 2009, 20:10
  3. Single digit 7 Seg LED clock - PIC16F88
    By thirsty in forum Code Examples
    Replies: 4
    Last Post: - 17th July 2009, 08:42
  4. need help in lookup
    By malwww in forum mel PIC BASIC Pro
    Replies: 27
    Last Post: - 6th June 2009, 14:30
  5. 7 segment digit problem (using Mister E's code)
    By jmgelba in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 9th September 2005, 20:25

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