public void Run(IProperties properties, GlobalDic <string, object> globalDic)//virtual
        {
            config = properties as FindDeviceProperties;
            ComDut comDut = globalDic[typeof(ComDut).ToString()] as ComDut;
            ILog   log    = globalDic[typeof(ILog).ToString()] as ILog;

            //int ret = -1;
            //string returnString = "";
            string endLine = config.EndLine;

            TimeUtils.Execute(() =>
            {
                comDut.Write(config.TestPowerOnAT + endLine);
                //comDut.Write("AT+CSQ\r\n");

                Thread.Sleep(config.AtCommandInterval);
                string response = comDut.ReadExisting();
                //comDut.DtrEnable = false;
                //comDut.RtsEnable = false;

                //log.Info("AT Response=" + response);


                if (!string.IsNullOrEmpty(config.AtCommandOk))
                {
                    if (response.Contains(config.AtCommandOk))
                    {
                        log.Info(string.Format("检测到产品上电,AT response=[{0}]  contain =[{1}]", response, config.AtCommandOk));
                        //跳出循环执行
                        return(true);
                        //throw new BaseException(string.Format("AT response=[{0}] not contain error=[{1}]", response, config.AtCommandOk));
                    }
                }


                ////ret = ExeCommand(config, out returnString);
                //if (ret != 0)
                //{
                //    log.Fail(string.Format("详情:{0},检测设备失败 \r\n", returnString));
                //    //throw new BaseException(string.Format("详情:{0},检测设备失败,FAIL\r\n", returnString));

                //}
                //if (returnString.Contains("\tdevice\r\n\r\n"))
                //{
                //    log.Info(string.Format("详情:{0},检测到设备 \r\n", returnString));
                //    //跳出循环执行
                //    return true;
                //}



                //继续循环执行
                return(false);
            }, config.Timeout);
        }
Ejemplo n.º 2
0
        public void Run(IProperties properties, GlobalDic <string, object> globalDic)
        {
            AccessToMacProperties config = properties as AccessToMacProperties;

            ComDut comDut = globalDic[typeof(ComDut).ToString()] as ComDut;
            OpenPhoneProperties configOpenPhone = globalDic[typeof(OpenPhoneProperties).ToString()] as OpenPhoneProperties;
            ILog log = globalDic[typeof(ILog).ToString()] as ILog;

            configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles;

            //string moudleBtMac = configGv.Get("MAC_BT");
            string endLine = configOpenPhone.EndLine;

            if (!string.IsNullOrEmpty(endLine))
            {
                endLine = Parse_r_n(endLine);
            }

            string atCommand = PreTranslateAtCommand(config.AtCommand);

            log.Info("AT Commond=" + atCommand);

            comDut.DtrEnable = configOpenPhone.Dtr;
            comDut.RtsEnable = configOpenPhone.Rts;
            comDut.Write(atCommand + endLine);
            Thread.Sleep(config.AtCommandInterval);
            string response = comDut.ReadExisting();

            comDut.DtrEnable = false;
            comDut.RtsEnable = false;

            log.Info("AT Response=" + response);

            if (!string.IsNullOrEmpty(config.AtCommandError))
            {
                if (response.Contains(config.AtCommandError))
                {
                    throw new BaseException(string.Format("AT response=[{0}] contain error=[{1}]", response, config.AtCommandError));
                }
            }

            if (!string.IsNullOrEmpty(config.AtCommandOk))
            {
                if (!response.Contains(config.AtCommandOk))
                {
                    throw new BaseException(string.Format("AT response=[{0}] not contain error=[{1}]", response, config.AtCommandOk));
                }
            }

            if (config.CheckInfo != null)
            {
                for (int i = 0; i < config.CheckInfo.Length; i++)
                {
                    if (!string.IsNullOrEmpty(config.CheckInfo[i]))
                    {
                        string checkInfo = PreTranslateCheckInfo(config.CheckInfo[i]);
                        if (!response.Contains(checkInfo))
                        {
                            throw new BaseException(string.Format("AT response=[{0}] not contain check info=[{1}]", response, checkInfo));
                        }
                    }
                }
            }
            if (!response.Contains("BLE MAC:"))
            {
                throw new BaseException("不包含BLE MAC:信息");
            }


            if (!string.IsNullOrEmpty(config.GlobalVariblesKey) && !string.IsNullOrEmpty(config.GlobalVariblesKeyPattern))
            {
                string pattern    = Parse_r_n(config.GlobalVariblesKeyPattern);
                Match  matchValue = Regex.Match(response, pattern);
                if (!matchValue.Success)
                {
                    //ble mac为空
                    //log.Info("BLE未写过MAC");
                    throw new BaseException("BLE未写过MAC,请在前面工序写BLE MAC");
                }
                else
                {
                    string value = matchValue.Groups[1].ToString();
                    if (value == "000000000000")
                    {
                        log.Info(string.Format("BLE未写过MAC:{0}", value));
                        throw new BaseException("BLE未写过MAC,请在前面工序写BLE MAC");
                        //configGv.Add(GlobalVaribles.MAC_BT, value);
                    }
                    else
                    {
                        log.Info(string.Format("BLE已写过MAC:{0}", value));
                        //预检查{MoudleBtMac}

                        Match matchKey = Regex.Match(config.GlobalVariblesKey, this.pattern);//this.pattern
                        if (!matchKey.Success)
                        {
                            throw new BaseException("read info key fail");
                        }

                        string key = matchKey.Groups[1].ToString();
                        //预检查
                        MesProcess.PreCheck(value);

                        //赋值BT MAC,WIFI MAC,取消取号
                        configGv.Add(key, value);
                        //configGv.Add(GlobalVaribles.MAC_BT, value);
                        UInt64 macUInt64 = Convert.ToUInt64(value, 16);
                        string macWifi   = string.Format("{0:X}", macUInt64 - 1).PadLeft(12, '0');
                        configGv.Add(GlobalVaribles.MAC, macWifi);

                        log.Info(string.Format("自动计算WIFI MAC号:{0}", macWifi));
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void Run(IProperties properties, GlobalDic <string, object> globalDic)//virtual
        {
            config = properties as WriteWifiMapProperties;
            ComDut comDut = globalDic[typeof(ComDut).ToString()] as ComDut;
            ILog   log    = globalDic[typeof(ILog).ToString()] as ILog;

            configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles;
            String mapFileString = configGv.Get("MapFileStringMacUpdate");

            //int ret = -1;
            //string returnString = "";

            //循环写
            string[] splits  = { "\r", "\n", "\r\n" };
            string[] mapLine = mapFileString.Split(splits, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < mapLine.Length; i++)
            {
                //TimeUtils.Execute(() =>
                //{
                //循环写SSS
                int  retry      = 5;
                int  retryCount = 0;
                bool result     = false;
                do
                {
                    //Thread.Sleep(100);
                    comDut.Write(string.Format(config.WriteMapAtCommand, Convert.ToString(i * 0x10, 16), mapLine[i].Replace(" ", "")) + "\r\n");
                    Thread.Sleep(config.AtCommandInterval);
                    string response = comDut.ReadExisting();

                    if (!string.IsNullOrEmpty(config.AtCommandOk))
                    {
                        if (response.Contains(config.AtCommandOk) && !response.Contains(config.AtCommandError) && !response.Contains("FAIL") && !response.Contains("error"))
                        {
                            //log.Info(string.Format(",AT response=[{0}]  not contain =[{1}]", response, config.AtCommandOk));
                            //跳出循环执行
                            //return true;
                            //throw new BaseException(string.Format("AT response=[{0}] not contain error=[{1}]", response, config.AtCommandOk));
                            log.Info(string.Format("写入第{0}行MAP \r\nAT response:\r\n[{1}] \r\ncontain OK=[{2}] \r\nnot contain ERROR=[{3}] [FAIL]", i + 1, response, config.AtCommandOk, config.AtCommandError));
                            result = true;
                            break;
                        }
                        //else
                        //{
                        //    if (reTryCnt > 3)
                        //    {
                        //        throw new Exception(string.Format("写入错误 行数={0} \r\n串口返回:\r\n{1}", i + 1, response));
                        //    }
                        //}
                    }
                    Thread.Sleep(config.RetryInterval);
                    retry--;
                    retryCount++;
                    if (retry >= 0)
                    {
                        log.Info(string.Format("写入第{0}行MAP错误 \r\nAT response:\r\n[{1}] \r\ncontain OK=[{2}] \r\nnot contain ERROR=[{3}] [FAIL]", i + 1, response, config.AtCommandOk, config.AtCommandError));
                        log.Warn("重试第" + retryCount + "次");
                    }
                } while (retry >= 0);
                if (!result)
                {
                    throw new Exception(string.Format("写入错误 行数={0} \r\n", i + 1));
                }

                //comDut.Write(string.Format(config.WriteMapAtCommand, 0x00 + i * 0x10, mapLine[i].Replace(" ", "")) + "\r\n");
                //Thread.Sleep(config.AtCommandInterval);
                //string response = comDut.ReadExisting();

                //if (!string.IsNullOrEmpty(config.AtCommandOk))
                //{
                //    if (response.Contains(config.AtCommandOk) && !response.Contains(config.AtCommandError) && !response.Contains("FAIL") && !response.Contains("error"))
                //    {
                //        //log.Info(string.Format(",AT response=[{0}]  not contain =[{1}]", response, config.AtCommandOk));
                //        //跳出循环执行
                //        //return true;
                //        //throw new BaseException(string.Format("AT response=[{0}] not contain error=[{1}]", response, config.AtCommandOk));
                //        log.Info(string.Format("写入第{0}行MAP \r\nAT response:\r\n[{1}] \r\ncontain OK=[{2}] \r\nnot contain ERROR=[{3}] [FAIL]", i + 1, response, config.AtCommandOk, config.AtCommandError));

                //        //continue;
                //        //跳出循环执行
                //    }
                //    else
                //    {
                //        if (reTryCnt > 3)
                //        {
                //            throw new Exception(string.Format("写入错误 行数={0} \r\n串口返回:\r\n{1}", i + 1, response));
                //        }
                //    }
                //}



                //    //继续循环执行
                //    return false;
                //}, config.Timeout);
            }
        }
Ejemplo n.º 4
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            TimeSpan remainTime = countDown - (DateTime.Now - start);

            if (remainTime.Ticks <= 0)
            {
                //Timer timer = sender as Timer;
                timer.Stop();
                log.Info(string.Format("未返回正确状态关键字:{0}", this.formTipAndUartCheckProperties.AtCommandOk));

                log.Fail("Wait TimeOut, " + countDown.Seconds + "seconds");
                //Thread.Sleep(100);

                this.Close();
            }
            else
            {
                lblCountDown.Text = "倒计时:" + remainTime.Seconds + "秒";

                if (formTipAndUartCheckProperties.UartDataType == FormTipAndUartCheckProperties.EnumUartDataType.String)
                {
                    string response = comDut.ReadExisting();
                    log.Info("Response:" + response);

                    if (!string.IsNullOrEmpty(this.formTipAndUartCheckProperties.AtCommandOk))
                    {
                        if (response.Contains(this.formTipAndUartCheckProperties.AtCommandOk))
                        {
                            result = true;
                            timer.Stop();
                            //throw new BaseException(string.Format("not contain OK=[{0}]", this.formTipAndUartCheckProperties.AtCommandOk));
                            log.Pass(string.Format("包含关键字:{0}", this.formTipAndUartCheckProperties.AtCommandOk));
                            //Thread.Sleep(500);

                            this.Close();
                        }
                    }
                }
                else if (formTipAndUartCheckProperties.UartDataType == FormTipAndUartCheckProperties.EnumUartDataType.Hex)
                {
                    int n = comDut.BytesToRead;
                    //if (n>0)
                    //{
                    //    byte[] buf = new byte[n];
                    //    comDut.Read(buf, 0, n);

                    //    UartDisplay(buf, "R");

                    //}
                    log.Info(string.Format("接收的长度:{0}", n));
                    if (n != 0)
                    {
                        byte[] buf = new byte[n];
                        comDut.Read(buf, 0, n);
                        UartDisplay(buf, "R");
                        buffer.Clear();
                        buffer.AddRange(buf);
                    }
                    if (buffer.Count > 9)
                    {
                        if (buffer[0] == 0xA5)
                        {
                            //throw new BaseException(string.Format("Head Error"));
                            //if (&& buf[1] == 0xC3))
                            //{

                            //}
                            if (buffer[1] == 0xC3)
                            {
                                byte high         = buffer[2];
                                byte low          = buffer[3];
                                int  iTotalLength = (high & 0xFF) << 8 | low;

                                if (buffer.Count < iTotalLength) //数据区尚未接收完整
                                {
                                    //继续循环执行
                                    log.Info(string.Format("数据尚未接收完整,已接收:{0},总长度:{1}", buffer.Count, iTotalLength));
                                    return;
                                }
                                byte[] oneFrameBytes = new byte[iTotalLength];
                                buffer.CopyTo(0, oneFrameBytes, 0, iTotalLength);
                                buffer.RemoveRange(0, iTotalLength);

                                UartDisplay(oneFrameBytes, "R");

                                #region //开始校验-命令字
                                if (!(oneFrameBytes[6] == 0xA0 && oneFrameBytes[7] == 0x41))
                                {
                                    log.Info(string.Format("返回的命令字错误"));
                                    //继续循环执行
                                    return;
                                }
                                log.Info("收到DUT状态事件上报");
                                //异或校验 1字节
                                byte[] bufOutOxr = new byte[oneFrameBytes.Length - 1];
                                Array.Copy(oneFrameBytes, 0, bufOutOxr, 0, oneFrameBytes.Length - 1);
                                byte xor = ByteToXOR(bufOutOxr);

                                if (oneFrameBytes[iTotalLength - 1] != xor)
                                {
                                    log.Info(string.Format("核验RX的校验位:错误,返回校验位:{0:X2},计算校验位:{1:X2}", oneFrameBytes[iTotalLength - 1], xor));
                                    //继续循环执行
                                    return;
                                }
                                log.Info(string.Format("核验RX的校验位:正确,返回校验位:{0:X2},计算校验位:{1:X2}", oneFrameBytes[iTotalLength - 1], xor));


                                #region                                                      //再显示 按键事件,USB插入检查,电池状态,佩戴检测等状态
                                //数据内容
                                byte[] dataArry = new byte[iTotalLength - 9];                //config.DataLength
                                Array.Copy(oneFrameBytes, 8, dataArry, 0, iTotalLength - 9); //config.DataLength
                                //按键事件
                                switch (dataArry[0])
                                {
                                case 0x00:
                                    log.Info("无按键");
                                    break;

                                case 0x01:
                                    log.Info("电源键按下");
                                    break;

                                case 0x02:
                                    log.Info("加热键被按下");
                                    break;

                                case 0x03:
                                    log.Info("+键被按下");
                                    break;

                                case 0x04:
                                    log.Info("-键被按下");
                                    break;

                                default:
                                    break;
                                }
                                //USB插入事件
                                switch (dataArry[1])
                                {
                                case 0x00:
                                    log.Info("无状态改变");
                                    break;

                                case 0x01:
                                    log.Info("USB 未插入");
                                    break;

                                case 0x02:
                                    log.Info("USB 已插入");
                                    break;

                                default:
                                    break;
                                }
                                //电池状态
                                switch (dataArry[2])
                                {
                                case 0x00:
                                    log.Info("无状态改变");
                                    break;

                                case 0x01:
                                    log.Info("未充电");
                                    break;

                                case 0x02:
                                    log.Info("充电中");
                                    break;

                                case 0x03:
                                    log.Info("充满状态");
                                    break;

                                case 0x04:
                                    log.Info("电量不足");
                                    break;

                                default:
                                    break;
                                }
                                //佩戴检测状态
                                switch (dataArry[3])
                                {
                                case 0x00:
                                    log.Info("无状态改变");
                                    break;

                                case 0x01:
                                    log.Info("未检测到佩戴");
                                    break;

                                case 0x02:
                                    log.Info("检测到有佩戴");
                                    break;

                                default:
                                    break;
                                }
                                #endregion

                                if (formTipAndUartCheckProperties.CheckKeyEvent != FormTipAndUartCheckProperties.EnumCheckKeyEvent.检查)
                                {
                                    switch (formTipAndUartCheckProperties.CheckKeyEvent)
                                    {
                                    case FormTipAndUartCheckProperties.EnumCheckKeyEvent.无按键:
                                        if (dataArry[0] != 0x00)
                                        {
                                            return;
                                        }
                                        break;

                                    case FormTipAndUartCheckProperties.EnumCheckKeyEvent.电源键按下:
                                        if (dataArry[0] != 0x01)
                                        {
                                            return;
                                        }
                                        break;

                                    case FormTipAndUartCheckProperties.EnumCheckKeyEvent.加热键被按下:
                                        if (dataArry[0] != 0x02)
                                        {
                                            return;
                                        }
                                        break;

                                    case FormTipAndUartCheckProperties.EnumCheckKeyEvent.加键被按下:
                                        if (dataArry[0] != 0x03)
                                        {
                                            return;
                                        }
                                        break;

                                    case FormTipAndUartCheckProperties.EnumCheckKeyEvent.减键被按下:
                                        if (dataArry[0] != 0x04)
                                        {
                                            return;
                                        }
                                        break;

                                    default:
                                        break;
                                    }
                                    log.Pass(string.Format("PASS,检测到正确按键上报事件:{0}", formTipAndUartCheckProperties.CheckKeyEvent));
                                }
                                if (formTipAndUartCheckProperties.CheckUsbInsert != FormTipAndUartCheckProperties.EnumCheckUsbInsertEvent.检查)
                                {
                                    switch (formTipAndUartCheckProperties.CheckUsbInsert)
                                    {
                                    case FormTipAndUartCheckProperties.EnumCheckUsbInsertEvent.无状态改变:
                                        if (dataArry[1] != 0x00)
                                        {
                                            return;
                                        }
                                        break;

                                    case FormTipAndUartCheckProperties.EnumCheckUsbInsertEvent.USB未插入:
                                        if (dataArry[1] != 0x01)
                                        {
                                            return;
                                        }
                                        break;

                                    case FormTipAndUartCheckProperties.EnumCheckUsbInsertEvent.USB已插入:
                                        if (dataArry[1] != 0x02)
                                        {
                                            return;
                                        }
                                        break;

                                    default:
                                        break;
                                    }
                                    log.Pass(string.Format("PASS,检测到正确USB状态事件:{0}", formTipAndUartCheckProperties.CheckUsbInsert));
                                }
                                if (formTipAndUartCheckProperties.CheckBatteryStatus != FormTipAndUartCheckProperties.EnumCheckBatteryStatus.检查)
                                {
                                    switch (formTipAndUartCheckProperties.CheckBatteryStatus)
                                    {
                                    case FormTipAndUartCheckProperties.EnumCheckBatteryStatus.无状态改变:
                                        if (dataArry[2] != 0x00)
                                        {
                                            return;
                                        }
                                        break;

                                    case FormTipAndUartCheckProperties.EnumCheckBatteryStatus.未充电:
                                        if (dataArry[2] != 0x01)
                                        {
                                            return;
                                        }
                                        break;

                                    case FormTipAndUartCheckProperties.EnumCheckBatteryStatus.充电中:
                                        if (dataArry[2] != 0x02)
                                        {
                                            return;
                                        }
                                        break;

                                    case FormTipAndUartCheckProperties.EnumCheckBatteryStatus.充满状态:
                                        if (dataArry[2] != 0x03)
                                        {
                                            return;
                                        }
                                        break;

                                    case FormTipAndUartCheckProperties.EnumCheckBatteryStatus.电量不足:
                                        if (dataArry[2] != 0x04)
                                        {
                                            return;
                                        }
                                        break;

                                    default:
                                        break;
                                    }
                                    log.Pass(string.Format("PASS,检测到正确电池状态上报事件:{0}", formTipAndUartCheckProperties.CheckBatteryStatus));
                                }
                                if (formTipAndUartCheckProperties.CheckWearingStatus != FormTipAndUartCheckProperties.EnumCheckWearingStatus.检查)
                                {
                                    switch (formTipAndUartCheckProperties.CheckWearingStatus)
                                    {
                                    case FormTipAndUartCheckProperties.EnumCheckWearingStatus.无状态改变:
                                        if (dataArry[3] != 0x00)
                                        {
                                            return;
                                        }
                                        break;

                                    case FormTipAndUartCheckProperties.EnumCheckWearingStatus.未检测到佩戴:
                                        if (dataArry[3] != 0x01)
                                        {
                                            return;
                                        }
                                        break;

                                    case FormTipAndUartCheckProperties.EnumCheckWearingStatus.检测到有佩戴:
                                        if (dataArry[3] != 0x02)
                                        {
                                            return;
                                        }
                                        break;

                                    default:
                                        break;
                                    }
                                    log.Pass(string.Format("PASS,检测到正确的佩戴状态事件:{0}", formTipAndUartCheckProperties.CheckWearingStatus));
                                }

                                //if (formTipAndUartCheckProperties.== 检查是否是充满状态事件)
                                //{
                                //    if (dataArry[2] != 0x03)
                                //    {
                                //        return;
                                //    }
                                //}
                                //跳出循环执行
                                result = true;
                                timer.Stop();
                                //throw new BaseException(string.Format("not contain OK=[{0}]", this.formTipAndUartCheckProperties.AtCommandOk));
                                //log.Pass(string.Format("PASS,正确状态上报事件:{0}", this.formTipAndUartCheckProperties.AtCommandOk));
                                //Thread.Sleep(500);

                                this.Close();

                                #endregion
                            }
                            else
                            {
                                log.Info(string.Format("头部不是0xA5,0xC3,buffer.RemoveAt:{0:X2},{1:X2}", buffer[0], buffer[1]));
                                buffer.RemoveRange(0, 2);
                                ////继续循环执行
                                //return false;
                            }
                        }
                        else
                        {
                            log.Info(string.Format("头部不是0xA5,buffer.RemoveAt:{0:X2}", buffer[0]));
                            buffer.RemoveAt(0);
                        }
                    }

                    #region //字符串的检查关键字的方式
                    //string response = byteToHexStr(buf);

                    #region //先检查格式
                    //if (buf.Length < 9)
                    //{
                    //    return;
                    //    //throw new BaseException(string.Format("Length Not enough"));
                    //}
                    ////包头
                    //if (!(buf[0] == 0xA5 && buf[1] == 0xC3))
                    //{
                    //    return;

                    //    //throw new BaseException(string.Format("Head Error"));
                    //}
                    ////长度 2字节
                    //byte high = buf[2];
                    //byte low = buf[3];
                    //int iTotalLength = (high & 0xFF) << 8 | low;

                    //if (iTotalLength != n)
                    //{
                    //    return;
                    //    //throw new BaseException(string.Format("Length Error,长度位:{0},实际长度:{1}", iTotalLength, n));
                    //}

                    ////命令字
                    //if (!(buf[6] == 0xA0 && buf[7] == 0x41))
                    //{
                    //    return;
                    //    //throw new BaseException(string.Format("CMD Type Error"));
                    //}


                    ////异或校验 1字节
                    //byte[] bufOutOxr = new byte[buf.Length - 1];
                    //Array.Copy(buf, 0, bufOutOxr, 0, buf.Length - 1);
                    //byte xor = ByteToXOR(bufOutOxr);

                    //if (buf[n - 1] != xor)
                    //{
                    //    return;
                    //    //throw new BaseException(string.Format("校验不正确,返回校验位:{0},计算校验位:{1}", buf[n - 1], xor));
                    //}
                    //log.Info(string.Format("校验位核验正确,返回校验位:{0:X2},计算校验位:{1:X2}", buf[n - 1], xor));
                    #endregion

                    #region //再显示 按键事件,USB插入检查,电池状态,佩戴检测等状态
                    ////数据内容
                    //byte[] dataArry = new byte[iTotalLength - 9];//config.DataLength
                    //Array.Copy(buf, 8, dataArry, 0, iTotalLength - 9);//config.DataLength
                    ////按键事件
                    //switch (dataArry[0])
                    //{
                    //    case 0x00:
                    //        log.Info("无按键");
                    //        break;
                    //    case 0x01:
                    //        log.Info("电源键按下");
                    //        break;
                    //    case 0x02:
                    //        log.Info("加热键被按下");
                    //        break;
                    //    case 0x03:
                    //        log.Info("+键被按下");
                    //        break;
                    //    case 0x04:
                    //        log.Info("-键被按下");
                    //        break;

                    //    default:
                    //        break;
                    //}
                    ////USB插入事件
                    //switch (dataArry[1])
                    //{
                    //    case 0x00:
                    //        log.Info("无状态改变");
                    //        break;
                    //    case 0x01:
                    //        log.Info("USB 未插入");
                    //        break;
                    //    case 0x02:
                    //        log.Info("USB 已插入");
                    //        break;

                    //    default:
                    //        break;
                    //}
                    ////电池状态
                    //switch (dataArry[2])
                    //{
                    //    case 0x00:
                    //        log.Info("无状态改变");
                    //        break;
                    //    case 0x01:
                    //        log.Info("未充电");
                    //        break;
                    //    case 0x02:
                    //        log.Info("充电中");
                    //        break;
                    //    case 0x03:
                    //        log.Info("充满状态");
                    //        break;
                    //    case 0x04:
                    //        log.Info("电量不足");
                    //        break;

                    //    default:
                    //        break;
                    //}
                    ////佩戴检测状态
                    //switch (dataArry[3])
                    //{
                    //    case 0x00:
                    //        log.Info("无状态改变");
                    //        break;
                    //    case 0x01:
                    //        log.Info("未检测到佩戴");
                    //        break;
                    //    case 0x02:
                    //        log.Info("检测到有佩戴");
                    //        break;

                    //    default:
                    //        break;
                    //}
                    #endregion

                    //if (!string.IsNullOrEmpty(this.formTipAndUartCheckProperties.AtCommandOk))
                    //{
                    //    if (response.Contains(this.formTipAndUartCheckProperties.AtCommandOk))
                    //    {
                    //        result = true;
                    //        timer.Stop();
                    //        //throw new BaseException(string.Format("not contain OK=[{0}]", this.formTipAndUartCheckProperties.AtCommandOk));
                    //        log.Pass(string.Format("PASS,返回正确状态关键字:{0}", this.formTipAndUartCheckProperties.AtCommandOk));
                    //        //Thread.Sleep(500);

                    //        this.Close();
                    //    }
                    //}
                    #endregion
                }
            }
        }
Ejemplo n.º 5
0
        public void Run(IProperties properties, GlobalDic <string, object> globalDic)
        {
            AutoToUserModeProperties config     = properties as AutoToUserModeProperties;
            List <ComDut>            comDutList = globalDic[typeof(List <ComDut>).ToString()] as List <ComDut>;
            //ComDut comDut = globalDic[typeof(ComDut).ToString()] as ComDut;
            ComDut comDut = null;

            foreach (var item in comDutList)
            {
                if (item.PortName == config.PortName)
                {
                    comDut = item;
                    break;
                }
            }
            if (comDut == null)
            {
                throw new BaseException(string.Format("ComDut No PortName:{0}", config.PortName));
            }



            //OpenPhoneProperties configOpenPhone = globalDic[typeof(OpenPhoneProperties).ToString()] as OpenPhoneProperties;
            List <OpenPhoneProperties> configList      = globalDic[typeof(List <OpenPhoneProperties>).ToString()] as List <OpenPhoneProperties>;
            OpenPhoneProperties        configOpenPhone = null;

            foreach (var item in configList)
            {
                if (item.PortName == config.PortName)
                {
                    configOpenPhone = item;
                    break;
                }
            }
            if (configOpenPhone == null)
            {
                throw new BaseException(string.Format("OpenPhoneProperties No PortName:{0}", config.PortName));
            }

            ILog log = globalDic[typeof(ILog).ToString()] as ILog;

            configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles;

            string endLine = configOpenPhone.EndLine;

            if (!string.IsNullOrEmpty(endLine))
            {
                endLine = Parse_r_n(endLine);
            }
            //if (config.CommandType == AtCommandProperties.EnumCommandType.String)
            string response = configGv.Get("PowerOnLog");
            {
                string atCommand = PreTranslateAtCommand(config.AtCommand);

                //Thread.Sleep(config.AtCommandInterval);
                //string response = comDut.ReadExisting();
                //comDut.DtrEnable = false;
                //comDut.RtsEnable = false;

                log.Info("PowerOnLog=" + response);

                if (!response.Contains("The driver is for MP"))
                {
                    log.Info("无需转换模式");
                    return;
                }
                //包含的话,需要转模式

                log.Info("AT Commond=" + atCommand);

                comDut.DtrEnable = configOpenPhone.Dtr;
                comDut.RtsEnable = configOpenPhone.Rts;
                comDut.Write(atCommand + endLine);

                Thread.Sleep(config.AtCommandInterval);
                response         = comDut.ReadExisting();
                comDut.DtrEnable = false;
                comDut.RtsEnable = false;
                log.Info("AT Response=" + response);


                if (!string.IsNullOrEmpty(config.AtCommandError))
                {
                    if (response.Contains(config.AtCommandError))
                    {
                        throw new BaseException(string.Format("AT response=[{0}] contain error=[{1}]", response, config.AtCommandError));
                    }
                }

                if (!string.IsNullOrEmpty(config.AtCommandOk))
                {
                    if (!response.Contains(config.AtCommandOk))
                    {
                        throw new BaseException(string.Format("AT response=[{0}] not contain error=[{1}]", response, config.AtCommandOk));
                    }
                }

                if (config.CheckInfo != null)
                {
                    for (int i = 0; i < config.CheckInfo.Length; i++)
                    {
                        if (!string.IsNullOrEmpty(config.CheckInfo[i]))
                        {
                            string checkInfo = PreTranslateCheckInfo(config.CheckInfo[i]);
                            if (!response.Contains(checkInfo))
                            {
                                throw new BaseException(string.Format("AT response=[{0}] not contain check info=[{1}]", response, checkInfo));
                            }
                            log.Info(string.Format("contain check info=[{0}]", checkInfo));
                        }
                    }
                }

                if (config.GlobalVariblesKey != null && config.GlobalVariblesKeyPattern != null)
                {
                    if (config.GlobalVariblesKey.Length != config.GlobalVariblesKeyPattern.Length)
                    {
                        throw new BaseException("请保持GlobalVariblesKey与GlobalVariblesKeyPattern成对存在");
                    }
                    for (int i = 0; i < config.GlobalVariblesKey.Length; i++)
                    {
                        string pattern    = Parse_r_n(config.GlobalVariblesKeyPattern[i]);
                        Match  matchValue = Regex.Match(response, pattern);
                        if (!matchValue.Success)
                        {
                            throw new BaseException("read info value fail");
                        }

                        string value = matchValue.Groups[1].ToString();

                        Match matchKey = Regex.Match(config.GlobalVariblesKey[i], this.pattern);
                        if (!matchKey.Success)
                        {
                            throw new BaseException("read info key fail");
                        }

                        string key = matchKey.Groups[1].ToString();

                        configGv.Add(key, value);
                    }
                }
            }
            //else if (config.CommandType == AtCommandProperties.EnumCommandType.Hex)
            //{
            //    byte[] atCommand = strToToHexByte(config.AtCommand);
            //    //string atCommand = PreTranslateAtCommand(config.AtCommand);
            //    log.Info("AT Commond=" + config.AtCommand);

            //    comDut.DtrEnable = configOpenPhone.Dtr;
            //    comDut.RtsEnable = configOpenPhone.Rts;
            //    comDut.Write(atCommand, 0, atCommand.Length);
            //    log.Info("Tx:" + config.AtCommand);

            //    Thread.Sleep(config.AtCommandInterval);
            //    int length = comDut.ReadBufferSize;
            //    byte[] byteArray = new byte[length];
            //    comDut.Read(byteArray, 0, length);

            //    string hexStr = byteToHexStr(byteArray);
            //    log.Info("Rx:" + hexStr);
            //    string response = System.Text.Encoding.ASCII.GetString(byteArray);
            //    response = response.Replace("\0", "~");
            //    //string response = comDut.ReadExisting();
            //    //byte[] byteArray = System.Text.Encoding.ASCII.GetBytes(response);
            //    configGv.Add("RetBytes", byteArray);

            //    comDut.DtrEnable = false;
            //    comDut.RtsEnable = false;

            //    log.Info("Response:\r\n" + response);

            //    if (!string.IsNullOrEmpty(config.AtCommandError))
            //    {
            //        if (response.Contains(config.AtCommandError))
            //        {
            //            throw new BaseException(string.Format("AT response=[{0}] contain error=[{1}]", response, config.AtCommandError));
            //        }
            //    }

            //    if (!string.IsNullOrEmpty(config.AtCommandOk))
            //    {
            //        if (!response.Contains(config.AtCommandOk))
            //        {
            //            throw new BaseException(string.Format("AT response=[{0}] not contain error=[{1}]", response, config.AtCommandOk));
            //        }
            //    }

            //    if (config.CheckInfo != null)
            //    {
            //        for (int i = 0; i < config.CheckInfo.Length; i++)
            //        {
            //            if (!string.IsNullOrEmpty(config.CheckInfo[i]))
            //            {
            //                string checkInfo = PreTranslateCheckInfo(config.CheckInfo[i]);
            //                if (!response.Contains(checkInfo))
            //                {
            //                    throw new BaseException(string.Format("AT response=[{0}] not contain check info=[{1}]", response, checkInfo));
            //                }
            //            }
            //        }
            //    }

            //    if (config.GlobalVariblesKey != null && config.GlobalVariblesKeyPattern != null)
            //    {
            //        if (config.GlobalVariblesKey.Length != config.GlobalVariblesKeyPattern.Length)
            //        {
            //            throw new BaseException("请保持GlobalVariblesKey与GlobalVariblesKeyPattern成对存在");
            //        }
            //        for (int i = 0; i < config.GlobalVariblesKey.Length; i++)
            //        {
            //            string pattern = "-([0-9]{2}) ";
            //            Match matchValue = Regex.Match(response, pattern);
            //            if (!matchValue.Success)
            //            {
            //                throw new BaseException("read info value fail");
            //            }

            //            string value = matchValue.Groups[1].ToString();

            //            Match matchKey = Regex.Match(config.GlobalVariblesKey[i], this.pattern);
            //            if (!matchKey.Success)
            //            {
            //                throw new BaseException("read info key fail");
            //            }

            //            string key = matchKey.Groups[1].ToString();

            //            configGv.Add(key, value);
            //        }
            //    }
            //}
        }
Ejemplo n.º 6
0
        public void Run(IProperties properties, GlobalDic <string, object> globalDic)
        {
            IsitWrittenToTheBtMacProperties config = properties as IsitWrittenToTheBtMacProperties;

            ComDut comDut = globalDic[typeof(ComDut).ToString()] as ComDut;
            OpenPhoneProperties configOpenPhone = globalDic[typeof(OpenPhoneProperties).ToString()] as OpenPhoneProperties;
            ILog log = globalDic[typeof(ILog).ToString()] as ILog;

            configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles;

            //string moudleBtMac = configGv.Get("MAC_BT");
            string endLine = configOpenPhone.EndLine;

            if (!string.IsNullOrEmpty(endLine))
            {
                endLine = Parse_r_n(endLine);
            }

            string atCommand = PreTranslateAtCommand(config.AtCommand);

            log.Info("AT Commond=" + atCommand);

            comDut.DtrEnable = configOpenPhone.Dtr;
            comDut.RtsEnable = configOpenPhone.Rts;
            comDut.Write(atCommand + endLine);
            Thread.Sleep(config.AtCommandInterval);
            string response = comDut.ReadExisting();

            comDut.DtrEnable = false;
            comDut.RtsEnable = false;

            log.Info("AT Response=" + response);

            if (!string.IsNullOrEmpty(config.AtCommandError))
            {
                if (response.Contains(config.AtCommandError))
                {
                    throw new BaseException(string.Format("AT response=[{0}] contain error=[{1}]", response, config.AtCommandError));
                }
            }

            if (!string.IsNullOrEmpty(config.AtCommandOk))
            {
                if (!response.Contains(config.AtCommandOk))
                {
                    throw new BaseException(string.Format("AT response=[{0}] not contain error=[{1}]", response, config.AtCommandOk));
                }
            }

            if (config.CheckInfo != null)
            {
                for (int i = 0; i < config.CheckInfo.Length; i++)
                {
                    if (!string.IsNullOrEmpty(config.CheckInfo[i]))
                    {
                        string checkInfo = PreTranslateCheckInfo(config.CheckInfo[i]);
                        if (!response.Contains(checkInfo))
                        {
                            throw new BaseException(string.Format("AT response=[{0}] not contain check info=[{1}]", response, checkInfo));
                        }
                    }
                }
            }
            if (!response.Contains("BLE MAC:"))
            {
                if (config.ResultType == AILinkFactoryAuto.Task.SmartBracelet.Property.IsitWrittenToTheBtMacProperties.GetBtMacRetType.ThrowExcption)
                {
                    throw new BaseException("不包含BLE MAC:信息,未能获取到BLE MAC");
                }
                else if (config.ResultType == AILinkFactoryAuto.Task.SmartBracelet.Property.IsitWrittenToTheBtMacProperties.GetBtMacRetType.SKIP)
                {
                    log.Info("不包含BLE MAC:信息,未能获取到BLE MAC");
                    return;
                }
            }


            if (!string.IsNullOrEmpty(config.GlobalVariblesKey) && !string.IsNullOrEmpty(config.GlobalVariblesKeyPattern))
            {
                string pattern    = Parse_r_n(config.GlobalVariblesKeyPattern);
                Match  matchValue = Regex.Match(response, pattern);
                if (!matchValue.Success)
                {
                    if (config.ResultType == AILinkFactoryAuto.Task.SmartBracelet.Property.IsitWrittenToTheBtMacProperties.GetBtMacRetType.ThrowExcption)
                    {
                        throw new BaseException("回复信息不匹配正则表达式,BLE未写过MAC");
                    }
                    else if (config.ResultType == AILinkFactoryAuto.Task.SmartBracelet.Property.IsitWrittenToTheBtMacProperties.GetBtMacRetType.SKIP)
                    {
                        log.Info("回复信息不匹配正则表达式,BLE未写过MAC");
                    }
                }
                else
                {
                    string value = matchValue.Groups[1].ToString();
                    if (value == "000000000000")
                    {
                        if (config.ResultType == AILinkFactoryAuto.Task.SmartBracelet.Property.IsitWrittenToTheBtMacProperties.GetBtMacRetType.ThrowExcption)
                        {
                            throw new BaseException(string.Format("BLE未写过MAC:{0}", value));
                        }
                        else if (config.ResultType == AILinkFactoryAuto.Task.SmartBracelet.Property.IsitWrittenToTheBtMacProperties.GetBtMacRetType.SKIP)
                        {
                            log.Info(string.Format("BLE未写过MAC:{0}", value));
                        }
                    }
                    else
                    {
                        log.Info(string.Format("BLE已写过MAC:{0}", value));
                        //预检查{MoudleBtMac}

                        Match matchKey = Regex.Match(config.GlobalVariblesKey, this.pattern);//this.pattern
                        if (!matchKey.Success)
                        {
                            if (config.ResultType == AILinkFactoryAuto.Task.SmartBracelet.Property.IsitWrittenToTheBtMacProperties.GetBtMacRetType.ThrowExcption)
                            {
                                throw new BaseException("read info key fail");
                            }
                            else if (config.ResultType == AILinkFactoryAuto.Task.SmartBracelet.Property.IsitWrittenToTheBtMacProperties.GetBtMacRetType.SKIP)
                            {
                                log.Info("read info key fail");
                            }
                        }

                        string key = matchKey.Groups[1].ToString();
                        //预检查
                        if (config.ImesPreCheck)
                        {
                            MesProcess.PreCheck(value);
                        }
                        //{MoudleBtMac}
                        configGv.Add(key, value);
                        configGv.Add(key, value);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public void Run(IProperties properties, GlobalDic <string, object> globalDic)
        {
            GetBtRssiAtCommandProperties config = properties as GetBtRssiAtCommandProperties;

            ComDut comDut = globalDic[typeof(ComDut).ToString()] as ComDut;
            OpenPhoneProperties configOpenPhone = globalDic[typeof(OpenPhoneProperties).ToString()] as OpenPhoneProperties;
            ILog log = globalDic[typeof(ILog).ToString()] as ILog;

            configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles;

            string moudleBtMac = configGv.Get("MoudleBtMac");
            string endLine     = configOpenPhone.EndLine;

            if (!string.IsNullOrEmpty(endLine))
            {
                endLine = Parse_r_n(endLine);
            }

            string atCommand = PreTranslateAtCommand(config.AtCommand);

            log.Info("AT Commond=" + atCommand);

            comDut.DtrEnable = configOpenPhone.Dtr;
            comDut.RtsEnable = configOpenPhone.Rts;
            comDut.Write(atCommand + endLine);
            Thread.Sleep(config.AtCommandInterval);
            string response = comDut.ReadExisting();

            comDut.DtrEnable = false;
            comDut.RtsEnable = false;

            log.Info("AT Response=" + response);

            if (!string.IsNullOrEmpty(config.AtCommandError))
            {
                if (response.Contains(config.AtCommandError))
                {
                    throw new BaseException(string.Format("AT response=[{0}] contain error=[{1}]", response, config.AtCommandError));
                }
            }

            if (!string.IsNullOrEmpty(config.AtCommandOk))
            {
                if (!response.Contains(config.AtCommandOk))
                {
                    throw new BaseException(string.Format("AT response=[{0}] not contain error=[{1}]", response, config.AtCommandOk));
                }
            }

            if (config.CheckInfo != null)
            {
                for (int i = 0; i < config.CheckInfo.Length; i++)
                {
                    if (!string.IsNullOrEmpty(config.CheckInfo[i]))
                    {
                        string checkInfo = PreTranslateCheckInfo(config.CheckInfo[i]);
                        if (!response.Contains(checkInfo))
                        {
                            throw new BaseException(string.Format("AT response=[{0}] not contain check info=[{1}]", response, checkInfo));
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(config.GlobalVariblesKey) && !string.IsNullOrEmpty(config.GlobalVariblesKeyPattern))
            {
                string pattern = Parse_r_n(config.GlobalVariblesKeyPattern);//"E000E64CCACE:RSSI:([0-9-]{3,4})[:]"     E000E64CCACE:RSSI:-052:
                pattern = moudleBtMac + pattern;
                Match matchValue = Regex.Match(response, pattern);
                if (!matchValue.Success)
                {
                    throw new BaseException("read info value fail");
                }

                string value = matchValue.Groups[1].ToString();

                Match matchKey = Regex.Match(config.GlobalVariblesKey, this.pattern);
                if (!matchKey.Success)
                {
                    throw new BaseException("read info key fail");
                }

                string key = matchKey.Groups[1].ToString();

                configGv.Add(key, value);
            }
        }
Ejemplo n.º 8
0
        public void Run(IProperties properties, GlobalDic <string, object> globalDic)
        {
            GetLicenseProperties config = properties as GetLicenseProperties;

            ComDut comDut = globalDic[typeof(ComDut).ToString()] as ComDut;
            OpenPhoneProperties configOpenPhone = globalDic[typeof(OpenPhoneProperties).ToString()] as OpenPhoneProperties;
            ILog log = globalDic[typeof(ILog).ToString()] as ILog;

            configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles;

            SerialPort comlog = new SerialPort();

            comlog.PortName = config.PortName;
            comlog.DataBits = 8;
            comlog.StopBits = StopBits.One;
            comlog.Parity   = Parity.None;
            comlog.BaudRate = config.BaudRate;
            //comlog.DtrEnable = config.Dtr;
            //comlog.RtsEnable = config.Rts;
            comlog.Open();

            //string moudleBtMac = configGv.Get("MAC_BT");
            string endLine = config.EndLine;

            if (!string.IsNullOrEmpty(endLine))
            {
                endLine = Parse_r_n(endLine);
            }

            string atCommand = PreTranslateAtCommand(config.AtCommand);

            log.Info("AT Commond=" + atCommand);

            comDut.Write(atCommand + endLine);
            Thread.Sleep(config.AtCommandInterval);
            string response = comDut.ReadExisting();

            comDut.DtrEnable = false;
            comDut.RtsEnable = false;

            log.Info("AT Response=" + response);

            if (!string.IsNullOrEmpty(config.AtCommandError))
            {
                if (response.Contains(config.AtCommandError))
                {
                    throw new BaseException(string.Format("AT response=[{0}] contain error=[{1}]", response, config.AtCommandError));
                }
            }

            if (!string.IsNullOrEmpty(config.AtCommandOk))
            {
                if (!response.Contains(config.AtCommandOk))
                {
                    throw new BaseException(string.Format("AT response=[{0}] not contain error=[{1}]", response, config.AtCommandOk));
                }
            }

            //log口获取接收
            string responseLog = comlog.ReadExisting();

            if (config.IsToUpper)
            {
                responseLog = responseLog.ToUpper();
            }
            responseLog = responseLog.Replace("\r\n", "");

            if (config.CheckInfo != null)
            {
                for (int i = 0; i < config.CheckInfo.Length; i++)
                {
                    if (!string.IsNullOrEmpty(config.CheckInfo[i]))
                    {
                        string checkInfo = PreTranslateCheckInfo(config.CheckInfo[i]);
                        if (!responseLog.Contains(checkInfo))
                        {
                            throw new BaseException(string.Format("responseLog =\r\n{0} \r\n不包含License文件:\r\n{1}", responseLog, checkInfo));
                        }
                    }
                }
            }
            log.Info("LOG Response:\r\n" + responseLog);

            if (comlog.IsOpen)
            {
                comlog.Close();
            }
        }
Ejemplo n.º 9
0
        public void Run(IProperties properties, GlobalDic <string, object> globalDic)//virtual
        {
            config   = properties as FindDeviceProperties;
            configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles;
            List <ComDut> comDutList = globalDic[typeof(List <ComDut>).ToString()] as List <ComDut>;
            //ComDut comDut = globalDic[typeof(ComDut).ToString()] as ComDut;
            ComDut comDut = null;

            foreach (var item in comDutList)
            {
                if (item.PortName == config.PortName)
                {
                    comDut = item;
                    break;
                }
            }
            if (comDut == null)
            {
                throw new BaseException(string.Format("ComDut No PortName:{0}", config.PortName));
            }


            log = globalDic[typeof(ILog).ToString()] as ILog;

            //int ret = -1;
            //string returnString = "";
            string endLine  = config.EndLine;
            string response = "";

            if (config.CommandType == FindDeviceProperties.EnumCommandType.String)
            {
                TimeUtils.Execute(() =>
                {
                    comDut.Write(config.TestPowerOnAT + endLine);
                    Thread.Sleep(config.AtCommandInterval);
                    response += comDut.ReadExisting();
                    if (!string.IsNullOrEmpty(config.AtCommandOk))
                    {
                        if (response.Contains(config.AtCommandOk))
                        {
                            log.Info(string.Format("检测到产品上电,AT response=[{0}]  contain =[{1}]", response, config.AtCommandOk));
                            //跳出循环执行
                            return(true);
                        }
                    }
                    //继续循环执行
                    return(false);
                }, config.Timeout);

                if (!string.IsNullOrEmpty(config.AtCommandError))
                {
                    if (response.Contains(config.AtCommandError))
                    {
                        throw new BaseException(string.Format("AT response contain error:\r\n[{0}]", config.AtCommandError));
                    }
                }


                if (config.CheckInfo != null)
                {
                    for (int i = 0; i < config.CheckInfo.Length; i++)
                    {
                        if (!string.IsNullOrEmpty(config.CheckInfo[i]))
                        {
                            string checkInfo = PreTranslateCheckInfo(config.CheckInfo[i]);
                            if (!response.Contains(checkInfo))
                            {
                                throw new BaseException(string.Format("AT response not contain check info:\r\n{0}", checkInfo));
                            }
                            log.Info(string.Format("AT response contain check info:\r\n{0}", checkInfo));
                        }
                    }
                }
                if (config.GlobalVariblesKey != null && config.GlobalVariblesKeyPattern != null)
                {
                    if (config.GlobalVariblesKey.Length != config.GlobalVariblesKey.Length)
                    {
                        throw new BaseException("GlobalVariblesKey's length !=  GlobalVariblesKeyPattern's length");
                    }
                    for (int i = 0; i < config.GlobalVariblesKey.Length; i++)
                    {
                        if (!string.IsNullOrEmpty(config.GlobalVariblesKey[i]))
                        {
                            string pattern = Parse_r_n(config.GlobalVariblesKeyPattern[i]);
                            //response = response.Replace("\r\n", "").Replace("\r", "").Replace("\n", "");
                            Match matchValue = Regex.Match(response, pattern);
                            if (!matchValue.Success)
                            {
                                throw new BaseException(string.Format("read info {0} value fail", i));
                            }
                            string value    = matchValue.Groups[1].ToString();
                            Match  matchKey = Regex.Match(config.GlobalVariblesKey[i], this.pattern);
                            if (!matchKey.Success)
                            {
                                throw new BaseException(string.Format("read info {0} key fail", i));
                            }
                            string key = matchKey.Groups[1].ToString();
                            configGv.Add(key, value);
                        }
                    }
                }
            }
            else if (config.CommandType == FindDeviceProperties.EnumCommandType.Hex)
            {
                TimeUtils.Execute(() =>
                {
                    byte[] atCommand = strToToHexByte(config.TestPowerOnAT);
                    //string atCommand = PreTranslateAtCommand(config.AtCommand);
                    //log.Info("AT Commond=" + config.TestPowerOnAT);
                    comDut.Write(atCommand, 0, atCommand.Length);

                    Thread.Sleep(config.AtCommandInterval);
                    //string response = comDut.ReadExisting();

                    int n      = comDut.BytesToRead;
                    byte[] buf = new byte[n];
                    comDut.Read(buf, 0, n);
                    response = byteToHexStr(buf);

                    //comDut.Write(config.TestPowerOnAT + endLine);
                    //Thread.Sleep(config.AtCommandInterval);
                    //response += comDut.ReadExisting();
                    if (!string.IsNullOrEmpty(config.AtCommandOk))
                    {
                        if (response.Contains(config.AtCommandOk))
                        {
                            log.Info(string.Format("检测到产品上电,Response:\r\n{0}\r\n  contain:\r\n{1}", response, config.AtCommandOk));
                            //跳出循环执行
                            return(true);
                        }
                    }
                    //继续循环执行
                    return(false);
                }, config.Timeout);

                if (!string.IsNullOrEmpty(config.AtCommandError))
                {
                    if (response.Contains(config.AtCommandError))
                    {
                        throw new BaseException(string.Format("AT response contain error:\r\n[{0}]", config.AtCommandError));
                    }
                }


                if (config.CheckInfo != null)
                {
                    for (int i = 0; i < config.CheckInfo.Length; i++)
                    {
                        if (!string.IsNullOrEmpty(config.CheckInfo[i]))
                        {
                            string checkInfo = PreTranslateCheckInfo(config.CheckInfo[i]);
                            if (!response.Contains(checkInfo))
                            {
                                throw new BaseException(string.Format("AT response not contain check info:\r\n{0}", checkInfo));
                            }
                            log.Info(string.Format("AT response contain check info:\r\n{0}", checkInfo));
                        }
                    }
                }
                if (config.GlobalVariblesKey != null && config.GlobalVariblesKeyPattern != null)
                {
                    if (config.GlobalVariblesKey.Length != config.GlobalVariblesKey.Length)
                    {
                        throw new BaseException("GlobalVariblesKey's length !=  GlobalVariblesKeyPattern's length");
                    }
                    for (int i = 0; i < config.GlobalVariblesKey.Length; i++)
                    {
                        if (!string.IsNullOrEmpty(config.GlobalVariblesKey[i]))
                        {
                            string pattern = Parse_r_n(config.GlobalVariblesKeyPattern[i]);
                            //response = response.Replace("\r\n", "").Replace("\r", "").Replace("\n", "");
                            Match matchValue = Regex.Match(response, pattern);
                            if (!matchValue.Success)
                            {
                                throw new BaseException(string.Format("read info {0} value fail", i));
                            }
                            string value    = matchValue.Groups[1].ToString();
                            Match  matchKey = Regex.Match(config.GlobalVariblesKey[i], this.pattern);
                            if (!matchKey.Success)
                            {
                                throw new BaseException(string.Format("read info {0} key fail", i));
                            }
                            string key = matchKey.Groups[1].ToString();
                            configGv.Add(key, value);
                        }
                    }
                }
            }

            //configGv.Add("PowerOnLog", response);
        }