Assign com port number at the time of driver installation.

Hello Everyone,

I am creating multiple static com port for a USB printer device.We have assign a task to assign the COM-PORT number at the time of driver installation. For example suppose at the time of driver installation user select the 4 com port for a printer then that time there is option to assign desire com port number to the exported com-port.like

first com number -> 8 -> look like COM8
second com number -> 11 -> look like COM11
third com number -> 14 -> look like COM14
fourth com number -> 17 -> look like COM17

Thanks,

xxxxx@chetu.com wrote:

Hello Everyone,

I am creating multiple static com port for a USB printer device.We have assign a task to assign the COM-PORT number at the time of driver installation. For example suppose at the time of driver installation user select the 4 com port for a printer then that time there is option to assign desire com port number to the exported com-port.like

first com number -> 8 -> look like COM8
second com number -> 11 -> look like COM11
third com number -> 14 -> look like COM14
fourth com number -> 17 -> look like COM17

Typically, the COM port assignments are made by the system, not by the
user. You can use the registry to store the current assignments for
your driver.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Typically, the COM port assignments are made by the system, not by the
user. You can use the registry to store the current assignments for
your driver.

Thank you so much Tim for your valuable answer.
Actually my requirement is to assign the com number at the time of driver installation as per the user choice.So please give me some hint regarding this.
I just want to verify my understanding here, you told me to store the user choice in registry and use
these store number in assigning of com number. I am new in windows driver development so please
do the needful.

thanks,

I don’t think that COM ports have a number. But every COM port has a device description which is a human readable string that helps the user identify the COM port and should have a device interface string.

With the SetupAPI library, you can obtain the list of all available devices for the interface GUID_DEVINTERFACE_COMPORT with SetupDiGetClassDevs. This is the list of COM ports present on the system. For each device, you must then obtain the interface string.The intrerface string is a symbolic link used to open the device with CreateFile and read/write data to the COM port. This string identifies the device on the system.

So for each device you should have the device description and the interface string. Then you build a combo box list for the user. The combo box item’s text is the device description and the item data pointer is the address of the interface string. Once the user has selected the port (with the device description), you store the corresponding device interface string in the registry or a hash of the string.

Be careful when you read back the string. Be sure that it is a valid device interface string for a COM port.

Look at the following documentations:

https://msdn.microsoft.com/en-us/library/windows/hardware/ff545821(v=vs.85).aspx
https://msdn.microsoft.com/en-us/library/windows/hardware/ff551069(v=vs.85).aspx
https://msdn.microsoft.com/en-us/library/windows/hardware/ff551015(v=vs.85).aspx
https://msdn.microsoft.com/en-us/library/windows/hardware/ff551120(v=vs.85).aspx
https://msdn.microsoft.com/library/windows/hardware/ff551963
https://msdn.microsoft.com/en-us/library/windows/hardware/ff543530(v=vs.85).aspx

You just described the pnp way of finding a com port. It is righteous and correct. COM port applications are steeped in legacy code and only know the pre pnp way where COM ports DO have numbers.

If I remember correctly, the OP has a root driver which exposes a com port for each usb printer. For this scenario, the code that installs the root driver should call the ComDB APIs to claim 4 ports (https://msdn.microsoft.com/en-us/library/windows/hardware/ff546481(v=vs.85).aspx )

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Saturday, November 19, 2016 12:50 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Assign com port number at the time of driver installation.

I don’t think that COM ports have a number. But every COM port has a device description which is a human readable string that helps the user identify the COM port and should have a device interface string.

With the SetupAPI library, you can obtain the list of all available devices for the interface GUID_DEVINTERFACE_COMPORT with SetupDiGetClassDevs. This is the list of COM ports present on the system. For each device, you must then obtain the interface string.The intrerface string is a symbolic link used to open the device with CreateFile and read/write data to the COM port. This string identifies the device on the system.

So for each device you should have the device description and the interface string. Then you build a combo box list for the user. The combo box item’s text is the device description and the item data pointer is the address of the interface string. Once the user has selected the port (with the device description), you store the corresponding device interface string in the registry or a hash of the string.

Be careful when you read back the string. Be sure that it is a valid device interface string for a COM port.

Look at the following documentations:

https://msdn.microsoft.com/en-us/library/windows/hardware/ff545821(v=vs.85).aspx
https://msdn.microsoft.com/en-us/library/windows/hardware/ff551069(v=vs.85).aspx
https://msdn.microsoft.com/en-us/library/windows/hardware/ff551015(v=vs.85).aspx
https://msdn.microsoft.com/en-us/library/windows/hardware/ff551120(v=vs.85).aspx
https://msdn.microsoft.com/library/windows/hardware/ff551963
https://msdn.microsoft.com/en-us/library/windows/hardware/ff543530(v=vs.85).aspx


NTDEV is sponsored by OSR

Visit the list online at: http:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at http:

To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:>

Yes and should the user choose a COM port among those created by the driver only ?

Thank you so much, Doron and D.T for your suggestion.

Can we change the port number of installed driver using the application, except from the manual changing.
for example,

initially my device attached with com4 but i want to change it com5, but using the application.

Thanks,

The app can call the COMDB APIs too

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@chetu.com
Sent: Tuesday, November 22, 2016 9:47 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Assign com port number at the time of driver installation.

Can we change the port number of installed driver using the application, except from the manual changing.
for example,

initially my device attached with com4 but i want to change it com5, but using the application.

Thanks,


NTDEV is sponsored by OSR

Visit the list online at: http:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at http:

To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:>

Hello Doron,

Thanks for reply, I am creating an application an application using the com-db API as per the your suggestion, in which I am using the ComDBOpen function to open the the com port data base after that I am using the ComDBGetCurrentPortUsage function but not getting any desire data.Please show me the correct way to create the application.

err = ComDBOpen(&hComDB);

if (err != ERROR_SUCCESS) {

}

DWORD maxPortsReported;

ComDBGetCurrentPortUsage(hComDB, NULL, 0, CDB_REPORT_BYTES, &maxPortsReported);

if (err != ERROR_SUCCESS) {

ComDBClose(hComDB);

}

always getting maxPortsReported => 256