Termination Characters in NI-VISA

Publish Date: Dec 15, 2017 | 18 Ratings | 4.17 out of 5 | Print | 2 Customer Reviews | Submit your review

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.

Table of Contents

  1. Termination Character (TermChar)
  2. Termination Character Enabled (TermChar En)
  3. Serial End Modes for Reads (ASRL End In)
  4. Serial End Modes for Write (ASRL End Out)
  5. ASCII Communication
  6. Binary Communication
  7. Instruments Using Multiple Termination Characters
  8. Related Resources

1. Termination Character (TermChar)


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).

Back to Top

2. Termination Character Enabled (TermChar En)




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.

Back to Top

3. Serial End Modes for Reads (ASRL End In)


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.

Back to Top

4. Serial End Modes for Write (ASRL End Out)



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.

Back to Top

5. 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).

Back to Top

6. 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.


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.

Back to Top

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


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.

 

Back to Top

8. Related Resources

 

Back to Top

Customer Reviews
2 Reviews | Submit your review

KISS  - Jan 30, 2017

The instrument is going to terminate in a deterministic way. Configure VISA to terminate reads on the final termination character, then parse the return string using %[^<termination characters>], where <termination characters> are the appropriate slash codes. The final example uses a combination of string constants and format strings, which IMHO is unnecessarily confusing. The Scan from String's format string is specific to this query, not generalized to multiple termination characters.

  - Mar 14, 2012

Could not get the bottom example to work. What does "%[^,], TDS %d" mean?! As it will not accept it...

Bookmark & Share


Ratings

Rate this document

Answered Your Question?
Yes No

Submit