コード例 #1
0
 @Override
 protected void onResume() {
   super.onResume();
   mSerialDevice = UsbSerialProber.acquire(mUsbManager);
   Debug.d(TAG, "Resumed, mSerialDevice=" + mSerialDevice);
   if (mSerialDevice == null) {
     Debug.i(TAG, "No serial device.");
     mTextViewCmbsConnectedAns.setText(R.string.no);
     mTextViewHanConnectedDeviceAns.setText(R.string.not_available);
     mHanDeviceLinkedList.clear();
     updateHanDeviceTable();
     updateLedStatus();
   } else {
     try {
       mSerialDevice.open();
       mTextViewCmbsConnectedAns.setText(R.string.yes);
     } catch (IOException e) {
       Debug.e(TAG, "Error setting up device: " + e.getMessage());
       mTextViewCmbsConnectedAns.setText(R.string.no);
       mTextViewHanConnectedDeviceAns.setText(R.string.not_available);
       mHanDeviceLinkedList.clear();
       updateHanDeviceTable();
       updateLedStatus();
       try {
         mSerialDevice.close();
       } catch (IOException e2) {
         // Ignore.
       }
       mSerialDevice = null;
       return;
     }
     Debug.d(TAG, "Serial device: " + mSerialDevice);
   }
   onDeviceStateChange();
 }
コード例 #2
0
 private void sendPacket(byte[] pkt) {
   if (mSerialDevice != null) {
     try {
       mSerialDevice.write(pkt, 1000);
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
 }
コード例 #3
0
 @Override
 protected void onPause() {
   super.onPause();
   stopIoManager();
   if (mSerialDevice != null) {
     try {
       mSerialDevice.close();
     } catch (IOException e) {
       // Ignore.
     }
     mSerialDevice = null;
   }
 }