altera2015 / usbserial

Flutter Android USB Serial plugin
BSD 3-Clause "New" or "Revised" License
119 stars 83 forks source link

Reading messages with \x00 #78

Closed pieterbergmans closed 10 months ago

pieterbergmans commented 1 year ago

Hi...I'm trying to read a message that includes a null terminating character, \x00. The message looks like this..."\x01\x02\x8a\x00{\"errors\":null}\x03\x04". I'm using the Transaction.terminated method like this:

Transaction<Uint8List>? _transaction;

 _transaction = Transaction.terminated(
        _port!.inputStream!,
        Uint8List.fromList("\x03\x04".codeUnits),
);

Unsurprisingly, using the following code produces null since the \x00 terminates the stream.

_transaction!.stream.listen((data) {
        log.i('data: $data');
});

If I remove the \x00 from the message, it works. How can I read this message with \x00?

altera2015 commented 10 months ago

I think that your log is truncating the data, but the data is there. Try converting it to HEX data before printing.