2014-02-22 113 views
2

node-serialportnode-xbee来从RouterB配置中的XBee系列2读取传入的XBee帧。一个电位器连接到XBee的20引脚AD0模拟输入引脚。所有4个模拟引脚AD0AD1,AD2,AD3已启用,只有AD1连接到某物。使用Node-XBee和Node-SerialPort从XBee了解串行数据在以下代码中使用

如何解释frame_object中收到的data数组? Theres显然是一个趋势,当0V被馈送到XBee时,我们收到一个数组data10,结束元素0, 0, 2, 14, 2, 8, 2, 15。当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 ] } 

回答

2

检查文档以获取ATIS响应的格式。

标题字节包括帧的端点(232 = 0xE8)和簇(193,5 = 0xC105)。输入样本之前我不确定0,145和1。我认为5, 1解码后的字节如下:

以8位采样计数(0x01)开始。

然后读取已启用的数字输入(0x0000)的16位数据。

然后对启用的模拟输入(0x0F)进行8位读取。

如果有任何启用的数字输入,您将有一个16位值的所有数字读数。

接下来的四个模拟输入(3, 255 = 0x03FF),它们是一个缩放的10位值。因此,在你的情况下,3.3V * 0x03FF/0x03FF = 3.3V

0

理解数据,你可以做以下

xbeeAPI.on("frame_object", function (frame) { 
      console.log("OBJ> " + frame); 
      console.log("OBJ> " + util.inspect(frame)); 
      console.log("Data> " + util.inspect(frame.data.toString()));