Using LabVIEW To Send Commands Via RS232 To Ontrack Control Systems ADR Interfaces
Using LabVIEW To Send Commands Via RS232 To Ontrack Control Systems ADR Interfaces
ADR101 RS232 Data Acquisition Interface DAQ Ontrack companys lowest-cost solution. RS232 to 8 digital I/O lines and two, 0 - 5 VDC 8-bit analog inputs. Powered by a standard 9VDC wall adaptor. ADR112 RS232 Data Acquisition Interface DAQ Identical to the ADR101 except analog inputs feature 12bit resolution and space on the PCB is provided for current loop resistors for 4- 20 mA current input.
ADR Commands
The ADR interfaces operate using simple ASCII commands which can be sent using virtually any programming language without the use of special drivers. The following are the commands available for each ADR product
ANALOG COMMANDS RDn RAn Read analog port in decimal format ( n = 0 or 1 ) Read analog port in % full scale format ( n= 0 or 1 )
DIGITAL COMMAND SUMMARY CPAxxxxxxxx SPAxxxxxxxx RPA format RPAn MAddd 255 ) PA RESPAn SETPAn Configures data direction of PORT A ( x = 0 or 1 ) Outputs binary data to PORT A ( x = 0 or 1 ) Returns status of all I/O lines in PORT A in binary Returns status of I/O line specified by n ( n = 0 to 7 ) Outputs decimal data ( ddd) to PORT A ( ddd = 0 to Returns status of PORT A in decimal format Resets I/O line specified by n in PORT A ( n = 0 to 7 ) Sets I/O line specified by n in PORT A ( n = 0 to 7 )
Introduction
The following application demonstrates how LabVIEW can be used with ADR interfaces, or any ASCII based serial data acquisition and control interface. The application is a simple temperature measurement and plot using an ADR112 and an LM335 solid-state temperature sensor. Figure 1 shows a final operating panel for the application in operation. The panel allows adjustment of the sample rate via a rotary knob, and displays temperature vs. time in a graph format. A digital reading of present temperature is also provided. The hardware consists of an ADR112 connected to com2, interfaced to an LM335 temperature sensor connected to AN0.
Start labview, and an blank panel will appear called untitled.VI. Save the VI as a file called "START". We will now place various controls and indicators on the blank panel that will become the applications operating controls and indicators. Using the CONTROLS menu, place on the following on the panel; A waveform chart from CONTROLS/ARRAY AND GRAPH/WAVEFORM CHART A numeric knob from CONTROLS/NUMERIC/KNOB A vertical switch from CONTROLS/BOOLEAN/VERTICAL SWITCH A numeric indicator from CONTROLS/NUMERIC/DIGITAL INDICATOR. Arrange the items as shown in Figure 2 using the pointer to add labels by right clicking on each item and typing it in. Change the scale on the waveform chart vertical axis to 0 to 4095 using the hand icon.
We will now add the components required to have the loop execute at an adjustable interval by adding a few more components. Add the following three components; A wait function timer from FUNCTIONS/TIMEANDDIALOG/WAIT A multiply function from FUNCTIONS/ARITHMATIC/MULTIPLY A numeric constant from FUNCTIONS/STUCTSANDCONSTANTS/NUME RICCONSTANT
Position the items as shown in Figure 5 and wire them as shown using the wiring tool. The timer will now delay repeated execution of the loop by 1000 times the setting of the sample rate knob on the front panel.( in ms). If the knob is set at one, the sample rate will be 1 second ( 1000 X 1=1000ms ), if the knob is set at 0.5 the sample rate will be 0.5 seconds ( 1000 X 0.5 = 500ms), etc. The on/off slide switch is wired as shown to enable or disable the loop from running. It will serve as a simple enable/stop function on the front panel
Sequencer
The software in the loop must now be set up to send and receive ASCII data to the ADR112 via Com2. This is accomplished by using a sequencer and a number of serial port functions provided by LabVIEW. The sequence, as the name implies, allows the execution of code in a specific sequence similar to that of a PLC. The sequencer is a series of frames that code is placed into, that determines the actual execution sequence of the code. Add a sequencer to the control diagram using FUNCTIONS/STUCTSANDCONSTANTS/SEQUENC ER. position the sequencer as shown in Figure 6.
The default termination character for an ASCII string in LabVIEW is a linefeed character which will not cause the ADR112 to return data. The linefeed must be changed manually to a carriage return. This is done by right clicking on the data and selecting " CODES DISPLAY". When this is done, "RD0n" will be the displayed string data. Use the text icon to change the n to r ( carriage return ). If successful, the string will as be shown as in Figure 7 with the " CODES DISPLAY" function enabled.
Addition of Step
A second step is to be added to the sequencer where the serial read function will be placed. This is done by right clicking on the sequencer frame indicator and selecting " ADD FRAME AFTER". The sequencer will appear as shown in Figure 8
The data returned from the ADR112 will be read using a "serial read with timeout" vi. This vi is included with LabVIEW in the samples directory. Place it in the frame along with a "Format and Strip" function from FUNCTION/STRING/FORMATANDSTRIP. Wire as shown in Figure 9 including, a numeric constant of 5 for number of bytes to receive ( 4 plus CR ), and a string constant of "%d" to identify the incoming data as integer format. Wire the output of the " Format and Strip" function to both the " Present Temperature" display and the " Temperature Plot "
The display can then be customized to give the VI a more pleasing appearance. See your user manual for the various customizing options. The scale of the graph can also set using the hand icon to whatever range is to be measured in the application. Our final version was saved as "ADR112.VI" as appears as in Figure 12