Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write data to USB HID using JavaScript, HTML5, or any cross platform language (supports Android)

I've written an UI in HTML5 and JavaScript. I chose this implementation so that I could share the same code between both Android Chrome and Windows 8 RT.

Now, my next objective is to write data to a USB HID. The device that I'm communicating with is treated as an HID. I'm mentioning this part in case there's a way to write to an HID device rather than a USB RAW device.

I've done a lot of research on the matter. But, the HTML5 specifications are changing so often that maybe I missed something.

**Anyway, is there a language or implementation that I can use to share common code to access a USB device on Android and Windows 8 RT?

If there isn't a way to share between the two, how about a suggestion to get USB communication only on Android?**


Below is my research along with conclusions:

  • Silverlight: unsupported. In terms of web plugins, it is not supported on Windows 8 RT or Android

  • Flash: Possible option. It is supported in both operating systems, although they removed support for Android with release of Android 4.1 (Jelly Bean).

  • HTML5: unsupported

  • I looked at the GamePad API, but it seems to only support reading from a gamepad.

  • I looked at Device tag, but this tag no longer exists in the current draft. I read that the "navigator" object replaces it in JavaScript, but it seems completely different. Also, Device only targets acquiring video and audio

  • JavaScript: unsupported. From my understanding, this is because it'd be a security risk.

  • Chrome Packaged App: unsupported. I am unsure about support in Windows 8 RT. But, it is not supported in Android Chrome, either.

  • A USB API exists that accomplishes exactly what I need, but the API is only available to a packaged app.

  • Java applet: unsupported. I am unsure about support in Windows 8 RT. But, it is not supported in Android Chrome, either.

  • There are many resources available regarding how to communicate with USB devices. However, since Java applets aren't supported on smartphones, this ends up being unsupported.

  • A couple of useful posts

  • How can I send and receive data to a serial port or USB port in ASP.NET?

  • Is accessing USB from a web application for cross browser cross OS possible at all?

  • Is that possible to provide a JavaScript API to control USB, LPT, and COM devices?

like image 355
cheezy Avatar asked Mar 20 '13 21:03

cheezy


1 Answers

I've actually thought about how to do things similar to this...

Here's is one way sure way to do it if you have control over the computer which has the USB device attached:

Have the computer with the USB device run a web server such as Apache and PHP. Have it only listen to localhost.

Then in the HTML page being viewed, execute an Ajax post to localhost/somescript.php (or CGI or cfm or whatever).

In the PHP/CGI script, communicate to the USB device and then return a JSON string to the browser saying something happened.

Another approach is to use custom URL protocols. You create an executable and "install" it on the client computer along with your custom URL protocol.

Then you can invoke the executable from the browser using your custom URL protocol.

like image 133
Brian McGinity Avatar answered Sep 17 '22 23:09

Brian McGinity