【问题标题】:nodejs xbee not receiving messagenodejs xbee没有收到消息
【发布时间】:2014-06-01 00:15:23
【问题描述】:

我希望 nodejs 使用 xbee 发送和接收消息。我知道 xbee 设置有效,因为我在 x-ctu 上对其进行了测试。我尝试了以下但无法收到消息。它说它是开放的。

var util = require('util');
var SerialPort = require('serialport').SerialPort;
var xbee_api = require('xbee-api');

var C = xbee_api.constants;

var xbeeAPI = new xbee_api.XBeeAPI({
    api_mode: 1
});

var serialport = new SerialPort("COM7", {
    baudrate: 9600,
    parser: xbeeAPI.parseRaw(1000)
});

serialport.on("open", function() {
    console.log("open");
});

// All frames parsed by the XBee will be emitted here
//I think this is the problem
xbeeAPI.on("frame_object", function(frame) {
    console.log(">>", frame);
});

【问题讨论】:

    标签: node.js xbee


    【解决方案1】:

    我几天前就知道了。我觉得我可以只使用串口库。

    【讨论】:

      【解决方案2】:

      需要先监听串口,再用xbee-api解析数据

      serialport.on('data', function (data) {
          try {
              xbeeAPI.parseRaw(data);
          } catch (e) {
              console.error(e);
          }
          xbeeAPI.on("frame_object", function (frame) {
              console.log(frame);
              // do what do you want with the frame
          }
      }
      

      你需要处理帧切换他的frame.type,是ZIGBEE_RECEIVE_PACKET的情况你需要将数据转换为字符串frame.data.toString(),我不知道为什么使用API​​1模式但请尝试使用57600或更高的波特率避免校验和不匹配问题祝你好运。

      【讨论】:

        猜你喜欢
        • 2022-01-22
        • 2021-04-08
        • 2014-05-04
        • 2011-09-07
        • 2017-10-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-03
        相关资源
        最近更新 更多