 |
|
|
Topic: no COM ports shown in Win 7
|
By: Dave | Posted on: Sep 9 2014 at 11:58:01 AM | I have a 32 bit vb6 app running on windows 7. When the user opens our connection screen there are no available COM ports listed in the dropdown. But when on any other computer (xp, win7, win8) the available COM ports will be shown in the dropdown. Do you know of anything that would prevent your COM control from seeing COM ports on a win 7 machine? The specific port they are looking for is coming from a usb-to-serial adapter cable. | |
By: Guest | Posted on: Sep 9 2014 at 04:45:25 PM | How sure are you that the com ports are actually installed? If you go to windows Device Manager do you see the ports in there? | |
By: Guest | Posted on: Sep 11 2014 at 12:43:53 PM | Yes there are ports in device manager. Specifically COM 16 is what they have assigned to their usb-serial adapter cable. And I have a 2nd screen in the program which uses mscomm and it is displaying the COM port. | |
By: Guest | Posted on: Sep 11 2014 at 08:22:01 PM | Dave. You're talking about ports appearing in a dropdown.
I assume you've written code that searches for available ports and populates your dropdown.
What does that code look like? | |
By: Dave | Posted on: Sep 12 2014 at 02:21:18 PM | here is the scode for comm32 I am using to populate that dropdownlist...
Private Sub PopulateCommPortList()
Dim i As Integer
Me.MousePointer = vbHourglass
DoEvents
cbbPorts.Clear
' test for ports up to m_iNumPorts - you can test up to 255 if you want.
For i = 1 To m_iNumPorts
SComm.CommPort = i
If SComm.CommName = "" Then
' This Com Port does not exist at all
Else
' This port exists so show the DeviceName in the list
SComm.CommPort = i
cbbPorts.AddItem "COM " & i & " - " & SComm.CommName
' Also store i so that when the user selects one we'll know which port to open
cbbPorts.ItemData(cbbPorts.NewIndex) = i
End If
Next
If cbbPorts.ListCount > 0 Then
cbbPorts.ListIndex = 0 'select first item in the list
SComm.CommPort = cbbPorts.ItemData(0)
End If
Me.MousePointer = vbDefault
DoEvents
End Sub
And here is the code I was using to populate it using mscomm....
Private Sub FillCOMPorts()
Dim count As Integer, i As Integer
cbbPorts.Clear
For i = 1 To 16
If IsComPortAvailable(i) Then
cbbPorts.AddItem "COM " & CStr(i)
cbbPorts.ItemData(cbbPorts.NewIndex) = i
End If
Next
' select first port
If cbbPorts.ListCount 0 Then
cbbPorts.ListIndex = 0
End If
End Sub
Private Function IsComPortAvailable(ByVal portNum As Integer) As Boolean
Dim fnum As Integer
Err.Clear
On Error Resume Next
fnum = FreeFile
Open "COM" & CStr(portNum) For Binary Shared As #fnum
If Err = 0 Then
Close #fnum
IsComPortAvailable = True
Else
IsComPortAvailable = False
End If
End Function | |
By: Dave | Posted on: Sep 12 2014 at 02:21:59 PM | Wow. It lost all the indenting when it posted to your forum. Sorry about that. | |
By: Guest | Posted on: Sep 12 2014 at 08:44:18 PM | In your code you do
For i = 1 To m_iNumPorts
We can't see what is value of m_iNumPorts ? | |
By: Dave | Posted on: Sep 13 2014 at 06:34:17 PM | Damn !! There was a typo on the number of ports to check. It was set to 10 when it should have been set to 30. That's why it didn't find the customers port because they had set it to 16. You're a genius ... and I'm an idiot. Thanks!
ps. Is there a better way to check for available ports than what I'm doing in the code above? | |
By: Matt | Posted on: Sep 13 2014 at 08:59:00 PM | Your function IsComPortAvailable is probably quife fast so if all you want to do is find out which com ports are available then that is a fairly generic way of doing it.
But if the port exists but is busy, perhaps it's in use by another thread somewhere within your application, then your IsComPortAvailable function would return false even though the port exists. Perhaps thats what you want. After all, if the port is busy then its not available.
The SComm .PortName property returns the port name even if the port is busy so can be used to detect ports even if they're busy. The portname returned is the long 'friendly' name such as:-
"Prolific USB Serial Port Com23"
However getting the long portname can be a little slower especially when checking dozens of possible ports.
So, it's up to you which method you use depending on what functionality you want.
Consider using your IsComPortAvailable function to find out which ports are actually available and then use the SComm PortName function to get the full 'friendly' name of the existing ports to put into your combo.box for your users to see. | |
|