Skip to content

Commit

Permalink
Add SerialPort::isOpen getter
Browse files Browse the repository at this point in the history
Ref: #4
  • Loading branch information
jpnurmi committed Sep 26, 2020
1 parent b382f6f commit 2f11395
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/src/port.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ abstract class SerialPort {
/// Closes the serial port.
bool close();

/// Gets whether the serial port is open.
bool get isOpen;

/// Gets the name of the port.
///
/// The name returned is whatever is normally used to refer to a port on the
Expand Down Expand Up @@ -254,6 +257,14 @@ class _SerialPortImpl implements SerialPort {
@override
bool close() => dylib.sp_close(_port) == sp_return.SP_OK;

@override
bool get isOpen {
final handle = Util.toInt((ptr) {
return dylib.sp_get_port_handle(_port, ptr.cast());
});
return handle > 0;
}

@override
String get name => Util.fromUtf8(dylib.sp_get_port_name(_port));
@override
Expand Down

0 comments on commit 2f11395

Please sign in to comment.