public SerialDataFrame AsSerialDataFrame() { if (Header != SerialFrameHeader.SOF || Data == null) { throw new InvalidOperationException("Not a data frame"); } var result = new SerialDataFrame(Data); return(result); }
public async Task Write(SerialDataFrame frame, CancellationToken cancellationToken = default) { log.Information("Sending DataFrame for command {command}", frame.Command); await writeSemaphore.WaitAsync(cancellationToken); try { frame.UpdateCheckSum(); frameBeingSent = new TransmitedFrame(frame); log.Verbose("Sending bytes for command {command}", frame.Command); await frameStream.WriteAsync(frame.AsSerialFrame(), cancellationToken); log.Verbose("Awaiting ACK for command {command}", frame.Command); await frameBeingSent.Value.CompletionSource.Task; frameBeingSent = null; } finally { writeSemaphore.Release(); } log.Information("Sent with success"); }
public TransmitedFrame(SerialDataFrame data) { Data = data; CompletionSource = new TaskCompletionSource <bool>(); }