Getting Data From Serial Devices

The LI-6400 can be configured to collect input from an RS-232 device (such as GPS, bar code reader, etc.). There are two basic use cases: getting data for real time measurements, and getting data once in a while when answering a prompt, or adding a remark.

Data for Real Time Measurements

Suppose you have some sort of instrument that outputs data on RS-232 that you’d like to feed into the LI-6400. Suppose that each record that it output had a time stamp, a temperature, and a relative humidity, so a short piece of the data stream might look like what is shown in Figure 11‑40.

Figure 11‑40. A sampling of data records from a fictitious instrument. We are interested in capturing the 2nd and 3rd items.

For each item you’d like to pick off from this data stream, you need to define a variable. We’ll add two: one for the temperature we’ll call xTair, and one for humidity we’ll call xRH. Once that’s done, we need to configure the Comm port for this.

Adding xTair and xRH

  1. Access the “extras” node in the configuration tree
  2. In the configuration tree (Config Menu | View/edit), find the <open><comps> <file> <extras> node, and edit it (Figure 11‑41).
  3. Figure 11‑41. Accessing the Extras list.
  4. Add a numeric comm port item.
  5. Press f2 (Add), and you will be prompted to identify the type of item you wish to add. Pick Comm port item - numeric (Figure 11‑42).
  6. Figure 11‑42. There are two comm port items. We want the numeric one.
  7. Fill in the details
  8. You will be prompted for a label, a description, and what position in the incoming RS-232 record to look for the value (Figure 11‑43).
  9. Figure 11‑43. Adding an extra.
  10. Finish it
  11. Press f5 (OK).
  12. Now add an RH variable
  13. Repeat the process to add a second item. Call it xRH. It will be the 3rd item in the incoming data stream.
  14. Figure 11‑44. The setup RH variable.
  15. After you OK it, your extras list should look like (Figure 11‑45).
  16. Figure 11‑45. Both items successfully added.
  17. OK the List
  18. Press f5 (OK) to keep the list. You will be asked if you want to add these items to the New Measurements display, and to the log list. You do, so press Y in response to each question (Figure 11‑46).
  19. Figure 11‑46. When you exit the Extras List Editor, you are given a chance to add new additions to the New Measurements display, and to the Log List.

Configuring the Comm Port

To make this work, we need to configure the comm port, in two regards: 1) the baud rate, data bits, etc., and 2) Tell OPEN to parse incoming data. This latter item will happen automatically, since you have a user item that requires it.

  1. Access the Comm Config node
  2. In the configuration tree, find the <open> <comm> node (Figure 11‑47).
  3. Figure 11‑47. Configuring the comm port. Make sure the baud rate, etc. is what you need, and also that the <incoming> node is set for parsing.

Some Rules to Remember

Incoming data records are parsed according to the following rules:

  1. Records end with a newline character
  2. This character has a decimal value of 10.
  3. Delimiters are space, tab, and comma
  4. This record:
  5. 123,45.67 89

  6. would be considered to have three items available; Item #1 is “123”, and item #2 is “45.67”, and item #3 is 89 (note there are multiple spaces between items 2 and 3).
  7. Double quotes override delimiter characters
  8. The record
  9. 10.56 "123,45.67",The End

  10. would be considered to have four items: Item#1 is “10.56”, item #2 is “123,45.67”, item #3 is “The”, and item #4 is “End”. If an item is quoted, the quotes are stripped from the returned string.
  11. String and Numeric
  12. Lines are parsed as strings. If you are specifically looking for a numeric item, the string piece that is parsed has one more step to convert it to a floating point value. If the string is not a valid number, the value will be 0.

Data for Prompts and Remarks

Suppose you have a bar code reader, and want to be able to scan a label associated with each measurement site right before the measurement. The destination for this information might be the remarks field in a file, or a constant that you are prompted for prior to each measurement. All you have to do to make this happen is configure the comm port to match your (RS-232) bar code reader, and set the incoming comm node in the configuration to “Prompts and Remarks”.

Figure 11‑48. Two places you can configure for prompts and remarks: either the configuration tree, or else in the Comm Port Configuration screen from the Utility Menu.