Exemple #1
0
        /// <summary>
        /// 原始数据解析
        /// </summary>
        /// <param name="OriginalBuffer"></param>
        /// <returns></returns>
        public override FrameBase ParsingReceivedData(byte[] OriginalBuffer)
        {
            Console.WriteLine("串口收到数据<<--" + this.Encoder.ByteEncode(OriginalBuffer));
            FrameBase frame = new FrameBase(OriginalBuffer, null);

            FrameBase.ResultOfParsingFrame result = frame.ParseToFrame(OriginalBuffer);
            if (result.Equals(FrameBase.ResultOfParsingFrame.ReceivingCompleted))
            {
                int len = (int)OriginalBuffer[2];
                return(frame);
            }
            return(null);
        }
Exemple #2
0
        /// <summary>
        /// 原始数据解析
        /// </summary>
        /// <param name="OriginalBuffer"></param>
        /// <returns></returns>
        public override FrameBase ParsingReceivedData(byte[] OriginalBuffer)
        {
            Console.WriteLine("串口收到数据<<--" + this.Encoder.ByteEncode(OriginalBuffer));
            FrameBase frame = new FrameBase(OriginalBuffer, null);

            FrameBase.ResultOfParsingFrame result = frame.ParseToFrame(OriginalBuffer);
            if (result.Equals(FrameBase.ResultOfParsingFrame.ReceivingCompleted))
            {
                int len = (int)OriginalBuffer[2];
                if (OriginalBuffer.Length < len + 7)//数据接收不完整
                {
                    Console.WriteLine("串口丢弃数据-->>" + this.Encoder.ByteEncode(OriginalBuffer));
                    return(null);
                }
                return(frame);
            }
            else
            {
            }
            byte[]        RawBuffer = null;
            StringBuilder builder   = new StringBuilder();

            builder.Append(Encoding.ASCII.GetString(OriginalBuffer));
            string receive_content = builder.ToString();
            int    CRLF_AT         = -1;

            CRLF_AT = receive_content.IndexOf("\r\n", 2);
            if (CRLF_AT != -1)
            {
                string content = receive_content.Substring(0, CRLF_AT + 2);
                RawBuffer = Encoding.ASCII.GetBytes(content);
                return(new FrameBase(RawBuffer, new byte[] { }));
            }
            Console.WriteLine("串口丢弃数据-->>" + receive_content);
            return(null);
        }