SERIN w/ long string

John Chris

Senior Member
Hi there, I am using an 18X and must read an RS232 data string of the following general form. I have not experimented with this yet and am simply trying to prepare and get a few thoughts down.

xxx,B09730,x.xx,x,xx-xx-xx xx:xx:xx,x.xxx,pH,xxx.x,mV,xx.x,C,xx.x,%,x,xx

e.g. 112,B09730,2.22,1,10-09-2096 07:21:48,1.810,pH,313.3,mV,23.4,C,99.8,%,6,26

In order to extract numeric data. For instance, I must extract the x.xxx that precedes the 'pH'. I note that some fields may have variable field lengths

Using fixed sections of the string (those containing characters 'pH', 'mV', etc.) as qualifiers seems like a good place to start. For instance, if I were to use the command:

[
SERIN pin,baudmode,("pH,"),b0,b1,b2,b3,b4
]

I presume that each of the characters in the string x.xxx would be read into the respective variables. The units of each measurement FOLLOW the value, so the above code would read the value associated with the units 'mV'

The value of pH is preceeded by the date, so reading this value would be a little more tricky - I would have to have some a priori knowledge of the date.

Moving on, I would like to prompt the device (source of the data) only once. The code I would attempt to use to read two sections of data would be

[
SERIN pin,baudmode,("pH,"),b0,b1,b2,b3,b4
SERIN pin,baudmode,("mV,"),b5,b6,b7,b8
]

1) I assume the PIC is able to execute the first command and move onto the next fast enough to catch the data string?

Further questions:

2) If I wanted to read more data and the number of characters that were to be read exceeded the 13 variables that the 18X possesses, what alternatives exist?

3) Is there a wild card character for building qualifiers?

4) I assume the symbols ',' '.' and '-' occupy single 8-bit variable as their respective ascii representations

Any suggestions are appreciated, Thanks!

Chris
________
Ship sale
 
Last edited:

eclectic

Moderator
@John Chris

Only half-formed thoughts at the moment.
I realise that you said
“The value of pH is preceeded by the date, so reading this value would be a little more tricky - I would have to have some a priori knowledge of the date.”

Does your device send out a consistent date format, for the year?
As in say, 2009?
Could you not start from there?

And, why not upgrade to a 28X1?
Twice the variables, and, the potential to use Hserin.

e
 

lbenson

Senior Member
SERIN pin,baudmode,("pH,"),b0,b1,b2,b3,b4
SERIN pin,baudmode,("mV,"),b5,b6,b7,b8

1) I assume the PIC is able to execute the first command and move onto the next fast enough to catch the data string?

Further questions:

2) If I wanted to read more data and the number of characters that were to be read exceeded the 13 variables that the 18X possesses, what alternatives exist?

3) Is there a wild card character for building qualifiers?

4) I assume the symbols ',' '.' and '-' occupy single 8-bit variable as their respective ascii representations
I can't say I can be authoritative, but
1) Probably not
2) Unless you can control the timing of the inputs, the easiest alternative is probably to move to the 28X1 and use hserin to put the string into the 128-byte scratchpad
3) No wild card
4) Yes

Note that instead of
SERIN pin,baudmode,("pH,"),b0,b1,b2,b3,b4
SERIN pin,baudmode,("mV,"),b5,b6,b7,b8

This will probably work and waste no variables (by throwing away the "pH"--note triplication of b5)
SERIN pin,baudmode,("pH,"),b0,b1,b2,b3,b4,b5,b5,b5,b6,b7,b8
 
Last edited:

womai

Senior Member
Probably the easiest solution would be to move to a Picaxe 28X1 which can re receive strings of up to 128 bytes into the scratchpad using hserin, After that you can pick the string apart at leisure.

For the 18X, I can't see a generic way to receive all the data at once (i.e. with just a single query). But if you can query the device several times and each time extract only one value (e.g. pH value the first time, mV value at the second time, etc)., this can be done as long as the strings have constant length: Just use a dummy variable repeatedly to jump over uninteresting but non-constant sections; e.g.

serin pin, baud, ("B09730"), b0, b0, b0, ...... , b0, b0, b1, b2, b3, b4, b5

will ignore as many bytes in the middle as you want, and then capture the last 6 bytes it receives in b0 ... b5.

Doing repeated receives as you suggest could work, but only with an overclocked Picaxe at low enough baud rates and if you don't do much inbetween.

Let's say your true data strings are up to 7 bytes long, and you need to store them in memory using poke commands before you are ready to look for the next qualifier. At 8 MHz the 18X executes around 4000 commands per second. Storing 7 bytes (without any other actions - you'll process the data after everything has been captured) and starting the next serin command is a total of 8 commands, which will take approx. 2 msec. You only have a single character (a comma) between the end of a data value and the beginning of the next qualifier, so that gives you a dead time of 10/baud rate (start bit, 8 data bits, stop bit), which must be larger than the 2ms of processing time. With that you get an estimate for the maximum baud rate this can handle of

10/baud > 0.002sec

or

baud_max =10/0.002 = 5000 baud

So you'll be lucky to get this running at 4800 baud; more likely 2400 is the maximum (at 8 MHz clock) or 1200 at 4 MHz clock.

A second issue will be that your receive data alignment can be thrown off so the Picaxe tries to read starting in the middle of a data byte and as a result misses the data because it mis-reads the qualifier.

Wolfgang
 
Last edited:

John Chris

Senior Member
I appreciate the assistance. I will try the following - overwriting variables as suggested by various contributors.

- 27 chars separating "B09730," from the first character of the pH reading

B09730,2.22,1,10-09-2096 07:21:48,
SERIN pin,baudmode,("B09730,"),b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0

1.810
,b0,b1,b2,b3,b4

,pH,
b5,b5,b5,b5

313.3
b5,b6,b7,b8,b9

,mV,
b10,b10,b10,b10

23.4
b10,b11,b12,b13

The PIC does not care about what remains
,C,99.8,%,6,26

Putting all of this together

SERIN pin,baudmode,("B09730,"),b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b1,b2,b3,b4,b5,b5,b5,b5,b5,b6,b7,b8,b9,b10,b10,b10,b10,b10,b11,b12,b13
________
vapir oxygen vaporizer
 
Last edited:

lbenson

Senior Member
With "#picaxe 18X" in the simulator, after putting in a pin and baudmode and removing two extraneous spaces, I get:

Syntax check successful!

Memory used = 67 bytes out of 2048

Good luck!
 
Top