mardi 20 janvier 2015

How read continously hid data on website?

I want read data of hid device on my website. I have seen that it's not possible directly read usb on website but it's possible to use chrome extension to get this data or use webhidapi-firebreath. With the first way, I have a problem to read data (Get hid data on website). Using firebreath, I can read data but I don't understand what it's mean. I have plugged for example a keyboard.


I have test with key 'A', it return : "0000140000000000" and key 'B'"0000050000000000".


Have you an idea to translate this value ?


My second problem is that the page seems busy during the waiting of data. Is it possible to continious listen the data ? Should I have to use multithreading ?


Is there any other way to read data of hid device ?


Thank you for your help


Below the code of my app :


testHidapiBrowser.js :



function pluginLoaded() {
alert("Plugin loaded!");
}

function hidScan() {
console.log("la");
var plugin = document.getElementById("hidapiPlugin");
console.log("plugin", plugin)
var result = plugin.hid_enumerate();
alert("Number of devices " + result.length);
console.log("fin hidScan");
}

function testExchange() {
var plugin = document.getElementById("hidapiPlugin");
var result = plugin.hid_enumerate();
var path;
for (var i=0; i<result.length; i++) {
if (result[i]["vendor_id"] == 0x1241 && result[i]["product_id"] == 0x1603 &&
result[i]["interface_number"] == 0 ) {
path = result[i]["path"];
break;
}
}
if (typeof path == "undefined") {
alert("Device not found");
return;
}
var device = plugin.hid_open_path(path);
if (device == null) {
alert("Error opening device");
return;
}
console.log("device opened ");
i =device.hid_read(65);
console.log("result ",i);
device.close(device);
}


testHidapiBrowser.html



<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<script src="testHidapiBrowser.js"></script>
<object id="hidapiPlugin" type="application/x-hidapibrowserplugin" width="300" height="300">
<param name="onload" value="pluginLoaded" />
</object><br />

<a href="#" onclick="javascript:hidScan()">HID Scan</a> <br />
<a href="#" onclick="javascript:testExchange()">Exchange</a><br/>
</body>
</html>

Aucun commentaire:

Enregistrer un commentaire