Windmill Software Ltd
Windows Engineering Software

Free software - GPS to laptop PC
May 2006

Tips on Extracting Data

Home
Newsletters
Catalogue
Search

subscribe free

Parsing Messages from RS232 Instruments

If you have an instrument or device which you can plug into the PC's COM port, and it communicates using ASCII messages, chances are you can use the free Windmill software to collect its data. This is because Windmill's free LabIML driver was designed to be as flexible as possible and accommodate almost any instrument with an RS232 port. However, this flexibility has meant that the initial set up can be a case of trial and error. These notes should reduce the error and help you decide the best way to interpret, or parse, the messages from your instrument. (Our latest serial driver is more transparent, see http://www.windmillsoft.com/comiml.html for details.)

When an instrument sends a message it rarely just contains data. All sorts of extra characters and codes are in there. Here are some examples of messages.

A weighing scale might send:

+  125.32  g,

A GPS receiver might send:

$GPGLL,5330.12,N,00215.31,W,134531,A

A Parallax BASIC Stamp might send:

+66.4

A spectrophotometer might send:

DR/4000U S/N: 9807U0000905 2.303-APR-04  
10:05:56  MULTI-WAVELENGTHGroup 0000  Sample 
0002 -0.000 ABSA=K1A1+K2A2  
665.0 nm   -0.004 ABS  K1:  1.0000  750.0 nm   -
0.004 ABS  K2: -1.0000

Windmill doesn't just store the entire message, superfluous characters and all. It extracts the relevant data from each message, directing each data item to a channel: latitude readings to one channel, longitude to another and so on. Each data item can be up to 20 characters long. There is often no need to collect the units of the reading. You can use the SeupIML program to specify the units of each channel.

It's not only message formats that vary. Some instruments need a command prompt from Windmill before they will send data, others initiate data transfer themselves - often regularly sending data. In this case the message can be considered as a continuous stream of data that has a recurring pattern.

LabIML calls an instrument that sends one message after a command a Request/Response instrument. Devices which constantly send data are called Continuous Flow instruments.


Setting up Instructions to Extract Data

To set up parsing instructions use the Windmill ConfIML software and select the LabIML driver. Go to the Channels settings.

The first thing to do is to locate the data. You can do this by:

  1. Searching for specific characters in the message string.
  2. Ignoring characters until one of the ones in which you are interested appears.
  3. Ignoring a number of characters in the message string.

At first glance methods 1 and 2 seem to do the same job. However, when you search for characters the next action occurs AFTER the searched for characters. When you ignore characters the next action occurs ON the specified character. So if you searched for a + sign you would not be able to extract it, but if you ignored all characters until the + sign you would. Also, a search will look for the entire string specified (eg "abc"), whilst ignoring characters will stop at any of the characters specified (eg "a" or "b" or "c").

Be aware that with instruments that constantly send data LabIML will not know where the beginning of the message is. So, using the GPS example above, it's no use ignoring 8 characters and expecting the next value to be a latitude reading. Instead search for a unique string such as $GPGLL.

Once you've located the data you need to extract it. There are two ways to do this:

  1. Extract until a specified character occurs.
  2. Extract the next so many characters.

Extract until means that LabIML will extract values until it finds any one of the characters specified. The next command in the parse string then acts ON THIS character.

Using the GPS receiver as an example again

$GPGLL,5330.12,N,00215.31,W,134531,A

The data we might want to record from this string is the latitude and the longitude. These are the 5330.12 and 00215.31 figures respectively. We should have already created 2 channels: one to hold the latitude readings and one to hold the longitude. For the latitude channel we might:

Search for $GPGLL, and extract until ,

For the longitude we might:

Search for N, and extract until ,

As another example, the BASIC Stamp might continually send a reading comprising a leading sign character, a trailing carriage return to mark the end of data and a maximum length of six characters. For example -55.27 or +66.4 (where is the carriage return. In this case we could ignore all characters until we reach the + or - sign, and then extract all data up to the carriage return. This translates in LabIML's parse string to

\I"+-"\E"\C013"

Extracting Several Channels of Data
When you are extracting several channels of data from an instrument that continually sends data, the parsing proceeds along the string for each channel. For a request/response instrument, the parser goes back to the beginning of the string each time for each channel.


Home | Windmill Programs | Monitor | On-Line Shop | Free Literature and Software Demos | Contents | Search

Copyright Windmill Software Ltd 2001
PO Box 58, North District Office, Manchester, M8 8QR, UK.
E-mail: sales@windmill.co.uk, Tel: +44 161 833 2782
http://www.windmill.co.uk/gps.html
Data Acquisition News Feed (RSS) Free measurement news feed...
Designed by Studholme.net
Related Topics: