USB to VB6 CommPort Numbers
USB to VB6 CommPort Numbers
USB Question:
I have a ZX-24 tied to a FTDI UB232R USB to Serial Port module.
I have loaded the CDM 2.0 driver, as per FTDI's web site.
On my laptop it defines itself as CommPort 19.
On my desktop it defines itself as CommPort 20.
I can open either with Hyperterminal, and watch my data stream past.
I tried to open CommPort 20 using VB 6 and it gives an Invalid port number error.
Is there a maximum port number that VB 6 can utilize?
Have others opened high port numbers with VB 6?
Any thoughts would be appreciated.
JC
I have a ZX-24 tied to a FTDI UB232R USB to Serial Port module.
I have loaded the CDM 2.0 driver, as per FTDI's web site.
On my laptop it defines itself as CommPort 19.
On my desktop it defines itself as CommPort 20.
I can open either with Hyperterminal, and watch my data stream past.
I tried to open CommPort 20 using VB 6 and it gives an Invalid port number error.
Is there a maximum port number that VB 6 can utilize?
Have others opened high port numbers with VB 6?
Any thoughts would be appreciated.
JC
I have opened COM numbers that high in VB6 with the old MSCOMM control.
Some with devices that use the FTDI virtual port driver.
You might see if the port gets enumerated correctly.
Here's a VB6 enumerator I downloaded and have used in the past.
Some with devices that use the FTDI virtual port driver.
You might see if the port gets enumerated correctly.
Here's a VB6 enumerator I downloaded and have used in the past.
Code: Select all
Function listAvailSerialPorts(formObj As Form, ByRef portsExist() As String) ' bit 0 = COM0, etc.
Dim pcbNeeded As Long
Dim pcReturned As Long
Dim pi2() As PORT_INFO_2
Dim I As Integer
Dim sPortType As String
Dim ComName As String, description As String
Dim n As Integer
'To determine the required buffer size, call EnumPorts with
'cbBuf set to zero. EnumPorts fails, and Err.LastDLLError
'returns ERROR_INSUFFICIENT_BUFFER, filling in the pcbNeeded
'parameter with the size, in bytes, of the buffer required to
'hold the array of structures and their data.
n = 0
Call EnumPorts(vbNullString, 2, 0, 0, pcbNeeded, pcReturned)
If pcbNeeded Then
'The strings pointed to by each PORT_INFO_2 struct's members
'reside in memory after the end of the array of structs. So we're
'not only allocating memory for the structs themselves, but all the
'strings pointed to by each struct's member as well. Use floating
'point division, and add an extra struct to the array for padding.
ReDim pi2((pcbNeeded / SIZEOFPORT_INFO_2))
If EnumPorts(vbNullString, 2, pi2(0), pcbNeeded, pcbNeeded, pcReturned) Then
For I = 0 To (pcReturned - 1)
With pi2(I)
ComName = GetStrFromPtrA(.pPortName)
description = GetStrFromPtrA(.pDescription)
If Mid(ComName, 1, 3) = "COM" Then ''' BLIPS 2.3 change And Mid(description, 1, 5) = "Local" Then
n = n + 1
ReDim Preserve portsExist(1 To n)
portsExist(n) = ComName
Call formObj.log(ComName & " is a " & description & ", flags: " & CStr(.fPortType))
'Debug.Print ComName, GetStrFromPtrA(.pDescription), Hex(.fPortType)
End If
'If (.fPortType And PORT_TYPE_WRITE) Then sPortType = "write "
'If (.fPortType And PORT_TYPE_READ) Then sPortType = sPortType & "read "
'If (.fPortType And PORT_TYPE_REDIRECTED) Then sPortType = sPortType & "redirected "
'If (.fPortType And PORT_TYPE_NET_ATTACHED) Then sPortType = sPortType & "network"
'ctl.AddItem GetStrFromPtrA(.pPortName) & vbTab & _
GetStrFromPtrA(.pDescription) & vbTab & _
.fPortType & "-" & sPortType & vbTab & _
GetStrFromPtrA(.pMonitorName)
End With
Next
End If 'EnumPorts
End If 'pcbNeeded
End Function
Public Function GetStrFromPtrA(lpszA As Long) As String
GetStrFromPtrA = String$(lstrlenA(ByVal lpszA), 0)
Call lstrcpyA(ByVal GetStrFromPtrA, ByVal lpszA)
End Function
---------
a module
Public Enum PortTypes
PORT_TYPE_WRITE = &H1
PORT_TYPE_READ = &H2
PORT_TYPE_REDIRECTED = &H4
PORT_TYPE_NET_ATTACHED = &H8
End Enum
Public Type PORT_INFO_2
pPortName As Long
pMonitorName As Long
pDescription As Long
fPortType As Long
Reserved As Long
End Type
Public Const SIZEOFPORT_INFO_2 = 20
Public Declare Function lstrlenA Lib "kernel32" _
(lpString As Any) As Long
Re: USB to VB6 CommPort Numbers
It's been too long for me to recall the details but I believe ports above COM9 required a \\.\ prepended to the name if using CreateFile to open.DocJC wrote:Is there a maximum port number that VB 6 can utilize?
Have others opened high port numbers with VB 6?
Code: Select all
"\\.\COM10"
Dave, thank you for the input.
It appears (perhaps) that the system enumerated only up through port 9.
The device manager, however, lists several bluetooth drivers, and the USB port, extending up through port 20.
Hyperterminal lists and opens the port, and communicates without difficulty, on port 20.
I have been using MSCOMM, but will look into using CreateFile, with the prefix.
JC
It appears (perhaps) that the system enumerated only up through port 9.
The device manager, however, lists several bluetooth drivers, and the USB port, extending up through port 20.
Hyperterminal lists and opens the port, and communicates without difficulty, on port 20.
I have been using MSCOMM, but will look into using CreateFile, with the prefix.
JC
JC,
I have some VB4-32 code which enumerates all the ports correctly on all of my W98SE and XP machines. I no longer have a W2K machine to test it on. I'll try to post it here in a day or two. It uses MSComm. It should convert to VB6 with no problems.
It has always found all the ports found by Device Manager including an 8-port ByteRunner PCI card, 2 motherboard ports, a few virtual USB-serial ports and virtual ethernet-serial ports.
I have some VB4-32 code which enumerates all the ports correctly on all of my W98SE and XP machines. I no longer have a W2K machine to test it on. I'll try to post it here in a day or two. It uses MSComm. It should convert to VB6 with no problems.
It has always found all the ports found by Device Manager including an 8-port ByteRunner PCI card, 2 motherboard ports, a few virtual USB-serial ports and virtual ethernet-serial ports.
After checking several port enumerators, I note that the FTDI USB to Serial module is enumerated as USB Serial Port (COM20), as is displayed by WinXP device manager, and as listed by the Hyperterminal pull down list.
MS VB6, however, will still NOT connect to it, or to any port > 16 on my system, using the MSCOMM control.
Any other thoughts or tricks to make the MSCOMM control recognize the higher port numbers?
My first venture into USB is proving very frustrating, the project would be done if I'd stayed with RS-232...
JC
MS VB6, however, will still NOT connect to it, or to any port > 16 on my system, using the MSCOMM control.
Any other thoughts or tricks to make the MSCOMM control recognize the higher port numbers?
My first venture into USB is proving very frustrating, the project would be done if I'd stayed with RS-232...
JC
It is possible to change what com port the ftdi is using, follow this:
Right Click "My Computer" > Select "Manage"
Click on "Device Manager" in the list
Click on the "+" next to "Ports (COM & LPT)"
Right click on the FTDI Com device > Select "Properties"
Click on the tab labeled "Port Settings"
Click the Button "Advanced..."
In the next dialog, click the drop down "COM Port Number: " changing it from COM20 to what ever you want as long as it is not currently used by another device.
If it is, there will be an "(in use)" to the right of the com port number in the list. Also the OS can "Think" a port is in use for instance if you have a second usb adapter and it is not plugged in it will still say "in use" even though its unplugged. It is ok to use that port so long as you do not plug both adapters in at the same time.
Hope this helps,
-MikeD
Right Click "My Computer" > Select "Manage"
Click on "Device Manager" in the list
Click on the "+" next to "Ports (COM & LPT)"
Right click on the FTDI Com device > Select "Properties"
Click on the tab labeled "Port Settings"
Click the Button "Advanced..."
In the next dialog, click the drop down "COM Port Number: " changing it from COM20 to what ever you want as long as it is not currently used by another device.
If it is, there will be an "(in use)" to the right of the com port number in the list. Also the OS can "Think" a port is in use for instance if you have a second usb adapter and it is not plugged in it will still say "in use" even though its unplugged. It is ok to use that port so long as you do not plug both adapters in at the same time.
Hope this helps,
-MikeD
Mike,
It never occurred to me that I could set the port to one which the OS thought was already assigned... I remember the days of manually assigning com ports and interrupts and trying specifically not to do that...
I forced the device to use port 5 and VB6 MSCOMM can communicate with it now!
It is still of interest to me that others report using high value comm ports with VB6, yet my install can not access them. I installed (several) VB6 Service Packs, which made no difference.
In any event, THANK YOU!
JC
It never occurred to me that I could set the port to one which the OS thought was already assigned... I remember the days of manually assigning com ports and interrupts and trying specifically not to do that...
I forced the device to use port 5 and VB6 MSCOMM can communicate with it now!
It is still of interest to me that others report using high value comm ports with VB6, yet my install can not access them. I installed (several) VB6 Service Packs, which made no difference.
In any event, THANK YOU!
JC
I recall another Windows issue with USB serial ports... each time you plug in a USB to serial adapter with a different unique ID, a new com port number is used. These accumulate and show up in the device manager's Show Hidden Devices choice. I recall that you can delete (uninstall) these hidden devices to return their numbers to the unassigned pool.
FTDI offers a tool called FTClean that removes all FTDI-based devices. This is primarily useful for a manufacturing operation (where one USB device after another is connected to a computer for configuration and testing) but it may be useful in other situations as well.stevech wrote:I recall that you can delete (uninstall) these hidden devices to return their numbers to the unassigned pool.
- Don Kinzer
I'm out of town for the week, but will be back at it soon enough. Basic question, if one removes a device through device manager, and later plugs it back into the system, is the driver still known, and automatically reloaded, or must one re-install it from a CD? (Win XP).
I'll add FTDI's utility to my armamentarium...
I also learned of a hack for the MSCOMM ocx to change the number of ports it supports, (official MS support: 1-16), but I have not tried it yet. I haven't used a low level hex editor since the days of DOS, so I'll be looking for a freeware/shareware version for this test, any recommendations?
As always, I appreciate everyone's help!
JC
I'll add FTDI's utility to my armamentarium...
I also learned of a hack for the MSCOMM ocx to change the number of ports it supports, (official MS support: 1-16), but I have not tried it yet. I haven't used a low level hex editor since the days of DOS, so I'll be looking for a freeware/shareware version for this test, any recommendations?
As always, I appreciate everyone's help!
JC
DocJC wrote:f one removes a device through device manager, and later plugs it back into the system, is the driver still known, and automatically reloaded, or must one re-install it from a CD? (Win XP).
My experience is that XP somehow retains knowledge of the previously installed driver. This is annoying in cases where you need to or want to install a new driver but XP keeps using the previously installed one even though there are no existing devices using that driver.
- Don Kinzer