Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Bytes at port higher than serial buffer

Hi I am trying to make my serial communications program as robust as possible, and it would be a simple solution if my VISA communicatiosn port would only use what is available in the buffer. If I let data build up, the bytes at the port become beyond the buffer, and simply loses count at 8092  bytes even though I set the buffer to 2000. Is there a way to non programmatically  keep the bytes available limited to 2000 with a first in first out method? I cannot do this programmatically,  because this is only a problem when the port did not close properly and the actual VI is not running (however the serial port is still gathering data).

 

Thanks

0 Kudos
Message 1 of 2
(3,359 Views)

The buffer should not grow without limit. I would say that in this case, the buffer is 8092 bytes in length, so it is receiving that much data and everything else is probably being ignored. For the purposes of this post, I am assuming that you are running on Windows. When you use VISA to configure the buffer size, the call ends up passed down to the underlying serial driver in the operating system. The VISA help in LabVIEW states:

 

Note  Not all serial drivers support user-defined buffer sizes. Therefore, some implementations of VISA might not be able to perform this operation. If an application requires a specific buffer size for performance reasons and the VISA implementation cannot guarantee that size, use some form of handshaking to prevent overflow conditions.

 

Each driver implements this functionality differently. In the case of the underlying API that VISA uses in Windows, Microsoft allows you to specify a recommended size for the buffer. In the case of the Microsoft serial driver that is used for any built-in serial ports, I believe that the behavior is that you can increase the size of the buffer, but you cannot decrease the size below the default of 4096 bytes. It appears that your driver may either not allow you to adjust the buffer size, or will not use anything smaller than 8092.

 

It seems to me that you have two options to really resolve this issue:

 

1. Utilize explicit VISA Open and VISA Close calls in your VIs, and make sure that any error paths result in the port being closed.

 

2. When opening the port, if you believe that it may not have been properly closed, use the VISA Flush IO Buffer function to purge any unwanted data before you begin using the port.

 

-Jason S.

0 Kudos
Message 2 of 2
(3,338 Views)