2012-05-26 2 views
0

Im new в android develop application.Want, чтобы читать данные из буфера из моего гнезда bluetooth и отображать его. данные получены от датчика температуры (LM35> Micro-controller> bluetooth module> android device). ниже - это чтение и сохранение данных в буфер. Я хочу знать, как его отображать. надеюсь, что ребята могут мне помочь. Большое спасибо ..Как отобразить буфер данных в android?

  byte[] buffer = new byte[1024]; 
     int bytes; 
     try { 
       InputStream instream = Bee_btSocket.getInputStream(); 
       bytes = instream.read(buffer); 
      } 

     catch (IOException e) { 
     break; 
+0

У вас есть спецификация того, как данные организованы в таком буфере? –

+0

, если я попытаюсь использовать терминал для отображения данных, он будет показывать значение «36», «37» (LM35> MicroC> hyperterminal). Теперь я хочу отобразить его в приложении adnroid. – fendy

ответ

0

делает это по следующему коду ...

public ConnectedThread(BluetoothSocket socket) { 
 
      Log.d(TAG, "create ConnectedThread"); 
 
      mmSocket = socket; 
 
      InputStream tmpIn = null; 
 
      OutputStream tmpOut = null; 
 

 
      // Get the BluetoothSocket input and output streams 
 
      try { 
 
       tmpIn = socket.getInputStream(); 
 
       tmpOut = socket.getOutputStream(); 
 
      } catch (IOException e) { 
 
       Log.e(TAG, "temp sockets not created", e); 
 
      } 
 

 
      mmInStream = tmpIn; 
 
      mmOutStream = tmpOut; 
 
     } 
 

 
     public void run() { 
 
      Log.i(TAG, "BEGIN mConnectedThread"); 
 
      byte[] buffer = new byte[1024]; 
 
      int bytes; 
 

 
      // Keep listening to the InputStream while connected 
 
      while (true) { 
 
       try { 
 
        // Read from the InputStream 
 
        bytes = mmInStream.read(buffer); 
 

 
        // Send the obtained bytes to the UI Activity 
 
        mHandler.obtainMessage(BluetoothChat.MESSAGE_READ, bytes, -1, buffer) 
 
          .sendToTarget(); 
 
       } catch (IOException e) { 
 
        Log.e(TAG, "disconnected", e); 
 
        connectionLost(); 
 
        break; 
 
       } 
 
      } 
 
     }

Смежные вопросы