I've been looking at USB Api to connect to a USB relay.
Using chrome.usb.findDevices I can open the device but then I need to send some data to it. I'm thinking chrome.usb.controlTransfer is the way to do that. I have no idea how to get the ConnectionHandle which I need for the next step.
My findDevices code is below.
Any help would be gratefully received. I'm properly confused.
var usbConnection;
var onOpenCallback = function(connection) {
if (connection) {
usbConnection = connection;
document.getElementById("found").innerHTML ="Device opened.";
} else {
document.getElementById("found").innerHTML ="Device failed to open.";
}
}; chrome
chrome.usb.findDevices(DEVICE_INFO, onOpenCallback);
--
You received this message because you are subscribed to the Google Groups "Chromium Apps" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-app...@chromium.org.
To post to this group, send email to chromi...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-apps/.
For more options, visit https://groups.google.com/a/chromium.org/d/optout.
Brilliant... Thank you Ken
I'll go away and see if I can use getDevices.
Does it have any effect if the device drivers are loaded? Or not. Just something I read.
var onDeviceFound = function(devices) {
this.devices=devices;
if (devices) {
if (devices.length > 0) {
console.log("Device(s) found: "+ devices.length );
console.log("Device: "+ devices[0].device);
}
} else {
console.log("Device could not be found.");
}
};
chrome.usb.getDevices(DEVICE_INFO , onDeviceFound);
var usbConnection = null;
var onOpenCallback = function(connection) {
if (connection) {
usbConnection = connection;
console.log("Device opened.");
} else {
console.log("Device failed to open.");
}
};
chrome.usb.openDevice(device, onOpenCallback);
chrome.usb.findDevices(DEVICE_INFO, function(ConnectionHandle) {
if (ConnectionHandle) {
console.log("Handle " + ConnectionHandle.handle);
}
else {
console.log("Device could not be found.");
}
});