Com Port Enumeration


smackay

Recommended Posts

What would be the best way to create a list of active com ports from Windows in DAQFactory? During my research I found the following approaches:

1. CreateFile("COM" + 1->255)

Found com0com ports, took 234ms.

2. QueryDosDevice()

Found com0com ports, took 0ms.

3. GetDefaultCommConfig("COM" + 1->255)

Found com0com ports, took 235ms.

4. "SetupAPI1" using calls to SETUPAPI.DLL

Found com0com ports, also reported "friendly names", took 15ms.

5. "SetupAPI2" using calls to SETUPAPI.DLL

Did not find com0com ports, reported "friendly names", took 32ms.

6. EnumPorts()

Reported some non-COM ports, did not find com0com ports, took 15ms.

7. Using WMI calls

Found com0com ports, also reported "friendly names", took 47ms.

8. COM Database using calls to MSPORTS.DLL

/ Reported some non-COM ports, found com0com ports, took 16ms.

9. Iterate over registry key

HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM

Found com0com ports, took 0ms. This is apparently what SysInternals PortMon uses.

===================================================================

1) Option 9 would be nice but to my knowledge DAQFactory Registry variables will only point to HKEY_LOCAL_MACHINE\ Software\DAQFactory \Control\Variables. Is there a way to switch the path?

2) Options 4, 5 or 8 could possibly work with your help. I am not sure how to work the DLL call with regard to these APIs.

extern(DLL Name, Prototype, DAQFactory Function Name, Call Type, [Tip])

A) Does it matter where the DLL is located on the PC? Would you need to include a path along with the DLL Name ever? For example

Link to comment
Share on other sites

1) you can't switch the path for registry variables. You'd have to code your own registry reader in C and expose it as a DLL.

2) a) windows handles this. There is a predefined search path for DLL's, usually the local directory, then the system Path, then several default system folders (like system32). Unless its in a system folder, its usually best to fully qualify the path.

;) if the prototype doesn't have parameters, then it doesn't have parameters. Don't pass any.

c) Because extern() exposes the specified DLL's functions in the global namespace, we allow you to name the function whatever you want within DAQFactory to avoid any conflicts. You have to have a function name even if it takes no parameters and returns nothing. How else will you trigger the function?

d) these determine how parameters are passed. stdcall and cdecl are standard methods. Search the internet for details. Most likely you'll be stdcall.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.