コード例 #1
0
        public SerialDataFrame AsSerialDataFrame()
        {
            if (Header != SerialFrameHeader.SOF || Data == null)
            {
                throw new InvalidOperationException("Not a data frame");
            }

            var result = new SerialDataFrame(Data);

            return(result);
        }
コード例 #2
0
        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");
        }
コード例 #3
0
 public TransmitedFrame(SerialDataFrame data)
 {
     Data             = data;
     CompletionSource = new TaskCompletionSource <bool>();
 }