CTI Comet USB AutoFind
As the CTI Comet USB no longer works with fixed COM ports, some users may find it harder to setup their software with the correct COM port. To aid developers in making it easier for their customers, we have developed the following code which we will provide under the MIT Licence. (LICENCE) This means that you are free to use the code or binary as you wish however we will provide NO support for it in any way!
The code is reasonably simple, it queries the computer for all CTI Comet USB devices and returns the result as a string. There are two different ways this could be used.
- If your software uses VB.NET you could incorporate the code into your solution.
- Use the included executable and call from within your software parsing the result.
When the code/program is executed, it will print the COM ports of all the CTI Comet USB devices connected to the computer. This will either be a no devices or a single COM port as below:
Or it will output multiple COM ports with the character ; seperating them as below:
The code requires the .NET framework v4 (Download) (Microsoft Download Link) to satisfy the System.Management import.
Files you can download are below:
Below is the code used in the software that was written using Microsoft Visual Studio Express, remember to include the LICENCE if you copy this code. And dont forget to add System.Management under project references for the .NET project.
This code has been tested on Windows Vista and 7.
Imports System.Management
Module MainModule
Sub Main()
' Create the dictionary to hold all COMETS.
Dim result As New Dictionary(Of String, String)
' Search for all COMET devices.
result = findCOM()
' Output the result to the console.
Dim i As Integer
Dim str As String
str = ""
i = 0
For Each foundPort As KeyValuePair(Of String, String) In result
If Not (i = 0) Then
str += ";"
End If
str += "COM" + foundPort.Key
i = i + 1
Next
System.Console.Write(str)
End Sub
' Returns a list of COM port numbers for all attached CTI Comet USB devices.
' Formatted with a ; between each device.
Private Function findCOM()
Dim identPnpPorts As New Dictionary(Of String, String)
Dim returnSerials As New Dictionary(Of String, String)
Dim portNameData As String
Dim comPortNumber As String
Try
Dim portSearcher As New ManagementObjectSearcher("\root\CIMV2", "Select Name from Win32_PnPEntity")
For Each port As System.Management.ManagementObject In portSearcher.Get()
'search all of the PNP entries for the device
If port("Name").ToString.ToUpper.Contains("(COM") Then
portNameData = port("Name").ToString
comPortNumber = port("Name").ToString.Substring(port("Name").ToString.IndexOf("(COM") + 4)
comPortNumber = comPortNumber.TrimEnd(")"c)
identPnpPorts.Add(comPortNumber, portNameData)
End If
Next
Catch ex As Exception
'Need to handle possible errors
End Try
For Each foundPort As KeyValuePair(Of String, String) In identPnpPorts
If (foundPort.Value.Contains("CTI Comet USB COM Port")) Then
returnSerials.Add(foundPort.Key, foundPort.Value)
End If
Next
Return returnSerials
End Function
End Module