felHR85 / UsbSerial

Usb serial controller for Android
MIT License
1.78k stars 582 forks source link

SerialPortBuilder.getSerialPorts() returns duplicate devices when replug the same device #287

Open haoyuant opened 4 years ago

haoyuant commented 4 years ago

Hi, every time I replug the same device, and call the method below, the SerialPortCallback will give me a list with duplicate devices, for example, if I have replugged the same device 3 times, it will end up giving me a list of 3 same devices.

public void listAll(Context context, IFoundUsbDevicesCallback callback) {
        SerialPortCallback serialPortCallback = serialPorts -> {
            List<IAdvancedUsbDevice> devices = new ArrayList<>();
            for (UsbSerialDevice port : serialPorts) {
                devices.add(new AdvancedUsbDevice(port));
            }
            callback.onFoundUsbDevices(devices);
        };

        SerialPortBuilder builder = SerialPortBuilder.createSerialPortBuilder(serialPortCallback);
        builder.getSerialPorts(context);
    }