Creating a sensor driver
If your sensor uses HID we recommend that rather than creating a driver, you use the inbox HID class driver. If your sensor uses a transport other than HID, you should start with either the Sensors Geolocation Driver Sample or the SpbAccelerometer sample.
These samples provide basic working implementations for the classes and COM interfaces required by a sensor driver. The following procedure shows the steps that you should follow to create a driver from the samples:
Follow the instructions that are provided in the Creating a Persistent Unique Identifier topic to make sure that your driver is unique. When you work with the sample driver source, always provide new GUIDs and other identifiers.
Add a class to handle communication with your device hardware, or with the software data provider if your sensor is a logical sensor.
Add support for events, as needed. You have to write code to create a thread to raise events at a particular time interval. You also have to update the implementation for ISensorDriver::OnGetSupportedEvents in SensorDdi.cpp to report the list of events that the driver can raise.
Remove any code that is not needed.
Building the Driver
To build your driver, follow these steps:
- Start Microsoft Visual Studio 2012.
- Select the build configuration (for example, Debug) and the architecture (for example, Win32).
- Open your driver's solution or project file.
- Choose Build/Build Solution.
Installing the Sensors Geolocation Driver Sample for Testing
To install your driver for testing, follow these steps:
Make sure that your driver builds without errors.
Copy the DLL and INF files for your driver to a separate folder.
Locate the two co-installer DLL files (either checked or free) from the redist/wdf/processor_type folder where you installed the WDK. Copy these files to the folder that you created in step 3. For example, if you installed the WDK on your drive C, you might copy WUDFUpdate_01009.dll from C:\WinDDK\build#\redist\wdf\x86.
Run Devcon.exe. You can find this program in the tools\devcon folder where you installed the WDK. For example, for a sensor named WDKExample, you type:
devcon.exe install WDKExample.inf "Sensors\WDKExample"
Note Do not use Devcon.exe to install released drivers. This recommendation is for testing only.
If your driver cannot be installed, it is likely that one of the methods in step 2 returned an error code. To debug this problem, you must attach a debugger during installation. For information about how to debug UMDF drivers during loading, see Determining Why the UMDF Driver Fails to Load or the UMDF Device Fails to Start.
You should also verify that the class ID that you provided in the INF file matches the GUID that you used in the IDL file for the driver's coclass.
Uninstalling the Driver
You may have to uninstall the driver during testing, for example when you want to update the driver installation after you make a change to the code. To uninstall the driver, follow these steps:
Open Device Manager. For example, click Start, then in the Start Search box, type the following.
After that, press CTRL + ENTER.
Expand the Sensors node.
Right-click the name of your driver, and then click Uninstall.
Select Delete the driver software for this device.