HIDWrappers v1.09 & CTemperDevice v1.09
The classes provided are HID::CDevice which provides
a simple RAII wrapper for programming to the HID API on Windows and
HID::CTemperDevice which derives from HID::CDevice which encapsulates the
Temper USB thermometer.
Features
- Provides two simple C++ Header only modules to easily encapsulate HID
and the Temper device.
- Integrates with STL's and MFC's collection and string classes for easier client coding.
- Provides a RAII wrapper for the HANDLE returned from the CreateFile call when opening a
HID device.
- The HID wrapper class also provides generic enumeration of HID devices
given a device interface GUID, a USB PID and / or VID.
Usage
- To use the HID class in your project simply #include
HIDWrappers.h in your application.
- If you would like to use the Temper class in your project simply
#include TemperWrappers.h in your application.
- The classes are only supported on VC 2017 or later.
- Included in the download is a VC 2017 console based test application which
exercises all of the various functionality. If the sample app detects that
you have an Temper HID device attached to your computer (with a VID of 0xC45
and PID of 0x7401) then it
will initialize the device and spin in a loop reading the temperature from
the device every second. For more information about using this device from
Windows, please see
http://www.codeproject.com/Tips/1007522/Temper-USB-Thermometer-in-Csharp
on which the CTemperDevice code is partly based. Please note that some of
the information in this CodeProject article is incorrect as it mislabels
what it calls the "Control" interface. This interface is in fact the
"Interface 0" keyboard emulation interface exposed by the Temper devices.
Windows versions since Windows 2000 denies user mode code low level access to any
Keyboard or Mouse USB interface and the C# code from this article will fail
to open this interface with an Access Denied Error message. The temperature
related functionality of the device is on "Interface 1" anyway.
- For examples of interfacing to the Temper device please see the source
code of the demo application in the HIDWrappersDemo.cpp module in the
download.
- Please note that there are many variants of the Temper device being
sold. As it stands the CTemperDevice code has been tested with a device
which returns a VID of 0xC45, a PID of 0x7401 and with the initialization
strings as defined at the top of the HIDWrappersDemo.cpp module. Also the
version of the device I tested the code with returns the raw temperature
value in the sixth and seventh byte of the returned HID report of nine bytes
in total. The sample app will report the raw data sent and received from the
device so it should not be too difficult to change the code to suit other
devices. If you are interested in this you might want to check out
USBPcap and
WireShark to capture
USB traces to see how I reverse engineered the data my device generates.
If you have other variants of the Temper device please try the sample app
with it and drop me an email and we should be able to get the code working
with your variant of the device.
Copyright
- You are allowed to include the source code in any product (commercial, shareware,
freeware or otherwise) when your product is released in binary form.
- You are allowed to modify the source code in any way you want except you
cannot modify the copyright details at the top of each module.
- If you want to distribute source code with your application, then you are
only allowed to distribute versions released by the author. This is to maintain
a single distribution point for the source code.
History
v1.09 (13 April 2022)
- Updated copyright details.
- Added #pragma once to header file.
v1.08 (11 February 2022)
- Updated copyright details.
- Updated the code to use C++ uniform initialization for all variable
declarations.
v1.07 (21 February 2021)
- Updated copyright details.
- Reworked CDevice::EnumerateDevices to use std::vector<BYTE> for its
internal temporary buffer.
- Reworked CDevice::EnumerateDevices to use unary predicates and
lambdas.
- Provided new public CDevice::GetVendorID and GetProductID methods.
v1.06 (12 January 2020)
- Updated copyright details.
- Fixed more Clang-Tidy static code analysis warnings in the code.
v1.05 (16 December 2019)
- Fixed various Clang-Tidy static code analysis warnings in the code.
v1.04 (26 August 2019)
- Extended the CDevice::Open method to allow the "dwFlagsAndAttributes"
parameter to be passed to the CreateFile API call.
v1.03 (6 May 2019)
- Updated copyright details.
- Updated the code to clean compile on VC 2019
v1.02 (18 August 2018)
- Updated copyright details.
- Fixed a number of C++ core guidelines compiler warnings. These changes
mean that the code will now only compile on VC 2017 or later.
- Removed code which supported HIDWRAPPERS_MFC_EXTENSIONS
preprocessor.
v1.01 (28 November 2017)
- Updated copyright details.
- Replaced BOOL throughout the codebase with bool.
- Replaced CString::operator LPC*STR() calls with CString::GetString calls
v1.0 (27 December 2015)
Contacting the Author
PJ Naughter
Email: pjna@naughter.com
Web: http://www.naughter.com
13 April
2024