(转载)drivers for serial-attached devices
march 15, 2003 【程序编程相关:容器(Container)】 【推荐阅读:一些编程的心得】walter oney 【扩展信息:applet学习笔记1《转贴》】copyright © 2003 by walter oney. all rights reserved
i´ll explain in this article how to write a driver for a device that attaches to a serial port in a pc. with the advent of the universal serial bus, the standard rs-232 serial port has become much less important as an attachment point for pc hardware. one still finds devices that attach this way, though, including smartcard readers, bar code scanners, and one-off laboratory instruments.
the first section of the article describes the overall architecture of a driver for a serial-attached device and explains some of the factors you will need to consider in designing your hardware and in deciding which os platforms to support. the second section contains sample code for inclusion in a wdm driver for a device that provides a plug and play identification string. the third section discusses how you would write an equivalent vxd driver for the windows 9x/me platforms. the fourth and final section of this article describes the alterations you would want to make to your driver package for a seriously stupid device that doesn´t provide a pnp id.
overview:
let´s suppose you need to write the driver for a widget that connects to a pc through a standard serial port, as shown in figure one:
figure one
a serial-attached widgetyour driver fits into the system into the system between the serial port driver and other drivers, as suggested by figure two:
figure two
driver architecture for serial-attached devicefigure two doesn´t, unfortunately, accurately describe the stack of drivers that you´ll end up with in a real situation. think of it as an architectural picture that shows the logical flow information. to see an accurate picture, we have to know which os platform we´re talking about and whether our widget has a pnp id.
widgets with pnp identifiers, windows 2000 and later systems:
if your device follows the standard described in the plug and play external com device specification to provide a pnp id, the system serenum.sys driver will find your widget whenever it enumerates the serial port to which the end user has attached it. in this situation, serenum will act as a bus driver and create a physical device object (pdo) to represent the widget. your driver will be a standard wdm function driver that the pnp manager loads automatically. using a tool such as the devview utility that accompanies programming the microsoft windows driver model second edition (microsoft press 2003), you could inspect the tree of device objects to generate a picture like figure three:
figure three
driver stack for widget with pnp idin this figure, serenum appears twice: once in its role as an upper filter for a serial port, and once in its role as the bus driver that enumerates your widget.
in this architecture, serenum reads the pnp id from your widget. the id will be a pseudo-eisa identifer of the form xyz1234, where "xyz" is a 3-letter manufacturer prefix and "1234" is a 4-digit hex number you choose to differentiate your products, one from the other. todo describe how to obtain the 3-letter prefix. the inf file in your driver package will have a model statement like this one:
"acme widget model 101 (pnp)"=driverinstall,serenum\xyz1234
... 下一页