The CompactRIO platform is ideal for applications requiring a high degree of customization and control. Many embedded applications require communication with external instruments over different protocols. CompactRIO controllers make this communication easy with the built-in RS232 serial and ethernet ports. However, many instruments also communicate using GPIB. CompactRIO can also communicate with GPIB instruments by using the built-in serial port in conjunction with the GPIB-RS232 converter and the provided library of VIs. This document will discuss a simple example and the various functions of the provided VI library.
The provided example program allows the cRIO to control a GPIB network by using the NI GPIB-RS232 converter. The example follows the the same API used with many of our other drivers. The general API follows the following scheme: Open, Write, Read, Close, and Check for Errors. In the example the Init ConvBox.vi initializes communication with the converter box while the Write ConvBox.vi and Read ConvBox.vi send serial commands to the GPIB-RS232 converter. The serial commands then get converted to GPIB messages and are sent to instruments on the BUS. When the communication is finished the Close ConvBox.vi is used to terminate the session to the serial port.
Hardware and Software Requirements
Application Software: LabVIEW Full Development System
Steps to Implement or Execute Code
The VI library is modeled after the GPIB palette and provides basic functions for reading, writing, and serial polling as the GPIB controller in charge. The VIs included in the library are programmed using NI-VISA commands. For this example the GPIB-RS232 converter will be configured in S Mode and all function descriptions can be found in theNI GPIB-Serial Converter Help. This section will describe the individual VIs from the example program in more detail.
The Init ConvBox initializes communication with the GPIB-RS232 and configures the settings to communicate with instruments on the BUS. After opening a VISA session to the serial port theonl(online) function is sent to the converter box to restore all default power-on settings. After the settings have been successfully set thecaddr(change address) function sets the primary and secondary address of the box. Thesic(interface clear) function is sent to the box asserting an IFC* (Interface Clear) unaddressing all devices on the bus and making the GPIB-RS232 the controller in charge. Theeos(end of string) function is sent to define the end-of-string (EOS) specific character and theeot(termination character) function is used to configure the RS232 converter to automatically send or not send the GPIB END message with the last byte that it writes to the GPIB BUS.
The Write vi uses the specified GPIB address from Init ConvBox.vi to verify it is the controller in charge of the BUS. If the GPIB-RS232 is the controller in charge thewrt(write) function is concatenated with the address string and the desired characters to write over the GPIB BUS are sent to converter box. Following the write thestat(status) function is sent to see if the previous operation resulted in an error.
The Read ConvBox.vi also uses the specified GPIB address from the initialization step to verify it is the controller in charge and concatenates therd(read) function with the address sting and the byte count to read. The requested data is then returned from the instrument with the count buffer, which requires two reads to get all of the data. Thestat(status) function is then sent to see if the read operation resulted in an error.
The Close vi sends theonl(offline) function to the GPIB-RS232 converter to disable communication with the GPIB BUS and a VISA close is used to close the serial port session.
Installing the VIs in LabVIEW:
The provided library of VIs were developed in LabVIEW 8.0. To install the GPIB CompactRIO VIs on the functions palette in the LabVIEW development environment it requires copying the attached files in two directories. Download the attached folder and copy the ConvboxGPIB.mnu file from the convbox_gpib folder to theC:\Program Files\National Instruments\LabVIEW Directory\menus\categories\Instrumentdirectory. After the mun file is removed from the convbox_gpib folder copy the convbox_gpib folder with all the VIs to the vi.lib folder located in theC:\Program Files\National Instruments\LabVIEW Directory\vi.lib\convbox_gpibdirectory. If the VIs do not show up on the palette, restarting the computer will refresh all the LabVIEW directories and fix the issue.
With the addition of the GPIB-RS232 converter box and the provided VIs it is possible to control a GPIB network with a NI CompactRIO system.