예제 #1
0
파일: LEDHelper.cs 프로젝트: TGHGH/MES-CAR
        public void Close()
        {
            byte[] sendBytes = null;
            byte[] receiveBytes = null;
            LEDReceivePackage rPck = null;
            //开屏
            LEDSendPackage spTemp = new LEDSendPackage(LEDCommandType.TempSetDisplayStatus);
            spTemp.TempSetDisplayStatusType = TempSetDisplayStatusType.Start;
            sendBytes = spTemp.GetPackage();
            writer.Write(sendBytes);
            writer.Flush();

            receiveBytes = reader.ReadBytes(52);
            rPck = new LEDReceivePackage(receiveBytes);
            if (rPck.Result != LEDReceiveResult.Sucess)
            {
                throw new Exception("发送失败");
            }
            if (reader != null)
            {
                reader.Close();
            }
            if (writer != null)
            {
                writer.Close();
            }
            if (tcpClient != null)
            {
                tcpClient.Close();
            }
        }
예제 #2
0
파일: LEDHelper.cs 프로젝트: TGHGH/MES-CAR
        /// <summary>
        /// 10ms延迟,GPRS 1分钟;串口 200ms
        /// </summary>
        /// <param name="ip"></param>
        /// <param name="package"></param>
        public void SendMessage(LEDSendPackage package)
        {
            if (tcpClient.Connected)
            {
                byte[] sendBytes = null;
                byte[] receiveBytes = null;
                LEDReceivePackage rPck = null;
                //发送信息
                sendBytes = package.GetPackage();
                writer.Write(sendBytes);
                writer.Flush();

                receiveBytes = reader.ReadBytes(52);
                rPck = new LEDReceivePackage(receiveBytes);
                if (rPck.Result != LEDReceiveResult.Sucess)
                {
                    throw new Exception("发送失败");
                }

            }
        }
예제 #3
0
파일: LEDHelper.cs 프로젝트: TGHGH/MES-CAR
        public void Open(string ip)
        {
            ipAddr = IPAddress.Parse(ip);
            tcpClient = new TcpClient();
            if (!tcpClient.Connected)
                tcpClient.Connect(ipAddr, TCPPort);
            //if (tcpClient.Connected)

            netStream = tcpClient.GetStream();
            writer = new BinaryWriter(netStream);
            reader = new BinaryReader(netStream);
            byte[] sendBytes = null;
            byte[] receiveBytes = null;
            LEDReceivePackage rPck = null;
            //关屏
            LEDSendPackage spTemp = new LEDSendPackage(LEDCommandType.TempSetDisplayStatus);
            spTemp.TempSetDisplayStatusType = TempSetDisplayStatusType.Shutdown;
            sendBytes = spTemp.GetPackage();
            writer.Write(sendBytes);
            writer.Flush();

            receiveBytes = reader.ReadBytes(52);
            rPck = new LEDReceivePackage(receiveBytes);
            if (rPck.Result != LEDReceiveResult.Sucess)
            {
                throw new Exception("发送失败");
            }
        }