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(); } } }
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:"); }
@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(); }
/** Called when the user clicks the Send button */ public void SendMessage_1(View view) { // Do something in response to button FT_Device ftDev; if (uart_configured_1 == false) { Toast.makeText( DeviceFT2232HTestContext, "UART Port 1 not configured yet...", Toast.LENGTH_SHORT) .show(); return; } ftDev = ft_device_1; if (ftDev.isOpen() == false) { Log.e(">>@@", "SendMessage: ftDev not open!!!!!! index: 1"); } else { Log.e(">>@@", "SendMessage: ftDev open, index: 1"); /* Log.e(">>@@","port 1 isn:" + ftDev.deviceInfoNode.iSerialNumber + " bcd:" + ftDev.deviceInfoNode.bcdDevice + " id:" + ftDev.deviceInfoNode.id + " loc:" + ftDev.deviceInfoNode.location + " sn:" + ftDev.deviceInfoNode.serialNumber); */ } ftDev.setLatencyTimer((byte) 16); // ftDev.Purge(true, true); String writeData = writeText_1.getText().toString(); byte[] OutData = writeData.getBytes(); int iLen = ftDev.write(OutData, writeData.length()); Log.e(">>@@", "Port 1 write Len:" + iLen + " s:" + writeData); Toast.makeText( DeviceFT2232HTestContext, "Port 1 write Len:" + iLen + " s:" + writeData, Toast.LENGTH_SHORT) .show(); }
public boolean SetConfig( int index, int baud, byte dataBits, byte stopBits, byte parity, byte flowControl) { FT_Device ftDev; switch (index) { case 0: ftDev = ft_device_0; break; case 1: ftDev = ft_device_1; break; default: ftDev = ft_device_0; break; } if (ftDev.isOpen() == false) { Log.e(">>@@", "SetConfig: ftDev not open!!!!!! index:" + index); } else { Log.e(">>@@", "SetConfig: ftDev open, index:" + index); /* Log.e(">>@@", "port isn:" + ftDev.deviceInfoNode.iSerialNumber + " bcd:" + ftDev.deviceInfoNode.bcdDevice + " id:" + ftDev.deviceInfoNode.id + " loc:" + ftDev.deviceInfoNode.location + " sn:" + ftDev.deviceInfoNode.serialNumber); */ } // open our first device // ftdid2xx.openByIndex(0); // configure our port // reset to UART mode for 232 devices ftDev.setBitMode((byte) 0, D2xxManager.FT_BITMODE_RESET); // set 230400 baud rate // ftdid2xx.setBaudRate(9600 ); ftDev.setBaudRate(baud); // set 8 data bits, 1 stop bit, no parity // ftdid2xx.setDataCharacteristics(D2xx.FT_DATA_BITS_8, // D2xx.FT_STOP_BITS_1, D2xx.FT_PARITY_NONE); switch (dataBits) { case 7: dataBits = D2xxManager.FT_DATA_BITS_7; break; case 8: dataBits = D2xxManager.FT_DATA_BITS_8; break; default: dataBits = D2xxManager.FT_DATA_BITS_8; break; } switch (stopBits) { case 1: stopBits = D2xxManager.FT_STOP_BITS_1; break; case 2: stopBits = D2xxManager.FT_STOP_BITS_2; break; default: stopBits = D2xxManager.FT_STOP_BITS_1; break; } switch (parity) { case 0: parity = D2xxManager.FT_PARITY_NONE; break; case 1: parity = D2xxManager.FT_PARITY_ODD; break; case 2: parity = D2xxManager.FT_PARITY_EVEN; break; case 3: parity = D2xxManager.FT_PARITY_MARK; break; case 4: parity = D2xxManager.FT_PARITY_SPACE; break; default: parity = D2xxManager.FT_PARITY_NONE; break; } ftDev.setDataCharacteristics(dataBits, stopBits, parity); // set RTS/CTS flow control // ftdid2xx.setFlowControl(D2xx.FT_FLOW_RTS_CTS, (byte)0x00, // (byte)0x00); // ftdid2xx.setFlowControl(D2xx.FT_FLOW_NONE, (byte)0x00, (byte)0x00); short flowCtrlSetting; switch (flowControl) { case 0: flowCtrlSetting = D2xxManager.FT_FLOW_NONE; break; case 1: flowCtrlSetting = D2xxManager.FT_FLOW_RTS_CTS; break; case 2: flowCtrlSetting = D2xxManager.FT_FLOW_DTR_DSR; break; case 3: flowCtrlSetting = D2xxManager.FT_FLOW_XON_XOFF; break; default: flowCtrlSetting = D2xxManager.FT_FLOW_NONE; break; } // TODO : check xon, xoff // TODO : check xon, xoff ftDev.setFlowControl(flowCtrlSetting, (byte) 0x00, (byte) 0x00); switch (index) { case 0: uart_configured_0 = true; Toast.makeText(DeviceFT2232HTestContext, "Port 0 config done", Toast.LENGTH_SHORT).show(); break; case 1: uart_configured_1 = true; Toast.makeText(DeviceFT2232HTestContext, "Port 1 config done", Toast.LENGTH_SHORT).show(); break; default: ftDev = ft_device_0; break; } Log.e( ">>@@", "SCon[" + index + "] 0:0x" + Integer.toHexString(ft_device_0.getModemStatus()) + " 1:0x" + Integer.toHexString(ft_device_1.getModemStatus()) /*+ " 2:0x" + Integer.toHexString(ft_device_2.getModemStatus())*/ ); return true; }
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"); } }