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.
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.
12-16-2008 06:38 AM
Hi there,
I need to connect my PC to an OXI module. Before controlling and sending commands to the module, I need to determine the available 'COM' port and select the right one. After that I can connect my PC to the module. I managed to do this the easy way around my manually determining which serial COM port was free and try them out until I got the right one.
I want to do it more elegant now. I know that this can be done directly from the CVI, but I am not sure what functions to use. I imagine that in need a 'for' clause to check all the COM ports but I am not sure on how to determine which port is free and ready to use from all available.
Has anyone tried something similar?
I would appreciate a reply.
Many thanks.
Peter.
12-16-2008 10:13 AM
12-17-2008 04:22 AM
let's get a bit technical...
on windows, thanks to plug'n'play, devices are 'discovered' at system startup. this means that they are enumerated (the way they are is not relevant) and the informationsretrieved about each device is stored for use by the system. every device is classified according to a 'device class', this means that every device of the same type are flaged as belonging to the same group. classes are defined as GUID, and declared somewhere all accross the windows header files. and i can tell you there is a 'communication port' class.
in fact, when someone writes a virtual COM port, he writes a driver for a device whose class is declared as a 'communication port'. installing the driver allows the system to list this virtual port as if it were a standard COM port. (you can see virtual COM ports with bluetooth radio devices for example).
now, there is a part of Windows SDK, called the 'setup API', a subset of which allows you to enumerate devices installed on the system. there used to be a very good example of enumerating windows devices in the windows SDK, but it is not available anymore. have a look at the SetupDiGetClassDevs() function, make your way through the SDK, try by yourself. i do have a function for doing this on my computer, but it is rather long: if you are interrested, tell me and i will post it here.
12-17-2008 11:17 AM
The sample CVI 9.0 project in the zip attached to this post uses the Windows Setup API to locate either all available COM ports on a machine or those with friendly names containing a specific sub-string (typically used to find, say, all the "USB" COM ports).
See LocateCOMCVI.h for terse documentation of the function LocateCom() defined in LocateCOMCVI.c, and FindPortCVI.c for a simple example program that uses the function.
The code is mainly copied from a Microsoft example, with some conversion from C++ into C. Sorry to admit it is almost entirely uncommented (I wrote it in a hurry!).
12-18-2008 03:42 AM
Hi,
Yoy may enumerate the registry key:
HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM
to obtain the available serial communication ports.
To check the availability, you have to open them.
Jan
11-17-2010 08:55 AM
I also need to know all available serial port on my PC. So I tried opening all serial ports from 1 to 20. Physically I have only 1 serial port. Which is port number 1. But when I open port using OpenComConfig I could also open serial port 8 which is not connected (Not physically present) and doesn't show up in device manager.
I could open, and write data to this port. (Not sure where data is going though!) I use CVI built in library to open/write data to serial port.
When I open registry it shows up as Winachsf0. (See attached screenshot)
Any help is appreciated.
Thanks.
11-17-2010 09:07 AM
did you consider viFindRsrc? see here for example.
11-17-2010 10:14 AM - edited 11-17-2010 10:16 AM
There maybe several possibilities to have unexpected com ports in a PC: first of all, some motherboards and some serial interfaces have two ports physically available, only one of which is cabled on the rear panel while the second is available as an internal connector; notebooks frequently have built-in modems which actually are com ports; there may be other cases which I am not aware of. In Device manager frequently you can see some additional resources by checking View >> Show hidden devices.
In any case, using viFindRsrc as wolfgang suggests is normally a good option, but you may find that your system actually has some additional unexpected com port. Normally, going through properties of the devices shown you can have some details more to identify which type of device is; as an ultimate resource you may want to disable the device so that is no more accessible from the system: this should exclude it also from the search functions.
11-17-2010 10:21 AM
I believe winachfs0 is the name given to a port associated with a Conexant modem.