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);
        }
Пример #2
0
        public TipAndCheckUartForm(FormTipAndUartCheckProperties formTipAndUartCheckProperties, ILog log, ComDut comDut)
        {
            InitializeComponent();

            this.formTipAndUartCheckProperties = formTipAndUartCheckProperties;
            this.log = log;

            //lblInfoPass.Text = "PASS:请按" + userConfirmProperties.KeyPass + "键";
            //lblInfoFail.Text = "FAIL:请按" + userConfirmProperties.KeyFail + "键";
            txtTips.Text = formTipAndUartCheckProperties.Tips;
            countDown    = new TimeSpan(formTipAndUartCheckProperties.CountDownTime * 1000 * 10);

            this.comDut = comDut;
        }
Пример #3
0
        public void Run(IProperties properties, GlobalDic <string, object> globalDic)
        {
            FormTipAndUartCheckProperties config = properties as FormTipAndUartCheckProperties;
            ILog          log        = globalDic.Get <ILog>();
            List <ComDut> comDutList = globalDic[typeof(List <ComDut>).ToString()] as List <ComDut>;

            if (comDutList == null || comDutList.Count == 0)
            {
                throw new BaseException("COM为空");
            }
            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));
            }


            TipAndCheckUartForm formUserConfirm = new TipAndCheckUartForm(config, log, comDut)
            {
            };

            formUserConfirm.ShowDialog();

            if (!formUserConfirm.Result)
            {
                throw new BaseException("Fail");
            }
        }
Пример #4
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));
                    }
                }
            }
        }
Пример #5
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);
            }
        }
Пример #6
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);
            //        }
            //    }
            //}
        }
Пример #7
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);
                    }
                }
            }
        }
Пример #8
0
        public void Run(IProperties properties, GlobalDic <string, object> globalDic)
        {
            SKGControlCommandProperties config = properties as SKGControlCommandProperties;
            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));
            }

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

            comDut.Parity = configOpenPhone.Parity;
            string endLine = configOpenPhone.EndLine;

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

            string command = "";

            command += config.Head;

            //int型的处理-转2字节byte,连接到16进制字符串中
            int allLength = 9 + 17; //config.DataLength

            byte[] byteTemp    = new byte[2];
            byte[] oneByteTemp = new byte[1];

            byteTemp = intToBytes(allLength);
            command += byteToHexStr(byteTemp);

            command += config.ReservedWord;
            command += config.CommandWord;

            //DataContent部分
            //枚举类的处理
            int intTemp = (int)config.PowerOnOffSetting;//开关机设置

            if (config.PowerOnOffSetting != 0)
            {
                log.Info(string.Format("开关机设置:{0}", config.PowerOnOffSetting));
            }
            command += intTemp.ToString().PadLeft(2, '0');

            intTemp = (int)config.LedModeSetting;
            if (config.LedModeSetting != 0)
            {
                log.Info(string.Format("LED 模式设置:{0}", config.LedModeSetting));
            }
            command += intTemp.ToString().PadLeft(2, '0');

            intTemp = (int)config.EmsTestSwitch;
            if (config.EmsTestSwitch != 0)
            {
                log.Info(string.Format("EMS 测试开关设置:{0}", config.EmsTestSwitch));
            }
            command += intTemp.ToString().PadLeft(2, '0');

            //int型的处理
            byteTemp = intToBytes(config.EmsPWSetting);
            if (config.EmsPWSetting != 0)
            {
                log.Info(string.Format("EMS 脉宽设置:{0}uS", config.EmsPWSetting));
            }
            command += byteToHexStr(byteTemp);

            byteTemp = intToBytes(config.EmsFreqSetting);
            if (config.EmsFreqSetting != 0)
            {
                log.Info(string.Format("EMS 频率设置:{0}Hz", config.EmsFreqSetting));
            }
            command += byteToHexStr(byteTemp);

            byteTemp = intToBytes(config.EmsAmplitudeSetting);
            if (config.EmsAmplitudeSetting != 0)
            {
                log.Info(string.Format("EMS 幅度设置:{0}mV", config.EmsAmplitudeSetting));
            }

            command += byteToHexStr(byteTemp);

            //枚举类的处理
            intTemp = (int)config.HeatingGearControl;
            if (config.HeatingGearControl != 0)
            {
                log.Info(string.Format("加热档位控制:{0}", config.HeatingGearControl));
            }
            command += intTemp.ToString().PadLeft(2, '0');

            intTemp  = (int)config.VoiceControl;
            command += intTemp.ToString().PadLeft(2, '0');

            intTemp = (int)config.WritePcbaFinishFlag;
            if (config.WritePcbaFinishFlag != 0)
            {
                log.Info(string.Format("PCBA 测试完成标志:{0}", config.WritePcbaFinishFlag));
            }
            command += intTemp.ToString().PadLeft(2, '0');

            intTemp = (int)config.WholeMachineFinishFlag;
            if (config.WholeMachineFinishFlag != 0)
            {
                log.Info(string.Format("PCBA 测试完成标志:{0}", config.WholeMachineFinishFlag));
            }

            command += intTemp.ToString().PadLeft(2, '0');

            intTemp = (int)config.BtTestOnOffSetting;
            if (config.BtTestOnOffSetting != 0)
            {
                log.Info(string.Format("蓝牙模块测试:{0}", config.BtTestOnOffSetting));
            }
            command += intTemp.ToString().PadLeft(2, '0');

            intTemp = (int)config.MotorControl;
            if (config.MotorControl != 0)
            {
                log.Info(string.Format("电机控制:{0}", config.MotorControl));
            }
            command += intTemp.ToString().PadLeft(2, '0');

            intTemp = (int)config.AginTestOnOffSetting;
            if (config.AginTestOnOffSetting != 0)
            {
                log.Info(string.Format("老化测试开关:{0}", config.AginTestOnOffSetting));
            }
            command += intTemp.ToString().PadLeft(2, '0');

            //int型的处理-转为1字节byte
            oneByteTemp = intToOneBytes(config.AginTestTime);
            if (config.AginTestTime != 0)
            {
                log.Info(string.Format("老化测试时间:{0}分钟", config.AginTestTime * 10));
            }
            command += byteToHexStr(oneByteTemp);
            #region 多路振动控制
            //高位在前,第16位,为第16个电机
            if (true)
            {
                //int bit1 = (int)config.VibrationControl16;
                //bit1 = bit1 << 7;

                //int bit2 = (int)config.VibrationControl15;
                //bit2 = bit2 << 6;

                //int bit3 = (int)config.VibrationControl14;
                //bit3 = bit3 << 5;

                //int bit4 = (int)config.VibrationControl13;
                //bit4 = bit4 << 4;

                //int bit5 = (int)config.VibrationControl12;
                //bit5 = bit5 << 3;

                //int bit6 = (int)config.VibrationControl11;
                //bit6 = bit6 << 2;

                //int bit7 = (int)config.VibrationControl10;
                //bit7 = bit7 << 1;

                //int bit8 = (int)config.VibrationControl9;

                //int byte2 = bit1 | bit2 | bit3 | bit4 | bit5 | bit6 | bit7 | bit8;
                //command += byte2.ToString("X");//.PadLeft(2, '0')

                //bit1 = (int)config.VibrationControl8;
                //bit1 = bit1 << 7;

                //bit2 = (int)config.VibrationControl7;
                //bit2 = bit2 << 6;

                //bit3 = (int)config.VibrationControl6;
                //bit3 = bit3 << 5;

                //bit4 = (int)config.VibrationControl5;
                //bit4 = bit4 << 4;

                //bit5 = (int)config.VibrationControl4;
                //bit5 = bit5 << 3;

                //bit6 = (int)config.VibrationControl3;
                //bit6 = bit6 << 2;

                //bit7 = (int)config.VibrationControl2;
                //bit7 = bit7 << 1;

                //bit8 = (int)config.VibrationControl1;

                //int byte1 = bit1 | bit2 | bit3 | bit4 | bit5 | bit6 | bit7 | bit8;

                //command += byte1.ToString("X").PadLeft(2, '0');
            }
            #endregion
            #region 640nm 红光控制,G7 新增功能
            if (true)
            {
                //intTemp = (int)config.RedLightControl640nm;
                //command += intTemp.ToString("X").PadLeft(2, '0');//
            }
            #endregion
            //在加校验位
            byte[] exceptXor = strToToHexByte(command);
            byte   xor       = ByteToXOR(exceptXor);
            command += xor.ToString("X").PadLeft(2, '0');

            //发送完整控制命令
            byte[] atCommand = strToToHexByte(command);

            //string atCommand = PreTranslateAtCommand(config.AtCommand);
            UartDisplay(atCommand, "T");

            //log.Info("AT Commond=" + config.AtCommand);

            comDut.DtrEnable = configOpenPhone.Dtr;
            comDut.RtsEnable = configOpenPhone.Rts;
            comDut.Write(atCommand, 0, atCommand.Length);
            Thread.Sleep(config.AtCommandInterval);

            #region
            //DateTime start = DateTime.Now;
            //DateTime now = DateTime.Now;
            //TimeSpan timeSpan = now - start;
            //while (timeSpan.TotalMilliseconds <= config.Timeout)
            //{
            //    try
            //    {
            //        comDut.Write(atCommand, 0, atCommand.Length);
            //        Thread.Sleep(config.AtCommandInterval);

            //        int n = comDut.BytesToRead;
            //        byte[] buf = new byte[n];
            //        comDut.Read(buf, 0, n);
            //        //解析是否收到正确的包,包头,命令,校验位

            //        //如果收到的包正确
            //        if (true)
            //        {
            //            break;
            //        }
            //    }
            //    catch (Exception e)
            //    {
            //        Console.WriteLine(e);
            //    }

            //    Thread.Sleep(100);
            //    now = DateTime.Now;
            //    timeSpan = now - start;
            //}

            //if (timeSpan.TotalMilliseconds > config.Timeout)
            //{
            //    throw new BaseException("超时:");
            //}
            #endregion

            TimeUtils.Execute(() =>
            {
                int n = comDut.BytesToRead;
                //if (n == 0 )
                //{
                //    //继续循环执行
                //    return false;
                //}
                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);
                }
                //byte[] buf = new byte[n];
                //comDut.Read(buf, 0, n);
                //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(false);
                            }
                            byte[] oneFrameBytes = new byte[iTotalLength];
                            buffer.CopyTo(0, oneFrameBytes, 0, iTotalLength);
                            buffer.RemoveRange(0, iTotalLength);

                            UartDisplay(oneFrameBytes, "R");

                            #region //开始校验-命令字
                            if (config.CommandType == SKGControlCommandProperties.EnumCommandType.查询指令)
                            {
                                if (!(oneFrameBytes[6] == 0xA0 && oneFrameBytes[7] == 0x37))
                                {
                                    log.Info(string.Format("CMD Type Error"));
                                    //继续循环执行
                                    return(false);
                                }
                            }
                            else if (config.CommandType == SKGControlCommandProperties.EnumCommandType.控制指令)
                            {
                                if (!(oneFrameBytes[6] == 0xA0 && oneFrameBytes[7] == 0x40))
                                {
                                    log.Info(string.Format("CMD Type Error"));
                                    //继续循环执行
                                    return(false);
                                }
                            }
                            else if (config.CommandType == SKGControlCommandProperties.EnumCommandType.发授权)
                            {
                                if (!(oneFrameBytes[6] == 0xA0 && oneFrameBytes[7] == 0x23))
                                {
                                    log.Info(string.Format("CMD Type Error"));
                                    //继续循环执行
                                    return(false);
                                }
                            }
                            else
                            {
                                log.Info(string.Format("非法指令类型"));
                                //继续循环执行
                                return(false);
                            }

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

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

                            //数据内容 32个字节——长度是不固定的
                            byte[] dataArry = new byte[iTotalLength - 9];                //config.DataLength
                            Array.Copy(oneFrameBytes, 8, dataArry, 0, iTotalLength - 9); //config.DataLength

                            //添加到全局变量中
                            if (config.GlobalVariblesKey != null)
                            {
                                for (int i = 0; i < config.GlobalVariblesKey.Length; i++)
                                {
                                    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, dataArry);
                                    log.Info("应答报文格式检查PASS");
                                }
                            }

                            //跳出循环执行
                            return(true);

                            #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);
                        //继续循环执行
                        return(false);
                    }
                }
                else
                {
                    log.Info(string.Format("buffer.Count:{0}小于最小长度9", buffer.Count));
                    //继续循环执行
                    return(false);
                }
            }, config.Timeout);

            #region 原发送命令后等待一固定时间,再接收数据,对应不上则重试

            ////解析是否收到正确的包,包头,命令,校验位
            ////起始标志 数据长度 保留字     命令字     数据内容    异或校验码
            ////0XA5C3    9+N     0x0000      0x0037      Data        异或
            ////2 字节  2 字节    2 字节      2 字节      N 字节     1 字节
            //UartDisplay(buf, "R");
            //if (buf.Length < 9)
            //{
            //    throw new BaseException(string.Format("Response Length Not enough"));
            //}
            ////包头
            //if (!(buf[0] == 0xA5 && buf[1] == 0xC3))
            //{
            //    throw new BaseException(string.Format("Response Head Error"));
            //}
            ////长度 2字节
            //byte high = buf[2];
            //byte low = buf[3];
            //int iTotalLength = (high & 0xFF) << 8 | low;

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

            ////命令字
            //if (config.CommandType == SKGControlCommandProperties.EnumCommandType.查询指令)
            //{
            //    if (!(buf[6] == 0xA0 && buf[7] == 0x37))
            //    {
            //        throw new BaseException(string.Format("Response Command Type Error"));
            //    }
            //}
            //else if (config.CommandType == SKGControlCommandProperties.EnumCommandType.控制指令)
            //{
            //    if (!(buf[6] == 0xA0 && buf[7] == 0x40))
            //    {
            //        throw new BaseException(string.Format("Response Command Type Error"));
            //    }
            //}
            //else if (config.CommandType == SKGControlCommandProperties.EnumCommandType.下发授权)
            //{
            //    if (!(buf[6] == 0xA0 && buf[7] == 0x23))
            //    {
            //        throw new BaseException(string.Format("Response Command Type Error"));
            //    }
            //}
            //else
            //{
            //    throw new BaseException(string.Format("Response为非法指令类型"));
            //}


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

            //if (buf[n - 1] != retXor)
            //{
            //    throw new BaseException(string.Format("核验RX的校验位:错误,返回校验位:{0:X2},计算校验位:{1:X2}", buf[n - 1], retXor));
            //}
            //log.Info(string.Format("核验RX的校验位:正确,返回校验位:{0:X2},计算校验位:{1:X2}", buf[n - 1], retXor));


            ////数据内容 32个字节
            ////byte[] dataArry = new byte[config.DataLength];
            ////Array.Copy(buf, 8, dataArry, 0, config.DataLength);

            //byte[] dataArry = new byte[iTotalLength - 9];//config.DataLength
            //Array.Copy(buf, 8, dataArry, 0, iTotalLength - 9);//config.DataLength

            ////添加到全局变量中
            //if (config.GlobalVariblesKey != null)
            //{
            //    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, dataArry);
            //        log.Info("应答报文格式检查PASS");
            //    }
            //}
            #endregion
            //检查是否有效果!!!
            //通过另外一个AT口,去获取电流值



            ////如果收到的包正确
            //string str = byteToHexStr(buf);


            //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 (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);
            //    }
            //}
        }
Пример #9
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);
            }
        }
Пример #10
0
        public void Run(IProperties properties, GlobalDic <string, object> globalDic)
        {
            SKGProperties config     = properties as SKGProperties;
            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));
            }

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

            comDut.Parity = configOpenPhone.Parity;
            string endLine = configOpenPhone.EndLine;

            if (!string.IsNullOrEmpty(endLine))
            {
                endLine = Parse_r_n(endLine);
            }
            byte[] atCommand = strToToHexByte(config.AtCommand);
            //string atCommand = PreTranslateAtCommand(config.AtCommand);
            UartDisplay(atCommand, "T");

            //log.Info("AT Commond=" + config.AtCommand);

            comDut.DtrEnable = configOpenPhone.Dtr;
            comDut.RtsEnable = configOpenPhone.Rts;
            comDut.Write(atCommand, 0, atCommand.Length);
            Thread.Sleep(config.AtCommandInterval);

            #region
            //DateTime start = DateTime.Now;
            //DateTime now = DateTime.Now;
            //TimeSpan timeSpan = now - start;
            //while (timeSpan.TotalMilliseconds <= config.Timeout)
            //{
            //    try
            //    {
            //        comDut.Write(atCommand, 0, atCommand.Length);
            //        Thread.Sleep(config.AtCommandInterval);

            //        int n = comDut.BytesToRead;
            //        byte[] buf = new byte[n];
            //        comDut.Read(buf, 0, n);
            //        //解析是否收到正确的包,包头,命令,校验位

            //        //如果收到的包正确
            //        if (true)
            //        {
            //            break;
            //        }
            //    }
            //    catch (Exception e)
            //    {
            //        Console.WriteLine(e);
            //    }

            //    Thread.Sleep(100);
            //    now = DateTime.Now;
            //    timeSpan = now - start;
            //}

            //if (timeSpan.TotalMilliseconds > config.Timeout)
            //{
            //    throw new BaseException("超时:");
            //}
            #endregion
            //发命令后一直循环接收->检验->拼接,超过500ms还没检验通过则超时FAIL
            TimeUtils.Execute(() =>
            {
                int n = comDut.BytesToRead;
                //if (n==0)
                //{
                //    //继续循环执行
                //    return false;
                //}
                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);
                }

                //byte[] buf = new byte[n];
                //comDut.Read(buf, 0, n);
                //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(false);
                            }
                            byte[] oneFrameBytes = new byte[iTotalLength];
                            buffer.CopyTo(0, oneFrameBytes, 0, iTotalLength);
                            buffer.RemoveRange(0, iTotalLength);

                            UartDisplay(oneFrameBytes, "R");

                            #region //开始校验-命令字
                            if (config.CommandType == SKGProperties.EnumCommandType.查询指令)
                            {
                                if (!(oneFrameBytes[6] == 0xA0 && oneFrameBytes[7] == 0x37))
                                {
                                    log.Info(string.Format("CMD Type Error"));
                                    //继续循环执行
                                    return(false);
                                }
                            }
                            else if (config.CommandType == SKGProperties.EnumCommandType.控制指令)
                            {
                                if (!(oneFrameBytes[6] == 0xA0 && oneFrameBytes[7] == 0x40))
                                {
                                    log.Info(string.Format("CMD Type Error"));
                                    //继续循环执行
                                    return(false);
                                }
                            }
                            else if (config.CommandType == SKGProperties.EnumCommandType.发授权)
                            {
                                if (!(oneFrameBytes[6] == 0xA0 && oneFrameBytes[7] == 0x23))
                                {
                                    log.Info(string.Format("CMD Type Error"));
                                    //继续循环执行
                                    return(false);
                                }
                            }
                            else
                            {
                                log.Info(string.Format("非法指令类型"));
                                //继续循环执行
                                return(false);
                            }

                            //异或校验 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(false);
                            }
                            log.Info(string.Format("核验RX的校验位:正确,返回校验位:{0:X2},计算校验位:{1:X2}", oneFrameBytes[iTotalLength - 1], xor));

                            //数据内容 32个字节——长度是不固定的
                            byte[] dataArry = new byte[iTotalLength - 9];                //config.DataLength
                            Array.Copy(oneFrameBytes, 8, dataArry, 0, iTotalLength - 9); //config.DataLength

                            //添加到全局变量中
                            if (config.GlobalVariblesKey != null)
                            {
                                for (int i = 0; i < config.GlobalVariblesKey.Length; i++)
                                {
                                    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, dataArry);
                                    log.Info("应答报文格式检查PASS");
                                }
                            }

                            //跳出循环执行
                            return(true);

                            #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);
                        //继续循环执行
                        return(false);
                    }
                }
                else
                {
                    //继续循环执行
                    log.Info(string.Format("buffer.Count:{0}小于最小长度9", buffer.Count));

                    return(false);
                }
            }, config.Timeout);

            //int n = comDut.BytesToRead;
            //byte[] buf = new byte[n];
            //comDut.Read(buf, 0, n);
            #region
            ////1.缓存数据
            //buffer.AddRange(buf);

            //if (!flagCmdHandle)
            //{
            //    //如果接受到的上一帧数据未处理,软件只接受数据进buffer,不提取指令
            //    return;
            //}

            //2.完整性判断
            //while (buffer.Count >= 9) //至少包含帧头(2字节)、长度(1字节)、校验位(1字节);根据设计不同而不同
            //{
            //    //2.1 查找数据头
            //    if (buffer[0] == 0xAA) //传输数据有帧头1,用于判断
            //    {
            //        //if (buffer[1] == 0xFF) //传输数据有帧头2,用于判断
            //        //{
            //        int iDataLength = buffer[1];

            //        int iTotalLength = iDataLength + 1;//前两个与最后一个

            //        int cnt = 0;
            //        //for (int i = 0; i < buffer.Count; i++)
            //        //{
            //        //    if (buffer[i] == 0x55 && buffer[i - 1] == 0xFF)
            //        //    {
            //        //        cnt++;
            //        //    }
            //        //}

            //        //if (buffer.Count>)
            //        //{

            //        //}

            //        if (buffer.Count < iTotalLength + cnt) //数据区尚未接收完整
            //        {
            //            break;
            //        }

            //        //得到完整的数据,复制到rawBytes中进行校验

            //        iTotalLength = buffer.Count;

            //        byte[] rawBytes = new byte[iTotalLength];
            //        buffer.CopyTo(0, rawBytes, 0, iTotalLength);
            //        buffer.Clear();

            //        //if (buffer[10] == 0x01)
            //        //{

            //        //    byte[] rawBytes = { 0xFF, 0xFF, 0x2A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA5, 0x01, 0x04, 0x09, 0xE0, 0xB6, 0xF5, 0x18, 0x8D, 0x40, 0x13, 0x78, 0x0D, 0xE4, 0xDE, 0xE1, 0x15, 0x96, 0x4A, 0x3E, 0xDC, 0x1C, 0xE1, 0xAA, 0xFF, 0x55, 0x85, 0xDB, 0xC6, 0xFD, 0x76, 0x32, 0x39, 0x6F, 0x8E, 0x67, 0xFA };
            //        //}

            //        byte checksum = 0; //开始校验

            //        //if (rawBytes[rawBytes.Length - 1] == 0x55 && rawBytes[rawBytes.Length - 2] == 0xFF)
            //        //{
            //        //    for (int i = 2; i < rawBytes.Length - 2; i++)
            //        //    {
            //        //        checksum += rawBytes[i];
            //        //    }

            //        //    if (checksum != rawBytes[rawBytes.Length - 2]) //校验失败,最后一个字节是校验位
            //        //    {
            //        //        UartDisplay("Rx Error\r\n");
            //        //        continue;
            //        //    }
            //        //}
            //        //else
            //        //{
            //        for (int i = 1; i < rawBytes.Length - 1; i++)
            //        {
            //            checksum += rawBytes[i];
            //        }
            //        checksum = (byte)~checksum;
            //        checksum += 0x01;
            //        if (checksum != rawBytes[rawBytes.Length - 1]) //校验失败,最后一个字节是校验位
            //        {
            //            UartDisplay("Rx Error\r\n");
            //            continue;
            //        }
            //        //}

            //        UartDisplay(rawBytes, "R");


            //        //ReceiveBytes = new byte[rawBytes.Length];
            //        //rawBytes.CopyTo(ReceiveBytes, 0);
            //        flagCmdHandle = false;
            //        RecCmd_AC(rawBytes);
            //        //}
            //        rawBytes = null;
            //        flagCmdHandle = true;
            //    }
            //    else //帧头1不正确时,记得清除
            //    {
            //        buffer.RemoveAt(0);
            //    }
            //}
            #endregion

            #region
            ////解析是否收到正确的包,包头,命令,校验位
            ////起始标志 数据长度 保留字     命令字     数据内容    异或校验码
            ////0XA5C3    9+N     0x0000      0x0037      Data        异或
            ////2 字节  2 字节    2 字节      2 字节      N 字节     1 字节
            //UartDisplay(buf,"R");
            //if (buf.Length < 9)
            //{
            //    throw new BaseException(string.Format("Length Not enough"));
            //}
            ////包头
            //if (!(buf[0]==0xA5 && buf[1]==0xC3))
            //{
            //    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)
            //{
            //    throw new BaseException(string.Format("Length Error,长度位:{0},实际长度:{1}", iTotalLength,n));
            //}

            ////命令字
            //if (config.CommandType==SKGProperties.EnumCommandType.查询指令)
            //{
            //    if (!(buf[6] == 0xA0 && buf[7] == 0x37))
            //    {
            //        throw new BaseException(string.Format("CMD Type Error"));
            //    }
            //}
            //else if(config.CommandType == SKGProperties.EnumCommandType.控制指令)
            //{
            //    if (!(buf[6] == 0xA0 && buf[7] == 0x40))
            //    {
            //        throw new BaseException(string.Format("CMD Type Error"));
            //    }
            //}
            //else if(config.CommandType == SKGProperties.EnumCommandType.下发授权)
            //{
            //    if (!(buf[6] == 0xA0 && buf[7] == 0x23))
            //    {
            //        throw new BaseException(string.Format("CMD Type Error"));
            //    }
            //}
            //else
            //{
            //    throw new BaseException(string.Format("非法指令类型"));
            //}


            ////异或校验 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)
            //{
            //    throw new BaseException(string.Format("核验RX的校验位:错误,返回校验位:{0:X2},计算校验位:{1:X2}", buf[n - 1], xor));
            //}
            //log.Info(string.Format("核验RX的校验位:正确,返回校验位:{0:X2},计算校验位:{1:X2}", buf[n - 1], xor));



            ////数据内容 32个字节——长度是不固定的
            //byte[] dataArry = new byte[iTotalLength-9];//config.DataLength
            //Array.Copy(buf, 8, dataArry, 0, iTotalLength - 9);//config.DataLength

            ////添加到全局变量中
            //if (config.GlobalVariblesKey != null)
            //{
            //    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, dataArry);
            //        log.Info("应答报文格式检查PASS");
            //    }
            //}
            #endregion


            ////如果收到的包正确
            //string str = byteToHexStr(buf);


            //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 (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);
            //    }
            //}
        }
Пример #11
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();
            }
        }
Пример #12
0
        public void Run(IProperties properties, GlobalDic <string, object> globalDic)
        {
            config = properties as CheckHexUartPowerOnProperties;
            ILog log = globalDic[typeof(ILog).ToString()] as ILog;

            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));
            }



            //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));
            }


            string endLine = configOpenPhone.EndLine;

            if (!string.IsNullOrEmpty(endLine))
            {
                endLine = Parse_r_n(endLine);
            }
            //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.Parity = System.IO.Ports.Parity.Even;

            TimeUtils.Execute(() =>
            {
                Thread.Sleep(config.AtCommandInterval);
                int length       = comDut.ReadBufferSize;
                byte[] byteArray = new byte[length];
                comDut.Read(byteArray, 0, length);
                configGv.Add("RetBytes", byteArray);

                byte[] retArray = configGv.GetObject("RetBytes") as byte[];
                for (int i = 0; i < retArray.Length; i++)
                {//55 AA 03
                    if (retArray[i] == 0x55 &&
                        retArray[i + 1] == 0xAA &&
                        retArray[i + 2] == 0x03
                        )
                    {
                        //flageRightRes = true;
                        //startIndex = i;
                        //break;
                        log.Info(string.Format("检测到产品上电,55 AA 03"));
                        //跳出循环执行
                        return(true);
                    }
                }
                //继续循环执行
                return(false);
            }, config.Timeout);
        }
Пример #13
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);
        }
Пример #14
0
        public void Run(IProperties properties, GlobalDic <string, object> globalDic)
        {
            config = properties as CheckHexUartProperties;
            ILog log = globalDic[typeof(ILog).ToString()] as ILog;

            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));
            }



            //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));
            }


            string endLine = configOpenPhone.EndLine;

            if (!string.IsNullOrEmpty(endLine))
            {
                endLine = Parse_r_n(endLine);
            }
            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.Parity = System.IO.Ports.Parity.Even;
            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);
            #region
            //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 (!string.IsNullOrEmpty(config.GlobalVariblesKey) && !string.IsNullOrEmpty(config.GlobalVariblesKeyPattern))
            //{
            //    string pattern = Parse_r_n(config.GlobalVariblesKeyPattern);
            //    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);
            //}
            #endregion


            byte[] retArray   = configGv.GetObject("RetBytes") as byte[];
            int    startIndex = -1;
            //bool flageRightRes = false;
            for (int i = 0; i < retArray.Length; i++)
            {
                if (retArray[i] == 0xA6 &&
                    retArray[i + 1] == 0xA6)
                {
                    //flageRightRes = true;
                    startIndex = i;
                    break;

                    ////记录i的位置
                    //////核验校验位
                    ////sum += byteArray[i];
                }
            }

            //byte[] dataArray = new byte[6];

            //Array.Copy(retArray, startIndex, dataArray, 0, 6);
            //hexStr = byteToHexStr(dataArray);

            //log.Info(string.Format("收到7A 7A 21 D1 1B的回复:{0}\r\n", hexStr));

            //log.Info(string.Format("收到7e 7e 03 bc 94 53的回复:{0}\r\n", hexStr));


            if (startIndex == -1)
            {
                throw new BaseException("没有发现A6 A6 的回复");
            }


            byte[] versionBtyes = new byte[3];
            Array.Copy(retArray, startIndex + 3, versionBtyes, 0, 3);


            string strVersion = versionBtyes[2].ToString() + "." + versionBtyes[1].ToString() + "." + versionBtyes[0].ToString();
            configGv.Add("VERSION", strVersion);
            log.Info(string.Format("版本号:{0}", strVersion));


            byte[] wifiMacBtyes = new byte[12];
            Array.Copy(retArray, startIndex + 6, wifiMacBtyes, 0, 12);
            string strImei = System.Text.Encoding.ASCII.GetString(wifiMacBtyes);
            configGv.Add("DevWifi_MAC", strImei);
            log.Info("WIFI MAC:" + strImei);

            byte[] softNumberBtyes = new byte[9];
            Array.Copy(retArray, startIndex + 18, softNumberBtyes, 0, 9);
            string strSoftNumber = System.Text.Encoding.ASCII.GetString(softNumberBtyes);
            configGv.Add("SoftNumber", strSoftNumber);
            log.Info("软件编号:" + strSoftNumber);


            byte[] resultBtyes = new byte[4];
            Array.Copy(retArray, startIndex + 27, resultBtyes, 0, 4);
            string strResult = System.Text.Encoding.ASCII.GetString(resultBtyes);
            configGv.Add("RESULT", strResult);
            log.Info("联网测试结果:" + strResult);


            byte[] btMacBtyes = new byte[12];
            Array.Copy(retArray, startIndex + 31, btMacBtyes, 0, 12);
            string strBtMac = System.Text.Encoding.ASCII.GetString(btMacBtyes);
            log.Info("BT MAC:" + strBtMac);
            configGv.Add("DevBt_MAC", strBtMac);

            byte[] rssiBtyes = new byte[1];
            Array.Copy(retArray, startIndex + 43, rssiBtyes, 0, 1);

            string strRssi = "-" + rssiBtyes[0].ToString();

            log.Info("信号强度:" + strRssi);
            configGv.Add("RSSI", strRssi);


            //////byte[] iccidBtyes = new byte[20];
            //////Array.Copy(retArray, startIndex + 88, iccidBtyes, 0, 20);
            //////string strIccid = System.Text.Encoding.ASCII.GetString(iccidBtyes);

            //////log.Info("ICCID:" + strIccid);
            //////if (strImsi == "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0")
            //////{
            //////    throw new BaseException("ICCID为空,获取失败");
            //////}
            //////configGv.Add("ICCID", strIccid);
        }
Пример #15
0
        public void Run(IProperties properties, GlobalDic <string, object> globalDic)
        {
            SKGAuthorizeCommandProperties config = properties as SKGAuthorizeCommandProperties;
            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));
            }

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

            comDut.Parity = configOpenPhone.Parity;
            string endLine = configOpenPhone.EndLine;

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

            string command = "";

            command += config.Head;

            //int型的处理-转2字节byte,连接到16进制字符串中
            int allLength = 9 + 26;//config.DataLength

            byte[] byteTemp    = new byte[2];
            byte[] oneByteTemp = new byte[1];
            byteTemp = intToBytes(allLength);
            command += byteToHexStr(byteTemp);

            command += config.ReservedWord;
            command += config.CommandWord;

            //DataContent部分
            //枚举类的处理
            int intTemp = (int)config.AuthorizeEvent;

            command += intTemp.ToString().PadLeft(2, '0');

            //int型处理
            string snPcbaId = configGv.Get(GlobalVaribles.LABEL_SN);


            if (config.AuthorizeEvent == SKGAuthorizeCommandProperties.EnumAuthorizeEvent.SN_授权 ||
                config.AuthorizeEvent == SKGAuthorizeCommandProperties.EnumAuthorizeEvent.PCBA_ID授权
                )
            {
                #region //扫描的SN/PCBA码是直接16进制的连接
                //int effectiveLength = snPcbaId.Length / 2;
                //command += effectiveLength.ToString("X2");
                //command += snPcbaId.PadRight(48, '0');
                #endregion

                #region //扫描的SN/PCBA码是字符型,ASCII码的方式
                byte[] bytesSnPcba = System.Text.Encoding.ASCII.GetBytes(snPcbaId);
                command += bytesSnPcba.Length.ToString("X2");
                command += byteToHexStr(bytesSnPcba).PadRight(48, '0');
                #endregion
            }
            else if (config.AuthorizeEvent == SKGAuthorizeCommandProperties.EnumAuthorizeEvent.授权写入蓝牙广播报信息)
            {
                //V16版的协议不写蓝牙广播
                byte[] bytesSnPcba = System.Text.Encoding.ASCII.GetBytes(config.BleBroadcastName);
                command += bytesSnPcba.Length.ToString("X2");
                command += byteToHexStr(bytesSnPcba).PadRight(17, '0');

                command += config.DeviceType;
                command += config.ReservedWord1;
                command += config.ReservedWord2;
            }
            else if (config.AuthorizeEvent == SKGAuthorizeCommandProperties.EnumAuthorizeEvent.解锁SWD)
            {
                byte[] seroArry = new byte[25];
                command += byteToHexStr(seroArry);
            }


            #region
            //SN / PCBAID 需要填满 24 字节,不够 长的在后面补 0x00(例:SN 有效长度 为 16 字 节 则 第 17-24 字 节 填 充 0x00)
            //command += config.Sn_PCBA_ID.PadRight(48,'0');

            //intTemp = (int)config.LedModeSetting;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.EmsTestSwitch;
            //command += intTemp.ToString().PadLeft(2, '0');

            ////int型的处理
            //byteTemp = intToBytes(config.EmsPWSetting);
            //command += byteToHexStr(byteTemp);

            //byteTemp = intToBytes(config.EmsFreqSetting);
            //command += byteToHexStr(byteTemp);

            //byteTemp = intToBytes(config.EmsAmplitudeSetting);
            //command += byteToHexStr(byteTemp);

            ////枚举类的处理
            //intTemp = (int)config.HeatingGearControl;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VoiceControl;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.WritePcbaFinishFlag;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.WholeMachineFinishFlag;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.BtTestOnOffSetting;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.MotorControl;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.AginTestOnOffSetting;
            //command += intTemp.ToString().PadLeft(2, '0');

            ////int型的处理-转为1字节byte
            //oneByteTemp = intToOneBytes(config.AginTestTime);
            //command += byteToHexStr(byteTemp);
            //#region 多路振动控制
            //intTemp = (int)config.VibrationControl1;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VibrationControl2;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VibrationControl3;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VibrationControl4;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VibrationControl5;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VibrationControl6;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VibrationControl7;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VibrationControl8;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VibrationControl9;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VibrationControl10;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VibrationControl11;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VibrationControl12;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VibrationControl13;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VibrationControl4;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VibrationControl5;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VibrationControl6;
            //command += intTemp.ToString().PadLeft(2, '0');
            //#endregion
            //intTemp = (int)config.RedLightControl640nm;
            //command += intTemp.ToString().PadLeft(2, '0');

            #endregion
            //byteToHexStr();

            //byte[] atCommand = strToToHexByte(config.AtCommand);

            //计算校验位
            byte[] atCommandOutXor = strToToHexByte(command);
            byte[] atCommand       = new byte[atCommandOutXor.Length + 1];

            byte byteXor = ByteToXOR(atCommandOutXor);

            Array.Copy(atCommandOutXor, 0, atCommand, 0, atCommandOutXor.Length);
            //赋值最后一个校验位
            atCommand[atCommandOutXor.Length] = byteXor;

            //string atCommand = PreTranslateAtCommand(config.AtCommand);
            UartDisplay(atCommand, "T");

            //log.Info("AT Commond=" + config.AtCommand);

            comDut.DtrEnable = configOpenPhone.Dtr;
            comDut.RtsEnable = configOpenPhone.Rts;
            comDut.Write(atCommand, 0, atCommand.Length);
            Thread.Sleep(config.AtCommandInterval);

            //发命令后一直循环接收->检验->拼接,超过500ms还没检验通过则超时FAIL
            TimeUtils.Execute(() =>
            {
                int n = comDut.BytesToRead;
                //if (n == 0)
                //{
                //    //继续循环执行
                //    return false;
                //}
                //byte[] buf = new byte[n];
                //comDut.Read(buf, 0, n);
                //buffer.AddRange(buf);
                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(false);
                            }
                            byte[] oneFrameBytes = new byte[iTotalLength];
                            buffer.CopyTo(0, oneFrameBytes, 0, iTotalLength);
                            buffer.RemoveRange(0, iTotalLength);

                            UartDisplay(oneFrameBytes, "R");

                            #region //开始校验-命令字
                            if (config.CommandType == SKGAuthorizeCommandProperties.EnumCommandType.查询指令)
                            {
                                if (!(oneFrameBytes[6] == 0xA0 && oneFrameBytes[7] == 0x37))
                                {
                                    log.Info(string.Format("CMD Type Error"));
                                    //继续循环执行
                                    return(false);
                                }
                            }
                            else if (config.CommandType == SKGAuthorizeCommandProperties.EnumCommandType.控制指令)
                            {
                                if (!(oneFrameBytes[6] == 0xA0 && oneFrameBytes[7] == 0x40))
                                {
                                    log.Info(string.Format("CMD Type Error"));
                                    //继续循环执行
                                    return(false);
                                }
                            }
                            else if (config.CommandType == SKGAuthorizeCommandProperties.EnumCommandType.发授权)
                            {
                                if (!(oneFrameBytes[6] == 0xA0 && oneFrameBytes[7] == 0x23))
                                {
                                    log.Info(string.Format("CMD Type Error"));
                                    //继续循环执行
                                    return(false);
                                }
                            }
                            else
                            {
                                log.Info(string.Format("非法指令类型"));
                                //继续循环执行
                                return(false);
                            }

                            //异或校验 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.Fail(string.Format("核验RX的校验位:错误,返回校验位:{0:X2},计算校验位:{1:X2}", oneFrameBytes[iTotalLength - 1], xor));
                                //继续循环执行
                                return(false);
                            }
                            log.Info(string.Format("核验RX的校验位:正确,返回校验位:{0:X2},计算校验位:{1:X2}", oneFrameBytes[iTotalLength - 1], xor));

                            //数据内容 32个字节——长度是不固定的
                            byte[] dataArrys = new byte[iTotalLength - 9];                //config.DataLength
                            Array.Copy(oneFrameBytes, 8, dataArrys, 0, iTotalLength - 9); //config.DataLength

                            //添加到全局变量中
                            if (config.GlobalVariblesKey != null)
                            {
                                for (int i = 0; i < config.GlobalVariblesKey.Length; i++)
                                {
                                    Match matchKey = Regex.Match(config.GlobalVariblesKey[i], this.pattern);
                                    if (!matchKey.Success)
                                    {
                                        //throw new BaseException("read info key fail");
                                        log.Info("read info key fail");
                                        //继续循环执行
                                        return(false);
                                    }

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

                                    configGv.Add(key, dataArrys);
                                    log.Info("应答报文格式检查PASS");
                                }
                            }
                            //跳出循环执行
                            return(true);

                            #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);
                        //继续循环执行
                        return(false);
                    }
                }
                else
                {
                    log.Info(string.Format("buffer.Count:{0}小于最小长度9", buffer.Count));
                    //继续循环执行
                    return(false);
                }
            }, config.Timeout);

            //返回的数据部分处理
            byte[] dataArry = null;
            if (config.GlobalVariblesKey != null)
            {
                for (int i = 0; i < config.GlobalVariblesKey.Length; i++)
                {
                    Match matchKey = Regex.Match(config.GlobalVariblesKey[i], this.pattern);
                    if (!matchKey.Success)
                    {
                        throw new BaseException("read info key fail");
                        //log.Info("read info key fail");
                        ////继续循环执行
                        //return false;
                    }

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

                    dataArry = (byte[])configGv.GetObject(key);
                }
            }
            if (dataArry == null)
            {
                throw new BaseException("未获取到回复的数据部分");
            }
            string revAuthorizeContent  = byteToHexStr(dataArry).Substring(4, 48);
            string sendAuthorizeContent = command.Substring(20, 48);
            if (revAuthorizeContent != sendAuthorizeContent)
            {
                throw new BaseException(string.Format("授权失败\r\n回复的授权内容:{0}\r\n发送的授权内容:{1}\r\n不一致", revAuthorizeContent, sendAuthorizeContent));
                //log.Fail(string.Format("授权失败\r\n回复的授权内容:{0}\r\n发送的授权内容:{1}\r\n不一致", revAuthorizeContent, sendAuthorizeContent));
                ////继续循环执行
                //return false;
            }
            log.Info(string.Format("回复的授权内容:{0}\r\n发送的授权内容:{1}\r\n一致", revAuthorizeContent, sendAuthorizeContent));
            //MCU ID
            byte[] dataMcuId = new byte[12];
            Array.Copy(dataArry, 26, dataMcuId, 0, 12);
            string strDataMcuId = byteToHexStr(dataMcuId);
            log.Info(string.Format("MCU ID:{0}", strDataMcuId));
            if (strDataMcuId.Contains("00000000000000000000"))
            {
                throw new BaseException(string.Format("授权失败,数据为00的MCUID"));
                //log.Fail(string.Format("授权失败,数据为00的MCUID"));
                ////继续循环执行
                //return false;
            }
            //BLE MAC
            byte[] dataBleMac = new byte[6];
            Array.Copy(dataArry, 38, dataBleMac, 0, 6);
            //ASCII码的方式
            //string strDataMcuId = System.Text.Encoding.ASCII.GetString(dataMcuId);
            //BLE MAC:1F39A109,低位在前0x09,0xA1的直接16进制拼接方式
            string strDataBleMac = byteToHexStrReverse(dataBleMac);
            log.Info(string.Format("BLE MAC:{0}", strDataBleMac));
            log.Info(string.Format("授权成功"));



            #region
            //DateTime start = DateTime.Now;
            //DateTime now = DateTime.Now;
            //TimeSpan timeSpan = now - start;
            //while (timeSpan.TotalMilliseconds <= config.Timeout)
            //{
            //    try
            //    {
            //        comDut.Write(atCommand, 0, atCommand.Length);
            //        Thread.Sleep(config.AtCommandInterval);

            //        int n = comDut.BytesToRead;
            //        byte[] buf = new byte[n];
            //        comDut.Read(buf, 0, n);
            //        //解析是否收到正确的包,包头,命令,校验位

            //        //如果收到的包正确
            //        if (true)
            //        {
            //            break;
            //        }
            //    }
            //    catch (Exception e)
            //    {
            //        Console.WriteLine(e);
            //    }

            //    Thread.Sleep(100);
            //    now = DateTime.Now;
            //    timeSpan = now - start;
            //}

            //if (timeSpan.TotalMilliseconds > config.Timeout)
            //{
            //    throw new BaseException("超时:");
            //}
            #endregion
            //

            #region 原发送命令后等待一固定时间,再接收数据,对应不上则重试
            //int n = comDut.BytesToRead;
            //byte[] buf = new byte[n];
            //comDut.Read(buf, 0, n);
            ////解析是否收到正确的包,包头,命令,校验位
            ////起始标志 数据长度 保留字     命令字     数据内容    异或校验码
            ////0XA5C3    9+N     0x0000      0x0037      Data        异或
            ////2 字节  2 字节    2 字节      2 字节      N 字节     1 字节
            //UartDisplay(buf, "R");
            //if (buf.Length < 9)
            //{
            //    throw new BaseException(string.Format("Response Length Not enough"));
            //}
            ////包头
            //if (!(buf[0] == 0xA5 && buf[1] == 0xC3))
            //{
            //    throw new BaseException(string.Format("Response Head Error"));
            //}
            ////长度 2字节
            //byte high = buf[2];
            //byte low = buf[3];
            //int iTotalLength = (high & 0xFF) << 8 | low;

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

            ////命令字
            //if (config.CommandType == SKGAuthorizeCommandProperties.EnumCommandType.查询指令)
            //{
            //    if (!(buf[6] == 0xA0 && buf[7] == 0x37))
            //    {
            //        throw new BaseException(string.Format("Response Command Type Error"));
            //    }
            //}
            //else if (config.CommandType == SKGAuthorizeCommandProperties.EnumCommandType.控制指令)
            //{
            //    if (!(buf[6] == 0xA0 && buf[7] == 0x40))
            //    {
            //        throw new BaseException(string.Format("Response Command Type Error"));
            //    }
            //}
            //else if (config.CommandType == SKGAuthorizeCommandProperties.EnumCommandType.下发授权)
            //{
            //    if (!(buf[6] == 0xA0 && buf[7] == 0x23))
            //    {
            //        throw new BaseException(string.Format("Response Command Type Error"));
            //    }
            //}
            //else
            //{
            //    throw new BaseException(string.Format("Response为非法指令类型"));
            //}


            ////异或校验 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)
            //{
            //    throw new BaseException(string.Format("核验RX的校验位:错误,返回校验位:{0:X2},计算校验位:{1:X2}", buf[n - 1], xor));
            //}
            //log.Info(string.Format("核验RX的校验位:正确,返回校验位:{0:X2},计算校验位:{1:X2}", buf[n - 1], xor));



            ////数据内容 32个字节
            ////byte[] dataArry = new byte[config.DataLength];
            ////Array.Copy(buf, 8, dataArry, 0, config.DataLength);

            //byte[] dataArry = new byte[iTotalLength - 9];//config.DataLength
            //Array.Copy(buf, 8, dataArry, 0, iTotalLength - 9);//config.DataLength

            ////添加到全局变量中
            //if (config.GlobalVariblesKey != null)
            //{
            //    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, dataArry);
            //        log.Info("应答报文格式检查PASS");
            //    }
            //}
            #endregion
            //检查是否授权正确:
            //授权事件确认检查

            //string revAuthorizeContent = byteToHexStr(dataArry).Substring(4, 48);
            //string sendAuthorizeContent = command.Substring(20, 48);
            //if (revAuthorizeContent!= sendAuthorizeContent)
            //{
            //    throw new BaseException(string.Format("授权失败\r\n回复的授权内容:{0}\r\n发送的授权内容:{1}\r\n不一致", revAuthorizeContent, sendAuthorizeContent));
            //}
            //log.Info(string.Format("回复的授权内容:{0}\r\n发送的授权内容:{1}\r\n一致", revAuthorizeContent, sendAuthorizeContent));
            ////MCU ID
            //byte[] dataMcuId = new byte[12];
            //Array.Copy(dataArry, 26, dataMcuId, 0, 12);
            ////ASCII码的方式
            ////string strDataMcuId = System.Text.Encoding.ASCII.GetString(dataMcuId);
            ////MCU ID:1F39A109高位在前1F,39的直接16进制拼接方式
            //string strDataMcuId = byteToHexStr(dataMcuId);
            //log.Info(string.Format("MCU ID:{0}", strDataMcuId));
            //if (strDataMcuId.Contains("00000000000000000000"))
            //{
            //    throw new BaseException(string.Format("授权失败,数据为00的MCUID"));
            //}
            ////BLE MAC
            //byte[] dataBleMac = new byte[6];
            //Array.Copy(dataArry, 38, dataBleMac, 0, 6);
            ////ASCII码的方式
            ////string strDataMcuId = System.Text.Encoding.ASCII.GetString(dataMcuId);
            ////BLE MAC:1F39A109,低位在前0x09,0xA1的直接16进制拼接方式
            //string strDataBleMac = byteToHexStrReverse(dataBleMac);
            //log.Info(string.Format("BLE MAC:{0}", strDataBleMac));
            //log.Info(string.Format("授权成功"));



            ////如果收到的包正确
            //string str = byteToHexStr(buf);


            //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 (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);
            //    }
            //}
        }