HID device in web player...

Hey there everybody…

I have a problem that i’ve been researching for a while now, and can’t seem to grasp all aspects of it.

I’m looking for a way to connect a USB prototype device (HID compliant) to unity, and use it in a web player build. I am using the pro version, so plug-ins are an option. In device manager inside windows it doesn’t appear as a gamepad, just as a standart HID device. No special driver involved.

As I understand it, this means NO native code plug-ins.
The problem is that the libraries that I’ve found so far (LibUsb, LibUsb-Win32, #usblib, LibUsbDotNet) and other solutions (such as the one in here: A USB HID Component for C# - CodeProject) all eventually use either hid.dll (windows) or libusb0.dll (sort-of-windows).

Now, let’s skip the part where I get tons of DllNotFoundExceptions… please? :roll: Even if I get it running in single player builds, this will not do in the end…

What solution exactly WILL work here?

Lets say that I’m willing to code from scratch (or hire people to do that for a nice fee). What programming language am I allowed to use here, and is it even possible? Do I need to write drivers for both Windows and OSx on the kernel level?

Is there a way to write plug-ins in C# on the Mono or Visual Studio frameworks that will access the USB interface? (And BTW- Does it matter if it’s on VS or Mono?).
How about XCode? There is plenty of code floating around about HID devices, but again… isn’t it C++, C or Objective C? I’m a novice when it comes to programming for OSx, so maybe I’m missing something here?

The closest thing in that area that I could come up with is using System.IO.Ports in Mono, but it only lets you access serial ports… So no go.

A possible (dirty) solution I am considering is maybe having a tiny application to run in the background that will handle the communication between unity and the device using local networking. I rather avoid that one, if possible.

Any insight will help here guys and girls. I appreciate any thought you might have on the matter…

There is no solution. Webplayer stuff and on new browsers everything is run within a secure box.
You will with no means other than hacking the target machine get access to hardware level to hook in USB HID drivers and alike. thats the purpose of the secure sandboxes of IE7+ Firefox 3
The allowed languages are Unity scripting languages.

What you likely will do is offer the application so you can use plugins again. If the filesize is the problem you could use assetbundles which are available in Pro and download the stuff in the background.

Well it’s a HID device right? So technically you could write a driver that makes the device appear to be a joystick and then access the axes using the input manager. This would have to be installed separately. There are also apps available that do this already.

Thanks for the quick response.

Well, I’m looking into this, downloaded Microsoft’s WDK and looking into the documentation to see how complicated this is. Obviously, this is the path I would like to go, but only if it’s reasonable for someone like me who’s going to be writing drivers for the first time…

File size is not a problem at all. For the current project web browser integration is very important, since around the application itself a web site is being built. The site will keep statistics that will come from the application, and allow to create personal profiles that will be used in the application itself…

I’ve been looking into maybe adding an ActiveX OCX control to the web page, that will act as a layer between the unity application and the HID device. Maybe communicate the information using TCP/IP or through calls to javascript.

Has anyone ever tried doing something like that? (I’ve done javascript communication between unity and the web page it’s embedded in, but I have never written an ActiveX control. Especially not one that will need to access windows APIs).

The TCP/IP approach may work, I’ve done something similar to get data to and from a laser scanner.