Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

USBSER.sys: error when re-plugging

341 views
Skip to first unread message

Robin

unread,
Aug 6, 2004, 4:16:31 AM8/6/04
to
Hi

I have a USB device I'd like to be mapped to a COM port. As everybody
seems to highly recommend to use the usbser.sys instead if possible, I
try this approach now.

So I created an INF file that registers the device.

When I plug the device to the system (1st time) it works fine. When I
unplug and replug it, it doesn't work anymore (Device Manager: Windows
cannot load the drivers reqired, Code 31).

Anybody an idea why? (See the INF file below)

Many thanks

Robin

--------- INF file -------------------------
[Version]
Signature = "$CHICAGO$"
Class = Ports
ClassGUID = {4D36E978-E325-11CE-BFC1-08002BE10318}
Provider = %manuf%
DriverVer = 08/05/2004,0.0.0.1

[DestinationDirs]
DefaultDestDir = 11,
DriverFilesDir = 12,
InfFilesDir = 17,

[ControlFlags]
ExcludeFromSelect = *

[Manufacturer]
%manuf% = manuf.Models

[manuf.Models]
%MyUSBDevice.Descr% = MyUSBDevice.Install,USB\VID_1234&PID_4321,

[MyUSBDevice.Install]
AddReg = MyUSBDevice.Install.USB

[MyUSBDevice.Install.Services]
AddService = usbser, 0x00000002, MyUSBDevice.Install.Services.Install

[MyUSBDevice.Install.Services.Install]
DisplayName = %MyUSBDevice.Descr%
ServiceType = 1 ; SERVICE_KERNEL_DRIVER
StartType = 3 ; SERVICE_DEMAND_START
ErrorControl = 1 ; SERVICE_ERROR_NORMAL
ServiceBinary = %12%\usbser.sys

[MyUSBDevice.Install.USB]
HKR,,DevLoader,,*ntkern
HKR,,NTMPDriver,,usbser.sys
;HKR,,AttachedTo,,COM5 --> recommended to not use
HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider"

[Strings]
manuf = "MyCompany"
MyUSBDevice.Descr = "MyCompany's Serial COM Port Emulation"

Leo Havmøller

unread,
Aug 6, 2004, 5:32:30 AM8/6/04
to
"> When I plug the device to the system (1st time) it works fine. When I
> unplug and replug it, it doesn't work anymore (Device Manager: Windows
> cannot load the drivers reqired, Code 31).

Do you handle and answer the CDC requests properly (SetLineCoding,
GetLineCoding, SetControlLineState)?
Is any user-mode app keeping the COM port open?

Leo Havmøller.


Jonas Wetz

unread,
Aug 6, 2004, 6:32:32 AM8/6/04
to
I have an additional question regarding this topic. If I understand right,
I just have to create an .inf file to use the windows internal usb to serial
port emulation driver "usbser.sys". Does this mean I just have to write the
file, reference usbser.sys in this file and then I can install the device
using the .inf file? Would an other application be able to handle the device
connected via usb with the same syntax used for serial ports then?

I'm sorry for that stupid question, but I'm completely new to Windows driver
development.

Thanks in advance,

Jonas Wetz


"Leo Havmųller" <l...@nospamrtx.dk> schrieb im Newsbeitrag
news:%23fnxMh5...@TK2MSFTNGP09.phx.gbl...

> Leo Havmųller.
>
>


Alexander Grigoriev

unread,
Aug 6, 2004, 12:16:55 PM8/6/04
to
See "Include" and "Layout" INF directives. You should reference the system
INF file which describes usbser.sys

"Jonas Wetz" <jw...@kwest.de> wrote in message
news:eZB$1C6eE...@TK2MSFTNGP12.phx.gbl...

Robin

unread,
Aug 9, 2004, 3:56:41 AM8/9/04
to
> Do you handle and answer the CDC requests properly (SetLineCoding,
> GetLineCoding, SetControlLineState)?

I do not handle/answer anything. I just wrote the mentioned inf file
which references to use Microsoft usbser.sys driver. The error message
appears in the Device Manager Properties.

> Is any user-mode app keeping the COM port open?

There might be a user-mode app keeping the port open, depending on the
user. I tried with and without the app because I first thought this to
be the reason (port held open by app). But I get an in either case.

When attaching the device, starting the app and connecting the port, it
works. Then disconnecting the port, closing the app, removing the
device, re-attaching the device, starting the app again and connecting
the port, it doesn't work anymore. In this case the device manager even
tell that the device works properly...

Any idea? Thanks

Robin

Robin

unread,
Aug 9, 2004, 4:14:08 AM8/9/04
to
I found out new things:

The procedure as described before with proper plug/re-plug seems to fail
because of the device.

The other case (re-plug when user app is still connected to the port)
seems to fail on the Microsoft side (usbser.sys). In this case the
earlier mentioned error code 31 appears in the device manager.

So I need a solution for this case. Is it possible to do something
within the user app to prevent usbser.sys from fail (otherwise the user
must restart the PC everytime...)? Or is there a possibility with
writing a kind of driver, maybe a filter driver to usbser.sys, to handle
this?

Many thanks

Robin

Leo Havmøller

unread,
Aug 9, 2004, 4:25:36 AM8/9/04
to
"Robin" <ho...@nospam.com> wrote in message
news:urjKLaef...@TK2MSFTNGP11.phx.gbl...

>> Do you handle and answer the CDC requests properly (SetLineCoding,
>> GetLineCoding, SetControlLineState)?
>
> I do not handle/answer anything. I just wrote the mentioned inf file which
> references to use Microsoft usbser.sys driver. The error message appears
> in the Device Manager Properties.

You must handle and answer the mentioned requests in your USB device.
Get the USB CDC spec from
http://www.usb.org/developers/devclass_docs#approved

Leo Havmøller.


Leo Havmøller

unread,
Aug 9, 2004, 4:41:53 AM8/9/04
to
"Robin" <ho...@nospam.com> wrote in message
news:e0E$7jefEH...@TK2MSFTNGP09.phx.gbl...

You dont need to restart the PC. Just close the application and
unplug/replug the USB device.

See new thread "User-mode handle and USB device plug/unplug".

Leo Havmøller.


Robin

unread,
Aug 9, 2004, 5:24:32 AM8/9/04
to
Leo Havmøller wrote:
> You dont need to restart the PC. Just close the application and
> unplug/replug the USB device.
>
> See new thread "User-mode handle and USB device plug/unplug".

I read the thread, but I think it's better to answer here.

As the device developer told me that the methods you mentioned earlier
should be handled/answered correctly, I think it's the app that needs
some improvement.

I read some help about RegisterDeviceNotification and so on. Is it right
to register for DBT_DEVTYP_PORT and then handle WM_DEVICECHANGE in the
app for DBT_DEVICEREMOVEPENDING message and DBT_DEVTYP_PORT in the
DEV_BROADCAST_HDR? Will this be enough or do I need to handle other things?

Many thanks

Robin

Jonas Wetz

unread,
Aug 9, 2004, 8:42:10 AM8/9/04
to
Ok, then I have to write my own inf file and reference the inf file for
usbser.sys with the "layout" directive, but what I exactly want is a usb to
serial port emulation on top of the driver stack above the "normal" driver
that I have for that device. I'm looking for a way to attach the usbser.sys
driver at the top of the driver stack, working simply as an usb to serial
port emulation. Is this possible that way?

Thank you for any help provided

Jonas Wetz

"Alexander Grigoriev" <al...@earthlink.net> schrieb im Newsbeitrag
news:uBOWMD9e...@tk2msftngp13.phx.gbl...


> See "Include" and "Layout" INF directives. You should reference the system
> INF file which describes usbser.sys
>
> "Jonas Wetz" <jw...@kwest.de> wrote in message
> news:eZB$1C6eE...@TK2MSFTNGP12.phx.gbl...
> > I have an additional question regarding this topic. If I understand
> right,
> > I just have to create an .inf file to use the windows internal usb to
> serial
> > port emulation driver "usbser.sys". Does this mean I just have to write
> the
> > file, reference usbser.sys in this file and then I can install the
device
> > using the .inf file? Would an other application be able to handle the
> device
> > connected via usb with the same syntax used for serial ports then?
> >
> > I'm sorry for that stupid question, but I'm completely new to Windows
> driver
> > development.
> >
> > Thanks in advance,
> >
> > Jonas Wetz
> >
> >

> > "Leo Havmøller" <l...@nospamrtx.dk> schrieb im Newsbeitrag


> > news:%23fnxMh5...@TK2MSFTNGP09.phx.gbl...
> > > "> When I plug the device to the system (1st time) it works fine. When
I
> > > > unplug and replug it, it doesn't work anymore (Device Manager:
Windows
> > > > cannot load the drivers reqired, Code 31).
> > >
> > > Do you handle and answer the CDC requests properly (SetLineCoding,
> > > GetLineCoding, SetControlLineState)?
> > > Is any user-mode app keeping the COM port open?
> > >

> > > Leo Havmøller.
> > >
> > >
> >
> >
>
>


Robin

unread,
Aug 9, 2004, 9:28:09 AM8/9/04
to
Jonas Wetz wrote:

> Ok, then I have to write my own inf file and reference the inf file for
> usbser.sys with the "layout" directive, but what I exactly want is a usb to
> serial port emulation on top of the driver stack above the "normal" driver
> that I have for that device. I'm looking for a way to attach the usbser.sys
> driver at the top of the driver stack, working simply as an usb to serial
> port emulation. Is this possible that way?
>

As I understand you, that's exactly what you want. I (try to) do it the
same way. I have the INF file mentioned earlier in this thread (without
the layout.inf included) and it seems to work. What I'm trying to figure
out now ist how to handle the messages in the user-app.

Robin

Alexander Grigoriev

unread,
Aug 9, 2004, 9:35:05 AM8/9/04
to
You have your own driver below USBSER? Then it is causing a failure to
reload. Make sure to handle REMOVE_DEVICE and SURPRISE_REMOVAL correctly.

"Jonas Wetz" <jw...@kwest.de> wrote in message

news:OXlTY5g...@TK2MSFTNGP11.phx.gbl...

Jonas Wetz

unread,
Aug 10, 2004, 3:53:48 AM8/10/04
to
Yes I have a specific driver below USBSER, but it works correctly, just
without the emulation function I want. What I'm actually trying to do is to
just implement the emulation provided by USBSER. My initial question simply
is how to do that best and if it is really that easy just using the inf
file. I mean there has to be some communication of the underlying drivers
with the USBSER driver. Do I have to change the code of my lower level
drivers to make that possible or can I simply create an inf file of my other
driver and reference USBSER driver there?

Hope this helps precising my problem,

Jonas Wetz


"Alexander Grigoriev" <al...@earthlink.net> schrieb im Newsbeitrag

news:uvOGyWh...@TK2MSFTNGP11.phx.gbl...

Robin

unread,
Aug 10, 2004, 4:17:52 AM8/10/04
to
Jonas Wetz wrote:
> Yes I have a specific driver below USBSER, but it works correctly, just
> without the emulation function I want. What I'm actually trying to do is to
> just implement the emulation provided by USBSER. My initial question simply
> is how to do that best and if it is really that easy just using the inf
> file. I mean there has to be some communication of the underlying drivers
> with the USBSER driver. Do I have to change the code of my lower level
> drivers to make that possible or can I simply create an inf file of my other
> driver and reference USBSER driver there?

If you have an underlying driver, it should work for the usbser.sys with
just an inf file, because it doesn't bother the usbser.sys whether there
is a (correctly working) underlying driver or not. But you may need
another (or the same with extension) inf file to load the underlying
driver in a correct way.

0 new messages