Example Code

Serial Termination With More Than One Character

Code and Documents

Attachment

In some instances serial communication may be terminated by a string of multiple characters instead of just one. This example demonstrates how to build in the necessary extra logic to determine if a termination string has been reached.

Specifically, it terminates a VISA serial read from the last character of the supplied termination string and then checks if the rest of the string is matched. If so, the read will finish and the string will be returned. If not, it will read till it reaches the termination character, concatenate the previously read string to the new one, and check for a full termination string. It returns the string if found, otherwise it repeats the process.

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors