2013-02-14 9 views
0

나는 이클립스와 함께 응용 프로그램을 디버깅하려고합니다. USB를 사용하여 액세서리에 연결하므로 디버깅 할 수 없습니다. 무선으로 디버깅 할 수있는 ADB 연결을 사용하고 있지만이 앱을 사용하면 USB 케이블을 뽑아 플러그를 꽂아 앱을 실행시켜야합니다. 이렇게하면 일식 연결이 끊어집니다.안드로이드 도움말 토스트와 디버깅

그래서 내가 생각할 수있는 것은 토스트를 사용하여 수업에서 무슨 일이 벌어지고 있는지 파악하는 것입니다.

아마도 더 좋은 방법이 있을까요? 내가 .. 토스트 응용 프로그램 충돌을 호출 할 때

는하지만 브로드 캐스트 리시버와 같은 vaious 방법에 메시지를 토스트 할 수 있도록하려면, 그리고 ResumeAccessory

통화 사람이 어떻게 수업 시간에 토스트를 구현하는 말해?

더 나은

//

User must modify the below package with their package name 
package com.UARTDemo; 
import java.io.FileDescriptor; 
import java.io.FileInputStream; 
import java.io.FileOutputStream; 
import java.io.IOException; 

import android.app.Activity; 
import android.app.PendingIntent; 
import android.content.BroadcastReceiver; 
import android.content.Context; 
import android.content.Intent; 
import android.content.IntentFilter; 
import android.hardware.usb.UsbAccessory; 
import android.hardware.usb.UsbManager; 
import android.os.Handler; 
import android.os.Message; 
import android.os.ParcelFileDescriptor; 
import android.util.Log; 



/******************************FT311 GPIO interface class******************************************/ 
public class FT311UARTInterface extends Activity 
{ 

    private static final String ACTION_USB_PERMISSION = "com.UARTDemo.USB_PERMISSION"; 
    public UsbManager usbmanager; 
    public UsbAccessory usbaccessory; 
    public PendingIntent mPermissionIntent; 
    public ParcelFileDescriptor filedescriptor; 
    public FileInputStream inputstream; 
    public FileOutputStream outputstream; 
    public boolean mPermissionRequestPending = true; 
    public handler_thread handlerThread; 

    private byte [] usbdata; 
    private byte [] writeusbdata; 
    private byte [] readBuffer; /*circular buffer*/ 
    private int readcount; 
    private int totalBytes; 
    private int writeIndex; 
    private int readIndex; 
    private byte status; 
    private byte maxnumbytes = (byte)64; 

    public boolean datareceived = false; 



     /*constructor*/ 
    public FT311UARTInterface(Context context){ 
      super(); 
      /*shall we start a thread here or what*/ 
      usbdata = new byte[64]; 
      writeusbdata = new byte[64]; 
      /*128(make it 256, but looks like bytes should be enough)*/ 
      readBuffer = new byte [maxnumbytes]; 


      readIndex = 0; 
      writeIndex = 0; 
      /***********************USB handling******************************************/ 

      usbmanager = (UsbManager) context.getSystemService(Context.USB_SERVICE); 
      // Log.d("LED", "usbmanager" +usbmanager); 
      mPermissionIntent = PendingIntent.getBroadcast(context, 0, new Intent(ACTION_USB_PERMISSION), 0); 
      IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION); 
      filter.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED); 
      context.registerReceiver(mUsbReceiver, filter); 

      inputstream = null; 
      outputstream = null; 
     } 

     /*reset method*/ 
     public void Reset() 
     { 
      /*create the packet*/ 
      writeusbdata[0] = 0x49; 
      writeusbdata[1] = 0x00; 
      writeusbdata[2] = 0x00; 
      writeusbdata[3] = 0x00; 
      /*send the packet over the USB*/ 
      SendPacket(4); 
     } 



     public void SetConfig(int baud, byte dataBits, byte stopBits, 
          byte parity, byte flowControl) 
     { 

      /*prepare the baud rate buffer*/ 
      writeusbdata[0] = (byte)baud; 
      writeusbdata[1] = (byte)(baud >> 8); 
      writeusbdata[2] = (byte)(baud >> 16); 
      writeusbdata[3] = (byte)(baud >> 24); 

      /*data bits*/ 
      writeusbdata[4] = dataBits; 
      /*stop bits*/ 
      writeusbdata[5] = stopBits; 
      /*parity*/ 
      writeusbdata[6] = parity; 
      /*flow control*/ 
      writeusbdata[7] = flowControl; 

      /*send the UART configuration packet*/ 
      SendPacket((int)8); 
     } 


     /*write data*/ 
     public byte SendData(byte numBytes, char[] buffer) 

     { 

      status = 0x00; /*success by default*/ 
      /* 
      * if num bytes are more than maximum limit 
      */ 
      if(numBytes < 1){ 
       /*return the status with the error in the command*/ 
       return status; 
      } 

      /*check for maximum limit*/ 
      if(numBytes > 64){ 
       numBytes = 64; 

      } 


      /*prepare the packet to be sent*/ 
      for(int count = 0;count<numBytes;count++) 
      { 

       writeusbdata[count] = (byte)buffer[count]; 

      } 
      SendPacket((int)numBytes); 
      return status; 
     } 

     /*read data*/ 
     public byte ReadData(byte numBytes,char[] buffer, byte [] actualNumBytes) 
     { 
       status = 0x00; /*success by default*/ 

       /*should be at least one byte to read*/ 
       if((numBytes < 1) || (totalBytes == 0)){ 
        actualNumBytes[0] = 0x00; 
        return status; 
       } 

       /*check for max limit*/ 
       if(numBytes > 64){ 
        numBytes = 64; 
       } 
       if(numBytes > 64){ 
        numBytes = 64; 
       } 

       if(numBytes > totalBytes) 
        numBytes = (byte)totalBytes; 



       /*update the number of bytes available*/ 
       totalBytes -= numBytes; 

       actualNumBytes[0] = numBytes; 

       /*copy to the user buffer*/ 
       for(int count = 0; count<numBytes;count++) 
       { 
        buffer[count] = (char)readBuffer[readIndex]; 
        readIndex++; 
        /*shouldnt read more than what is there in the buffer, 
        * so no need to check the overflow 
        */ 
        readIndex %= maxnumbytes; 
       } 
       return status; 
     } 





     /*method to send on USB*/ 
     private void SendPacket(int numBytes) 
     { 


      try { 
       if(outputstream != null){ 
        outputstream.write(writeusbdata, 0,numBytes); 
       } 
      } catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 

     } 




     /*resume accessory*/ 
     public void ResumeAccessory() 
     { 
      // Intent intent = getIntent(); 
      if (inputstream != null && outputstream != null) { 
       return; 
      } 

      UsbAccessory[] accessories = usbmanager.getAccessoryList(); 
      UsbAccessory accessory = (accessories == null ? null : accessories[0]); 
      if (accessory != null) { 
       if (usbmanager.hasPermission(accessory)) { 
        OpenAccessory(accessory); 
       } 
       else 
       { 
        synchronized (mUsbReceiver) { 
         if (!mPermissionRequestPending) { 
          usbmanager.requestPermission(accessory, 
            mPermissionIntent); 
          mPermissionRequestPending = true; 
         } 
       } 
      } 
      } else {} 

     } 

     /*destroy accessory*/ 
     public void DestroyAccessory(){ 
      unregisterReceiver(mUsbReceiver); 
      CloseAccessory(); 
     } 



/*********************helper routines*************************************************/  

     public void OpenAccessory(UsbAccessory accessory) 
     { 
      filedescriptor = usbmanager.openAccessory(accessory); 
      if(filedescriptor != null){ 
       usbaccessory = accessory; 
       FileDescriptor fd = filedescriptor.getFileDescriptor(); 
       inputstream = new FileInputStream(fd); 
       outputstream = new FileOutputStream(fd); 
       /*check if any of them are null*/ 
       if(inputstream == null || outputstream==null){ 
        return; 
       } 
      } 

      handlerThread = new handler_thread(handler, inputstream); 
      handlerThread.start(); 
     } 

     private void CloseAccessory() 
     { 
      try{ 
       if(filedescriptor != null) 
        filedescriptor.close(); 

      }catch (IOException e){} 

      try { 
       if(inputstream != null) 
         inputstream.close(); 
      } catch(IOException e){} 

      try { 
       if(outputstream != null) 
         outputstream.close(); 

      }catch(IOException e){} 
      /*FIXME, add the notfication also to close the application*/ 

      filedescriptor = null; 
      inputstream = null; 
      outputstream = null; 

      System.exit(0); 

     } 


     /***********USB broadcast receiver*******************************************/ 
     private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() 
     { 
      @Override 
      public void onReceive(Context context, Intent intent) 
      { 
       String action = intent.getAction(); 
       if (ACTION_USB_PERMISSION.equals(action)) 
       { 
        synchronized (this) 
        { 
         UsbAccessory accessory = (UsbAccessory) intent.getParcelableExtra(UsbManager.EXTRA_ACCESSORY); 
         if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) 
         { 
          OpenAccessory(accessory); 
         } 
         else 
         { 
          Log.d("LED", "permission denied for accessory "+ accessory); 

         } 
         mPermissionRequestPending = false; 
        } 
       } 
       else if (UsbManager.ACTION_USB_ACCESSORY_DETACHED.equals(action)) 
       { 
        UsbAccessory accessory = (UsbAccessory)intent.getParcelableExtra(UsbManager.EXTRA_ACCESSORY); 
        if (accessory != null)//&& accessory.equals(usbaccessory)) 
        { 
         CloseAccessory(); 
        } 
       }else 
       { 
        Log.d("LED", "...."); 
       } 
      } 
     }; 





     final Handler handler = new Handler() 
     { 
      @Override 
      public void handleMessage(Message msg) 
      { 
       for(int count = 0;count<readcount;count++){ 

        readBuffer[writeIndex] = usbdata[count]; 
        /*move to the next write location*/ 
        writeIndex++; 
        writeIndex %= maxnumbytes; 
        /*FIXME,check for overflow*/ 
        //if(writeIndex == readIndex){ 

        //} 

       } 

       /*caluclate the available bytes to read*/ 
       if(writeIndex >= readIndex) 
        totalBytes = writeIndex-readIndex; 
       else 
        totalBytes = (maxnumbytes-readIndex)+writeIndex; 


      } 

     }; 


     /*usb input data handler*/ 
     private class handler_thread extends Thread { 
      Handler mHandler; 
      FileInputStream instream; 

      handler_thread(Handler h,FileInputStream stream){ 
       mHandler = h; 
       instream = stream; 
      } 

      public void run() 
      { 

       while(true) 
       { 
        Message msg = mHandler.obtainMessage(); 
        try{ 
         if(instream != null) 
         { 
         readcount = instream.read(usbdata,0,64); 
         if(readcount > 0) 
         { 
          datareceived = true; 
          msg.arg1 = usbdata[0]; 
          msg.arg2 = usbdata[1]; 
         } 
         mHandler.sendMessage(msg); 
         } 
         }catch (IOException e){} 
       } 
      } 
     } 



    } 
+0

실제로 로그 팩을 읽거나 사실 후에 로그 캣을 읽거나, 블루투스/wifi를 통한 adb 연결을 통해 데이터를 읽는 것이 더 나을 것입니다. (시도한 적은 없지만 확실히 할 수 있습니다.) –

+0

USB 허브를 사용하는 경우 부속 장치에 연결할 수 있으며 이클립스 할 수 있습니다. – Squonk

+0

허브를 통해 어떻게 연결 하시겠습니까? USB를 통해 USB 액세서리에 직접 연결하는 Xoom 태블릿을 사용하고 있습니다. – user1895526

답변

0

그것은 Log.d(TAG, text)

또는

사용 활동의 서브 클래스에서

당신은 할 수 있습니다 :

Toast.makeText (getApplicationContext(), "텍스트", Toast.LENGTH_LONG를) .show();