Future<bool> write(int command, [List<int> data = const []])

Writes a command and optional data to the port.

Completes the returned Future with success of this command.

Source

Future<bool> write(int command, [List<int> data = const <int>[]]) {
  if (data.length > maxDataLength) return new Future.error(
      new ArgumentError('Oversized $command write: '
          '${data.length + packetOverhead} > $maxPacketSize'));
  data = [data.length + 5, (_ack++ & 0xFF), command]..addAll(data);
  int sum = fletcher16(data, data.length);
  int f0 = sum & 0xFF;
  int f1 = (sum >> 8) & 0xFF;

  int c0 = 255 - ((f0 + f1) % 0xFF);
  int c1 = 255 - ((f0 + c0) % 0xFF);
  data..add(c0)..add(c1);

  var work = new _Work(data, new Completer())..sent = _watch.elapsed;
  if (_errorHoldoff != null || // don't break the rules.
      _waitQueue.isNotEmpty || // don't skip in line.
      data.length + _bytesOut > maxPacketSize) {
    _waitQueue.add(work);
  } else {
    _sendWork(work);
  }
  return work.completer.future;
}