LabVIEW provides three termination character string constants: Carriage Return, Line Feed, and End of Line. When adding one of the termination character constants to a string, they appear to have the same result – a line break. However, at the operating system level, each character is interpreted differently. This document discusses the differences between these termination characters and how they appear in LabVIEW.
Each termination character representation depends on the string format being used.
In the section below, each character is presented in backslash codes display, ASCII, Hex, and LabVIEW visualization. Each character explanation also contains a LabVIEW snippet where the termination character constant is used to create a string output displayed in Normal view and in Backslash code View.
Notice that for each snippet, the Normal view shows the same outcome for the termination characters – a line break. However, if you look at the ‘\’ Code Display (i.e. machine-readable output), you will see that the output depends on the termination character used.
Note: the termination character you should use depends on your use case and communication protocol your device uses. Consult the manual for your instrument to determine which termination character and format you should use.
The Carriage Return (CR) character moves the cursor to the beginning of the line without advancing to the next line. This character is used as the new line character in Commodore and Early Macintosh operating systems (Mac OS 9 and earlier).
Codes Display | ASCII Decimal | Hex | LabVIEW Glyph |
---|---|---|---|
\r | 13 | 0x0D |
The Line Feed (LF) character moves the cursor down to the next line without returning to the beginning of the line. This character is used as the new line character in Unix based systems (Linux, macOS X, Android, etc).
Codes Display | ASCII Decimal | Hex | LabVIEW Glyph |
---|---|---|---|
\n | 10 | 0x0A |
The End of Line (EOL) character is actually two ASCII characters – the combination of the CR and LF characters. It moves the cursor both down to the next line and to the beginning of that line; this is the equivalent of the enter key in most typing software. The EOL character is used as the new line character in most other non-Unix operating systems, including Microsoft Windows and Symbian OS.
Codes Display | ASCII Decimal | Hex | LabVIEW Glyph |
---|---|---|---|
\r\n | 13 10 | 0x0D0A |
Termination character choice is important when communicating with instruments as each device follows its own communication protocol. Independent of whether you are using the LabVIEW built-in character constants or sending text-based commands, it is important to consider your device’s communication protocol and termination character needs.