Skip to content

Commit

Permalink
Merge pull request #205 from felHR85/multiple_ports_fix
Browse files Browse the repository at this point in the history
Disconnect different UsbSerialDevice objects from same device
  • Loading branch information
felHR85 authored Feb 17, 2019
2 parents aec9b11 + 04db582 commit 0593683
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,18 @@ public boolean disconnectDevice(UsbSerialDevice usbSerialDevice){
}

public boolean disconnectDevice(UsbDevice usbDevice){
Optional<UsbSerialDevice> optionalDevice = Stream.of(serialDevices)
List<UsbSerialDevice> devices = Stream.of(serialDevices)
.filter(p -> usbDevice.getDeviceId() == p.getDeviceId())
.findSingle();
.toList();

if(optionalDevice.isPresent()){
UsbSerialDevice disconnectedDevice = optionalDevice.get();
disconnectedDevice.syncClose();
int removedDevices = 0;
for(UsbSerialDevice device : devices){
device.syncClose();
serialDevices = Utils.removeIf(serialDevices, p -> usbDevice.getDeviceId() == p.getDeviceId());
return true;
removedDevices ++;
}
return false;

return removedDevices == devices.size();
}

public void unregisterListeners(Context context){
Expand Down

0 comments on commit 0593683

Please sign in to comment.