Exemple #1
0
        /// <summary>
        /// 解析接收数据
        /// </summary>
        private void ParseReceive()
        {
            while (true)
            {
                Thread.Sleep(100);

                if (this.dataReceiveStr != "")
                {
                    string tmpReceiveStr = dataReceiveStr;

                    if (tmpReceiveStr.IndexOf("B5") == 0 && tmpReceiveStr.Length % 9 == 0)
                    {
                        this.dataReceiveStr = "";

                        byte[] bufferSend = Converts.StringToBytes(tmpReceiveStr);

                        ByteConvertString(bufferSend);

                        if (EventDataArrival != null && dataArrival.Count > 0)
                        {
                            this.EventDataArrival(dataArrival);
                        }

                        this.dataArrival.Clear();
                    }
                    else
                    {
                        this.dataReceiveStr = "";
                    }
                }
            }
        }
Exemple #2
0
        public bool SendData(string[] strData)
        {
            try
            {
                string message = "A5" + strData[0] + strData[1] + "5A";

                byte[] buffer = Converts.StringToBytes(message);

                this.socket.Send(buffer);

                this.countSend = this.countSend + buffer.Length;

                return(true);
            }
            catch
            {
                return(false);
            }
        }