2016-04-08 16 views
0

Belirli bir Bluetooth aygıtı veri gönderiyorken görüntülenen bir krom uygulaması oluşturmaya çalışıyorum. Özellikle, 2 bluetooth fareye sahibim ve hangisinin belirli bir zamanda taşındığını tanımlamak istiyorum. Chrome dev doc'ı takip ettim ve cihazdan gelen verileri görüntülemek için bir dinleyici eklemeyi denemeye kadar başarılı oldu. "Özellik 'addListener' undefined 'hata okunamıyor" alıyorum. Error messageChrome App bluetooth

İşte bu docs kontrol etti

chrome.bluetooth.getDevices(function(devices) { 
 
    for (var i = 0; i < devices.length; i++) { 
 
    //Displaying device names 
 
    console.log(i+": "+devices[i].name); 
 
    } 
 
    //uuid for a specific device 
 
    var uuid = "00001200-0000-1000-8000-00805f9b34fb"; 
 
    // var uuid = devices[4].uuid; 
 
    
 
    var onConnectedCallback = function() { 
 
     if (chrome.runtime.lastError) { 
 
     console.log("Connection failed: " + chrome.runtime.lastError.message); 
 
     } else { 
 
     // Profile implementation here. 
 
     } 
 
    }; 
 

 

 
    chrome.bluetoothSocket.create(function(createInfo) { 
 
     chrome.bluetoothSocket.connect(createInfo.socketId, 
 
     devices[4].address, uuid, onConnectedCallback); 
 
     console.log(createInfo); 
 
     chrome.bluetoothSocket.onRecieve.addListener(function(receiveInfo) { 
 
      if (receiveInfo.socketId != socketId) 
 
      return; 
 
     console.log(receiveInfo); 
 
     }); 
 
    }); 
 
});

cevap

0

ile çalışıyorum kod ve benzer görmek başardı: Ben bu hatayı almaya başladığı

Bu

olduğunu kod pasajı:

chrome.bluetoothSocket.onRecieve.addListener(function(receiveInfo) { 
    if (receiveInfo.socketId != socketId) 
    return; 
    // receiveInfo.data is an ArrayBuffer. 
}); 

Dikkatle bakarsanız, örnekte onRecieve bölümündeki bir yazım hatası var gibi görünüyor. onReceive olmalıdır. Doğru örnek here'u görebilirsiniz.

I C sonrası hariç e, önce. ;) Bu yardımcı olur umarım. İyi şanslar.