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: 

OpenComConfig finds ports that do not exist

I work on software that communicates thru the serial port to a controller. Recently we have had a few reports of communication errors, mainly on laptops.
 
The attached code uses the basic loop I have used for nearly 10 years. It will test com 1 thru com 32 and indicate the return value from OpenComConfig.
 
Testing on a laptop here, I found that OpenComConfig returns 0 on Com 3, indicating a valid port. However there is no Com 3 present on this laptop.
 
I suspect that something in the laptop is simulating a port, so it does not show up in the hardware listing but is sensed by CVI. Is there any other way to find the available ports? I found one example that looks at the registry, however it does not work.
0 Kudos
Message 1 of 9
(5,173 Views)

 


@kmagas wrote:
I found one example that looks at the registry, however it does not work.


Hello,

Some time ago I wrote a small example program that finds the ports in the registry, thanks to a tip of Roberto. Is this the example that you are talking about? It works great on every system that I used it for...

0 Kudos
Message 2 of 9
(5,155 Views)

Yes Wim that  is the one. Doesnt work on my PC. See attached screenshot, I have the registry open showing Com 1 and 2.

 

0 Kudos
Message 3 of 9
(5,150 Views)
That's odd. I'm afraid you will have to debug the ComportDetect function yourself, since it works on my sytem Smiley Sad.
0 Kudos
Message 4 of 9
(5,148 Views)
A little while ago I wrote a DLL that finds COM ports (all COM ports, or COM ports with a specific name) in a different way. You can find it in this thread.
--
Martin
Certified CVI Developer
0 Kudos
Message 5 of 9
(5,137 Views)

Wim the problem was with the line with RegEnumerateValue. RegEnumerateValue was returning -57, buffer passed is too small for the operation. I put in a buffer instead of NULL values and it worked.

When I tried to run the exe on another PC I got errors about incompatable UIR versions, even after making an installation kit. So I modified your code so it does not need a UIR, attached is this modified c file. When I rund this on my laptop, it shows Com3 is available. However looking at the hardware configuration I found that on the laptop com 3 is not really a serial port it is used for a modem.

So apparently when CVI opens a port it using OpenCom or OpenComonfig it doesn't care if it is a serial port or a modem. Your code also has this issue.

0 Kudos
Message 6 of 9
(5,123 Views)
As I understand it, a modem converts between an analog signal that is transmitted across the communication medium (phone line) and some digital protocol, usually serial.  The communication still requires that the modem be connected to a serial port to/from which data is sent/received.  External modems needed to be connected to an existing port on the machine, while internal modems contained their own, internal serial hardware.  This explains why your machine reports having a com port for which you don't see a physical connector on the motherboard.  It's not that OpenCom fails to distinguish between serial ports and modems -- it just doesn't distinguish between serial ports that have external connectors and those that are internally dedicated to a device.  Your program would have to use this dedicated port if it wanted to send or receive data from the modem.  The tie between modems and and serial ports is more apparent when you consider that one of the RS-232 pins is a "ring indicator," and that some common file transfer protocols over serial are called XMODEM, YMODEM, and ZMODEM.

Mert A.
National Instruments
0 Kudos
Message 7 of 9
(5,116 Views)
Mert's right. There are several different devices that can appear to Windows - and Windows applications - as COM ports, including real COM ports and 'virtual' COM ports such as modems and USB-to-serial adapters. The reason I wrote the DLL that I posted a link to earlier in this thread is that I wanted to be able to find a COM port according to its description (aka 'friendly name' as seen in the hardware device list). For this reason, the DLL uses the Windows Setup API rather than interrogating the registry directly (the latter method is not guaranteed to work across Windows versions).
--
Martin
Certified CVI Developer
0 Kudos
Message 8 of 9
(5,096 Views)
Thanks for the explanations. However, irregardless of the reasons why, CVI does not have a function to tell what comports are actual physical ports. I will try the DLL to see if this can do the job. I suspect the only way to accurately accomplish this is to read the registry, which as noted may be different for various Windows versions.
0 Kudos
Message 9 of 9
(5,028 Views)