sendBytesImmediate method

Future<bool> sendBytesImmediate(
  1. List<int> message
)

Use this method ONLY inside a scheduled task to avoid deadlock.

Implementation

Future<bool> sendBytesImmediate(List<int> message) async {
  if (!_inner.isOpen) {
    _log('[PORT][$portName] sendBytes failed: port not open.');
    return false;
  }

  final payload = Uint8List.fromList(message);
  final framed = (payload.isNotEmpty &&
      payload.first == stx &&
      payload.last  == etx)
      ? payload
      : _frameBytes(payload);

  _log('[TX][$portName] ${ascii.decode(payload, allowInvalid: true)} '
      '(${framed.length} bytes: ${framed})');

  return _writeAll(framed);
}