2013-09-24 42 views
1

我正在爲Windows 8下的Google Chrome編寫擴展程序,以便從連接到Arduino Nano電路的HC-05藍牙模塊讀取數據。如何正確使用chrome.bluetooth.read函數

連接正常後,我試着去閱讀使用chrome.bluetooth.read功能數據,但該方案被堆放在這一點上。

任何人都可以給我一些建議,使用該功能?

chrome.bluetooth.read(
      {socket: socket}, 
      function(myBuffer) 

      { 
       myView = new Uint8Array(myBuffer); 
       log("mi buffer = " + JSON.stringify(myView)); 
      } 
     ); 

謝謝

JC

回答

0

這是很難正確地使用,所以它被帶走,取而代之的是一個更容易的事件:

chrome.bluetoothSocket.onReceive

例:

chrome.bluetoothSocket.onReceive.addListener(function(receiveInfo) { 
    console.log("Received " + receiveInfo.data.byteLength + " bytes"); 

    var bytes = new Uint8Array(receiveInfo.data); 
    console.log("buffer = " + JSON.stringify(bytes)); 
    })