Upload
deborah-lancaster
View
57
Download
2
Tags:
Embed Size (px)
DESCRIPTION
Developing WIA Drivers Byron Changuion Developer Windows Imaging Group Microsoft Corporation. Preamble. What is this presentation about? Selected topics regarding development of WIA mini-drivers (“full” WIA drivers) This talk is not necessary for you, if your device is: - PowerPoint PPT Presentation
Citation preview
Developing WIA DriversDeveloping WIA Drivers
Byron ChanguionByron ChanguionDeveloperDeveloperWindows Imaging GroupWindows Imaging GroupMicrosoft CorporationMicrosoft Corporation
PreamblePreamble What is this presentation about?What is this presentation about?
Selected topics regarding development of Selected topics regarding development of WIA mini-drivers (“full” WIA drivers)WIA mini-drivers (“full” WIA drivers)
This talk is not necessary for you, if This talk is not necessary for you, if your device is:your device is: PTP camera or Mass Storage devicePTP camera or Mass Storage device
Class driver existsClass driver exists Simple flatbed scannerSimple flatbed scanner
Can write “micro-driver” insteadCan write “micro-driver” instead
AgendaAgenda Overview of WIA ComponentsOverview of WIA Components WIA Item TreesWIA Item Trees Run-time behavior of WIA DriversRun-time behavior of WIA Drivers Troubleshooting and DebuggingTroubleshooting and Debugging Hints and TipsHints and Tips What can What can youyou do next? do next?
WIA Component WIA Component ArchitectureArchitecture
Process Process boundaryboundary
STI STI InterfaceInterface WIA / STI serviceWIA / STI service
TWAIN Data TWAIN Data SourceSource
Microsoft Microsoft ComponentComponentIHV ComponentIHV ComponentISV ComponentISV Component
KeyKey
USB DriverUSB Driver 1394 Driver1394 Driver SCSI DriverSCSI Driver Serial DriverSerial Driver
USDUSD
WIA ApplicationWIA Application
User ModeUser Mode
Kernel ModeKernel Mode
USDUSD
TWAIN ApplicationTWAIN Application
COM ProxyCOM Proxy
Default UIDefault UI Optional Optional vendor UIvendor UI
WIA Item TreesWIA Item TreesGeneralGeneral
Device (and any data) represented Device (and any data) represented by “Items”by “Items”
Two kinds of itemsTwo kinds of items Driver items and Application itemsDriver items and Application items
Driver creates tree of Driver itemsDriver creates tree of Driver items WIA Service will build copy of tree for WIA Service will build copy of tree for
applications (using Application items)applications (using Application items)
WIA Item TreesWIA Item TreesGeneralGeneral
RootRootIWiaItemIWiaItem
Second ChildSecond ChildIWiaItemIWiaItem
First ChildFirst ChildIWiaItemIWiaItem
Application 2Application 2
RootRootIWiaItemIWiaItem
Second ChildSecond ChildIWiaItemIWiaItem
First ChildFirst ChildIWiaItemIWiaItem
Application 1Application 1
RootRootIWiaDrvItemIWiaDrvItem
Second ChildSecond ChildIWiaDrvItemIWiaDrvItem
First ChildFirst ChildIWiaDrvItemIWiaDrvItem
WIA DriverWIA Driver
WIA Item TreesWIA Item TreesGeneralGeneral
Each Application item has its own Each Application item has its own property streamproperty stream
Service will call driver to set initial Service will call driver to set initial property valuesproperty values
Driver notified when Application Driver notified when Application reads/writes propertiesreads/writes properties
WIA Item TreesWIA Item TreesItem TypesItem Types
Informs applications how to treat an Informs applications how to treat an itemitem For example, For example, WiaItemTypeAudioWiaItemTypeAudio
Item types are not exclusiveItem types are not exclusive For example, For example,
((WiaItemTypeFile | WiaItemTypeImageWiaItemTypeFile | WiaItemTypeImage)) Driver specifies item type when it Driver specifies item type when it
creates the itemcreates the item
WIA Item TreesWIA Item TreesAnnotationsAnnotations
Some data may be associated with other Some data may be associated with other datadata Example: Audio recording for a pictureExample: Audio recording for a picture
WIA represents annotations with WIA represents annotations with child-itemschild-items
Items with annotations have special Items with annotations have special item type flagsitem type flags
WIA Item TreesWIA Item TreesAnnotations: ExampleAnnotations: Example
Audio Annotation for Picture 1(WiaItemTypeFile | WiaItemTypeAudio)
Picture 1(WiaItemTypeFile | WiaItemTypeImage)
Picture 2(WiaItemTypeFile | WiaItemTypeImage)
Audio Annotation for Picture 1(WiaItemTypeFile | WiaItemTypeAudio)
Picture 1(WiaItemTypeFile | WiaItemTypeImage | WiaItemTypeHasAttachments)
Picture 2(WiaItemTypeFile | WiaItemTypeImage)
Data on Data on DeviceDevice
WIA Item treeWIA Item treeRepresentationRepresentation
WIA Item TreesWIA Item TreesInteractions with DriverInteractions with Driver
Image data exposed through itemsImage data exposed through items Characteristics exposed through Characteristics exposed through
properties, for exampleproperties, for example CamerasCameras
Picture width / height, Time picture Picture width / height, Time picture was taken, and so onwas taken, and so on
ScannersScanners Set resolution, Set data type, and so onSet resolution, Set data type, and so on
WIA Item TreesWIA Item TreesInteractions with DriverInteractions with Driver
Microsoft ComponentMicrosoft Component
IHV ComponentIHV Component
ISV ComponentISV Component
KeyKey
WIAWIA
DriverDriver
ApplicationApplication
Read Property XRead Property X
drvReadItemPropertiesdrvReadItemProperties If needed, return If needed, return new value for Xnew value for X
Current value for XCurrent value for X
WIA updates WIA updates property storageproperty storage
Reading Property ExampleReading Property Example
WIA Item TreesWIA Item TreesInteractions with Driver: ExampleInteractions with Driver: Example
Walk through sample codeWalk through sample code
WIA Item TreesWIA Item TreesInteractions with DriverInteractions with Driver
WIAWIA
DriverDriver
ApplicationApplication
Write Property XWrite Property X
1.1. drvValidateItemPropertiesdrvValidateItemProperties
Return appropriateReturn appropriateerror codeerror code
2.2. Driver updates Driver updates dependant propertiesdependant properties
3.3. Driver calls generic Driver calls generic property validation property validation helperhelper
4.4. Helper returns errorHelper returns error5.5. Driver returns errorDriver returns error
WIA performs rollback by WIA performs rollback by restoring property streamrestoring property stream
Writing Invalid Property Writing Invalid Property ExampleExample
Microsoft ComponentMicrosoft Component
IHV ComponentIHV Component
ISV ComponentISV Component
KeyKey
Run-Time BehaviorRun-Time BehaviorUpdating the Driver TreeUpdating the Driver Tree
Drivers may add and/or remove WIA Drivers may add and/or remove WIA items, for exampleitems, for example Take pictureTake picture Delete pictureDelete picture
Need to let applications knowNeed to let applications know Use WIA events, for exampleUse WIA events, for example
WIA_EVENT_ITEM_CREATEDWIA_EVENT_ITEM_CREATED WIA_EVENT_ITEM_DELETEDWIA_EVENT_ITEM_DELETED WIA_EVENT_TREE_UPDATEDWIA_EVENT_TREE_UPDATED
Run-Time Behavior Run-Time Behavior Updating the Driver Tree: ExampleUpdating the Driver Tree: Example
Walk through sample codeWalk through sample code
Run-Time Behavior Run-Time Behavior drvInitializeWia / drvUnitializeWiadrvInitializeWia / drvUnitializeWia
Used to bracket application sessionsUsed to bracket application sessions Similar to AddRef / ReleaseSimilar to AddRef / Release
Can use to maintain session Reference Can use to maintain session Reference CountCount
Multiple drvInitializeWia calls can Multiple drvInitializeWia calls can be made before the equivalent be made before the equivalent drvUninitializeWia calls (i.e., can drvUninitializeWia calls (i.e., can more than one active session)more than one active session)
Run-Time Behavior Run-Time Behavior drvInitializeWia / drvUnitializeWia: drvInitializeWia / drvUnitializeWia: ExampleExample
Walk through sample codeWalk through sample code
Run-Time Behavior Run-Time Behavior drvNotifyPnPEventdrvNotifyPnPEvent
Called AsynchronouslyCalled Asynchronously Plug and PlayPlug and Play
WIA_EVENT_DEVICE_CONNECTEDWIA_EVENT_DEVICE_CONNECTED WIA_EVENT_DEVICE_DISCONNECTEDWIA_EVENT_DEVICE_DISCONNECTED
Power ManagementPower Management WIA_EVENT_POWER_SUSPENDWIA_EVENT_POWER_SUSPEND WIA_EVENT_POWER_RESUMEWIA_EVENT_POWER_RESUME
I/O CancellationI/O Cancellation WIA_EVENT_CANCEL_IOWIA_EVENT_CANCEL_IO
Run-Time Behavior Run-Time Behavior drvNotifyPnPEvent: ExampledrvNotifyPnPEvent: Example
Walk through sample codeWalk through sample code
TroubleshootingTroubleshooting WIA Service Log fileWIA Service Log file
%windir%\wiadebug.log%windir%\wiadebug.log Turn on Warnings and Errors:Turn on Warnings and Errors:
[HKLM\System\CurrentControlSet\Control\ [HKLM\System\CurrentControlSet\Control\ StillImage\Debug\wiaservc.dll]StillImage\Debug\wiaservc.dll]
““DebugFlags = 0x3”DebugFlags = 0x3” Example snippet:Example snippet:wiasValidateItemProperties, invalid RANGE value for : wiasValidateItemProperties, invalid RANGE value for : (propID) Horizontal Start Position, value = 3000(propID) Horizontal Start Position, value = 3000Valid RANGE is: MIN = 0, MAX = 1274, STEP = 1Valid RANGE is: MIN = 0, MAX = 1274, STEP = 1
DebuggingDebuggingOverviewOverview
Why use a debugger?Why use a debugger? Driver faults (without debugger - service Driver faults (without debugger - service
will catch and simply return “failed”)will catch and simply return “failed”) Service faults (without debugger – service Service faults (without debugger – service
process is terminated)process is terminated) When do you start the debugger?When do you start the debugger?
Automatically on startupAutomatically on startup Attach at run-timeAttach at run-time
DebuggingDebugging
Hints And TipsHints And Tips USD does not show U.I.!USD does not show U.I.! Multiple instances of driver Multiple instances of driver
when using STIwhen using STIProcess Process boundaryboundary
STI STI InterfaceInterface WIA / STI serviceWIA / STI service
TWAIN Data TWAIN Data SourceSource
Microsoft Microsoft ComponentComponent
IHV ComponentIHV Component
ISV ComponentISV Component
KeyKey
USB DriverUSB Driver 1394 Driver1394 Driver SCSI DriverSCSI Driver Serial Serial DriverDriver
USDUSD
WIA ApplicationWIA Application
User ModeUser Mode
Kernel ModeKernel Mode
USDUSD
TWAIN TWAIN ApplicationApplication COM ProxyCOM Proxy
Default UIDefault UI Optional Optional vendor UIvendor UI
Hints And TipsHints And Tips IWiaMiniDrvIWiaMiniDrv portion of driver only portion of driver only
initialized and/or used when application initialized and/or used when application talks WIAtalks WIA
drvInitializeWiadrvInitializeWia / / drvUnitializeWiadrvUnitializeWia not not used to indicate driver loading used to indicate driver loading or unloadingor unloading
Use WIA’s pre-defined Use WIA’s pre-defined Event GUIDsEvent GUIDs for for Scan, Fax, and so onScan, Fax, and so on
What Can What Can YouYou Do Next Do Next Reference the platform SDK/DDKReference the platform SDK/DDK For more technical details about WIA For more technical details about WIA
driver developmentdriver development http://www.microsoft.com/http://www.microsoft.com/hwdevhwdev//wiawia
For information about WHQL testingFor information about WHQL testing http://www.microsoft.com/http://www.microsoft.com/hwtesthwtest
Send e-mail toSend e-mail to [email protected]@microsoft.com