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 void Run(IProperties properties, GlobalDic <string, object> globalDic)//virtual
        {
            config = properties as CmdFindDeviceProperties;
            ILog log = globalDic[typeof(ILog).ToString()] as ILog;

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

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

            log.Info("请放入产品,检查产品上电中....");
            log.Info("CMD Commond=" + config.Command);

            TimeUtils.Execute(() =>
            {
                ret = ExeCommand(config.Command, out returnString);
                Thread.Sleep(config.CommandInterval);
                if (ret != 0)
                {
                    //throw new BaseException(string.Format("详情:{0},检测设备失败,FAIL\r\n", returnString));
                    return(true);
                }
                //if (returnString.Contains("\tdevice\r\n\r\n"))
                //{
                //    log.Info(string.Format("详情:{0},检测到设备 \r\n", returnString));
                //    //跳出循环执行
                //    return true;
                //}


                if (!string.IsNullOrEmpty(config.CommandOk))
                {
                    if (returnString.Contains(config.CommandOk))
                    {
                        log.Info(string.Format("检测到产品上电,ADB Response:\r\n{0}  contain: \r\n{1}", returnString, config.CommandOk));
                        //跳出循环执行
                        ret = 0;
                        return(true);
                    }
                }

                //继续循环执行
                return(false);
            }, config.Timeout);
            if (ret != 0)
            {
                throw new BaseException(string.Format("详情:{0},检测设备失败 \r\n", returnString));
            }


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

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

            //if (!string.IsNullOrEmpty(config.CommandOk))
            //{
            //    if (!returnString.Contains(config.CommandOk))
            //    {
            //        throw new BaseException(string.Format("CMD response,not contain Ok=[{0}]", config.CommandOk));
            //    }
            //}

            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]);
                        string checkInfo = config.CheckInfo[i];
                        if (!returnString.Contains(checkInfo))
                        {
                            throw new BaseException(string.Format("ADB response,not contain check info=[{0}]", 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(returnString, 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);
                }
            }
        }
示例#3
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);
            //    }
            //}
        }
示例#4
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);
            //    }
            //}
        }
示例#5
0
        public void Run(IProperties properties, GlobalDic <string, object> globalDic)//virtual
        {
            config   = properties as CmdSplThdCheckProperties;
            log      = globalDic[typeof(ILog).ToString()] as ILog;
            configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles;

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

            log.Info("CMD Commond=\r\n" + config.Command);
            //string cmd = String.Format("HiBurnV3.1.exe -com:{0} -bin:{1} -signalbaud:2000000 -2ms -forceread:10 -timeout:{2} -console", listPortsName[index - 1].Replace("COM", ""), textBox1.Text, powerOnTimeout);
            ////%ERRORLEVEL%
            //CmdThread cmdThread;
            string path = string.Format("./adb/mic.bat");

            string[] contentSrtList = new string[] { config.Command };
            try
            {
                WriteForTxt(path, contentSrtList);
            }
            catch (Exception ex)
            {
                throw new BaseException(string.Format("MIC测试,写bat失败:{0}", ex.Message));
            }
            string fileName = Path.GetFileName(path);

            dataRev = "";
            ret     = ExeCommand(fileName, out returnString);
            TimeUtils.Execute(() =>
            {
                if (string.IsNullOrEmpty(dataRev))
                {
                    return(false);
                }
                if (!string.IsNullOrEmpty(config.CommandError))
                {
                    if (dataRev.Contains(config.CommandError))
                    {
                        ret = -1;
                        //跳出循环执行
                        return(true);
                    }
                }

                if (!string.IsNullOrEmpty(config.CommandOk))
                {
                    if (dataRev.Contains(config.CommandOk))
                    {
                        log.Info(string.Format("ADB Response接收完毕:\r\ncontain:{0}", config.CommandOk));
                        ret = 0;

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

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

                //继续循环执行
                return(false);
            }, config.Timeout);
            if (ret != 0)
            {
                throw new BaseException(string.Format("CMD response,contain error=[{0}]", config.CommandError));
            }

            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]);
                        string checkInfo = config.CheckInfo[i];
                        if (!dataRev.Contains(checkInfo))
                        {
                            throw new BaseException(string.Format("CMD response,not contain check info=[{0}]", 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(dataRev, 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);
                }
            }
            //
            string[] splits           = new string[] { "channel" };
            string[] channelDataLists = dataRev.Split(splits, StringSplitOptions.RemoveEmptyEntries);

            string[] splitsLine        = new string[] { "\r\n" };
            bool     channelContain984 = false;

            float maxSpl = -100;
            float minSpl = -1;

            float maxThd = 0;
            float minThd = 100;

            for (int i = 0; i < channelDataLists.Length - 1; i++)
            {
                //一个通道
                channelContain984 = false;
                string[] eachLines = channelDataLists[i].Split(splitsLine, StringSplitOptions.RemoveEmptyEntries);

                ////本通道最大,最小spl,thd
                //float thisChanelMaxSpl = -100;
                //float thisChanelMinSpl = -1;

                //float thisChanelMaxThd = 0;
                //float thisChanelMinThd = 100;
                for (int j = 0; j < eachLines.Length; j++)
                {
                    if (eachLines[j].Contains(config.CheckFreqValue.ToString()))
                    {
                        channelContain984 = true;
                        //解析每个通道的spl thd值
                        //281	 -52.983902	 18.399385
                        //bool isMatch = Regex.IsMatch(eachLines[j], config.CheckFreqValue.ToString() + "\t ([-.0-9]{9,10})\t ([.0-9]{8,9})");
                        //if (!isMatch)
                        //{
                        //    throw new BaseException(string.Format("channel{0}:{1}HZ所在行不匹配正则格式", i, config.CheckFreqValue));
                        //}

                        //MatchCollection matchValue = Regex.Matches(eachLines[j], config.CheckFreqValue.ToString()+"\t ([-.0-9]{9,10})\t ([.0-9]{8,9})");
                        //float[] result = new float[matchValue.Count];
                        //if (matchValue.Count > 0)
                        //{
                        //    for (int k = 0; k < matchValue.Count; k++)
                        //    {
                        //        float splValue = float.Parse(matchValue[k].Groups[1].ToString());
                        //        float thdValue = float.Parse(matchValue[k].Groups[2].ToString());
                        //        if (splValue > thisChanelMaxSpl)
                        //        {
                        //            thisChanelMaxSpl = splValue;
                        //        }
                        //        if (splValue < thisChanelMinSpl)
                        //        {
                        //            thisChanelMinSpl = splValue;
                        //        }

                        //        if (thdValue > thisChanelMaxThd)
                        //        {
                        //            thisChanelMaxThd = thdValue;
                        //        }
                        //        if (thdValue < thisChanelMinThd)
                        //        {
                        //            thisChanelMinThd = thdValue;
                        //        }
                        //        //matchValue[k].Groups[1].ToString();
                        //        //result[k] = float.Parse(matchValue[k].Value);
                        //    }
                        //}
                        Match matchValue = Regex.Match(eachLines[j], config.CheckFreqValue.ToString() + "\t ([-.0-9]{9,10})\t ([.0-9]{8,9})");
                        if (!matchValue.Success)
                        {
                            throw new BaseException(string.Format("channel{0}:{1}HZ所在行不匹配正则格式", i, config.CheckFreqValue));
                        }
                        //string strSpl = matchValue.Groups[1].ToString();
                        //string strThd = matchValue.Groups[2].ToString();
                        float splValue = float.Parse(matchValue.Groups[1].ToString());
                        float thdValue = float.Parse(matchValue.Groups[2].ToString());

                        //log.Info(string.Format("Channel{0},测试频率:{1}Hz,最大Spl:{2},最小Spl:{3},最大Thd:{4},最小Thd:{5}", i, config.CheckFreqValue, thisChanelMaxSpl, thisChanelMinSpl, thisChanelMaxThd, thisChanelMinThd));
                        if (splValue > maxSpl)
                        {
                            maxSpl = splValue;
                        }
                        if (splValue < minSpl)
                        {
                            minSpl = splValue;
                        }

                        if (thdValue > maxThd)
                        {
                            maxThd = thdValue;
                        }
                        if (thdValue < minThd)
                        {
                            minThd = thdValue;
                        }
                    }
                }
                //一个通道解析完成
                if (!channelContain984)
                {
                    throw new BaseException(string.Format("channel{0}:不包含要检查的{1}HZ", i, config.CheckFreqValue));
                }
            }
            //所有通道解析完成
            float splDifferValue = maxSpl - minSpl;
            float thdDifferValue = maxThd - minThd;

            if (splDifferValue > config.SplMaxOffset)
            {
                throw new BaseException(string.Format("\r\nMIC通道间最大灵敏度值:{0}dB\r\n最小灵敏度值:{1}dB\r\n差值{2}dB超出标准{3}dB", maxSpl, minSpl, splDifferValue, config.SplMaxOffset));
            }
            log.Info(string.Format("\r\nMIC通道间最大灵敏度值:{0}dB\r\n最小灵敏度值:{1}dB\r\n差值{2}dB在标准{3}dB内", maxSpl, minSpl, splDifferValue, config.SplMaxOffset));
            if (thdDifferValue > config.ThdMaxOffset)
            {
                throw new BaseException(string.Format("\r\nMIC通道间谐波失真最大值:{0}%\r\n最小失真值:{1}%\r\n差值{2}%超出标准{3}%", maxThd, minThd, thdDifferValue, config.ThdMaxOffset));
            }
            log.Info(string.Format("\r\nMIC通道间谐波失真最大值:{0}%\r\n最小失真值:{1}%\r\n差值{2}%在标准{3}%内", maxThd, minThd, thdDifferValue, config.ThdMaxOffset));


            //if (true)
            //{

            //}
        }
示例#6
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);
        }
示例#7
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);
        }
示例#8
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);
            //    }
            //}
        }