Reputation: 11
I'm trying to get an Serial connection with a chrome app. I can connect to a device and send out data without a problem but cannot receive anything.
var onReceiveCallback = function(info) {
if (info.connectionId == expectedConnectionId && info.data) {
var str = convertArrayBufferToString(info.data);
if (str.charAt(str.length-1) === '\n') {
stringReceived += str.substring(0, str.length-1);
onLineReceived(stringReceived);
stringReceived = '';
} else {
stringReceived += str;
}
}
setStatus('Recieved');
};
chrome.serial.onReceive.addListener(onReceiveCallback);
I am using the chrome serial library and copied the example code from the website.
Upvotes: 1
Views: 834
Reputation: 5629
Have a look at https://github.com/GoogleChrome/chrome-app-samples/blob/master/samples/serial/espruino/main.js for a complete implementation of chrome.serial
.
You may also want to check for errors with chrome.serial.onReceiveError.addListener(onReceiveErrorCallback);
Upvotes: 1