Why don't you try it this way
hserIN 65535, oops, [STR smallp\5\","]
hserIN 65535, oops, [STR largep\5\13]
then you have the values in 2 streams, each left justified-
David
Why don't you try it this way
hserIN 65535, oops, [STR smallp\5\","]
hserIN 65535, oops, [STR largep\5\13]
then you have the values in 2 streams, each left justified-
David
Wow, second post and you are already helping . . . <B><H2>WELCOME TO THE FORUM DAVID !
If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
Hi David,
That would almost work. The problem is that neither string is guaranteed to be exactly 5 characters. So if the sent data was 1499,136 I would actually get 1499, likewise if the data is only 3 characters like 210,152 I would actually get 210,1
confusing!!
That is what the option end character is good for. By setting the end character to a "," then the command will take up to but not necessarily 5 characters until it gets the "," or in the second line the Line feed. I put a 13-should be 10, as you mentioned earlier the line feed comes after the carriage return. So assuming you reset the stream before each update to all 0s if you sent the stream
1499,136(CR)(LF)
then
hserIN 65535, oops, [STR smallp\5\","]
would give you an array with "1"-"4"-"9"-"9"-0 in smallp and
hserIN 65535, oops, [STR largep\5\10]
would give you "1"-"3"-"6"-13-0 in largep
You would just then ignore the 13 or re zero it when you do your parsing
Thanks for the welcome Joe, I've been in the forum reading all week, mostly older threads. I'm finally sort of caught up on what is still relevant.
That was the way I read the manual as well. I thought that as soon as the function saw a character meeting the WAIT criteria it would terminate collecting any more characters. In fact what I'm seeing is that it continues to gather all 5 characters, so it collects the comma as well if the string is less than 5!
The manual says the string length is determined by the count OR when the optional character is encountered. Unfortunately that sentence can be interpreted two ways.
Hi,
Played with this some more...
Without a qualifier for some reason the buffer keeps the last data sent and returns it with the next. I guess you do not have a qualifier at the beginning of the string so use the LF or CR at the end.
This is what I am sending
123456789,987654321
and I have my terminal set to terminate the line with a CR LF.
The working code
###############
Code:<html> <head></head> <body><!--StartFragment--><pre><code><font color="#000080"> '18F6680 02/14/09 INFEED PARSE TEST BAUD 9600 </i></font><font color="#FF0000"><b>DEFINE </b></font><font color="#0000FF"><b>OSC </b></font>20 @ <font color="#0000FF"><b>__CONFIG _CONFIG1H</b></font>, <font color="#0000FF"><b>_OSC_HS_1H </b></font>@ <font color="#0000FF"><b>__CONFIG _CONFIG2H</b></font>, <font color="#0000FF"><b>_WDT_ON_2H </b></font>& <font color="#0000FF"><b>_WDTPS_128_2H </b></font>@ <font color="#0000FF"><b>__CONFIG _CONFIG4L</b></font>, <font color="#0000FF"><b>_LVP_OFF_4L </b></font><font color="#FF0000"><b>DEFINE </b></font><font color="#0000FF"><b>LCD_DREG PORTG </b></font><font color="#FF0000"><b>DEFINE </b></font><font color="#0000FF"><b>LCD_DBIT </b></font>0 <font color="#FF0000"><b>DEFINE </b></font><font color="#0000FF"><b>LCD_RSREG PORTE </b></font><font color="#FF0000"><b>DEFINE </b></font><font color="#0000FF"><b>LCD_RSBIT </b></font>0 <font color="#FF0000"><b>DEFINE </b></font><font color="#0000FF"><b>LCD_EREG PORTE </b></font><font color="#FF0000"><b>DEFINE </b></font><font color="#0000FF"><b>LCD_EBIT </b></font>1 <font color="#FF0000"><b>DEFINE </b></font><font color="#0000FF"><b>LCD_BITS </b></font>4 <font color="#FF0000"><b>DEFINE </b></font><font color="#0000FF"><b>LCD_LINES </b></font>4 <font color="#FF0000"><b>DEFINE </b></font><font color="#0000FF"><b>LCD_COMMANDUS </b></font>3000 <font color="#FF0000"><b>DEFINE </b></font><font color="#0000FF"><b>LCD_DATAUS </b></font>150 <font color="#000080"><i>'############################################### </i></font><font color="#FF0000"><b>PAUSE </b></font>100 : <font color="#FF0000"><b>LCDOUT </b></font>$FE,1,<font color="#00FF00"><b><i>"TEST" </i></b></font><font color="#0000FF"><b>N1 </b></font><font color="#FF0000"><b>VAR LONG</b></font>:<font color="#0000FF"><b>N2 </b></font><font color="#FF0000"><b>VAR LONG </b></font><font color="#0000FF"><b>START</b></font>: <font color="#0000FF"><b>N1 </b></font>= 0 : <font color="#0000FF"><b>N2 </b></font>= 0 <font color="#FF0000"><b>HIGH </b></font><font color="#0000FF"><b>PORTG</b></font>.4 :<font color="#FF0000"><b>PAUSE </b></font>250:<font color="#FF0000"><b>LOW </b></font><font color="#0000FF"><b>PORTG</b></font>.4 <font color="#0000FF"><b>RCSTA</b></font>.4 = 0 : <font color="#0000FF"><b>RCSTA</b></font>.4 = 1 <font color="#000080"><i>'CHANGE LINE FEED AND CARRIAGE RETURN AS REQUIRED </i></font><font color="#0000FF"><b>RCSTA</b></font>=$90:<font color="#0000FF"><b>TXSTA</b></font>=$24:<font color="#0000FF"><b>SPBRG</b></font>=129:<font color="#FF0000"><b>HSERIN</b></font>[<font color="#0000FF"><b>WAIT</b></font>($a),<font color="#0000FF"><b>WAIT</b></font>($d),<font color="#FF0000"><b>DEC </b></font><font color="#0000FF"><b>N1</b></font>,<font color="#0000FF"><b>WAIT</b></font>(<font color="#00FF00"><b><i>","</i></b></font>),<font color="#FF0000"><b>DEC </b></font><font color="#0000FF"><b>N2</b></font>] <font color="#FF0000"><b>LCDOUT </b></font>$FE,1,<font color="#FF0000"><b>DEC </b></font><font color="#0000FF"><b>N1 </b></font>: <font color="#FF0000"><b>LCDOUT </b></font>$FE,$C0,<font color="#FF0000"><b>DEC </b></font><font color="#0000FF"><b>N2 </b></font>: <font color="#FF0000"><b>GOTO </b></font><font color="#0000FF"><b>START </b></font></code></pre><!--EndFragment--></body> </html>
Dave
Always wear safety glasses while programming.
Hi Dave,
I think your latest solution might have worked, but I had already got it working by parsing it after the fact based on Jersons parse routine. I really appreciate everyones input. Here is what the working code looks like:
hserIN 65535, oops, [STR inputdata\12\10] 'get the serial data
gosub ParseNumber 'split the raw data into 2 numbers
ParseNumber: ' collect both pieces of the data in sep arrays
for Cntr = 0 to 10
if inputdata[Cntr] <> "," then ' Found comma? We've got first
smallp[Cntr] = inputdata[Cntr]
else
Cntr2 = Cntr 'marks where the comma was
'goto earlyexit
goto GetNum2 ' Now get the second number
endif
next
earlyexit:
return
GetNum2:
CNTR = Cntr + 1 'get past the comma
for Cntr = Cntr to 10
if inputdata[Cntr] < "0" then
RETURN
else
If inputdata[Cntr] > "9" then
RETURN
ELSE
largep[Cntr-Cntr2-1] = inputdata[Cntr] ' It's a valid number
endif
ENDIF
next
return
I had to modify the array pointer for the second number by subtracting the point at which the comma was found on the first pass from it's pointer. In other words the pointer for the input data can't be used directly to point to the second number.
<b>Proof Again</b> There is more than 1 right way to do almost everything.
If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
Bookmarks