首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >nodejs xbee未收到消息

nodejs xbee未收到消息
EN

Stack Overflow用户
提问于 2014-06-01 08:15:24
回答 2查看 540关注 0票数 2

我想让nodejs用xbee发送和接收消息。我知道xbee设置可以工作,因为我在x-ctu上测试了它。我尝试了以下方法,但没有收到消息。上面说它是开着的。

代码语言:javascript
复制
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);
});
EN

回答 2

Stack Overflow用户

发布于 2014-06-06 23:58:14

我几天前就想明白了。我意识到我可以只使用串口库。

票数 0
EN

Stack Overflow用户

发布于 2021-10-21 09:08:56

您需要先侦听串口,然后使用xbee-api解析数据

代码语言:javascript
复制
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(),我不知道为什么使用API1模式,但请尽量使用57600波特率或更高,以避免校验和不匹配的问题,祝你好运。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23975642

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档