LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

USB VISA Communication

Hi,

I currently use USB A to B cable to communicate to my electronic load and power supply. I would like to know the depth of the buffer so I can read messages only when there is a message in the buffer. I tried to use the Serial Bytes at Port property node, but it outputs Error: -1073807331 (The specified attribute is not defined or supported by the referenced resource). 

 

The real problem at hand is that I need to clear the buffer during operation to avoid any buffer overrun that may occur. The shipped equipment's LabVIEW drivers writes a single message and expects a single reply. There is no handling/parsing of unexpected extra messages the equipment may send. I would like to avoid a buffer over run error. 

 

I was thinking that every time I run their LabVIEW driver I could clear the buffer of any extra messages left over. To clear the buffer should I read until there is no messages left, should I disconnect then reconnect the VISA session to clear the buffer, or use an entirely different approach?   

 

This is for work so I do not think I can post the code, but any advice helps!

 

Regards,

Ryan Lehman

 

Regards,

Ryan Lehman

 

0 Kudos
Message 1 of 7
(2,133 Views)

First off what is the device?  Does it install a "virtual serial port"?

 

I am not sure what you are so worried about clearing the buffer. With all of the instruments I have used over the years, I can not recall any instrument that ever required clearing the VISA Serial buffer for any reason... and every time I thought "stale data in the buffer" was causing the issue, I was wrong.

 

But without knowing any more specifics all I can give is some general advice about VISA and serial ports

  1. Don't use "bytes at port", it rarely does what you expect it to do.
  2. If your instrument sends a Termination Character USE IT!!!
    1. Even if it is simply ending every transition with a LF or CR, or ,
  3. With TermChar enabled and set to the proper character
    1. Set VISA Read to read an arbitrary number of bytes that is larger than you expect to receive
    2. Set the VISA timeout to be longer than it should ever take to receive a complete transmission
    3. Now the VISA read will receive everything waiting until
      1. The Termination Character is received
      2. A time out occurs. 

 

========================
=== Engineer Ambiguously ===
========================
Message 2 of 7
(2,121 Views)

The device that I was worried about is the IT8500 electronic load. The drivers are here:  http://sine.ni.com/apps/utf8/niid_web_display.download_page?p_id_guid=DA7159442ABC3F6FE0440021287E6E....

 

I do not think it installs a virtual serial port. I have a USB to serial driver installed on my computer, but it still shows up as a COM port. 

 

I was worried about the buffer because I have ran into the VISA error: -1073807252. The cause I have yet to debug, but you are correct it is much more likely that I have made a mistake than the equipment.

 

Thank you for the help,

1). I will take out these from my code

2). I am using termination, so I don't think any problem here but I will double check.

3). I will try to integrate it into my code

        1). The LabVIEW driver I downloaded has it set to 26. I will increase it.

        2). Right now it is set to 10 seconds, which I believe will work. 

 

 

0 Kudos
Message 3 of 7
(2,099 Views)

Most people "who understand VISA" set the VISA Read to be 1000 bytes.  I, myself, prefer 1024 ...

 

Bob Schor

Message 4 of 7
(2,057 Views)

@Bob_Schor wrote:

Most people "who understand VISA" set the VISA Read to be 1000 bytes.  I, myself, prefer 1024 ...


It just has to be more than a message will be to guarantee the read is stopped by the termination character.  I tend to use 50 most instruments.  If making a generic driver, I would probably just go with the 4096.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 5 of 7
(2,037 Views)

@RyanLehman wrote:

 

I do not think it installs a virtual serial port. I have a USB to serial driver installed on my computer, but it still shows up as a COM port. 

 


Just in case anyone else ends up scratching their head trying to understand this sentence. If your USB device shows up as a COM port, it is functioning as a virtual serial port. So to translate the sentence above:

 

I do not think it installs a virtual serial port. I have installed a virtual serial port driver, but it still shows up as a virtual serial port.

 

Here's a link to start reading (The rabbit hole is very very deep, so beware)

Message 6 of 7
(2,003 Views)

Hi all, 

 

I have made the following changes. 

  1. Removed all "bytes at port". Q: Can I still use this property to visually inspect the buffer on the front panel, if so what is the nominal value, my guess would be 0 or any number <4096?
  2. I checked using a property node, the termination character is set to 0xA, and both ASRL in and out end is set to termination (note: When I checked the Interface type it reported as ASRL, so as @Intaris stated it is a virtual serial port). 
  3. I ran a couple of tests using a generated runtime exe. 
    1. Ran the test at VISA read 26 bytes (default value set by the ITECH LabVIEW drivers).
    2. Ran the test at VISA read 1024 bytes. It outputted multiple errors: 0xBFFF0015 (VI_ERROR_TMO).

Maybe I have set the termination character incorrectly, any other things I can do to check/verify? I have attached the two NI I/O Trace files, which might not be helpful info, but can't hurt. 

 

Regards,

Ryan Lehman 

0 Kudos
Message 7 of 7
(1,988 Views)