PDA

View Full Version : Need SERIN parsing help



Enginerd
01-28-2006, 08:11 AM
I am a fairly new BSII programmer and am trying to get a simple program to interface with a LabVIEW program I have written. The LabVIEW prog outputs a string to the com port without a problem (I can·get the correct string from the·BSII Debug window).

I have two 3-digit numbers I want to put into variables in the BSII. The string being sent is "P123T456" where 123 is the data I want in variable "Pan" and 456 into "Tilt"

The command I use to parse is:

Pan VAR Word
Tilt VAR Word

SERIN 0,84,[WAIT("P"), DEC3 Pan, DEC3 Tilt]

My variable Tilt is always the same as Pan.

I get the same results with the following:
SERIN 0,84,[WAIT("P"), DEC3 Pan, WAIT("T"), DEC3 Tilt]

What could I be doing wrong? Or is this not a good way to exchange data between the BSII and computer.

Your input is greatly appreciated,

Marc

Jon Williams
01-28-2006, 08:17 AM
What does the stream into the BASIC Stamp look like? Are you actually getting three digits per value, i.e. P020T005? If the pan and tilt values are not a fixed width, change DEC3 to DEC -- that will work fine in either case. The only time you need to use something like DEC3 is when you have fixed-width fields that are run together without any separating characters.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

Enginerd
01-28-2006, 08:42 AM
My values are always 3 digits - the stream looks like: "P001T002". I have tried DEC and DEC3 with the same results. I am using Basic Stamp Editor v2.2.5 with a Basic Stamp 2 v1.0.

What else could be causing my two variable to be the same. I have tried renaming them. Is there a better way to parse the data?

Thank-you for your help.

Jon Williams
01-28-2006, 08:54 AM
I've attached a version that works with DEBUGIN -- should work with SERIN.· You don't need to wait on the "T" as this will get ignored by the second DEC3 modifier.


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

Post Edited (Jon Williams (Parallax)) : 1/28/2006 2:00:31 AM GMT

Enginerd
01-31-2006, 06:33 AM
Thank-you for your test program. I have finally tracked down the problem - it seems that if all the data is sent at once with the LabVIEW program, the problem occurs - however, if the data is sent in sections (ie: P123 then T456), the data is parsed correctly.

It is strange to note that both methods will capture the same string correctly, but only the second parses it correctly. Perhaps since the BS2 does not have a serial buffer, it misses a character when parsing? I will have to look into it further, but for now things are working.

Jon Williams
01-31-2006, 06:56 AM
If you use flow control (would take extra pins) then you might not see that problem -- so long as LabVIEW could also work with flow control.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax