Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI
This Document is not yet Rated  Rate this Document

Reading and Writing to GPIB to Serial Converter in S Mode

Hardware: GPIB>>External Controllers/Convertors>>GPIB-RS232

Problem:
I want to read and write from my GPIB-RS232/485/422 device in S Mode in LabVIEW. What are the commands I can use to do this, and what is the syntax of these commands?

Solution:
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.

If you are using LabVIEW or LabVIEW Real-Time, Developer Zone: Communicating with GPIB Instruments using NI CompactRIO (GPIB-RS232 only) can provide a library of VIs that outline all of the considerations for using the converter with a LabVIEW program. If you are developing in another environment or are interested in the underlying operation here are the instructions to communicate with the device.

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 the GPIB-Serial Converter help file.

To read from a device:
In order to read command, you need to send a rd command to a VISA Read function. This VISA Read 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.

Example:
rd #128 2+1\r
This command will read back 128 bits from primary address 2 with Secondary Address 1.


Additional programming resource can be found the NI GPIB-Serial Converter Help. Including discussion of more advanced functionality of S-Mode as well as other modes the GPIB-Serial Converter can be programmed in.  National Instruments also offers some text based examples in the NI Developer Zone Tutorial: GPIB-RS232/485/422.

Attached is SMode 8.zip. This file includes a LabVIEW project that will test the primary and secondary address for a listener and if valid, proceed to write and read from a command provided. This example is written in LabVIEW 8.0.



Related Links:
KnowledgeBase 2U2JRRLD: How Do I Set the Serial Port Characteristics on the GPIB to Serial Hardware in G Mode?
GPIB Support: GPIB Installation/Configuration Troubleshooter
Product Manual: NI GPIB-Serial Converter Help
NI Developer Zone Tutorial: GPIB-RS232/485/422

Attachments:
SMode 8.zip




Report Date: 01/19/2009
Last Updated: 08/06/2009
Document ID: 4TIA98Q7

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit