LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

After repeated Close functions, I still get the VISA Error "The Resource is Valid, but VISA cannot currently access it"

Solved!
Go to solution

I am currently building an application on a cDAQ unit which involves the use of a scale. The scale uses RS232 communications, but is connected to an RS232-to-USB adaptor and plugged into one of the cDAQ's USB ports (COM 10). I am communicating with the scale using the basic VISA Functions: VISA Open > VISA Read > VISA Clear > VISA Close. I built one application using the scale that worked correctly, but now every time that I attempt to access the scale- be it through MAX, a VI, or a rebuilt version of the same application- I get the error "the resource is valid, but VISA cannot currently access it."

 

The scale has three options for data transmission: "No Data Output" "Continuous Data Output" and "Normal output when the Print Key is pressed." I have it set for "Continuous Data Output," I don't know if this information helps.

The c-DAQ is an NI cDAQ-9138

 

I have tried several things to get rid of this error:

-Restarting the cDAQ

-Repeatedly running "VISA Close" functions on the COM Port

-Completely unplugging and powering off the scale

-Plugging the scale into a different COM Port

-Repeatedly running "unlock port" VISA functions on the COM Port, as a colleague suggested that may be the problem

None of these have worked.

 

Does anybody have any suggestions for reliably getting rid of this error?

 

I have attached a vi showing how I am attempting to read from the device. Any help would be appreciated.

0 Kudos
Message 1 of 10
(5,730 Views)

"MB Serial init" subVI is missing, so I cannot look inside what is going on. Can you attach this subVI?

Remove the sequence structure, it will not help with your recent problem, but you do not need it. Use the error wire to specify execution order.

 

edit: you wrote a comment in the block diagram that you get the error at the second "MB Serial init" subVI call. Are you sure the first does not generate one already? Connect the error wires properly. The situation is not clear to me...

0 Kudos
Message 2 of 10
(5,720 Views)

"MB Serial Init.vi" is a VI in the Modbus library that is downloadable in multiple places on ni.com. I have attached the digital library containing the vi as well as an image of the vi's block diagram to this response.

 

Yes, the first instance of the "MB Serial Init.vi" also outputs the "resource is valid but VISA cannot currently access it" error. Sorry for the confusion.

Download All
0 Kudos
Message 3 of 10
(5,700 Views)

Do you have a program open elsewhere that is also trying to access the serial port?  Are you still running something in MAX while simultaneously trying to use it in LabVIEW?

 

Also,  it doesn't seem like your device is communicating in Modbus, so why are you using Modbus Serial Init?  You should be using the Serial Configure VI.

0 Kudos
Message 4 of 10
(5,671 Views)

All other programs are closed when I attempt to access the scale with the VI that I am programming. I close MAX completely and I close any other programs that were running; the only program running when I attempt to access the scale is the vi that I'm programming.

 

I replaced the Modbus Serial Init.vi with the VISA Serial Init.vi, but it also experiences the same error.

0 Kudos
Message 5 of 10
(5,645 Views)

Something, somewhere must have that port open.  Is it possible that any other software you might have used starts up a service and is keeping the port open.  Or there used a .dll that could have opened the port and failed to close it when the software shutdown?

 

Have you tried shutting down everything including the PC, then tried?

0 Kudos
Message 6 of 10
(5,636 Views)
It is Windows that prevents more than one process to access a com port at a time so I would check to see if there is anything listed in the task manager.
0 Kudos
Message 7 of 10
(5,629 Views)
Solution
Accepted by topic author DLJ1

A colleague from the company's electrical engineering department has resolved the issue. The scale has a hardware flaw that will cause it to continuously attempt to communicate with a VISA session even if the session has long since closed on the computer. Essentially, the VISA session on the scale doesn't end, even if it ends on the computer. He said it's an error that he hasn't seen in 3-4 years.

 

The way to fix the error is to unplug everything from the scale and leave it unplugged for at least 30 seconds to make sure that all of its hardware powers down completely. When you plug the scale back in, it will be responsive to a new VISA session. I have tried it and the scale is working through VISA again.

0 Kudos
Message 8 of 10
(5,561 Views)

Technically, there is no such thing as a VISA session on the scale.  The VISA drivers are only something that exist on the PC side of things.

 

I don't understand why closing and opening a VISA resource on the PC would affect how the scale behaves.  The scale wouldn't know whether the PC has done anything with opening or closing the port within software.

 

But there could be a hardware error on that scale that is a pretty bad bug considering serial port technology has been around for decades.  Perhaps the scale detects a change in one of the handshaking lines and the UART locks up.

0 Kudos
Message 9 of 10
(5,552 Views)
On Windows PCs, and especially with USB serial adapters, there is a chronic problem related to Windows device discovery/enumeration. Consider this likely scenario: Windows reboots, and discovers a USB device. It hands it off to an "enumerator", which determines the device is of serial port class. This loads a device driver, and Windows now hands the new serial port off to another enumerator. This one notices serial data incoming (you did say you set your scale to continuous output mode). The enumerator is rudimentary and ALWAYS assumes such a serial stream represents a mouse. It loads a mouse driver, which captures the COM port. Note that this chain of events can also happen without a reboot - like if you plug the USB side of your adapter in with the serial device already sending characters.

Next time you find yourself in this situation, pull up the Windows device manager and check under the pointing devices category for an unfamiliar serial mouse (frequently an MS Ballpoint mouse). If found, uninstall it, and see if the port frees up. Then, Google for the registry token "SkipEnumerations" and read how to apply it so this never happens again.

Hope this helps.
Dave
David Boyd
Sr. Test Engineer
Abbott Labs
(lapsed) Certified LabVIEW Developer
Message 10 of 10
(5,541 Views)