From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

usb to serial communication problem

 

I have a program that is looking for an input from a Click PLC(which is basically being used as an I/O device).   the click plc is hooked up to the computer using a USB to rs-232 cable.  

 

the program will run fine for anywhere between 10 minutes and 2 hours before it appears to stop communicating with the PLC.  There is ultimately a timeout error, that is returned.  We have tried different PLC's and different computers with no luck. the only way to get it back up and running again is to restart the computer.  upon restart, the program will again run for a number of minutes.

 

within the labview program we initialize the communication using the VISA configure serial port VI at the beginning of the program.  we then go into the main program loop and call sub vi's(that use the MB serial master query.vi) to check the status of "coils"/or  bits on the PLC.  when one goes high, that kicks the program into sub loops.    

 

my question is, should we be opening or closing the serial communication port in each "main loop" or is it valid to configure the serial port once and leave it "open" indefinitely, or do we need to open/close the serial communication port each time through the high level loop?

 

I thought it might have something to do with overflowing a buffer, but in putting in a "VISA bytes at serial port" i get a 0 returned at the start of each main loop.  As a precaution, i also have put in a "VISA flush I/O buffer" at the beginning of the main program loop but it doesn't seem to change anything.   

 

thoughts?

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

I think you are running into the Windows USB selective suspend power setting.  Basically windows is trying to use less energy and disabling USB ports.  As a result VISA looses track of the device handles it was using and your LabVIEW program fails.

 

There are windows settings you can enable to prevent this from happening. See instructions here - https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000P7POSA0&l=en-CA

 

I'd try the power settings for USB, remove all the bytes at port and buffer flushing, then retest.  USB is not a great protocol for long term unattended data collection.  If you can dedicate a PC with a physical serial port.

 

As far as opening and closing VISA, it depends on the frequency of your read and writes.  If you only send commands 1/minute or in short bursts followed by long breaks; then yes, close them.  If you send/receive every second open/close is probably just going to slow things down and is unnecessary.

 

Craig

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

cstory pretty much summed it up.  You are likely running into USB power setting issues, which is common with a lot of USB devices.  Windows is just trying to "save power" by turning off USB hubs whenever it feels like it.

 

Generally, you should leave the port open and not have to flush it or anything like that.  There are some rare instances, but since you are seeing 0 bytes left at the port, the flush will do nothing.


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
0 Kudos
Message 3 of 3
(2,318 Views)