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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Com Port Finder

I have created this Vi to show which COM ports are in use. The reason for this is because the hardware that would be plugged in returned ASRL#::INSTR. The number varied. This Vi searches for the number that the COM port is connected to. The problem is if the number is 2 digits, only the first digit is shown. If I were to increase the length of the search the numbers of digit 1 would return #:. How do I search for a number no matter how many digits?
CLD Certified 2014
0 Kudos
Message 1 of 17
(3,775 Views)
This is what I have come up with. Is there a better way?
Message Edited by ADrexelDragon on 04-23-2010 11:52 AM
CLD Certified 2014
0 Kudos
Message 2 of 17
(3,769 Views)

The 2nd attempt is better, but still too much code. All you need...

 

Message Edited by Broken Arrow on 04-23-2010 12:20 PM
Richard






Message 3 of 17
(3,747 Views)
Thank you. This vi shows what changes I made.
Message Edited by ADrexelDragon on 04-23-2010 01:08 PM
CLD Certified 2014
0 Kudos
Message 4 of 17
(3,720 Views)

OK, but your loops don't make much sense to me - perhaps they are an artifact from something else you are doing and not showing. All you need is...

 

Message Edited by Broken Arrow on 04-23-2010 02:19 PM
Richard






Message 5 of 17
(3,702 Views)
And if you had chosen to return aliases with the VISA Find Resources instead of canonical names, you would have gotten ComX back and that would have been easier to parse.
0 Kudos
Message 6 of 17
(3,663 Views)
How do I figure out which COM port is connected to something?
CLD Certified 2014
0 Kudos
Message 7 of 17
(3,645 Views)

The port itself doesn't know if anything is connected.

 

You'd have to send out a test message to each com port and see if you get a response back.  Some instruments respond to the IDN? command.

 

 

0 Kudos
Message 8 of 17
(3,630 Views)
I came up with this Vi. Will this work? How can I send more than one command because some hardware take IDN? while other take *idn?
CLD Certified 2014
0 Kudos
Message 9 of 17
(3,622 Views)

No.  For one thing, why do you have a wire going into the bytes to read for the VISA read that comes from the return count of the VISA write?

 

I don't know what is the proper IDN code or if there is more than one variation that might work.  If it is possible to have more than one, than you can try all combinations in a loop.  Even then, you might have an instrument connected that doesn't respond to that code.

 

What is it you are really trying to do in the end?  Why do you need to search for all your com ports and then determine if something is connected?  It should be up to the user of your application to know which device they have connected to which com port.

0 Kudos
Message 10 of 17
(3,610 Views)