Incorrect Data Reading From Serial Device Using "VISA Read" VI in LabVIEW

Updated Oct 27, 2022

Issue Details

I use NI-VISA for communicating with a third-party serial device. I send a command to the device, wait for a response from it and send another one this is done four times. The subVI for Writing and Reading data is inserted into a while loop and the data is transferred from one iteration to the other, via Shift Registers.
This logic does not cause any errors, but the data read from the device is incorrect. For the first VISA Read, the data is either correct or incomplete, but for the rest, it includes the remainder of the data that should be got in the previous read operations. Flushing the buffer each time before writing a new command did not help me,
image.png

Solution

The VISA Read operation uses termination character when reading the data. This means that there is a byte that indicates the end of the data that should be read. By default, this termination character is enabled in the "VISA Read.vi" function. In this case, the data is read incomplete and the rest of it is stored in the device buffer. This is the reason that the device returns the remainder of the previous read operation when reading new data. To avoid these types of situations, there is a need either to not use the VISA Read function inside the while loop, so the system interrupts the communication after the data is read, or disable the termination character when using a series of VISA Read functions. 
As a solution, you can use the "VISA Configure Serial Port.vi" function and the "VISA Property Node" to make the right configurations.
First, set the "Enable Termination Char (T)" input of the "VISA Configure Serial Port.vi" to false
image.png
Then use the "VISA Property Node" and set the "End Mode for Reads" to "None".
image.png
 

Additional Information

Before making major changes to your VI have a look at the user manual of your Device to know if it supports termination character or not.