示例#1
0
        public async Task Send(FrameContent frameContent, CancellationToken cancellationToken)
        {
            byte[] data = _frameSerializer.Serialize(new Frame(frameContent));


            await _writeSemaphoreSlim.WaitAsync(cancellationToken);

            try
            {
#if NETCORE
                await _serialPort.OutputStream.WriteAsync(data.AsBuffer());
#else
                await _serialPort.WriteAsync(data, 0, data.Length, cancellationToken);

                await _serialPort.FlushAsync(cancellationToken);
#endif
            }
            finally
            {
                _writeSemaphoreSlim.Release();
            }
        }