[#KINECTSDK] Kinect Missile Launcher (II): moving the rocket missile launcher



In the post yesterday explaining how to work with a HID device. Today we will see how to work with it, sending information to the device.

The first thing we must do is decide that library will use to work with a HID device. In my case I will use one that works pretty well, created by Florian Leitner-Fischer, and that can be downloaded from here.

In the post on the previous link, Florian explains the necessary groundwork about how works its creation. In this post we will do the following:

  • Connect to the device
  • Validate the connection
  • Send a message to move the Lance missiles USB

For this we follow the following steps

1. Create a console application

2. Add a reference to the USBHIDDRIVER library


3 Change the settings so that the application is X 86, rather than AnyCPU

4. Already we have our application list

Next we need to determine the VendorId and ProductId of our application. While we saw in the previous post, the following lines of code show us all HID devices you have connected

   1: var getAllDevices = new USBHIDDRIVER.USBInterface("_");

   2: getAllDevices.Connect();

   3: var devices = getAllDevices.getDeviceList();

   4: foreach (var device in devices)

   5: {

   6:     Console.WriteLine("device: " + device);

   7: }

When we run the application, we see this output in the console Windows

device: \\?\hid#vid_413c & pid_3012 # 7 & 39484631 & 0 & 0000 # {4d1e55b2-f16f-11cf-88cb-001111000030}

device: \\?\hid#vid_0a81 & pid_ff01 # 7 & b08aa68 & 0 & 0000 # {4d1e55b2-f16f-11cf-88cb-001111000030}

Assuming that our device is the second, the values be thus:

  • VendorId = vid_0a81
  • ProductId = pid_ff01

If for example move the missile down, we have to pass an array of bytes with 2 elements, zero and two. The code would be as follows:

   1: var usb = new USBHIDDRIVER.USBInterface(@"vid_0a81", @"pid_ff01");

   2: usb.Connect();

   3: var startCMD = new byte[2] {0, 2};

   4: // move down

   5: usb.UsbDevice.writeDataSimple(startCMD);

Well, if you you’ve downloaded the library of Florian, you see that the writeDataSimple() function does not exist. This is because Florian adds a double validation process to send always "clean" arrays to USB devices.

I am a person who lives to the limit and since I have no fear of the BSOD, create the following function to send messages to the device.

   1: public bool writeDataSimple(byte[] bDataToWrite)

   2: {

   3:     var success = false;

   4:     if (getConnectionState())

   5:     {

   6:         try

   7:         {

   8:             var myOutputReport = new OutputReport();

   9:             success = myOutputReport.Write(bDataToWrite, myUSB.HidHandle);

  10:         }

  11:         catch (AccessViolationException ex)

  12:         {

  13:             success = false;

  14:         }

  15:     }

  16:     return success;

  17: }

The previous function avoids validations on the buffer to send to the device and sends directly to the array of bytes. On many occasions this might return us a false or throw an exception not handled, but if we already know that the Lance missile works with a buffer of 2 bytes, because we have it easier.

Now, for this information I returned using the SimpleHIDWrite tool. The same when you select a device shows the number of items must have the input array.


In my case, and knowing that they were 2 bytes to implement buffer writing, because I began to try the method of trial/error and came to the following values:

  • 00, 00. Stop
  • 00, 01. Down
  • 00, 02. Up
  • 00, 04. Rotation schedule anti
  • 00, 08. Rotation schedule
  • 00, 10. It shoots missiles

With this data I already have almost everything to start. But of course, in the way I find that CodePlex is a project that already gives me interaction with the Lance missiles, with the Wii remote, etc. But of course, it doesn’t work the first and I have no place to write why. But they have an implementation of a class Rocket, the truth is that is very well.

So I replaced the component used for connection with the HID, I’ve done a little refactoring and I has been a class with the following structure.


Is now only a little work with KinectSDK and ready!




Saludos @ Home

El Bruno

image image image

1 comment

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: