How to Use the GPIB to Serial Converter in S Mode

Updated Dec 19, 2023

Environment

Hardware

  • GPIB-RS232
  • GPIB-RS485

Software

  • LabVIEW Full
  • LabVIEW Professional
  • LabVIEW Base

Driver

  • NI-VISA
  • NI-488.2
  • NI-Serial
  • Miscellaneous GPIB Software (Legacy)
  • GPIB Software

  • I want to read and write from my GPIB-RS232/485/422 device, configures in S Mode, using NI LabVIEW.
  • What are the commands to communicate to a serial converter, and what is their syntax?
  • How do I differentiate between connected devices to my Serial converter device?

The GPIB to Serial Converter is not software transparent, meaning that there are additional commands to send to the converter to differentiate between connected devices. When you send a VISA command to your GPIB to Serial Converter, you are communicating directly with your converter. 

 

To write to a device

In order to send data or commands to the GPIB device, you will need to send a wrt command to a VISA Write function. This VISA Write function should be set to synchronous I/O. You can change the mode of a VISA function from asynchronous to synchronous in LabVIEW by right-clicking on the VISA function, expanding the Synchronous I/O Mode menu, and selecting Synchronous. The syntax for this command is as follows: 

 

wrt #[x] [Address]<LF>[Data]<CR>

Remove the brackets [ ] when writing commands. 

 

#[x] - represents the length of the data to be sent, where x is the number of bytes. This part of the command is optional, as the converter will use the termination character to determine where the end of the command is. However, if the command being sent to the device requires a termination character, then this value is required. 

 

[Address]<LF> - represents the Primary and Secondary Address (PAD and SAD) your instrument(s) are set to. The primary and secondary addresses are separated by a plus character: [+] . If there are multiple instruments connected to your converter, you can include them by appending the PAD and SAD with a comma character: [,] . The <LF>("\n") defines the limits between the address and the first data character. 

 

[Data]<CR> - represents the data you wish to send to your instrument(s). <CR>("/r") is used as a termination character to the wrt command, and will not be a part of the actual data that you send. 

 

Example:

wrt #6 1,2+1\n*idn?\r

This command will send *idn?\r to instruments at Primary Address 1 and Primary Address 2 with Secondary Address 1. Additional examples can be found in Locate Help Documentation for NI GPIB-RS232 and GPIB-RS485 .

 

To read from a device

In order perform a read operation, you need to send a rd command using the VISA Write function. This VISA Write function should also be set to synchronous I/O. The syntax for this command is as follows: 

 

rd #[x] [Address]<CR>

Remove the brackets [ ] when writing commands. 

 

#[x] - represents the amount of data in bytes to read from the instrument. You should make x a number greater than the amount of bytes expecting to be read. The converter will terminate the read when it either receives the amount of bytes requested, or it receives the termination character. 

 

[Address]<CR> - represents the Primary and Secondary Addresses of the device(s) you wish to read. The <CR>("/r") is used to terminate the rd command. 

 

After the rd command has been sent out to the converter, you will need to read the serial buffer for the COM port the converter is connected to. Use the VISA Read command to do this. 

 

Once you read the data from the serial buffer using the VISA Read, the converter will automatically place statistics regarding the recent command into the serial buffer. The statistics contain spaces for the number of bytes requested more than were available, followed by the number of bytes actually read. For example, if you request 64 bytes from the device, and the device replies with only 60 bytes of data, once the read command completes "    60" in the serial buffer. The 4 spaces indicate the number of extra bytes you requested, and the 60 represents the actual bytes of data read. You will either need to read this data out of the serial buffer, or flush the buffer before running any other commands.

 

Example: 

rd #128 2+1\r 

This command will read back 128 bytes from primary address 2 with Secondary Address 1. After the command is sent, the data will be available at the serial buffer. Perform a VISA read to obtain the available data.

Additional Information