Пример #1
0
 public static void fillDevice() {
   dev = getDevice();
   if (dev != null) {
     VendorId = HexDump.toHex(dev.getIdVendor()).toUpperCase();
     DeviceId = HexDump.toHex(dev.getIdProduct()).toUpperCase();
     try {
       dev.open();
       Serial = dev.get_string_ascii((byte) 3);
       dev.close();
     } catch (LibUsbNoDeviceException e) {
       dev = null;
       VendorId = "";
       DeviceId = "";
       Serial = "";
     } catch (LibUsbPermissionException e) {
       MyLogger.getLogger().error("No permission on device. Add valid udev rules");
       dev = null;
       VendorId = "";
       DeviceId = "";
       Serial = "";
     } catch (LibUsbOtherException e) {
       dev = null;
       VendorId = "";
       DeviceId = "";
       Serial = "";
     }
   } else {
     VendorId = "";
     DeviceId = "";
     Serial = "";
   }
 }
Пример #2
0
 public static void open()
     throws LibUsbNoDeviceException, LibUsbPermissionException, LibUsbOtherException,
         LibUsbNotFoundException, LibUsbBusyException, LibUsbInvalidParameterException {
   dev.open();
   if (dev.kernel_driver_active(0)) dev.detach_kernel_driver(0);
   dev.claim_interface(0);
 }
Пример #3
0
 public static void writeBytes(byte[] towrite) throws Exception {
   ByteArrayInputStream in = new ByteArrayInputStream(towrite);
   boolean hasData = true;
   int loop = 0;
   while (hasData) {
     try {
       int read = in.read(data);
       if (read > 0) {
         dev.bulk_write(0x01, BytesUtil.getReply(data, read), 0);
       } else hasData = false;
     } catch (LibUsbTimeoutException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     } catch (LibUsbPipeException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     } catch (LibUsbNoDeviceException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     } catch (LibUsbTransmissionException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     } catch (LibUsbOtherException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
   }
   in.close();
 }
Пример #4
0
 public static byte[] readBytes(int timeout)
     throws LibUsbTimeoutException, LibUsbPipeException, LibUsbOverflowException,
         LibUsbNoDeviceException, LibUsbOtherException {
   int read = dev.bulk_read(0x81, data, timeout);
   return BytesUtil.getReply(data, read);
 }
Пример #5
0
 public static void close() throws Exception {
   dev.release_interface(0);
   dev.close();
 }