HSERIN uses the same syntax as SERIN2, so do the "separation" as the data is coming in.
HSERIN uses the same syntax as SERIN2, so do the "separation" as the data is coming in.
Dave
Always wear safety glasses while programming.
Ok, since you have the string to be parsed, you will need a parser too! I dont have anything ready at hand but, I'll give it a shot anyway. UNTESTED CODE FOLLOWS
You could modify this code to do a repetitive parse. Every time you call it, it would return you a number, but I'll leave that to you.Code:' assume the string is TOPARSE ' it will return you 2 numbers, one from before the comma, one from after the comma Number1 var Long Number2 var Long Cntr var byte ' counter to index the string ParseNumber: Number1 = 0 ' start with 0 in both numbers Number2 = 0 'collect Number1 for Cntr = 0 to 10 ' you said your string is 10 places long if TOPARSE[Cntr] <> "," then Number1=Number1*10 ' x10 to make place for the new digit Number1 = Number1+TOPARSE[Cntr]-'0' ' I'm assuming this is an ASCII string else goto GetNum2 ' collect the remainder as number2 endif next return GetNum2: for Cntr=Cntr+1 to 10 if TOPARSE[Cntr] <> "," then Number2=Number2*10 Number2 = Number2+TOPARSE[Cntr]-'0' ' I'm assuming this is an ASCII string else return ' because, you said there are only 2 numbers ;) endif next return
Good luck.
Last edited by Jerson; - 11th February 2009 at 16:12. Reason: GetNum2: for Cntr=Cntr+1 to 10
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.
If you need the data in an array just modify the above with STR...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
Last edited by mackrackit; - 11th February 2009 at 15:09.
Dave
Always wear safety glasses while programming.
Both great suggestions for which I appreciate!!! I'm pondering....
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...
From the manual:
[STR smallp\10\,]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.
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.
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....
Bookmarks