2014-02-22 33 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()));