LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial communication problem with VISA

I think you are getting buffer overruns.  The data is coming in faster than it can be processed.  For example, lets say your input buffer is 250 bytes.  Your program is reading 50 bytes at a time every millisecond, but the device is sending 100 bytes every millisecond.  It won't take long before your 250 byte buffer is full and the incoming bytes get lost because there is no place for the computer to store them.  In this case you must use handshaking.  The most popular type is software handshaking, or XON/XOFF.  When the buffer gets close to being full, the software sends the XOFF character to the device.  The device recognizes the XOFF character and stops sending data.  When the buffer is close to being empty, the software sends the XON character to signal the device to start transmitting again.  This goes on and on throughout the transmission.  Another type is hardware handshaking, RTS/CTS.  There are two lines on the RS232 interface called RTS (Request to Send) and CTS (Clear to Send).  Same action.  When the buffer is near full, the computer hardware lowers the CTS line, signaling the device to stop sending.  When the buffer is near empty, the computer raises the CTS line, signaling the device that it is clear to send more data.  The device usually raises the RTS line to signify that it is wanting to send data, and the computer responds with CTS if it is ready, or keeps CTS low if it is not yet ready.  These parameters are set up in the serial config vi.
- tbob

Inventor of the WORM Global
Message 11 of 13
(820 Views)

Hi tbob,

    my communication is already working with hardware handshaking RTS/CTS. This is my procedure for every command I send:

1. Open VISA session and configure serial port

2. Send Command and read until I find the expected bytes to be received. I have inside a TimeOut. Always after a VISA Read I can see the sent bytes and the received bytes.

3. Close VISA session

The computer has a serial buffer, isn't it? The thing is that I'm sending one instruction working OK, afterwards the equipment is sending me data during 10 or 20 seconds that I don't need at all but I read it anyway to avoid filling the computer buffer and then I send a Stop command. The problem always ocurres at this point but not always. During those 10 or 20 seconds I was not reading data before and the problem was appearing, but now the problem should have dissapeared and it has not.

What happens if the equipment send me all the time data and in the meanwhile I open visa session, send data and read it and close it? Does this procedure affects to the communication?

0 Kudos
Message 12 of 13
(801 Views)
While you are doing other things besides reading the data, the computer should store all incoming data in a buffer.  The Bytes at Port function actually reads the number of bytes in the buffer.  When you read, you are actually reading the buffer and emptying it at the same time.  If RTS/CTS is working, you should not miss any data.  The only thing I can think of is that the device does not stop sending data when CTS is lowered.  That will cause a buffer overrun.  Check your device documentation to see if it supports CTS.  One thing you could do to troubleshoot the problem is to put a serial port monitor or breakout box in line to see if the data is stopping and starting with RTS/CTS.  A monitor will allow you to see the characters as they are transmitted.  This will help determine where the missing characters are going.
- tbob

Inventor of the WORM Global
0 Kudos
Message 13 of 13
(794 Views)