LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA (COM) STATUS

Solved!
Go to solution

1.How can i check if my COM port is (via VISA) connected or not in my LabVIEW Code ? I have tried using property node "is connected" but its always giving False. Is there any other way to check the connection in code?

0 Kudos
Message 1 of 18
(473 Views)

 

Is your serial port belonging to special NI hardware?

 

From https://forums.ni.com/t5/forums/replypage/board-id/170/message-id/1292869

Serial Settings:Is Port Connected

Returns whether the port is properly connected to another port or device. This property is valid only with serial drivers developed by National Instruments and documented to support this feature with the corresponding National Instruments hardware

 

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 2 of 18
(460 Views)

Hi, No it does not belong to Special NI Hardware. Is there any other way to check if the port is connected?

0 Kudos
Message 3 of 18
(454 Views)

@Faizan_habib wrote:

Is there any other way to check if the port is connected?


1. Send a command and read the response.

2. Depending on the device you are connected to, you could check the handshaking lines.  No promises here as there are many hardware reasons this could not work.


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 4 of 18
(425 Views)

You could search for available com ports.

 

cCapture.PNG

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 5 of 18
(406 Views)

@RTSLVU wrote:

You could search for available com ports.

 

cCapture.PNG


While this returns all installed serial ports (that VISA has found on the system), it does not say anything about if anything is connected to them. The only way to detect that is by trying to attempt to communicate with the device. This requires to know at least one command that the remote device understands and which will produce a response. There is no other way since at the time the serial port was invented the fact that you could communicate with a device through just a receive and transmit data line was quite revolutionary. USB and other buses later explicitly added extra protocol elements to the specification for managing the connection itself but serial port has no such common basic protocol elements. 

Rolf Kalbermatter
My Blog
Message 6 of 18
(397 Views)

Thanks for your reply. I have tried to communicate with the device and its working fine. But the point is that I want my code to know that there is a connection and on that basis i want to implement some logic. 


0 Kudos
Message 7 of 18
(375 Views)

@Faizan_habib wrote:

Thanks for your reply. I have tried to communicate with the device and its working fine. But the point is that I want my code to know that there is a connection and on that basis i want to implement some logic. 


And as I have already commented, that requires you to try to communicate with the device. With proper error handling you can detect if a port is connected to your device or not.

 

While the LabVIEW beginner often forgets to even connect the error clusters, the next step is to just connect them all through and error out whenever something causes an error. But real world applications never will be able to work that way. There can be errors sometimes that are expected and should be ignored, others that indicate to retry the operation as it usually will work the next time and then there are the ones that are real errors and indicate that you simply need to give up. Programming real world applications is among other things to know when what sort of error happens and how to deal with it.

 

In this specific case you would likely have to enumerate all the serial ports as RTSLVU showed you, then go through each and try to communicate with it, By using a short read timeout you can limit the time needed to go through all ports. If there is a timeout error, there is either no device that can respond or now device that knows about the command you tried and you can ignore that error and try with the next port. If you get a response, you can check that to be the expected one. For instance if your device supports an identification query you could issue that command and if there is a successful response, check that to contain the expected device identifier.

Rinse and repeat for every port in your system until you scanned them all (or you found the first port that responded as expected).

Rolf Kalbermatter
My Blog
0 Kudos
Message 8 of 18
(368 Views)

I am facing an issue while communicating with my hardware. I am using VISA to handle the communication and after connecting once when I disconnect the cable I still see the COM Port in use (Screen Shot attached) in "VISA RESOUCE NAME" control. And also the "VISA Find Resources" also detecting the port after disconnecting. I am opening and closing the VISA as well (Code's SS attached). How can i over come this issue and whenever I disconnect my cable "Visa Resource Name" should not detect the COM port.

Thanks
Faizan Habib 

Download All
0 Kudos
Message 9 of 18
(389 Views)

Are you using a USB-to-RS232 converter?

Did you disconnect the serial cable or the USB-serial adapter?

-------------------------------------------------------
Control Lead | Intelline Inc
0 Kudos
Message 10 of 18
(362 Views)