Partager via


Windows 7 Sensor and Location API – The API Details

Windows 7 provides a Win32 COM API for working with sensors. There are 3 COM Interfaces:

  • ISensorManager - Sensor enumeration, attachment event, request permissions
  • ISensor - Get and set properties, get report, events (new report, detachment, state change, custom) and more
  • ISensorDataReport - Get sensor data report data fields

clip_image001

clip_image002

clip_image003

 

Sensor COM Interfaces

 

To make developing to this API straightforward for .NET Developers, a .NET Framework COM Wrapper Class Library is provided (note: at the time of this article, the library is offered as open source and is not supported. That said, I have found it to be very stable and easy to use).

image

clip_image007

clip_image008

 

Sensor Wrapper Library

 

Steps to programming to the Sensor API:

Step 1: Enumerate your sensors, all or by Category and type GUIDs

Category represents what is being sensed (for example, environment, location, motion, electrical systems). Type represents how it is being sensed (for example, by thermometer, GPS, accelerometer, voltage)

Step 2: Read, Display and in some cases update Sensor Properties

Each sensor has several properties that you can read and display such as Description, Manufacturer, Serial Number, etc. and some that are updatable like Report Interval.

Step 3: Receive Real-Time Sensors Data and React

Each Sensor raises events that you can hook into. The main event is called ‘DataUpdate’. When you receive this event, you can get the raw data from the sensor and have your application react to it appropriately. It is recommended that you handle this event asynchronously as the sensor will be raising this event continuously.

Back