lpwnd
驱动小牛
驱动小牛
  • 注册日期2003-03-04
  • 最后登录2012-01-20
  • 粉丝0
  • 关注0
  • 积分2分
  • 威望1点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1100回复:0

idea

楼主#
更多 发布于:2003-10-16 19:32
I\'ll give this a shot, not that I am a driver expert (nor do I dispute
Walter\'s claim you have to be - just that I did one last year for a
USB to Serial device and can explain my approach to get you started).

The 2k driver (the easiest) I developed was done the following way
(because of the design approach I took and to allow more of a shared
base, I used a 3 driver approach, the underlying USB driver to handle
the device, a serial bus enumerator to handle the usb pnp - virtual
serial port creation, and the serial driver, loaded from the
enumerator.  The steps to create the serial driver are outlined:
(these are not detailed, but an overview giving you a jumping off
point to get started).

1. start from the DDK toaster example, it has most of the power mgmnt
and pnp code in it - and start adding on from this base.
2. write a test app - one that intially just uses file i/o to talk to
your driver.  Don\'t start with a full blown comm app (like hyperterm)
- it\'ll expect everything to be supported and you\'ll get caught up in
the details.  Use the canned comm apps to test your final driver - and
several of them, because each have their unique way of handling serial
ports.
3. you will need routines to handle IRP_MJ_CREATE, IRP_MJ_CLOSE,
IRP_MJ_READ, and IRP_MJ_WRITE to handle i/o to/from the device.  In
these, more thought has to be given to your device demands.  For
instance, I had to buffer i/o, so alot of work had to be toward proper
handling and queueing irps, plus buffering the i/o data.  You can
kluge up data i/o by just completing the writes and copying static
data into the reads to pass back up to an app.
4. alot of work will be in the IRP_MJ_DEVICE_CONTROL routine, which is
the dispatch for the serial ioctls - here you have to understand the
workings of a serial port to make sense of the serial IOCTLs and what
they really mean.

My resources and ideas came from the following:
1. A Microsoft USB Point of Sale driver out on the web (look for
usbpos).  I grabbed the mechanism to create a virtual serial port from
it (not much else though, because it really isn\'t that great of a
driver - the problems it has will kill you in the long run - I know -
I try to kluge from it and ended up scrapping it - but it was good for
example code).
2. Walter\'s WDM book, grabbed various examples to complete individual
tasks, for instance I used his repeater irp example and built on it to
complete a mechanism in the enumerator (again, buitl from the DDK
toaster bus example).
3. The USBPOS lists the serial IOCTLs you need to handle, but use your
own ideas because you will need to handle serial flags and handshaking
in a virtual environment - I mapped a virtual UART in memory and wrote
the supporting code.
4. The DDK help - not exacting about everything - but invaluable none
游客

返回顶部