Ejemplo n.º 1
0
        public Recive(AtComm atComm)
        {
            //解析字符串

            /*
             *
             *
             * */
            string souceStr = atComm.ReceviceStr;

            //if (!souceStr.EndsWith("\r\n"))
            //return;
            //截取字符串并放入字符串数组
            //int lines = souceStr.Split(new string[] { "\r\n"},StringSplitOptions.RemoveEmptyEntries).Length;//获取字符串的总行数
            //strs = new string[lines];
            strs = souceStr.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            //for (int i = 0; i < lines; i++)
            //{
            //    int sLength = souceStr.IndexOf("\n") + 1;
            //    string temp = souceStr.Substring(0, sLength);
            //    strs[i] = temp;
            //    souceStr = souceStr.Remove(0, sLength);
            //}
            //解析的字符串与期望值对比
            if (!atComm.CommState)
            {
                Application.DoEvents();
                if (!atComm.IsTimeOut)
                {
                    Commpare(atComm);
                }
                else
                {
                    atComm.CommState = false;
                    return;
                }
            }
        }
Ejemplo n.º 2
0
        private void Commpare(AtComm atComm)
        {
            string expectStr  = atComm.ExpectStr.Substring(1, atComm.ExpectStr.Length - 1);
            char   expectHead = atComm.ExpectStr.Substring(0, 1).ToCharArray()[0];

            switch (expectHead)
            {
            case (char)'S':
                if (strs[0].Contains(expectStr))
                {
                    atComm.CommState = true;
                }
                else
                {
                    if (atComm.IsTimeOut)
                    {
                        atComm.CommState = false;
                    }
                }
                break;

            case (char)'C':
                string afterS = "";
                for (int i = 0; i < strs.Length; i++)
                {
                    afterS += strs[i];
                }
                if (afterS.Contains(expectStr))
                {
                    atComm.CommState = true;
                }
                else
                {
                    if (atComm.IsTimeOut)
                    {
                        atComm.CommState = false;
                    }
                }
                break;

            case (char)'E':
                if (strs[strs.Length - 1].StartsWith(expectStr))
                {
                    atComm.CommState = true;
                }
                else
                {
                    if (atComm.IsTimeOut)
                    {
                        atComm.CommState = false;
                    }
                }
                break;

            default:
                if (atComm.IsTimeOut)
                {
                    atComm.CommState = false;
                }
                break;
            }
        }