PDA

View Full Version : SERIN2 digit parsing



skimask
- 7th January 2007, 03:46
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?

Darrel Taylor
- 7th January 2007, 04:14
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,

skimask
- 7th January 2007, 04:23
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...

Archangel
- 7th January 2007, 07:34
Well, right there in the manual on page 135 :)



HTH,

_____ Touche'

skimask
- 7th January 2007, 08:11
_____ 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...

Darrel Taylor
- 7th January 2007, 09:19
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>

skimask
- 7th January 2007, 09:49
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.

rhino
- 7th January 2007, 23:15
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.

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!