LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Flush USB buffer

Solved!
Go to solution

We are using VISA usb to get data from a USB device of ours. 

 

Everything appears to be working fine, we can read from and write to the device fine.

 

We are running into one problem though: if we loose connection with the device, before we read all the bytes in the RX buffer and close the device, we get these bytes when we re-open the device.

 

VISA flush doesn't appear to work on USB (as any of the 4 pre-defined masks are refised). VISA clear doesn't appear to help either.

 

What is the right way to empty the leftover USB bytes in the device when we open the VISA usb bulk interface?

 

Serge/

0 Kudos
Message 1 of 8
(6,764 Views)

smalouin wrote:

What is the right way to empty the leftover USB bytes in the device when we open the VISA usb bulk interface?

 

Serge/


Read bytes at port and throw them into the trash.  Niether flush mask 16 or mask 64 perform IO with a serial device so the only way to move the bytes out of the device is to reset the device or read its TX buffer


"Should be" isn't "Is" -Jay
0 Kudos
Message 2 of 8
(6,755 Views)

 

That's what I thought I was doing.

 

When I do that, it works consistently 50% of the time. (The 50% it doesn't work, it goes beyond that little flushing loop, but it timesout on a VISA Read down the road, at a point that doesn't appear to be releated).

 

Any other way I should do that instead?

readAndTrash.jpg

0 Kudos
Message 3 of 8
(6,750 Views)
Solution
Accepted by topic author smalouin

Well if VISA Clear doesn't work and, bytes at port doesn't work we'll need to dig into the manual for the device on the other end and see just how badly some FW engineer butchered a simple mesage based serial protocol and what really is supported by the device.


"Should be" isn't "Is" -Jay
Message 4 of 8
(6,745 Views)

Regardless of the serial protocol on the device, if we do not read the byte until a read timeout to flush the USB RX right after opening the device. (with the little screen shot I attached up here) everything works fine.

 

Looks like the read on an empty USB RX buffer renders the USB read dead. Once we've had a timeout on a USB read, do we need to do anything to be able to read something again? Looks like closing and re-opening the USB gets it back on its feet... once.

 

work... doesn't work.... work.... doesn't work.... work....   consistently?

0 Kudos
Message 5 of 8
(6,737 Views)

What if... it's not so much that the VISA read after the timeout timesout, but just that we somethow we get the same timeout error code again?

 

And if this is the problem, how can I clear that timeout error?

0 Kudos
Message 6 of 8
(6,733 Views)

Just in case somebody reads that thread because of a similar issue: The problem wasn't related to labview at all. I solved my problem, and the problem was indeed a device firmware problem.

 

(For those interested, the device is a MSP430F5529, and I wasn't following my X and Y register properly when a USB endponit halt happened, simply reading the TOGGLE bit insteaf of keeping track of the register works)

 

thanks for the help.

Message 7 of 8
(6,676 Views)

Thanks for closing the loop and updating the thread.  I do have to admit that's one of the funnier solutions I've caught. 


"Should be" isn't "Is" -Jay
Message 8 of 8
(6,665 Views)