蓝牙响应同步错误Titanium

时间:2014-10-24 05:04:38

标签: javascript android bluetooth titanium response

我希望在通过蓝牙发送一些数据后捕获一些响应数据。但是在捕获数据时我遇到了问题。我将“a”发送到我的蓝牙模块并期望响应为1或0.但是捕获的部分发送了一个错误,它发送数据并让我回答之前的响应。

例如:

正确

App                            Bluetooth                             App
Send "a"          ===>         get "a"         must response 1 but   NULL
Send "b"          ===>         get "b"         must response 0 but   1   
Send "a"          ===>         get "a"         must response 1 but   0 

捕获以前的数据!!!请帮助!

以下是代码:

var ilu1= Ti.UI.createButton({
  width : Ti.UI.FILL,
  height : '80dp',
  shadowColor: '#000',
  hadowOffset: {x:0, y:0},
  hadowRadius: 2,
  font:{
    fontSize:55,
    fontFamily: customFont2
  },
  textAlign : Titanium.UI.TEXT_ALIGNMENT_CENTER,
  verticalAlign : Titanium.UI.TEXT_VERTICAL_ALIGNMENT_BOTTOM,
  title : 'L',
  color : '#fff',
  backgroundColor:'#005a93',
  backgroundSelectedColor: '#1f2d46', 
  backgroundFocusedColor: '#1f2d46', 
  touchEnabled: true, 
    zIndex:2
});

ilu1.addEventListener('click', function() {
  novarumbluetooth.sendData('a');
  actualizalabel.text = 'Actualizando';
  var responsebtilu = novarumbluetooth.addEventListener('nb_onReceiveData', function(e)
  {        
    Ti.App.responsebt2 = e.data;    
  });
  alert(Ti.App.responsebt2);
  if (Ti.App.responsebt2=='1') {
    ilu1.title = 'K';
    actualizalabel.text = 'Actualizado';
  } else {
    actualizalabel.text = 'Error';
  };    
})

谢谢!

0 个答案:

没有答案