繁体   English   中英

nodejs xbee 没有收到消息

[英]nodejs xbee not receiving message

我希望 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);
});

我几天前就知道了。 我认为我只能使用串行端口库。

需要先监听串口,然后用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 波特率或更高以避免校验和不匹配问题祝你好运。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM