Transaction<T> class

The transaction class is an easy way to use the UsbPort class in a more linear way without blocking.

Example

// Create a parser that splits incoming data on endline newline combination ( \r\n)
var c = Transaction.terminated(p.inputStream, Uint8List.fromList([13, 10]));

// Listen asynchronously if you need this:
c.stream.listen((data) {
  print("ASYNC LISTEN $data");
});

var request_1 = Uint8List.fromList([65]);
// Wait two seconds for the answer

Uint8List response_1 = await c.transaction(p, request_1, Duration(seconds: 2));
if (response_1 == null ) {
   print("Failed to get a response.");
}

Constructors

Transaction(Stream<Uint8List> stream, DisposableStreamTransformer<Uint8List, T> transformer)
Transaction Constructor, pass it the untransformed input stream and the transformer to work on the stream.

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stream Stream<T>
getter/setter pair

Methods

dispose() → void
Call dispose when you are done with the object. this will release the underlying stream.
flush() Future<void>
Flush all existing messages from the queue.
getMsg(Duration duration) Future<T?>
Get the next message from the queue if any. returns data or null on error.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
transaction(AsyncDataSinkSource port, Uint8List message, Duration duration) Future<T?>
The transaction functions does 3 things.

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

magicHeader(Stream<Uint8List> stream, List<int> header) Transaction<Uint8List>
Create a transaction that uses MagicHeaderAndLengthByteTransformer
stringTerminated(Stream<Uint8List> stream, Uint8List terminator) Transaction<String>
Create a transaction that transforms the incoming stream into events delimited by 'terminator', returning Strings.
terminated(Stream<Uint8List> stream, Uint8List terminator) Transaction<Uint8List>
Create a transaction that transforms the incoming stream into events delimited by 'terminator'.