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.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Available RS232 Ports

Hello,
 
Is there any way to get the available serial ports on my system in Labwindows? A solution would be trying to open ports COM1 to COMx using OpenCom and checking if the function returns an error, but I'm wondering if there is a more decent way to get the information...
 
0 Kudos
Message 1 of 14
(8,654 Views)

According to this Microsoft Knowledge Base article, serial ports are recorded in the registry under this key:

\HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System \MultifunctionAdapter\0\SerialController\...

However, this seems to apply only to NT machines, and infact in my XP machine with 3 com ports I only detect one port in this registry key (the one on the motherboard).
 
Nevertheless, under this other key I can find all com ports available in the system:
\HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM.
Your problem so seems to be solved by enumerating all values available under this key.
 
Hope this helps
Roberto


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 14
(8,647 Views)
Thanks Roberto for your post, can be really useul!

The improvement to be done, is a unique wrapper, that locates this information in the same way even in different operating systems.  I hope National is going to provide such a tool!

Have a nice day!

graziano
Message 3 of 14
(8,641 Views)
Thanks a lot, Roberto
Message 4 of 14
(8,639 Views)
Hello,

NI already has a platform-independent mechanism for enumerating resources such as serial ports: VISA!  The following code will discover all the serial ports available on a system:

viFindRsrc (resourceMgr, "ASRL?*INSTR", &foundList, &numberFound, resourceString);
while (numberFound--)
{
    /* do something with resourceString */

    viFindNext (foundList, resourceString);
}


Of course, I left out the error checking, as well as the creation of resourceMgr, but the idea is that you pass in a resource query string ("ASRL?*INSTR" for serial ports), and VISA will create a list of all matching resources it can find.  However, I do not recommend these functions for Wim's needs, as they will only return a VISA resource string (which can be used for specifying a port in other VISA functions), not a proper COM specifier as is needed by the RS232 library functions.  For example, "ASRL5::INSTR" is not guaranteed to map to COM5.  In order to get that information from VISA, you need to open the port then use viGetAttribute to get the VI_ATTR_INTF_INST_NAME attribute.

Point being, if you want to develop platform-independent code that communicates with instruments, VISA is a good choice.

Mert A.
National Instruments
Message 5 of 14
(8,639 Views)
Thanks Mert!

   Since I'm used with DAQmx, I've not deep knowledge on VISA (even not at all, perhaps!).

   Thanks!

graziano
Message 6 of 14
(8,630 Views)

Thanks Mert,

It is always good to discover little "tricks" like this.

😄

Message 7 of 14
(8,589 Views)
The 'proper' way in Windows of finding the available RS-232 ports is to use functions in the Setup API, which are obscure to say the least.


I have a DLL that will return all the COM ports in the system, or all the ports with a 'friendly' name that contains a particular substring. I actually wrote it for locating the virtual com port associated with a particular USB device, but it works with any com ports. If you would like a copy, let me know and I can either upload it here or email it direct.


Martin.

--
Martin
Certified CVI Developer
Message 8 of 14
(8,576 Views)

Hello Martin,

I am very interested in that DLL file. Is it possible to post it here?

Thanks a lot Smiley Very Happy

Message 9 of 14
(8,567 Views)
I recall that have posted it in this forum before. You will find it here.

Martin.

--
Martin
Certified CVI Developer
Message 10 of 14
(8,551 Views)