While both of the above suggestions still stand as good ideas, another way to solve the problem is to be able to filter out the COM ports that are available on the PC, but are already in use.
Is that possible somehow?
This is the code I use to populate the 'available' COM ports:
' Get the com ports, and add them to the list of available com ports
Local vData() As String
Local nItems As Long
Local Counter As Long
Local Position As Long
Local ComputerName As String Value OS_GetComputerName
Local sBuffer As String
Local Ports() As String
sBuffer = WMI_GetData(ComputerName, "", "", "", "Win32_PnPEntity", "", "Name" )
'---Parse returned data into single lines
nItems = Parse( sBuffer, vData(), $CRLF)
'---Print lines
For Counter = 1 To nItems
Position = InStr(Ucase$(vData(Counter)),"(COM")
If Position Then
ReDim Preserve Ports(UBound(Ports)+1)
PortS(UBound(Ports)) = Extract$(Position+1,vData(Counter),")")
End If
Next
COMBOBOX Reset CBHNDL, %ID_CommandSerialCombobox
If UBound(Ports) >= LBound(Ports) Then
For Counter = LBound(Ports) To UBound(Ports)
COMBOBOX Add CBHNDL, %ID_CommandSerialCombobox, Ports(Counter)
Next
COMBOBOX Select CBHNDL, %ID_CommandSerialCombobox, 1
End If
Control Redraw CBHNDL, %ID_CommandSerialCombobox
I don't know much about WMI_GetData(). Is there another call that could be made to detect which COM ports are already opened in other applications?
*Brian
Bookmarks