Skip to content

Commit

Permalink
SerialPortReader: report stream errors
Browse files Browse the repository at this point in the history
This does not a solution to #4 as it does not handle re-subscribtion
or so, just helps to see what's going on.

Ref: #4
  • Loading branch information
jpnurmi committed Sep 26, 2020
1 parent a8db051 commit 42ef0ca
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/src/reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ class _SerialPortReaderImpl implements SerialPortReader {

void _startRead() {
_receiver = ReceivePort();
_receiver.listen((data) => _controller.add(data));
_receiver.listen((data) {
if (data is SerialPortError) {
_controller.addError(data);
} else {
_controller.add(data);
}
});
final args = _SerialPortReaderArgs(
address: _port.address,
timeout: _timeout,
Expand Down Expand Up @@ -119,6 +125,9 @@ class _SerialPortReaderImpl implements SerialPortReader {
return dylib.sp_nonblocking_read(port, ptr.cast(), bytes);
});
args.sendPort.send(data);
} else if (bytes < 0) {
args.sendPort.send(SerialPortError(
SerialPort.lastErrorMessage, SerialPort.lastErrorCode));
}
}
_releaseEvents(events);
Expand Down

0 comments on commit 42ef0ca

Please sign in to comment.