Пример #1
0
        /// <summary>
        /// 发送请求数据
        /// </summary>
        /// <param name="sendFrameBase"></param>
        private void Request(SendFrameBase sendFrameBase)
        {
            if (sendFrameBase == null)
            {
                throw new ArgumentNullException(nameof(sendFrameBase));
            }
            var         data      = sendFrameBase.FullFrame;
            TXContainer container = new TXContainer(data);

            SerialPort.Write(container.FullFrame, 0, container.FullFrame.Length);
            SerialPort.DataReceived += SerialPort_DataReceived;
        }
Пример #2
0
        /// <summary>
        /// 发送请求数据
        /// </summary>
        /// <param name="sendFrameBase"></param>
        /// <returns></returns>
        private async Task <T> Request <T>(SendFrameBase sendFrameBase) where T : ReceiveFrameBase, new()
        {
            if (sendFrameBase == null)
            {
                throw new ArgumentNullException(nameof(sendFrameBase));
            }
            var         data      = sendFrameBase.FullFrame;
            TXContainer container = new TXContainer(data);

            SerialPort.Write(container.FullFrame, 0, container.FullFrame.Length);
            WriteData?.Invoke(container.FullFrame);
            return(await GetRespond <T>());
        }