chrome.bluetooth.write error? IOReturn code: 37580

2019-07-29 05:57发布

问题:

I'm working on a simple chrome web store app that uses a new API called chrome.bluetooth. The API is rather new and only available to the google chrome dev channel.

I have managed to discover all devices, search through their services and if they have the service I need to connect, it establishes a connection.

My chrome.bluetooth.onConnection function works fine, it returns a socket which I am attempting to write to:

chrome.bluetooth.onConnection.addListener(function(socket){
log("Connected", arguments);
if (socket) {
    sockets.push(socket);
    var data = str2ab("hello"); //My string to array buffer converter
    chrome.bluetooth.write({ //Try to write to socket
        socket:socket,
        data:data
    },function(){
        log("Wrote to socket",socket,data,arguments)
    })
}
});

After I attempt to write, chrome.runtime.lastError message is:

"Failed to send data. IOReturn code: 3758097088"

Im not quite sure what I am doing wrong, mainly because I don't understand the error. What does "IOReturn code: 3758097088" mean? I was wondering if anybody knows what I am doing wrong and what this error means?

Cheers,

回答1:

There have been recent improvements to the API, including a big update to the OS X support; the code would be replaced by chrome.bluetoothSocket.send now. Give that a try.



回答2:

In the event you have not tracked this down yet, if your running on OSX (at least) that maps to "kIOReturnNoDevice" as defined in IOReturn.h: http://www.opensource.apple.com/source/xnu/xnu-1504.7.4/iokit/IOKit/IOReturn.h

After tracking the error back through the chrome source code, I determined that this is the error returned by "IOBluetoothRFCOMMChannel writeAsync" in chrome "bluetooth_socket_mac.mm" method "BluetoothSocketMac::Send"

This error is made more obtuse because IOReturn.h refers to 0x2c0 for "kIOReturnNoDevice", but when the constants are defined 0xe0000000 seems to be added to each of them (presumably this is an offset so they don't collide with other constants), thus the decmal value is 3758097088 rather then 704.

I can't tell you exactly what OSX is trying to tell you with that error code, but hopefully that provides you with the context you need to find your issue.