How to Detect UU Cable Connnected Programmatically: Difference between revisions

From wizarPOS
(Created page with "Snippet code: <syntaxhighlight lang="java"> /** * Obtain whether the UU cable is connected to the terminal. * 1,getSystemService(Context.USB_SERVICE); * 2,getDeviceList();...")
 
No edit summary
Line 10: Line 10:
  *  UU Cable UsbDevice info :
  *  UU Cable UsbDevice info :
  * [mName=/dev/bus/usb/001/002,
  * [mName=/dev/bus/usb/001/002,
  * mVendorId=1659,mProductId=8963,  // UU Cable : vid,pid
  * mVendorId=1659,mProductId=8963, 9123, 9155,  // UU Cable : vid,pid
  * mClass=0,mSubclass=0,mProtocol=0,
  * mClass=0,mSubclass=0,mProtocol=0,
  * mManufacturerName=Prolific Technology Inc. ,
  * mManufacturerName=Prolific Technology Inc. ,
Line 26: Line 26:
     Log.d("getDeviceList", "device.toString:" + device.toString());
     Log.d("getDeviceList", "device.toString:" + device.toString());
     if (device.getVendorId() == 1659
     if (device.getVendorId() == 1659
         && device.getProductId() == 8963
         && (device.getProductId() == 8963||device.getProductId() == 9123||device.getProductId() == 9155)
         && device.getProductName().startsWith("USB-Serial Controller D")) {
         && device.getProductName().toLowerCase().contains("serial")) {
         // UU Cable connected. TODO
         // UU Cable connected. TODO
     }
     }
}
}
</syntaxhighlight >
</syntaxhighlight >

Revision as of 09:15, 15 November 2023

Snippet code:

/**
 * Obtain whether the UU cable is connected to the terminal.
 * 1,getSystemService(Context.USB_SERVICE);
 * 2,getDeviceList();
 * 3,finding UU cable features;
 */
/**
 *  UU Cable UsbDevice info :
 * [mName=/dev/bus/usb/001/002,
 * mVendorId=1659,mProductId=8963, 9123, 9155,  // UU Cable : vid,pid
 * mClass=0,mSubclass=0,mProtocol=0,
 * mManufacturerName=Prolific Technology Inc. ,
 * mProductName=USB-Serial Controller D,  // UU Cable : productName
 * mVersion=1.16,mSerialNumber=null,
 * mConfigurations=[UsbConfiguration[mId=1,mName=null,mAttributes=128,mMaxPower=50,mInterfaces=[
 * UsbInterface[mId=0,mAlternateSetting=0,mName=null,mClass=255,mSubclass=0,mProtocol=0,mEndpoints=[
 * UsbEndpoint[mAddress=129,mAttributes=3,mMaxPacketSize=10,mInterval=1]
 * UsbEndpoint[mAddress=2,mAttributes=2,mMaxPacketSize=64,mInterval=0]
 * UsbEndpoint[mAddress=131,mAttributes=2,mMaxPacketSize=64,mInterval=0]]]]
 */
UsbManager usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
HashMap<String, UsbDevice> deviceList = usbManager.getDeviceList();
for (UsbDevice device : deviceList.values()) {
    Log.d("getDeviceList", "device.toString:" + device.toString());
    if (device.getVendorId() == 1659
        && (device.getProductId() == 8963||device.getProductId() == 9123||device.getProductId() == 9155)
        && device.getProductName().toLowerCase().contains("serial")) {
        // UU Cable connected. TODO
    }
}