Home .Net PowerMate programming in .Net – Part 1
formats

PowerMate programming in .Net – Part 1

I’m currently working on using the Griffin PowerMate USB device from .Net.

The PowerMate is a beautiful little rotary controller made of brushed steel with a blue “underglow” LED light. You can rotate it and click it, and that’s basically all. It does one thing, and does it well. Steve would have liked it.

The PowerMate costs $45 from Griffin’s webshop, and they charge only $8 to ship it all the way to Norway. Even though Griffin’s webpage  only states compatibility with Windows XP and Vista (and OSX, of-course), the device runs just fine on my Windows 7 x64 laptop. IIRC, I didn’t have to do anything out of the ordinary when I installed it. It comes with an application that can map rotation and clicks to keyboard events, mouse events, volume control, power control, file open and misc iTunes events.

I plan on using it to control my favourite Digital Audio Workstation, Ableton Live, through a small self-made program that reads the rotation and click events from the PowerMate and translates it into MIDI, easily digestible by AbletonLive.

But first, I had to figure out how to talk to the PowerMate. I emailed Griffin support and Jitin was kind enough to send me the HID specifications for the PowerMate, together with some sample code. For more information about Human Interface Devices (HID) programming, visit the excellent HID page. The example from Griffin was a MFC-based C++ application. It required the Windows Driver Kit. To use the WDK, you also need the latest version of the Windows SDK, or you’ll get compile errors looking like this:

c:\program files (x86)\microsoft visual studio 10.0\vc\include\crtdefs.h(543): error C2065: ‘_In_opt_z_’ : undeclared identifier
c:\program files (x86)\microsoft visual studio 10.0\vc\include\new.h(52): error C2065: ‘_In_opt_’ : undeclared identifier

The version of the Windows SDK that comes with VisualStudio won’t work with the latest WDK. Also, make sure you add the include and lib directories before any Visual C++ directories, or you’ll get the same type of errors. In Visual Studio, go to “Project | Properties | VC++ Directories” and set “Include Directories” to something like this:

$(WindowsSdkDir)include
$(VCInstallDir)include
$(VCInstallDir)atlmfc\include
$(FrameworkSDKDir)\include
E:\programs\WinDDK\7600.16385.1\inc\api
E:\programs\WinDDK\7600.16385.1\inc\ddk

And the “Library Directories” to something like this:

$(WindowsSdkDir)lib
$(VCInstallDir)lib
$(VCInstallDir)atlmfc\lib
$(FrameworkSDKDir)\lib
E:\programs\WinDDK\7600.16385.1\lib\win7\i386

The sample application from Griffin has a simple user interface that lets you control LED intensity and LED pulsing, as well as read knob rotation and button state.

The sample application and the PowerMate HID spec was great for understanding the protocol used to talk to the PowerMate.

I wanted to inspect the actual data being sent to and from the device, and stumbled upon a USB packed sniffer called Busdog. I had to enable unsigned drivers to get it to work on my Windows 7 x64 laptop (described in this article). This tool is great for tracking down protocol related bugs, and I ended up using it a lot. In the end, I had to uninstall it (disabling unsigned drivers in the process), as it made my laptop unstable with regards to hibernation.

The sample code uses MFC, which is a bit long in the tooth. Now, I’ve done my fair share of MFC programming in the past, so I guess I could have based my PowerMate-to-MIDI application on the MFC-based sample, but since I’m working mostly with C# and .Net these days (and enjoying it), I decided to do it the .Net way instead.

This is work in progress, and I’ll do another post when the .Net part is done.

More information can be found on the project page.

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
3 Comments  comments 

3 comments on “PowerMate programming in .Net – Part 1

  1. Marc on said:

    Any more luck in that code? Unfortunately for me the Powermate didnt work in windows 7. Actually could you tell me what version of Powermate your running? incase there is a new version that i cant get to.

  2. Thomas Hammer on said:

    Hi Marc.

    I’ve come far with regards to talking to the PowerMate from C#. I’ll do a writeup and post code soon.

    The PowerMate hardware doesn’t have any version information on it. On the software side, I’m running version 2.0.1 for XP & Vista from http://www.griffintechnology.com/support/powermate.

    Here’s what I did to install it on my Windows 7 x64 computer, step for step.

    1. Uninstall any previous versions of the PowerMate software.
    2. Make sure the PowerMate is unplugged.
    3. Run the installer for PowerMate version 2.0.1 for XP & Vista from http://www.griffintechnology.com/support/powermate.
    4. Windows 7 will pop up a User Account Control dialog – say yes :-) .
    5. Accept license agreement and finish the installation.
    6. Plug in the PowerMate. On my computer, the disk drive was busy for about 45 seconds, but I got no notifications about any driver being installed.
    7. From the Start Menu, run Griffin Technology | PowerMate | PowerMate.
    8. Apparently, nothing happens, but there is now a small PowerMate icon in the notification area of the taskbar.
    9. Double-click the PowerMate icon to bring up the PowerMate application.
    10. Click on the small arrow-in-a-box in the lower left corner of the PowerMate application.
    11. A list of PowerMates should pop up. Click on one of them, and the PowerMate LED should pulse for a second.
    12. Click on Global Setting in the upper left corner of the application.
    13. Click on one of the actions in the list.
    14. Select an action type in the drop-down box in the lower right part of the application. Try “Scroll up” and “Scroll down” first.
    15. Select some other application that reacts to scrolling and try rotating the PowerMate knob to see if you can now control scrolling in any application with the PowerMate.

    The PowerMate application must be running for this to work. It stays in the notification area of the task-bar until you selects “File | Exit” from the menu.

    Hope this can be of any help to you, Marc. Let me know how it works out.

  3. Brilliant Thomas…………..It works!

    Thanks for the step-by-step!

Leave a Reply to Thomas Hammer Cancel reply

Your email address will not be published. Required fields are marked *

*

HTML tags are not allowed.