2

node-serialport次のコードでnode-xbee使用され、Router AT 構成の XBee シリーズ 2 から着信 XBee フレームを読み取ります。ポテンショメータはAD0、XBee のピン 20 アナログ入力ピンに接続されています。4 つのアナログ ピンAD0AD1AD2AD3すべて有効で、 のみAD1が何かに接続されています。

受信したdata配列をどのように解釈しますか? frame_object0V が XBee に供給されると、dataelements で終わる配列を受け取ります0, 0, 2, 14, 2, 8, 2, 15。3.3V が XBee に供給されると、data配列は elements で終了します3, 255, 3, 255, 3, 255, 3, 255

これらの生の値をより意味のあるものに変換するにはどうすればよいでしょうか? 3, 2553.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 ] }
4

2 に答える 2

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()));
于 2016-11-18T15:49:47.553 に答える