chrome.usb.findDevices not working shows error message Failed to open device: Entity not found in chrome://device-log/

834 views
Skip to first unread message

Santinath Mishra

unread,
Mar 22, 2016, 11:31:58 PM3/22/16
to Chromium-dev
Hi Folks,

I am developing a chrome app to communicate to HID device using chrome.usb APIs. I am using below chrome APIs

1. chrome.usb.findDevices
2. chrome.usb.controlTransfer

So far I am not able to make it work. chrome://device-log/ shows below error message. 

USBEvent[13:54:01] Failed to open device: Entity not found

I am using right VendorId and ProductId in decimal format, Which I have extracted from device manager info.


Does anyone know about this issue? Any kind of help will be highly appreciated.



Below is the code snippet I am using.

    chrome.usb.findDevices(DEVICE_INFO, function (devices) {
        if (!devices || !devices.length) {
            console.log('device not found');
        }

        console.log("Devices: " + devices);
        console.log(devices[0]);

 var TransferData = {
    "requestType": "class",
    "recipient": "interface",
    "direction": "out",
    "request": 0xx9,
    "value": 0xxx0,
    "index": 0,
   "data": new Uint8Array([00,05, 47, 76, 66, 48, 47,00]).buffer
  };


        setTimeout(function () {
            chrome.usb.controlTransfer(devices[0], TransferData, function (config) {
                if (chrome.runtime.lastError) {
                    console.log(chrome.runtime.lastError);
                } else {
                    console.log('Data Transfer completed');
                }
            });
        }, 3000);
    });

Reilly Grant

unread,
Mar 23, 2016, 1:31:39 PM3/23/16
to santina...@gmail.com, Chromium-dev
Questions like this are better answered on Stack Overflow. Please include extra details such as:

1. What console log messages are printed by your code.
2. The value of chrome.runtime.lastError if it is set.
3. A larger snippet of chrome://device-log.
4. Why your are using the chrome.usb API instead of the chrome.hid API. If the device is recognized by the system as HID then it will not be available via chrome.usb.findDevices.

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev

Alex Vallee

unread,
Mar 23, 2016, 6:34:04 PM3/23/16
to Chromium-dev

Santinath Mishra

unread,
Mar 24, 2016, 6:30:13 AM3/24/16
to Chromium-dev, santina...@gmail.com
Thanks Reilly for your reply.

Here is my log message

Script.js:42 App was granted the "usbDevices" permission.
Script.js:50 Devices: [object Object]
Script.js:51 Object {handle: 2, productId: 34, vendorId: 4323}
Script.js:57  Data Transfer completed


chrome.runtime.lastError is set to undefined



I have also tried using chrome.hid API, here are the code snippet and error message

Error message

Device Length: 1
mychromeapp.js:109 Found device: 9
mychromeapp.js:112 ProductId: 34
mychromeapp.js:113 VendorId: 4323
mychromeapp.js:118 Connected to the HID device!
mychromeapp.js:119 ObjectconnectionId: 6__proto__: Object
mychromeapp.js:150 Info received by device
extensions::lastError:133 Unchecked runtime.lastError while running hid.send: Transfer failed.
    at Object.callback (chrome-extension://nnchpnlblaiehgoljobkmbfhenneaejp/mychromeapp.js:149:20)reportIfUnchecked @ extensions::lastError:133



Sample code using chrome.hid


 
var  VENDOR_ID = 4323;  
var  PRODUCT_ID = 34;  
var DEVICE_INFO = { "vendorId": VENDOR_ID, "productId": PRODUCT_ID };
 
 
chrome.hid.getDevices(DEVICE_INFO, function(devices) {
console.log('Device Length: '+devices.length);
if (!devices || !devices.length) {
 console.log('device not found');
 return;
}
console.log('Found device: ' + devices[0].deviceId);
myHidDevice = devices[0].deviceId;
       
console.log('ProductId: '+devices[0].productId.toString(16));
console.log('VendorId: '+devices[0].vendorId.toString(16));
 
  chrome.hid.connect(myHidDevice, function(connection) {
console.log('Connected to the HID device!');
console.log(connection);
connectionId = connection.connectionId;
var arrayLength = 24;
var message = new Uint8Array(arrayLength);

message[0] = 0x05; 
message[1] = 0x2F; 
message[2] = 0x43; 
message[3] = 0x4C; 
message[4] = 0x3C; 
message[5] = 0x2F; 
for (var i = 6; i < arrayLength; i++) {
message[i] = 0x00;
}

var TransferData = {
"requestType": "class",
"recipient": "interface",
"direction": "out",
"request": 0x09,
"value": 0x0300,
"index": 0,
"data": message.buffer
};

        chrome.hid.send(connectionId,0, message.buffer, function() {
console.log("Info received by device");
}); 
  });
});

Reilly Grant

unread,
Mar 24, 2016, 3:23:38 PM3/24/16
to santina...@gmail.com, Chromium-dev
In the first example you have there the transfer is completing successfully. The error you see in chrome://device-log is likely not related. There are often failures that show up there during device enumeration and unfortunately it doesn't tell you which device the error was related to.
Reply all
Reply to author
Forward
0 new messages