【问题标题】:Reading Serial with Chrome App使用 Chrome 应用阅读序列
【发布时间】:2017-10-30 06:06:15
【问题描述】:

我正在尝试与 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 串行库并从网站上复制了示例代码。

【问题讨论】:

  • 我建议使用串行调试工具来确保发送数据,就像您希望首先确保它是您的代码一样。有一个作为 Chrome 应用程序编写的,也可用于证明是否可以从 Chrome 应用程序成功读取数据:chrome.google.com/webstore/detail/serial-monitor/…

标签: javascript google-chrome google-chrome-extension serial-port google-chrome-app


【解决方案1】:

查看https://github.com/GoogleChrome/chrome-app-samples/blob/master/samples/serial/espruino/main.js 以获得chrome.serial 的完整实现。

您可能还想检查chrome.serial.onReceiveError.addListener(onReceiveErrorCallback); 的错误

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-12
    • 2011-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多