Skip to content

Commit

Permalink
Re-scan USB ports when connecting
Browse files Browse the repository at this point in the history
  • Loading branch information
Bing-Rover committed Mar 16, 2024
1 parent c6ad777 commit 7aec596
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/src/serial/device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class SerialDevice extends Service {
required this.logger,
}) : _port = SerialPortInterface.factory(portName);


/// Whether the port is open (ie, the device is connected).
bool get isOpen => _port.isOpen;

Expand All @@ -43,6 +44,7 @@ class SerialDevice extends Service {
_controller = StreamController<Uint8List>.broadcast();
return result;
} catch (error) {
logger.warning("Could not open port $portName", body: "$error");
return false;
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/src/serial/port_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "port_interface.dart";
/// A serial port implementation that delegates to [`package:libserialport`](https://pub.dev/packages/libserialport)
class DelegateSerialPort extends SerialPortInterface {
/// A list of all available ports on the device.
static List<String> allPorts = SerialPort.availablePorts;
static List<String> get allPorts => SerialPort.availablePorts;

SerialPort? _delegate;

Expand All @@ -23,6 +23,7 @@ class DelegateSerialPort extends SerialPortInterface {
_delegate = SerialPort(portName);
return _delegate!.openReadWrite();
} catch (error) {
print("Delegate failed to open port $portName\n $error");
return false;
}
}
Expand Down

0 comments on commit 7aec596

Please sign in to comment.