使用Chrome App读取串行



我正在尝试与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/serial/espruino/main.js,以完成chrome.serial的完整实现。

您可能还想检查使用chrome.serial.onReceiveError.addListener(onReceiveErrorCallback);

检查错误

最新更新