我正在尝试与 Chrome 应用程序建立串行连接。我可以连接到设备并毫无问题地发送数据,但无法接收任何内容。
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);
我正在使用 chrome 串行库并从网站复制了示例代码。
最佳答案
看看https://github.com/GoogleChrome/chrome-app-samples/blob/master/samples/serial/espruino/main.js完整实现 chrome.serial
。
您可能还想使用 chrome.serial.onReceiveError.addListener(onReceiveErrorCallback);
检查错误
关于javascript - 使用 Chrome 应用程序阅读连续剧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44250817/