LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

check serial port availability

I would like to check is a serial port availble (not already opened by another application) without opening and closing the port.  Currently, the program opens and closes the serial port a lot.   Sometimes, an port access deny error occurs.  We suspect that after a the close command is issued, the port didn't close immediately and another application try to acces the port at the time, which generated the error.  Any idea? 

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 1 of 7
(3,639 Views)

 

 

You might want to ask yourself why your program opens and closes the serial port a lot.

 

You should open the serial port once at the beginning of your program, pass the VISA reference throughout, then close it once at the end of your program

========================
=== Engineer Ambiguously ===
========================
Message 2 of 7
(3,624 Views)

Agree with suggestion to ask yourself why the port is closing and opening so much. That is going to a cause a lot of confusion.

 

If you still want to close and open it a lot, look at the error you get when trying to open the port. Error -1073807246 tells you that the VISA resource is valid, but it can't be accessed. That is a pretty good indicator that the port is in use somewhere else.

Message 3 of 7
(3,604 Views)

opening, pining, and closing is for searching through all the existing comm port to see which port I am communicating on.

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 4 of 7
(3,516 Views)

The opening and closing is due by a custom .net DLL function. 

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 5 of 7
(3,514 Views)
As already mentioned, you have to attempt to open the port and check the error returned.
0 Kudos
Message 6 of 7
(3,496 Views)

@jyang72211 wrote:

The opening and closing is due by a custom .net DLL function. 


Well without any code to look at I have two suggestions...

 

1. Dump the DLL and either use LabVIEW to search for the port the device is on or just tell LabVIEW what port to use.

2. Put a delay in your program every time the DLL is called to make sure it is done with the ports before LabVIEW tries to access it.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 7 of 7
(3,482 Views)