在下面的代码中使用node-serialport和node-xbee从路由器AT配置中的XBee系列2读取传入的XBee帧。电位器连接到20 AD0模拟输入引脚的XBee。所有4个模拟引脚( AD0、AD1、AD2、AD3 )都已启用,只有AD1连接到某物。
如何解释接收到的data数组?这里有一个明显的趋势,当0V被输入到XBee时,我们收到一个以元素0, 0, 2, 14, 2, 8, 2, 15结尾的数组data。当3.3V被输入到XBee时,data数组以3, 255, 3, 255, 3, 255, 3, 255元素结束。
如何将这些原始值转换为更有意义的值?3, 255看起来像一对表示3.3V的值?但是我们如何从3, 255到电压读数呢?
读取串口数据
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("/dev/cu.usbserial-A702NY8S", {
baudrate: 9600,
parser: xbeeAPI.rawParser()
});
xbeeAPI.on("frame_object", function(frame) {
console.log("OBJ> "+util.inspect(frame));
});XBee帧当XBee引脚被馈送0V时
OBJ> { type: 145,
remote64: '0013a20040b19213',
remote16: '56bc',
receiveOptions: 232,
data: [ 232, 0, 146, 193, 5, 1, 1, 0, 0, 15, 0, 0, 2, 14, 2, 8, 2, 15 ] }
OBJ> { type: 145,
remote64: '0013a20040b19213',
remote16: '56bc',
receiveOptions: 232,
data: [ 232, 0, 146, 193, 5, 1, 1, 0, 0, 15, 0, 0, 2, 16, 2, 14, 2, 14 ] }
OBJ> { type: 145,
remote64: '0013a20040b19213',
remote16: '56bc',
receiveOptions: 232,
data: [ 232, 0, 146, 193, 5, 1, 1, 0, 0, 15, 0, 0, 2, 17, 2, 11, 2, 9 ] }XBee帧当XBee引脚被喂入3.3V时
OBJ> { type: 145,
remote64: '0013a20040b19213',
remote16: '56bc',
receiveOptions: 232,
data: [ 232, 0, 146, 193, 5, 1, 1, 0, 0, 15, 3, 255, 3, 255, 3, 255, 3, 255 ] }
OBJ> { type: 145,
remote64: '0013a20040b19213',
remote16: '56bc',
receiveOptions: 232,
data: [ 232, 0, 146, 193, 5, 1, 1, 0, 0, 15, 3, 255, 3, 255, 3, 255, 3, 255 ] }
OBJ> { type: 145,
remote64: '0013a20040b19213',
remote16: '56bc',
receiveOptions: 232,
data: [ 232, 0, 146, 193, 5, 1, 1, 0, 0, 15, 3, 255, 3, 255, 3, 255, 3, 255 ] }发布于 2014-02-27 17:36:54
查看文档以获得ATIS响应的格式。
头字节包括帧的端点(232 = 0xE8)和集群(193,5=0xC 105)。我不确定输入样本之前的0,145和额外1。我认为5, 1后的字节解码如下:
从8位样本计数开始(0x01)。
然后对启用的数字输入进行16位读取(0x0000)。
然后对启用的模拟输入(0x0F)进行8位读取。
如果有任何启用的数字输入,您将有一个16位值的所有数字读数。
四个模拟输入跟随(3, 255 = 0x03FF),它们是一个缩放的10位值。
reference voltage * reading / 0x03FF所以,在你的例子中,3.3V * 0x03FF / 0x03FF = 3.3V。
发布于 2016-11-18 15:49:47
要了解数据,可以执行以下操作
xbeeAPI.on("frame_object", function (frame) {
console.log("OBJ> " + frame);
console.log("OBJ> " + util.inspect(frame));
console.log("Data> " + util.inspect(frame.data.toString()));https://stackoverflow.com/questions/21952233
复制相似问题