public void notifyUSBDeviceAttach(Intent intent) {
    ftdid2xx.createDeviceInfoList(OpenDeviceFragmentContext);
    usbDev = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);

    if (ftdid2xx.isFtDevice(usbDev)) {
      ftDevice = ftdid2xx.openByUsbDevice(OpenDeviceFragmentContext, usbDev);
      if (ftDevice == null) {
        txtOpenUsbDev1.setText("Open By UsbDevice: Fail(ftDevice == null)");
      } else {
        if (ftDevice.isOpen()) {
          txtOpenUsbDev1.setText("Open By UsbDevice: Pass");
        } else {
          txtOpenUsbDev1.setText("Open By UsbDevice: Fail");
        }
        ftDevice.close();
      }

      ftDevice = ftdid2xx.openByUsbDevice(OpenDeviceFragmentContext, usbDev, d2xxDrvParameter);
      if (ftDevice == null) {
        txtOpenUsbDev2.setText("Open By UsbDevice with Parameter: Fail(ftDevice == null)");
      } else {
        if (ftDevice.isOpen()) {
          txtOpenUsbDev2.setText("Open By UsbDevice with Parameter: Pass");
        } else {
          txtOpenUsbDev2.setText("Open By UsbDevice with Parameter: Fail");
        }
        ftDevice.close();
      }
    }
  }
 @Override
 public void onDestroy() {
   Log.e(">>@@", "onDestroy");
   bReadThreadGoing_0 = false;
   bReadThreadGoing_1 = false;
   try {
     Thread.sleep(50);
   } catch (InterruptedException e) {
   }
   ft_device_0.close();
   ft_device_1.close();
   super.onDestroy();
 }
  public void resetClick() {
    int devCount = 0;

    devCount = ftdid2xx.createDeviceInfoList(OpenDeviceFragmentContext);
    Log.i("Misc Function Test ", "Device number = " + Integer.toString(devCount));

    if (devCount > 0) {
      ftDevice = ftdid2xx.openByIndex(OpenDeviceFragmentContext, 0);
      ftDevice.resetDevice();
      ftDevice.close();
    }

    txtOpenIndex.setText("Open By Index:");
    txtOpenSn.setText("Open By Serial Number:");
    txtOpenLocation.setText("Open By Location:");
    txtOpenDesc.setText("Open By Description:");
    bufnumValue.setText("");
    bufsizeValue.setText("");
    transizeValue.setText("");
    readtimeValue.setText("");
    txtOpenIndex2.setText("Open By Index:");
    txtOpenSn2.setText("Open By Serial Number:");
    txtOpenLocation2.setText("Open By Location:");
    txtOpenDesc2.setText("Open By Description:");
    txtOpenUsbDev1.setText("Open By UsbDevice:");
    txtOpenUsbDev2.setText("Open By UsbDevice with Parameter:");
  }
  public void startOpenDevParam() {
    int devCount = 0;
    devCount = ftdid2xx.createDeviceInfoList(OpenDeviceFragmentContext);

    if (devCount > 0) {
      D2xxManager.FtDeviceInfoListNode[] deviceList =
          new D2xxManager.FtDeviceInfoListNode[devCount];
      ftdid2xx.getDeviceInfoList(devCount, deviceList);

      // openByIndex
      ftDevice = ftdid2xx.openByIndex(OpenDeviceFragmentContext, 0, d2xxDrvParameter);
      if (ftDevice.isOpen()) {
        txtOpenIndex2.setText("Open By Index: Pass");
      } else {
        txtOpenIndex2.setText("Open By Index: Fail");
      }
      ftDevice.close();

      // openBySerialNumber
      if (deviceList[0].serialNumber != null) {
        ftDevice =
            ftdid2xx.openBySerialNumber(
                OpenDeviceFragmentContext, deviceList[0].serialNumber, d2xxDrvParameter);
        if (ftDevice.isOpen()) {
          txtOpenSn2.setText("Open By Serial Number: Pass");
        } else {
          txtOpenSn2.setText("Open By Serial Number: Fail");
        }
        ftDevice.close();
      } else {
        txtOpenSn2.setText("Open By Serial Number: Skip(No serial number)");
      }

      // openByLocation
      ftDevice =
          ftdid2xx.openByLocation(
              OpenDeviceFragmentContext, deviceList[0].location, d2xxDrvParameter);
      if (ftDevice.isOpen()) {
        txtOpenLocation2.setText("Open By Location: Pass");
      } else {
        txtOpenLocation2.setText("Open By Location: Fail");
      }
      ftDevice.close();

      // openByDescription
      if (deviceList[0].description != null) {
        ftDevice =
            ftdid2xx.openByDescription(
                OpenDeviceFragmentContext, deviceList[0].description, d2xxDrvParameter);
        if (ftDevice.isOpen()) {
          txtOpenDesc2.setText("Open By Description: Pass");
        } else {
          txtOpenDesc2.setText("Open By Description: Fail");
        }
        ftDevice.close();
      } else {
        txtOpenDesc2.setText("Open By Description: Skip(No Description)");
      }

    } else {
      txtOpenIndex2.setText("Open By Index: Fail");
      txtOpenSn2.setText("Open By Serial Number: Fail");
      txtOpenDesc2.setText("Open By Description: Fail");
      txtOpenLocation2.setText("Open By Location: Fail");
    }
  }
  public void startOpenDev() {
    int devCount = 0;

    devCount = ftdid2xx.createDeviceInfoList(OpenDeviceFragmentContext);
    Log.i("Misc Function Test ", "Device number = " + Integer.toString(devCount));

    if (devCount > 0) {
      D2xxManager.FtDeviceInfoListNode deviceList = ftdid2xx.getDeviceInfoListDetail(0);

      // openByIndex
      ftDevice = ftdid2xx.openByIndex(OpenDeviceFragmentContext, 0, d2xxDrvParameter);
      if (ftDevice.isOpen()) {
        txtOpenIndex.setText("Open By Index: Pass");
      } else {
        txtOpenIndex.setText("Open By Index: Fail");
      }
      ftDevice.close();

      // openBySerialNumber
      if (deviceList.serialNumber != null) {
        ftDevice = ftdid2xx.openBySerialNumber(OpenDeviceFragmentContext, deviceList.serialNumber);
        if (ftDevice.isOpen()) {
          txtOpenSn.setText("Open By Serial Number: Pass");
        } else {
          txtOpenSn.setText("Open By Serial Number: Fail");
        }
        ftDevice.close();
      } else {
        txtOpenSn.setText("Open By Serial Number: Skip(No serial number)");
      }

      // openByLocation
      ftDevice = ftdid2xx.openByLocation(OpenDeviceFragmentContext, deviceList.location);
      if (ftDevice.isOpen()) {
        txtOpenLocation.setText("Open By Location: Pass");
      } else {
        txtOpenLocation.setText("Open By Location: Fail");
      }
      ftDevice.close();

      // openByDescription
      if (deviceList.description != null) {
        ftDevice = ftdid2xx.openByDescription(OpenDeviceFragmentContext, deviceList.description);
        if (ftDevice.isOpen()) {
          txtOpenDesc.setText("Open By Description: Pass");
        } else {
          txtOpenDesc.setText("Open By Description: Fail");
        }
        ftDevice.close();
      } else {
        txtOpenDesc.setText("Open By Description: Skip(No description)");
      }

      // openByUsbDevice
    } else {
      txtOpenIndex.setText("Open By Index: Fail");
      txtOpenSn.setText("Open By Serial Number: Fail");
      txtOpenDesc.setText("Open By Description: Fail");
      txtOpenLocation.setText("Open By Location: Fail");
    }
  }