node-serialport并node-xbee在以下代码中用于从路由器 AT 配置中的 XBee 系列 2 读取传入的 XBee 帧。一个电位器连接到AD0XBee 的 20 号模拟输入引脚。所有 4 个模拟引脚AD0, AD1, AD2,AD3均已启用,仅AD1连接到某物。
你如何解释接收到的data数组frame_object?这里显然有一个趋势,当 0V 输入 XBee 时,我们会收到一个data以 elements 结尾的数组0, 0, 2, 14, 2, 8, 2, 15。当 3.3V 被馈送到 XBee 时,data数组以 elements 结束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 引脚馈电 0V 时的 XBee 帧
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 引脚馈入 3.3V 时的 XBee 帧
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 ] }