Termination Characters in NI-VISA

Overview

Various message-based buses use termination characters to indicate the end of a message transmission. For VISA resource types that correspond to a complete 488.2 protocol (GPIB Instr, VXI/GPIB-VXI Instr, USB Instr, and TCPIP Instr), you generally do not need to use termination characters, because the protocol implementation also has a native mechanism to specify the end of a message. You need to tell VISA how messages are terminated only when using other VISA resource types (Serial Instr, USB Raw, and TCPIP Socket).

Both incoming and outgoing messages can have termination characters. Two common termination characters are Line Feed (codes display '\n', ASCII decimal 10, or hex 0x0A) and Carriage Return (codes display '\r', ASCII decimal 13, or hex 0x0D).

Four main NI-VISA properties deal with termination. Two fall under Message-Based Settings, and the other two under Serial Settings. The message-based properties are Termination Character and Termination Character Enabled, and the serial-specific properties are Serial End Modes for Reads and Serial End Modes for Writes. We will discuss each property in detail and then discuss special considerations.

Contents

Termination Character (TermChar)

Termination Character


This property takes an unsigned 8-bit integer as an input. Therefore, unless you know the ASCII value for your termination character, it is best to typecast the value to set the property, as shown above. Use this property value as the termination character for both reads and writes. Setting this property value does not affect whether it is used.

Although TermChar is not restricted to serial communication, you may want to use other termination mechanisms when communicating on buses with a complete 488.2 protocol, as discussed in the introduction. For example, when communicating over GPIB, the standard is to use a hardware line—EOI—for termination.

Note: VISA Configure Serial Port.vi sets this property through the termination char parameter, which defaults to a Line Feed (0x0A = '\n' = LF).

Termination Character Enabled (TermChar En)


Termination Character Enabled

If set to True, this property instructs VISA to stop reading when Termination Character is encountered. Notice that it is not restricted to serial; you can use this property for terminating reads on other buses.

Important: This property is ignored and does not return an error if Serial End Modes for Reads (discussed below) is set to Term Char.

This property does not affect the termination character for writes.

Note: VISA Configure Serial Port.vi sets this property through the Enable Termination Char parameter, which defaults to True.

Serial End Modes for Reads (ASRL End In)

Serial End Modes for Reads


This property specifies the method used to terminate a read operation from the software buffer for serial communication only. Valid values are:

Value
Description
None (0)The read does not stop when the termination character is encountered.
Last Bit (1)The read stops as soon as a character arrives with its last bit set.
TermChar (2)
(Default)
The read stops when the termination character is encountered. This is the default value.


Important: If the value is set to TermChar (2), the Termination Character Enabled property value is ignored.

If the byte count (specified by VISA Read) or timeout (VISA property) is reached, the read terminates regardless of what value this property is set to.

This property can be disabled by setting the Suppress End Enabled (Suppress End En) property to true.

Note: VISA Configure Serial Port.vi sets this property to None if the Enable Termination Char input is set to F; it sets it to TermChar if the Enable Termination Char input is set to T.

Serial End Modes for Write (ASRL End Out)

Serial End Modes for Write



This property specifies the method used to terminate write operations. Valid values are:

Value
Description
None (0)
(Default)
No termination character is appended to writes.
Last Bit (1)The write sends all but the last character with the highest bit clear and transmits the last character with the highest bit set.
TermChar (2)The value of Termination Character is appended to the end of all writes.
Break (3)A serial break is sent after each write. A serial break is a series of continuous space values often used to instruct an instrument either to stop the operation in progress or discard any data in the output butter. Use this method with caution.


You may see older instrument drivers appending a termination character before the VISA Write. This was because older versions of VISA did not support this property, so users had to explicitly append termination characters. This is no longer necessary, as setting this property does it for you.

You can disable this property by setting the Send End Enabled (Send End En) property to false.

Note: VISA Configure Serial Port.vi does not set this property. You must set it through a property node, as shown in the figure above.

ASCII Communication


When performing ASCII communication, set your termination properties and other bus communication settings at the beginning of your application or driver initialization routine. Termination character settings must match your instrument configuration. Remember that some instruments have configurable settings. Consult the user manual for your particular instrument.

Recommendation: For more robust applications that may deal with multiple buses, always keep Termination Character Enabled and Serial End Modes for Reads in sync (that is, when you enable/disable one, set the other also).

Binary Communication


When performing binary communication, the read can terminate prematurely if one binary data value has the same binary representation as the termination character. Therefore, disable the termination character by setting Termination Character Enabled to false and Serial End Modes for Reads to None (0), as shown below. You must rely on a different method of terminating the read, such as a hardware line or byte count.

performing binary communication


Note: When using VISA resource types that correspond to a complete 488.2 protocol (GPIB Instr, VXI/GPIB-VXI Instr, USB Instr, and TCPIP Instr), because you generally do not need to enable termination characters in the first place, binary communication is easier because you do not need to worry about first disabling the termination character settings.

Instruments Using Multiple Termination Characters


Some instruments send multiple termination characters such as Carriage Return Line Feed (codes display '\r\n' or ASCII hex 0x0D0A). Because VISA allows only one termination character, you must find an alternate solution. First, check if the instrument termination sequence is configurable. If not, you can set VISA to terminate on the last character and use Scan from String to parse out the other character(s) from the actual message. The following figure shows code that works for either '\r\n' or '\n' termination.

multiple termination characters


Note: In order to use this configuration the property Display Style must be set to Backslash ('\') Codes. For more information on Backslash ('\') Codes Display see Backslash ('\') Codes Display - LabVIEW Help.

 

Was this information helpful?

Yes

No