start method

void start(
  1. SendPort setupSendPort
)

Implementation

void start(SendPort setupSendPort) async {
  log('starting');
  ttyFd = _openPort(portPath);
  if (ttyFd! <= 0)
    throw 'open port failed: $ttyFd, ${_lastError()}, $portPath';

  cmdPort.listen(processCmds);
  setupSendPort.send(cmdPort.sendPort);

  // Read and forward any messages from the port
  while (ttyFd != null) {
    log('reading...');
    var data = _read(ttyFd!);
    log('read ${data.runtimeType} : $data');
    if (data is int) {
      log('one byte read');
      notificationSendPort.send(data);
      if (data < 0) {
        notificationSendPort.send(_lastError());
      }
    } else if (data != null) {
      log('multiple bytes read');
      notificationSendPort.send(data);
    } else {
      log('sleep before trying to read again');
      await Future.delayed(const Duration(milliseconds: 100));
    }
  }
  log('exit read loop');
}