コード例 #1
0
        public void Send(byte[] bytes)
        {
            //仅仅用于显示调试信息
            var stringbuilder = new StringBuilder();

            foreach (var b in bytes)
            {
                stringbuilder.Append($"{b:X2}" + " ");
            }
            _commucationFacade.SendDataShow("已发送:" + stringbuilder);
            Debug.WriteLine("已发送:" + stringbuilder);

            if (_comm.IsOpen)
            {
                try
                {
                    _comm.Write(bytes, 0, bytes.Length);
                }
                catch (InvalidOperationException ex)
                {
                    _commucationFacade.CommClientFailed("串口发送数据异常");
                    Debug.WriteLine("客户端串口断开连接");
                    Debug.WriteLine("错误代码:" + ex.Message);
                }
            }
            else
            {
                _commucationFacade.CommClientFailed("comm.IsOpen==false 串口断开");
            }
        }
コード例 #2
0
        public void Send(byte[] bytes)
        {
            try
            {
                //仅仅用于显示调试信息
                var stringbuilder = new StringBuilder();
                foreach (var b in bytes)
                {
                    stringbuilder.Append($"{b:X2}" + " ");
                }
                _commucationFacade.SendDataShow("已发送:" + stringbuilder);
                Debug.WriteLine("已发送:" + stringbuilder);
                Debug.WriteLine("已发送数量:" + bytes.Length);

                _socketTcp?.Send(bytes);
            }
            catch (SocketException)
            {
                _commucationFacade.CommClientFailed("connDisconnect");
            }
        }