UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
edt.append("USB device count :" + String.valueOf(deviceList.size()) + "\r\n");
Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
while (deviceIterator.hasNext()) {
UsbDevice device = deviceIterator.next();
UsbInterface devInterface = device.getInterface(0);
int devInterfaceID = devInterface.getId();
UsbEndpoint OutEndPoint = devInterface.getEndpoint(0);
UsbEndpoint InEndPoint = devInterface.getEndpoint(1);
UsbDeviceConnection connection = manager.openDevice(device);
connection.claimInterface(devInterface, true);
byte[] bytes;
connection.controlTransfer(CP210x_REQTYPE_HOST2DEVICE, CP210x_IFC_ENABLE, CP210x_IFC_ON, devInterfaceID, null, 0,250);
connection.controlTransfer(CP210x_REQTYPE_HOST2DEVICE, CP210x_SET_MHS, CP210x_MHS_DTR_ON, devInterfaceID, null, 0, 200);
int br = 3686400 / 9600;
connection.controlTransfer(CP210x_REQTYPE_HOST2DEVICE, CP210x_SET_BAUDDIV, br, devInterfaceID, null, 0, 200);
bytes = new byte[]{0x2a, 0x00, 0x2a};
byte[] InBuff = new byte[100];
connection.controlTransfer(CP210x_REQTYPE_DEVICE2HOST, CP210x_GET_COMM_STATUS, 0, devInterfaceID, InBuff, 0x0014, 200);
for (int i = 0; i < 20; i++) {
connection.bulkTransfer(OutEndPoint, bytes, 3, 200);
while (InBuff[9]!=18) {
connection.controlTransfer(CP210x_REQTYPE_DEVICE2HOST, CP210x_GET_COMM_STATUS, 0, devInterfaceID, InBuff, 0x0014, 200);
}
int rc = connection.bulkTransfer(InEndPoint, InBuff, 18, 500);
if (rc == 18) {
edt.append("18 Zeichen empfangen !\r\n");
} else {
edt.append("ERROR Zeichen empfangen !\r\n");
}
connection.close();
}