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

前端 未结 5 488
太阳男子
太阳男子 2021-02-04 08:24

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 ob

相关标签:
5条回答
  • 2021-02-04 08:48

    Please have a look at JSFS. It works similar to Chris_vr's approach and is already a working solution.

    https://github.com/jsfsproject/jsfs. It's free and licensed under GPL.

    0 讨论(0)
  • 2021-02-04 08:50

    Writing to a serial port:

    var writeSerial = function(str) {
      chrome.serial.write(connectionId, str2ab(str), onWrite);
    }
    
    // Convert string to ArrayBuffer
    var str2ab = function(str) {
      var buf = new ArrayBuffer(str.length);
      var bufView = new Uint8Array(buf);
      for (var i=0; i<str.length; i++) {
        bufView[i] = str.charCodeAt(i);
      }
      return buf;
    }
    

    More is at http://developer.chrome.com/apps/app_hardware.html.

    0 讨论(0)
  • 2021-02-04 08:59

    There is one more alternative Web Socket.Create a web socket server which will access the usb device in local system.

    Connect your web server using Web Socket from Web Application.Web Socket has standard Api

    You can do something like this

      var host = "wss://localhost:25000/test";
    
      Websokcet ws = new WebSocket(host);
    

    You can create your web sokcet Server using RFC 6455

    for older browser you can think of http server as well.

    0 讨论(0)
  • 2021-02-04 09:04

    If the USB device you want to control is a barcode printer, you can use jZebra.

    This is an applet which directly communicates to locally connected printers.

    0 讨论(0)
  • 2021-02-04 09:05

    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.

    0 讨论(0)
提交回复
热议问题