public void Run(IProperties properties, GlobalDic <string, object> globalDic)//virtual { //config = properties as CheckBtRssiProperties; ILog log = globalDic[typeof(ILog).ToString()] as ILog; configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles; try { string labImei = configGv.Get("IMEI"); string nbImei = configGv.Get("NBIMEI"); if (string.IsNullOrEmpty(labImei) && !string.IsNullOrEmpty(nbImei)) { configGv.Add("IMEI", nbImei); } else if (!string.IsNullOrEmpty(labImei))//有标签BT MAC,则肯定经过一致性检查 { configGv.Add("IMEI", nbImei); } else { log.Fail(string.Format("打印标签的IMEI 设置为NB IMEI失败\r\n,NB IMEI:{0} \r\n", nbImei)); } log.Info(string.Format("打印标签的IMEI 设置为NB IMEI:\r\n{0} PASS \r\n", nbImei)); } catch (Exception ex) { throw new Exception("打印标签的IMEI 设置为NB IMEI出错," + ex.Message); } }
public void Run(IProperties properties, GlobalDic <string, object> globalDic)//virtual { //config = properties as CheckBtRssiProperties; ILog log = globalDic[typeof(ILog).ToString()] as ILog; configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles; try { string strBtMac = configGv.Get("MAC_BT"); string strMoudleBtMac = configGv.Get("MoudleBtMac"); if (string.IsNullOrEmpty(strBtMac) && !string.IsNullOrEmpty(strMoudleBtMac)) { configGv.Add("MAC", strMoudleBtMac); } else if (!string.IsNullOrEmpty(strBtMac) && !string.IsNullOrEmpty(strMoudleBtMac))//有标签BT MAC,则肯定经过一致性检查 { configGv.Add("MAC", strMoudleBtMac); } else if (!string.IsNullOrEmpty(strBtMac) && string.IsNullOrEmpty(strMoudleBtMac))//有标签BT MAC,则肯定经过一致性检查 { configGv.Add("MAC", strBtMac); } else { log.Fail(string.Format("LOG MAC设置为BT MAC失败\r\n,取号BT MAC{0},模块BT MAC:{1} \r\n", strBtMac, strMoudleBtMac)); } log.Info(string.Format("LOG MAC设置为BT MAC:\r\n{0} PASS \r\n", strMoudleBtMac)); } catch (Exception ex) { throw new Exception("LOG MAC设置为BT MAC出错," + ex.Message); } }
public void Run(IProperties properties, GlobalDic <string, object> globalDic)//virtual { config = properties as FilterOutCharsProperties; configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles; log = globalDic[typeof(ILog).ToString()] as ILog; if (config.GlobalVariblesKey != null) { for (int i = 0; i < config.GlobalVariblesKey.Length; i++) { if (!string.IsNullOrEmpty(config.GlobalVariblesKey[i])) { 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(); string value = configGv.Get(key); for (int j = 0; j < config.FilterOutChars.Length; j++) { value = value.Replace(config.FilterOutChars[j], ""); } configGv.Add(key, value); } } } }
//private List<WIFISSID> ssids=new List<WIFISSID>(); //private wifiSo wifiso; public void Run(IProperties properties, GlobalDic <string, object> globalDic)//virtual { config = properties as SocketConnectProperties; ILog log = globalDic[typeof(ILog).ToString()] as ILog; configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles; try { Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPAddress ip = IPAddress.Parse(config.Ip); socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 2500); socket.Connect(ip, Convert.ToInt16(config.Port)); if (!socket.Connected) { throw new Exception(string.Format("Socke连接服务器失败,{0}:{1}\r\n连接状态为false", config.Ip, config.Port)); } log.Info(string.Format("Socke连接服务器连接成功,{0}:{1}", config.Ip, config.Port)); configGv.Add("ObjSocket", socket); } catch (Exception ex) { throw new Exception(string.Format("Socke连接服务器失败,{0}:{1}\r\n详情:{2}", config.Ip, config.Port, ex.Message)); } }
public void Run(IProperties properties, GlobalDic <string, object> globalDic)//virtual { //config = properties as FindDeviceProperties; ILog log = globalDic[typeof(ILog).ToString()] as ILog; configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles; //int ret = -1; //string returnString = ""; FormScanCode formScanCode = new FormScanCode() { //DutName = config.DutName, //ShowInTaskbar = true, //StartPosition = FormStartPosition.CenterScreen }; DialogResult dialogResult = DialogResult.None; lock (myLock) { dialogResult = formScanCode.ShowDialog(); } if (dialogResult != DialogResult.OK) { //sync.CountDown("ScanCodeExecuter"); throw new BaseException("user discard scan code"); } configGv.Add(GlobalVaribles.LABEL_SN, formScanCode.LabelSn); }
public void Run(IProperties properties, GlobalDic <string, object> globalDic)//virtual { config = properties as ReadMapProperties; ILog log = globalDic[typeof(ILog).ToString()] as ILog; //int ret = -1; string mapFileString = ""; try { mapFileString = Read(config.MapFilePath); } catch (Exception ex) { throw new Exception(string.Format("读取MAP文件失败,异常:{0}", ex.Message)); } log.Info(string.Format("读取MAP文件成功:\r\n{0}", mapFileString)); //更新MAP内存中的MAC地址 string[] splits = { "\r\n" }; string[] mapFileStringLines = mapFileString.Split(splits, StringSplitOptions.RemoveEmptyEntries); //IMES获取的MAC*************** configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles; string macFromImes = configGv.Get("MAC"); //更新MAP //byte[] bytesMac = strToToHexByte(macFromImes); //byte[] bytesReverseMac = bytesConvert(bytesMac); //string stringReverseMac = byteToHexStr(bytesReverseMac); //string reverseMacAddSpace = AddSpaceEachTwoBtye(stringReverseMac); string reverseMacAddSpace = AddSpaceEachTwoBtye(macFromImes); string mapFileStringMacUpdate = ""; for (int i = 0; i < mapFileStringLines.Length; i++) { if (i == 17) { //前面固定部分+反转并添加空格的MAC mapFileStringLines[i] = mapFileStringLines[i].Substring(0, 25) + reverseMacAddSpace; } mapFileStringMacUpdate += mapFileStringLines[i] + "\r\n"; } //存为byte数组应该会好些,这样可以定位地址,当MAC的偏移地址发生变化时,只需改地址值 log.Info(string.Format("更新MAP文件中的MAC成功:\r\n{0}", mapFileStringMacUpdate)); GlobalVaribles configGv1 = globalDic.Get <GlobalVaribles>(); configGv1.Add("MapFileStringMacUpdate", mapFileStringMacUpdate); //globalDic.Add(typeof(OpenPhoneProperties).ToString(), config); }
public void Run(IProperties properties, GlobalDic <string, object> globalDic)//virtual { config = properties as LabelGetAndCheckProperties; ILog log = globalDic[typeof(ILog).ToString()] as ILog; configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles; string[] data = configGv.Get(GlobalVaribles.LABEL_SN).Split(new[] { ',' }); string gimiSn = data[0]; CheckSn(gimiSn); gimiSn = gimiSn.Insert(config.InsertIndex, config.Value); configGv.Add("GimiSn", gimiSn); log.Info(string.Format("标签:{0}\r\n插入内容后:{1}", data[0], gimiSn)); //try //{ // string strBtMac = configGv.Get("MAC_BT"); // string strMoudleBtMac = configGv.Get("MoudleBtMac"); // if (string.IsNullOrEmpty(strBtMac) && !string.IsNullOrEmpty(strMoudleBtMac)) // { // configGv.Add("MAC", strMoudleBtMac); // } // else if (!string.IsNullOrEmpty(strBtMac) && !string.IsNullOrEmpty(strMoudleBtMac))//有标签BT MAC,则肯定经过一致性检查 // { // configGv.Add("MAC", strMoudleBtMac); // } // else if (!string.IsNullOrEmpty(strBtMac) && string.IsNullOrEmpty(strMoudleBtMac))//有标签BT MAC,则肯定经过一致性检查 // { // configGv.Add("MAC", strBtMac); // } // else // { // log.Fail(string.Format("LOG MAC设置为BT MAC失败\r\n,取号BT MAC{0},模块BT MAC:{1} \r\n", strBtMac, strMoudleBtMac)); // } // log.Info(string.Format("LOG MAC设置为BT MAC:\r\n{0} PASS \r\n", strMoudleBtMac)); //} //catch (Exception ex) //{ // throw new Exception("LOG MAC设置为BT MAC出错," + ex.Message); //} }
public void Run(IProperties properties, GlobalDic <string, object> globalDic)//virtual { //config = properties as CheckBtRssiProperties; ILog log = globalDic[typeof(ILog).ToString()] as ILog; configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles; //string[] data = configGv.Get(GlobalVaribles.LABEL_SN).Split(new[] { ',' }); //configGv.Add("GimiSn", data[0]); //log.Info(string.Format("Sn={0}", configGv.Get("GimiSn"))); configGv.Add("MAC", configGv.Get("GimiSn")); log.Info(string.Format("设置LOG的Mac={0}成功", configGv.Get("GimiSn"))); //try //{ // string strBtMac = configGv.Get("MAC_BT"); // string strMoudleBtMac = configGv.Get("MoudleBtMac"); // if (string.IsNullOrEmpty(strBtMac) && !string.IsNullOrEmpty(strMoudleBtMac)) // { // configGv.Add("MAC", strMoudleBtMac); // } // else if (!string.IsNullOrEmpty(strBtMac) && !string.IsNullOrEmpty(strMoudleBtMac))//有标签BT MAC,则肯定经过一致性检查 // { // configGv.Add("MAC", strMoudleBtMac); // } // else if (!string.IsNullOrEmpty(strBtMac) && string.IsNullOrEmpty(strMoudleBtMac))//有标签BT MAC,则肯定经过一致性检查 // { // configGv.Add("MAC", strBtMac); // } // else // { // log.Fail(string.Format("LOG MAC设置为BT MAC失败\r\n,取号BT MAC{0},模块BT MAC:{1} \r\n", strBtMac, strMoudleBtMac)); // } // log.Info(string.Format("LOG MAC设置为BT MAC:\r\n{0} PASS \r\n", strMoudleBtMac)); //} //catch (Exception ex) //{ // throw new Exception("LOG MAC设置为BT MAC出错," + ex.Message); //} }
public void Run(IProperties properties, GlobalDic <string, object> globalDic)//virtual { config = properties as ToggleCaseProperties; configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles; log = globalDic[typeof(ILog).ToString()] as ILog; string preGlobalVaribles = configGv.Get(config.PreGlobalVaribles); string value = ""; if (config.ToggleCase == ToggleCaseProperties.CaseEnum.ToLower) { value = preGlobalVaribles.ToLower(); } else if (config.ToggleCase == ToggleCaseProperties.CaseEnum.ToUper) { value = preGlobalVaribles.ToUpper(); } configGv.Add(config.AfterGlobalVaribles, value); }
//private string pattern; //public ReverseNumberExecuter() //{ // this.pattern = GlobalVaribles.PATTERN; //} public void Run(IProperties properties, GlobalDic <string, object> globalDic)//virtual { config = properties as ReverseNumberProperties; ILog log = globalDic[typeof(ILog).ToString()] as ILog; configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles; try { string number = configGv.Get(config.PreGlobalVariable); //string mac = configGv.Get(GlobalVaribles.MAC); byte[] byteMac = strToToHexByte(number); Array.Reverse(byteMac); string reverseMac = byteToHexStr(byteMac); configGv.Add(config.AfterGlobalVariable, reverseMac); log.Info(string.Format("倒序16进制Number成功:{0}", reverseMac)); } catch (Exception ex) { throw new BaseException(string.Format("倒序16进制Number转换失败,{0}", ex)); } //string reverseMac = mac.Substring(0, 12); //string reScanLabelMac = reScanLabel.Substring(12, 12); //string macLabel = configGv.Get(GlobalVaribles.MAC); //if (!(reScanLabelFixedPart == config.FixedPart)) //{ // throw new BaseException(string.Format("重扫标签的固定部分:{0}与标准固定部分:{1}不一致", reScanLabelFixedPart, config.FixedPart)); //} //log.Info(string.Format("重扫标签的固定部分:{0}与标准固定部分:{1}一致", reScanLabelFixedPart, config.FixedPart)); //if (!(reScanLabelMac == macLabel)) //{ // throw new BaseException(string.Format("重扫标签的MAC部分:{0}与标签MAC:{1}不一致", reScanLabelMac, macLabel)); //} //log.Info(string.Format("重扫标签的MAC部分:{0}与标签MAC:{1}一致", reScanLabelMac, macLabel)); }
public void Run(IProperties properties, GlobalDic <string, object> globalDic)//virtual { ILog log = globalDic[typeof(ILog).ToString()] as ILog; configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles; //取存储的关键字为MoudleBtMac的value值 string DevWifi_MAC = configGv.Get("DevWifi_MAC"); string DevBt_MAC = configGv.Get("DevBt_MAC"); DevWifi_MAC = DevWifi_MAC.Replace(":", "").Replace(":", "").ToUpper(); DevBt_MAC = DevBt_MAC.Replace(":", "").Replace(":", "").ToUpper(); if (Convert.ToInt64(DevWifi_MAC, 16) + 1 != Convert.ToInt64(DevBt_MAC, 16)) { throw new BaseException(string.Format("WIFI MAC:{0},BT MAC:{1} 非+1关系,未通过校验 FAIL\r\n", DevWifi_MAC, DevBt_MAC)); } log.Info(string.Format(string.Format("WIFI MAC:{0},BT MAC:{1} 通过 +1关系校验 PASS\r\n", DevWifi_MAC, DevBt_MAC))); string labelMAC = configGv.Get(GlobalVaribles.MAC); if (string.IsNullOrEmpty(labelMAC)) { configGv.Add(GlobalVaribles.MAC, DevWifi_MAC); } }
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); } } }
public void Run(IProperties properties, GlobalDic <string, object> globalDic) { SocketCommandProperties config = properties as SocketCommandProperties; ILog log = globalDic[typeof(ILog).ToString()] as ILog; configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles; Socket objSocket = configGv.GetObject("ObjSocket") as Socket; if (objSocket == null) { throw new BaseException(string.Format("objSocket is null")); } if (config.CommandType == SocketCommandProperties.EnumCommandType.String) { string atCommand = PreTranslateAtCommand(config.SocketCommand); log.Info("SocketCommand:\r\n" + atCommand); byte[] bytesCommand = Encoding.ASCII.GetBytes(atCommand); objSocket.Send(bytesCommand, bytesCommand.Length, SocketFlags.None); Thread.Sleep(config.SocketCommandInterval); byte[] data = new byte[objSocket.ReceiveBufferSize]; int len = objSocket.Receive(data); string response = Encoding.ASCII.GetString(data, 0, len); log.Info("Socket Response:\r\n" + response); if (!string.IsNullOrEmpty(config.SocketCommandError)) { if (response.Contains(config.SocketCommandError)) { throw new BaseException(string.Format("contain error:[{0}]", config.SocketCommandError)); } } if (!string.IsNullOrEmpty(config.SocketCommandOk)) { if (!response.Contains(config.SocketCommandOk)) { throw new BaseException(string.Format("not contain ok:[{0}]", config.SocketCommandOk)); } log.Info(string.Format("contain ok:[{0}]", config.SocketCommandOk)); } 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("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(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); } } } }
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); // } //} }
//private List<WIFISSID> ssids=new List<WIFISSID>(); //private wifiSo wifiso; public void Run(IProperties properties, GlobalDic <string, object> globalDic)//virtual { config = properties as ConnectSsiProperties; ILog log = globalDic[typeof(ILog).ToString()] as ILog; configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles; bool hasSsid = false; string mac = configGv.Get(GlobalVaribles.MAC); string ssid = string.Format(config.SSID, mac); Wifi g_wifi; try { //WlanClient client = new WlanClient(); //foreach (WlanClient.WlanInterface wlanIface in client.Interfaces) //{ WlanClient client = new WlanClient(); foreach (WlanClient.WlanInterface wlanIface in client.Interfaces) { wlanIface.Scan(); } Thread.Sleep(1000); g_wifi = new Wifi(); List <AccessPoint> wifiList = g_wifi.GetAccessPoints(); foreach (AccessPoint item in wifiList) { if (item.Name == ssid) { hasSsid = true; if (!item.IsConnected) { AuthRequest authRequest = new AuthRequest(item); bool bConnect = item.Connect(authRequest); if (bConnect) { log.Info(string.Format("连接网络成功")); configGv.Add("ObjWifi", g_wifi); } } else { log.Info(string.Format("网络已处于连接状态,无需连接")); configGv.Add("ObjWifi", g_wifi); } break; } } // wlanIface.Scan(); //} if (!hasSsid) { throw new BaseException(string.Format("未扫描到SSID:{0}", ssid)); } ////WlanClient client = new WlanClient(); //foreach (WlanClient.WlanInterface wlanIface in client.Interfaces) //{ // wlanIface.Scan(); //} //#region //WlanClient client = new WlanClient(); //WIFISSID targetSSID; //foreach (WlanClient.WlanInterface wlanIface in client.Interfaces) //{ // // Lists all networks with WEP security // Wlan.WlanAvailableNetwork[] networks = wlanIface.GetAvailableNetworkList(Wlan.WlanGetAvailableNetworkFlags.IncludeAllAdhocProfiles); // foreach (Wlan.WlanAvailableNetwork network in networks) // { // //ssids.Add(targetSSID); // //wifiListOKADDitem(GetStringForSSID(network.dot11Ssid), network.dot11DefaultCipherAlgorithm.ToString(), // // network.dot11DefaultAuthAlgorithm.ToString(), (int)network.wlanSignalQuality); // if (GetStringForSSID(network.dot11Ssid).Equals(ssid)) // { // //var obj = new wifiSo(targetSSID, config.Key); // targetSSID = new WIFISSID(); // targetSSID.wlanInterface = wlanIface; // targetSSID.wlanSignalQuality = (int)network.wlanSignalQuality; // targetSSID.SSID = GetStringForSSID(network.dot11Ssid); // //targetSSID.SSID = Encoding.Default.GetString(network.dot11Ssid.SSID, 0, (int)network.dot11Ssid.SSIDLength); // targetSSID.dot11DefaultAuthAlgorithm = network.dot11DefaultAuthAlgorithm.ToString(); // targetSSID.dot11DefaultCipherAlgorithm = network.dot11DefaultCipherAlgorithm.ToString(); // ConnectToSSID(targetSSID, config.Key); // hasSsid = true; // log.Info(string.Format("连接网络成功")); // return; // //Thread wificonnect = new Thread(obj.ConnectToSSID); // //wificonnect.Start(); // //WifiSocket wifiscoket = new WifiSocket(); // //wifiscoket.fuwu(); // //wifiscoket.kehuduan(); // //wifiso.ConnectToSSID(targetSSID, "ZMZGZS520");//连接wifi // //connectWifiOK.Text = GetStringForSSID(network.dot11Ssid); // //Image img = new Bitmap(Environment.CurrentDirectory + "/image/wifi.png");//这里是你要替换的图片。当然你必须事先初始化出来图 // //pictureBoxW.BackgroundImage = img; // //Console.WriteLine(">>>>>>>>>>>>>>>>>开始连接网络!" + targetSSID.SSID + GetStringForSSID(network.dot11Ssid) + GetStringForSSID(network.dot11Ssid).Equals("DZSJ1")); // } // } // wlanIface.Scan(); //} //if (!hasSsid) //{ // throw new BaseException(string.Format("未扫描到SSID:{0}", ssid)); //} //#endregion } catch (Exception ex) { throw new Exception("连接热点出错," + ex.Message); } }
public void Run(IProperties properties, GlobalDic <string, object> globalDic) { GetBtRssiAtCommandProperties config = properties as GetBtRssiAtCommandProperties; ComDut comDut = globalDic[typeof(ComDut).ToString()] as ComDut; OpenPhoneProperties configOpenPhone = globalDic[typeof(OpenPhoneProperties).ToString()] as OpenPhoneProperties; ILog log = globalDic[typeof(ILog).ToString()] as ILog; configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles; string moudleBtMac = configGv.Get("MoudleBtMac"); string endLine = configOpenPhone.EndLine; if (!string.IsNullOrEmpty(endLine)) { endLine = Parse_r_n(endLine); } string atCommand = PreTranslateAtCommand(config.AtCommand); log.Info("AT Commond=" + atCommand); comDut.DtrEnable = configOpenPhone.Dtr; comDut.RtsEnable = configOpenPhone.Rts; comDut.Write(atCommand + endLine); Thread.Sleep(config.AtCommandInterval); string response = comDut.ReadExisting(); comDut.DtrEnable = false; comDut.RtsEnable = false; log.Info("AT Response=" + response); if (!string.IsNullOrEmpty(config.AtCommandError)) { if (response.Contains(config.AtCommandError)) { throw new BaseException(string.Format("AT response=[{0}] contain error=[{1}]", response, config.AtCommandError)); } } if (!string.IsNullOrEmpty(config.AtCommandOk)) { if (!response.Contains(config.AtCommandOk)) { throw new BaseException(string.Format("AT response=[{0}] not contain error=[{1}]", response, config.AtCommandOk)); } } if (config.CheckInfo != null) { for (int i = 0; i < config.CheckInfo.Length; i++) { if (!string.IsNullOrEmpty(config.CheckInfo[i])) { string checkInfo = PreTranslateCheckInfo(config.CheckInfo[i]); if (!response.Contains(checkInfo)) { throw new BaseException(string.Format("AT response=[{0}] not contain check info=[{1}]", response, checkInfo)); } } } } if (!string.IsNullOrEmpty(config.GlobalVariblesKey) && !string.IsNullOrEmpty(config.GlobalVariblesKeyPattern)) { string pattern = Parse_r_n(config.GlobalVariblesKeyPattern);//"E000E64CCACE:RSSI:([0-9-]{3,4})[:]" E000E64CCACE:RSSI:-052: pattern = moudleBtMac + pattern; Match matchValue = Regex.Match(response, pattern); if (!matchValue.Success) { throw new BaseException("read info value fail"); } string value = matchValue.Groups[1].ToString(); Match matchKey = Regex.Match(config.GlobalVariblesKey, this.pattern); if (!matchKey.Success) { throw new BaseException("read info key fail"); } string key = matchKey.Groups[1].ToString(); configGv.Add(key, value); } }
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) //{ //} }
public void Run(IProperties properties, GlobalDic <string, object> globalDic)//virtual { config = properties as CmdReadMacProperties; ILog log = globalDic[typeof(ILog).ToString()] as ILog; configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles; ////取存储的关键字为MoudleBtMac的value值 //string DevWifi_MAC = configGv.Get("DevWifi_MAC"); //DevWifi_MAC = DevWifi_MAC.Replace(":", "").Replace(":", ""); //string labelMAC = configGv.Get(GlobalVaribles.MAC); //if (DevWifi_MAC != labelMAC) //{ // throw new BaseException(string.Format("WIFI MAC:{0},与标签MAC:{1} 不一致 FAIL\r\n", DevWifi_MAC, labelMAC)); //} //log.Info(string.Format(string.Format("WIFI MAC:{0},与标签MAC:{1} 一致 PASS\r\n", DevWifi_MAC, labelMAC))); int ret = -1; string returnString = ""; log.Info(string.Format("读取产品MAC中...\r\n")); ret = ExeCommand(config.GetMacCmd, out returnString); if (ret != 0) { log.Fail(string.Format("详情:{0},异常 \r\n", returnString)); throw new BaseException(string.Format("详情:{0},异常 \r\n", returnString)); } if (returnString.Contains("ERROR") || returnString.Contains("Error")) { log.Fail(string.Format("详情:{0}\r\n执行{1}错误 \r\n", returnString, config.GetMacCmd)); throw new BaseException(string.Format("详情:{0}\r\n执行{1}错误,返回包含ERROR \r\n", returnString, config.GetMacCmd)); } if (!returnString.Contains("ESP_MAC:"))// { throw new BaseException(string.Format("详情:{0}\r\n执行{1}错误,返回不包含: ESP_MAC:\r\n", returnString, config.GetMacCmd)); } log.Info(string.Format("详情:{0}\r\n执行{1}成功 \r\n", returnString, config.GetMacCmd)); string mac = ReadMac(returnString); if (mac == null) { mac = "FFFFFFFFFFFF"; configGv.Add(config.DeviceMac, mac); throw new BaseException(string.Format("详情:{0}\r\n获取MAC失败 \r\n", returnString)); } ////returnString = returnString.Substring(returnString.IndexOf("SYS_STAGE: 2")); ////正则匹配MAC //Match matchKey = Regex.Match(returnString, config.Pattern);//this.pattern //if (!matchKey.Success) //{ // throw new BaseException(string.Format("详情:{0}\r\n获取MAC失败,返回字符串未匹配获取MAC的正则 \r\n", returnString)); //} //string key = matchKey.Groups[1].ToString(); log.Info(string.Format("获取产品MAC成功:{0}\r\n", mac)); configGv.Add(config.DeviceMac, mac); }
private List <byte> buffer = new List <byte>(4096); //uart 接受数据buffer 未做任何处理 //public SKGExecuter() //{ // this.pattern = GlobalVaribles.PATTERN; //} public void Run(IProperties properties, GlobalDic <string, object> globalDic) { log = globalDic[typeof(ILog).ToString()] as ILog; SkgQueryCheckProperties config = properties as SkgQueryCheckProperties; //解析是否收到正确的包,包头,命令,校验位 //起始标志 数据长度 保留字 命令字 数据内容 异或校验码 //0XA5C3 9+N 0x0000 0x0037 Data 异或 //2 字节 2 字节 2 字节 2 字节 N 字节 1 字节 configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles; byte[] dataArry = (byte[])configGv.GetObject(config.GlobalVariblesKey); //string fireWareVersion = config.FirewareVersion; //string softwareVersion = config.SoftwareVersion; //string firmwareName = config.FirmwareName; #region //是否完成过PCBA 0x01:已完成过 其他值:未完成过 if (config.IfCheckFinishTest == SkgQueryCheckProperties.EnumIfCheckFinishTest.检查是否完成过PCBA测试 || config.IfCheckFinishTest == SkgQueryCheckProperties.EnumIfCheckFinishTest.全检 ) { if (dataArry[0] == 0x00) { log.Info("完成过PCBA测试"); } else { //if (config.IfCheckFinishTest== SkgQueryCheckProperties.EnumIfCheckFinishTest.检查是否完成过PCBA测试) //{ throw new BaseException("未完成过PCBA测试"); //} //log.Info("未完成过PCBA测试"); } } //查询是否完成过整机测试 0x01:已完成过 其他值:未完成过 if (config.IfCheckFinishTest == SkgQueryCheckProperties.EnumIfCheckFinishTest.检查是否完成过整机测试 || config.IfCheckFinishTest == SkgQueryCheckProperties.EnumIfCheckFinishTest.全检 ) { if (dataArry[1] == 0x00) { log.Info("完成过整机测试"); } else { //if (config.IfCheckFinishTest == SkgQueryCheckProperties.EnumIfCheckFinishTest.检查是否完成过整机测试) //{ throw new BaseException("未完成过整机测试"); //} //log.Info("未完成过整机测试"); } } //查询是否完成过老化测试 0x01:已完成过 其他值:未完成过 if (config.IfCheckFinishTest == SkgQueryCheckProperties.EnumIfCheckFinishTest.检查是否完成过老化测试 || config.IfCheckFinishTest == SkgQueryCheckProperties.EnumIfCheckFinishTest.全检 ) { if (dataArry[2] == 0x00) { log.Info("完成过老化测试"); } else { //if (config.IfCheckFinishTest == SkgQueryCheckProperties.EnumIfCheckFinishTest.检查是否完成过老化测试) //{ throw new BaseException("未完成过老化测试"); //} //log.Info("未完成过老化测试"); } } //硬件版本号(高位) 0x00 硬件版本号(高位) if (!string.IsNullOrEmpty(config.FirewareVersion)) { byte[] dataFirmwareVersion = new byte[2]; Array.Copy(dataArry, 3, dataFirmwareVersion, 0, 2); string strFirmwareVersion = byteToHexStr(dataFirmwareVersion); //strFirmwareVersion = System.Text.Encoding.Unicode.GetString(dataFirmwareVersion);//ASCII //string strFirmwareVersion = byteToHexStr(dataFirmwareVersion); if (strFirmwareVersion != config.FirewareVersion) { throw new BaseException(string.Format("硬件版本号:{0},与设置版本号:{1}不一致", strFirmwareVersion, config.FirewareVersion)); } log.Info(string.Format("硬件版本号:{0},与设置版本号:{1}一致", strFirmwareVersion, config.FirewareVersion)); } //软件版本号(高位) 0x00 软件版本号 6 //软件版本号 0x01 软件版本号 7 //软件版本号 0x02 软件版本号 8 //软件版本号(低位) 0x03 软件版本号(低位) if (!string.IsNullOrEmpty(config.SoftwareVersion)) { byte[] dataSoftwareVersion = new byte[4]; Array.Copy(dataArry, 5, dataSoftwareVersion, 0, 4); string strSoftwareVersion = byteToHexStr(dataSoftwareVersion); //strSoftwareVersion = System.Text.Encoding.ASCII.GetString(dataSoftwareVersion); //string strSoftwareVersion = byteToHexStr(dataSoftwareVersion); if (strSoftwareVersion != config.SoftwareVersion) { throw new BaseException(string.Format("软件版本号:{0},与设置版本号:{1}不一致", strSoftwareVersion, config.SoftwareVersion)); } log.Info(string.Format("软件版本号:{0},与设置版本号:{1}一致", strSoftwareVersion, config.SoftwareVersion)); } //MCU ID byte[] dataMcuId = new byte[12]; Array.Copy(dataArry, 9, 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)); //BLE MAC byte[] dataBleMac = new byte[6]; Array.Copy(dataArry, 21, 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)); configGv.Add(GlobalVaribles.MAC, strDataBleMac); //电池电压 //长度 2字节 if (!(config.VolMaxValue == 0 && config.VolMinValue == 0)) { byte high = dataArry[27]; byte low = dataArry[28]; int vol = (high & 0xFF) << 8 | low; CheckRange("电压值(mV):", vol, config.VolMaxValue, config.VolMinValue); } //NTC温度 //长度 2字节 if (!(config.Ntc1MaxValue == 0 && config.Ntc1MinValue == 0)) { byte high = dataArry[29]; if (high == 0x80) { throw new BaseException(string.Format("NTC1 开路或短路,NTC温度输出 0x8000")); } byte low = dataArry[30]; int ntc = (high & 0xFF) << 8 | low; CheckRange("NTC1温度值(单位0.1摄氏度):", ntc, config.Ntc1MaxValue, config.Ntc1MinValue); } //PCBA-ID if (config.CheckNumberInFlash == SkgQueryCheckProperties.EnumCheckNumberInFlash.检查是否写入过PCBA_ID) { if (dataArry[30] > 0x18) { throw new BaseException(string.Format("PCBID 有效长度:{0}不在0~24的合理范围内,未授权过", dataArry[31])); } byte[] dataPcbaId = new byte[24]; Array.Copy(dataArry, 31, dataPcbaId, 0, 24); //ASCII码的方式 //string strDataMcuId = System.Text.Encoding.ASCII.GetString(dataMcuId); //MCU ID:1F39A109高位在前1F,39的直接16进制拼接方式 string strDataPcbaId = Encoding.ASCII.GetString(dataPcbaId);//byteToHexStr(dataPcbaId); strDataPcbaId = strDataPcbaId.Replace("\0", ""); log.Info(string.Format("读取的PCBA-ID:{0}", strDataPcbaId)); //int型处理 string preSnPcbaId = configGv.Get(GlobalVaribles.LABEL_SN); if (preSnPcbaId != strDataPcbaId) { throw new BaseException(string.Format("预写PCBIDA-ID :{0}与写入的PCBA-ID :{1},不一致", preSnPcbaId, strDataPcbaId)); } log.Info(string.Format("预写PCBIDA-ID :{0}与写入的PCBA-ID :{1},一致", preSnPcbaId, strDataPcbaId)); //configGv.Add("ReadPcbaId", strDataPcbaId); } else if (config.CheckNumberInFlash == SkgQueryCheckProperties.EnumCheckNumberInFlash.检查是否写入过SN) { if (dataArry[56] > 0x18)//31 { throw new BaseException(string.Format("SN 有效长度:{0}不在0~24的合理范围内,未授权过", dataArry[31])); } byte[] dataSn = new byte[24]; Array.Copy(dataArry, 57, dataSn, 0, 24);//32 //ASCII码的方式 //string strDataMcuId = System.Text.Encoding.ASCII.GetString(dataMcuId); //MCU ID:1F39A109高位在前1F,39的直接16进制拼接方式 //不足的,需要判断补0? //string strDataSn = byteToHexStr(dataSn); string strDataSn = Encoding.ASCII.GetString(dataSn);//byteToHexStr(dataPcbaId); strDataSn = strDataSn.Replace("\0", ""); log.Info(string.Format("读取的SN:{0}", strDataSn)); //int型处理 string preSn = configGv.Get(GlobalVaribles.LABEL_SN); if (preSn != strDataSn) { throw new BaseException(string.Format("预写SN :{0}与写入的SN :{1},不一致", preSn, strDataSn)); } //configGv.Add("ReadSn", strDataSn); } else if (config.CheckNumberInFlash == SkgQueryCheckProperties.EnumCheckNumberInFlash.检查是否写入过蓝牙广播信息) { //预留-查询返回信息中没有蓝牙广播信息 } else if (config.CheckNumberInFlash == SkgQueryCheckProperties.EnumCheckNumberInFlash.检查) { //跳过 } //固件名称 if (!string.IsNullOrEmpty(config.FirmwareName)) { //byte[] dataFirmwareName = new byte[8]; //Array.Copy(dataArry, 81, dataFirmwareName, 0, 8); byte[] dataFirmwareName = new byte[5]; Array.Copy(dataArry, 80, dataFirmwareName, 0, 5); string strDataFirmwareName = System.Text.Encoding.ASCII.GetString(dataFirmwareName); strDataFirmwareName = strDataFirmwareName.Replace("\0", " "); //string strSoftwareVersion = byteToHexStr(dataSoftwareVersion); //log.Info("固件名称:" + strDataFirmwareName); if (strDataFirmwareName != config.FirmwareName) { throw new BaseException(string.Format("固件名称:{0},与设置固件名称:{1}不一致", strDataFirmwareName, config.FirmwareName)); } log.Info(string.Format("固件名称:{0},与设置固件名称:{1}一致", strDataFirmwareName, config.FirmwareName)); } //电机转速 if (!(config.MotorSpeedMaxValue == 0 && config.MotorSpeedMinValue == 0)) { byte high = dataArry[89]; byte low = dataArry[90]; int motorSpeed = (high & 0xFF) << 8 | low; CheckRange("电机转速:", motorSpeed, config.MotorSpeedMaxValue, config.MotorSpeedMinValue); } //NTC2温度 if (!(config.Ntc2MaxValue == 0 && config.Ntc2MinValue == 0)) { byte high = dataArry[91]; if (high == 0x80) { throw new BaseException(string.Format("NTC2 开路或短路,NTC温度输出 0x8000")); } byte low = dataArry[92]; int ntc = (high & 0xFF) << 8 | low; CheckRange("NTC2温度值(单位0.1摄氏度):", ntc, config.Ntc2MaxValue, config.Ntc2MinValue); } //NTC3温度 if (!(config.Ntc3MaxValue == 0 && config.Ntc3MinValue == 0)) { byte high = dataArry[93]; if (high == 0x80) { throw new BaseException(string.Format("NTC3 开路或短路,NTC温度输出 0x8000")); } byte low = dataArry[94]; int ntc = (high & 0xFF) << 8 | low; CheckRange("NTC3温度值(单位0.1摄氏度):", ntc, config.Ntc3MaxValue, config.Ntc3MinValue); } #endregion }
public void Run(IProperties properties, GlobalDic <string, object> globalDic) { config = properties as CheckHexUartProperties; ILog log = globalDic[typeof(ILog).ToString()] as ILog; configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles; List <ComDut> comDutList = globalDic[typeof(List <ComDut>).ToString()] as List <ComDut>; //ComDut comDut = globalDic[typeof(ComDut).ToString()] as ComDut; ComDut comDut = null; foreach (var item in comDutList) { if (item.PortName == config.PortName) { comDut = item; break; } } if (comDut == null) { throw new BaseException(string.Format("ComDut No PortName:{0}", config.PortName)); } //OpenPhoneProperties configOpenPhone = globalDic[typeof(OpenPhoneProperties).ToString()] as OpenPhoneProperties; List <OpenPhoneProperties> configList = globalDic[typeof(List <OpenPhoneProperties>).ToString()] as List <OpenPhoneProperties>; OpenPhoneProperties configOpenPhone = null; foreach (var item in configList) { if (item.PortName == config.PortName) { configOpenPhone = item; break; } } if (configOpenPhone == null) { throw new BaseException(string.Format("OpenPhoneProperties No PortName:{0}", config.PortName)); } string endLine = configOpenPhone.EndLine; if (!string.IsNullOrEmpty(endLine)) { endLine = Parse_r_n(endLine); } byte[] atCommand = strToToHexByte(config.AtCommand); //string atCommand = PreTranslateAtCommand(config.AtCommand); log.Info("AT Commond=" + config.AtCommand); //comDut.DtrEnable = configOpenPhone.Dtr; //comDut.RtsEnable = configOpenPhone.Rts; //comDut.Parity = System.IO.Ports.Parity.Even; comDut.Write(atCommand, 0, atCommand.Length); log.Info("Tx:" + config.AtCommand); Thread.Sleep(config.AtCommandInterval); int length = comDut.ReadBufferSize; byte[] byteArray = new byte[length]; comDut.Read(byteArray, 0, length); #region //string hexStr = byteToHexStr(byteArray); ////log.Info("Rx:" + hexStr); //string response = System.Text.Encoding.ASCII.GetString(byteArray); ////response = response.Replace("\0", "~"); ////string response = comDut.ReadExisting(); ////byte[] byteArray = System.Text.Encoding.ASCII.GetBytes(response); configGv.Add("RetBytes", byteArray); //comDut.DtrEnable = false; //comDut.RtsEnable = false; ////log.Info("Response:\r\n" + response); //if (!string.IsNullOrEmpty(config.AtCommandError)) //{ // if (response.Contains(config.AtCommandError)) // { // throw new BaseException(string.Format("AT response=[{0}] contain error=[{1}]", response, config.AtCommandError)); // } //} //if (!string.IsNullOrEmpty(config.AtCommandOk)) //{ // if (!response.Contains(config.AtCommandOk)) // { // throw new BaseException(string.Format("AT response=[{0}] not contain error=[{1}]", response, config.AtCommandOk)); // } //} //if (config.CheckInfo != null) //{ // for (int i = 0; i < config.CheckInfo.Length; i++) // { // if (!string.IsNullOrEmpty(config.CheckInfo[i])) // { // string checkInfo = PreTranslateCheckInfo(config.CheckInfo[i]); // if (!response.Contains(checkInfo)) // { // throw new BaseException(string.Format("AT response=[{0}] not contain check info=[{1}]", response, checkInfo)); // } // } // } //} //if (!string.IsNullOrEmpty(config.GlobalVariblesKey) && !string.IsNullOrEmpty(config.GlobalVariblesKeyPattern)) //{ // string pattern = Parse_r_n(config.GlobalVariblesKeyPattern); // Match matchValue = Regex.Match(response, pattern); // if (!matchValue.Success) // { // throw new BaseException("read info value fail"); // } // string value = matchValue.Groups[1].ToString(); // Match matchKey = Regex.Match(config.GlobalVariblesKey, this.pattern); // if (!matchKey.Success) // { // throw new BaseException("read info key fail"); // } // string key = matchKey.Groups[1].ToString(); // configGv.Add(key, value); //} #endregion byte[] retArray = configGv.GetObject("RetBytes") as byte[]; int startIndex = -1; //bool flageRightRes = false; for (int i = 0; i < retArray.Length; i++) { if (retArray[i] == 0xA6 && retArray[i + 1] == 0xA6) { //flageRightRes = true; startIndex = i; break; ////记录i的位置 //////核验校验位 ////sum += byteArray[i]; } } //byte[] dataArray = new byte[6]; //Array.Copy(retArray, startIndex, dataArray, 0, 6); //hexStr = byteToHexStr(dataArray); //log.Info(string.Format("收到7A 7A 21 D1 1B的回复:{0}\r\n", hexStr)); //log.Info(string.Format("收到7e 7e 03 bc 94 53的回复:{0}\r\n", hexStr)); if (startIndex == -1) { throw new BaseException("没有发现A6 A6 的回复"); } byte[] versionBtyes = new byte[3]; Array.Copy(retArray, startIndex + 3, versionBtyes, 0, 3); string strVersion = versionBtyes[2].ToString() + "." + versionBtyes[1].ToString() + "." + versionBtyes[0].ToString(); configGv.Add("VERSION", strVersion); log.Info(string.Format("版本号:{0}", strVersion)); byte[] wifiMacBtyes = new byte[12]; Array.Copy(retArray, startIndex + 6, wifiMacBtyes, 0, 12); string strImei = System.Text.Encoding.ASCII.GetString(wifiMacBtyes); configGv.Add("DevWifi_MAC", strImei); log.Info("WIFI MAC:" + strImei); byte[] softNumberBtyes = new byte[9]; Array.Copy(retArray, startIndex + 18, softNumberBtyes, 0, 9); string strSoftNumber = System.Text.Encoding.ASCII.GetString(softNumberBtyes); configGv.Add("SoftNumber", strSoftNumber); log.Info("软件编号:" + strSoftNumber); byte[] resultBtyes = new byte[4]; Array.Copy(retArray, startIndex + 27, resultBtyes, 0, 4); string strResult = System.Text.Encoding.ASCII.GetString(resultBtyes); configGv.Add("RESULT", strResult); log.Info("联网测试结果:" + strResult); byte[] btMacBtyes = new byte[12]; Array.Copy(retArray, startIndex + 31, btMacBtyes, 0, 12); string strBtMac = System.Text.Encoding.ASCII.GetString(btMacBtyes); log.Info("BT MAC:" + strBtMac); configGv.Add("DevBt_MAC", strBtMac); byte[] rssiBtyes = new byte[1]; Array.Copy(retArray, startIndex + 43, rssiBtyes, 0, 1); string strRssi = "-" + rssiBtyes[0].ToString(); log.Info("信号强度:" + strRssi); configGv.Add("RSSI", strRssi); //////byte[] iccidBtyes = new byte[20]; //////Array.Copy(retArray, startIndex + 88, iccidBtyes, 0, 20); //////string strIccid = System.Text.Encoding.ASCII.GetString(iccidBtyes); //////log.Info("ICCID:" + strIccid); //////if (strImsi == "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0") //////{ ////// throw new BaseException("ICCID为空,获取失败"); //////} //////configGv.Add("ICCID", strIccid); }
public void Run(IProperties properties, GlobalDic <string, object> globalDic)//virtual { config = properties as CmdProperties; ILog 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); ret = ExeCommand(config.Command, out returnString); log.Info("CMD Response=\r\n" + returnString); if (!string.IsNullOrEmpty(config.CommandError)) { if (returnString.Contains(config.CommandError)) { throw new BaseException(string.Format("CMD 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("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(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); } } }
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); }
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); // } //} }
public void Run(IProperties properties, GlobalDic <string, object> globalDic) { IsitWrittenToTheBtMacProperties config = properties as IsitWrittenToTheBtMacProperties; ComDut comDut = globalDic[typeof(ComDut).ToString()] as ComDut; OpenPhoneProperties configOpenPhone = globalDic[typeof(OpenPhoneProperties).ToString()] as OpenPhoneProperties; ILog log = globalDic[typeof(ILog).ToString()] as ILog; configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles; //string moudleBtMac = configGv.Get("MAC_BT"); string endLine = configOpenPhone.EndLine; if (!string.IsNullOrEmpty(endLine)) { endLine = Parse_r_n(endLine); } string atCommand = PreTranslateAtCommand(config.AtCommand); log.Info("AT Commond=" + atCommand); comDut.DtrEnable = configOpenPhone.Dtr; comDut.RtsEnable = configOpenPhone.Rts; comDut.Write(atCommand + endLine); Thread.Sleep(config.AtCommandInterval); string response = comDut.ReadExisting(); comDut.DtrEnable = false; comDut.RtsEnable = false; log.Info("AT Response=" + response); if (!string.IsNullOrEmpty(config.AtCommandError)) { if (response.Contains(config.AtCommandError)) { throw new BaseException(string.Format("AT response=[{0}] contain error=[{1}]", response, config.AtCommandError)); } } if (!string.IsNullOrEmpty(config.AtCommandOk)) { if (!response.Contains(config.AtCommandOk)) { throw new BaseException(string.Format("AT response=[{0}] not contain error=[{1}]", response, config.AtCommandOk)); } } if (config.CheckInfo != null) { for (int i = 0; i < config.CheckInfo.Length; i++) { if (!string.IsNullOrEmpty(config.CheckInfo[i])) { string checkInfo = PreTranslateCheckInfo(config.CheckInfo[i]); if (!response.Contains(checkInfo)) { throw new BaseException(string.Format("AT response=[{0}] not contain check info=[{1}]", response, checkInfo)); } } } } if (!response.Contains("BLE MAC:")) { if (config.ResultType == AILinkFactoryAuto.Task.SmartBracelet.Property.IsitWrittenToTheBtMacProperties.GetBtMacRetType.ThrowExcption) { throw new BaseException("不包含BLE MAC:信息,未能获取到BLE MAC"); } else if (config.ResultType == AILinkFactoryAuto.Task.SmartBracelet.Property.IsitWrittenToTheBtMacProperties.GetBtMacRetType.SKIP) { log.Info("不包含BLE MAC:信息,未能获取到BLE MAC"); return; } } if (!string.IsNullOrEmpty(config.GlobalVariblesKey) && !string.IsNullOrEmpty(config.GlobalVariblesKeyPattern)) { string pattern = Parse_r_n(config.GlobalVariblesKeyPattern); Match matchValue = Regex.Match(response, pattern); if (!matchValue.Success) { if (config.ResultType == AILinkFactoryAuto.Task.SmartBracelet.Property.IsitWrittenToTheBtMacProperties.GetBtMacRetType.ThrowExcption) { throw new BaseException("回复信息不匹配正则表达式,BLE未写过MAC"); } else if (config.ResultType == AILinkFactoryAuto.Task.SmartBracelet.Property.IsitWrittenToTheBtMacProperties.GetBtMacRetType.SKIP) { log.Info("回复信息不匹配正则表达式,BLE未写过MAC"); } } else { string value = matchValue.Groups[1].ToString(); if (value == "000000000000") { if (config.ResultType == AILinkFactoryAuto.Task.SmartBracelet.Property.IsitWrittenToTheBtMacProperties.GetBtMacRetType.ThrowExcption) { throw new BaseException(string.Format("BLE未写过MAC:{0}", value)); } else if (config.ResultType == AILinkFactoryAuto.Task.SmartBracelet.Property.IsitWrittenToTheBtMacProperties.GetBtMacRetType.SKIP) { log.Info(string.Format("BLE未写过MAC:{0}", value)); } } else { log.Info(string.Format("BLE已写过MAC:{0}", value)); //预检查{MoudleBtMac} Match matchKey = Regex.Match(config.GlobalVariblesKey, this.pattern);//this.pattern if (!matchKey.Success) { if (config.ResultType == AILinkFactoryAuto.Task.SmartBracelet.Property.IsitWrittenToTheBtMacProperties.GetBtMacRetType.ThrowExcption) { throw new BaseException("read info key fail"); } else if (config.ResultType == AILinkFactoryAuto.Task.SmartBracelet.Property.IsitWrittenToTheBtMacProperties.GetBtMacRetType.SKIP) { log.Info("read info key fail"); } } string key = matchKey.Groups[1].ToString(); //预检查 if (config.ImesPreCheck) { MesProcess.PreCheck(value); } //{MoudleBtMac} configGv.Add(key, value); configGv.Add(key, value); } } } }
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); }
public void Run(IProperties properties, GlobalDic <string, object> globalDic) { AutoToUserModeProperties config = properties as AutoToUserModeProperties; List <ComDut> comDutList = globalDic[typeof(List <ComDut>).ToString()] as List <ComDut>; //ComDut comDut = globalDic[typeof(ComDut).ToString()] as ComDut; ComDut comDut = null; foreach (var item in comDutList) { if (item.PortName == config.PortName) { comDut = item; break; } } if (comDut == null) { throw new BaseException(string.Format("ComDut No PortName:{0}", config.PortName)); } //OpenPhoneProperties configOpenPhone = globalDic[typeof(OpenPhoneProperties).ToString()] as OpenPhoneProperties; List <OpenPhoneProperties> configList = globalDic[typeof(List <OpenPhoneProperties>).ToString()] as List <OpenPhoneProperties>; OpenPhoneProperties configOpenPhone = null; foreach (var item in configList) { if (item.PortName == config.PortName) { configOpenPhone = item; break; } } if (configOpenPhone == null) { throw new BaseException(string.Format("OpenPhoneProperties No PortName:{0}", config.PortName)); } ILog log = globalDic[typeof(ILog).ToString()] as ILog; configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles; string endLine = configOpenPhone.EndLine; if (!string.IsNullOrEmpty(endLine)) { endLine = Parse_r_n(endLine); } //if (config.CommandType == AtCommandProperties.EnumCommandType.String) string response = configGv.Get("PowerOnLog"); { string atCommand = PreTranslateAtCommand(config.AtCommand); //Thread.Sleep(config.AtCommandInterval); //string response = comDut.ReadExisting(); //comDut.DtrEnable = false; //comDut.RtsEnable = false; log.Info("PowerOnLog=" + response); if (!response.Contains("The driver is for MP")) { log.Info("无需转换模式"); return; } //包含的话,需要转模式 log.Info("AT Commond=" + atCommand); comDut.DtrEnable = configOpenPhone.Dtr; comDut.RtsEnable = configOpenPhone.Rts; comDut.Write(atCommand + endLine); Thread.Sleep(config.AtCommandInterval); response = comDut.ReadExisting(); comDut.DtrEnable = false; comDut.RtsEnable = false; log.Info("AT Response=" + response); if (!string.IsNullOrEmpty(config.AtCommandError)) { if (response.Contains(config.AtCommandError)) { throw new BaseException(string.Format("AT response=[{0}] contain error=[{1}]", response, config.AtCommandError)); } } if (!string.IsNullOrEmpty(config.AtCommandOk)) { if (!response.Contains(config.AtCommandOk)) { throw new BaseException(string.Format("AT response=[{0}] not contain error=[{1}]", response, config.AtCommandOk)); } } if (config.CheckInfo != null) { for (int i = 0; i < config.CheckInfo.Length; i++) { if (!string.IsNullOrEmpty(config.CheckInfo[i])) { string checkInfo = PreTranslateCheckInfo(config.CheckInfo[i]); if (!response.Contains(checkInfo)) { throw new BaseException(string.Format("AT response=[{0}] not contain check info=[{1}]", response, checkInfo)); } log.Info(string.Format("contain check info=[{0}]", checkInfo)); } } } if (config.GlobalVariblesKey != null && config.GlobalVariblesKeyPattern != null) { if (config.GlobalVariblesKey.Length != config.GlobalVariblesKeyPattern.Length) { throw new BaseException("请保持GlobalVariblesKey与GlobalVariblesKeyPattern成对存在"); } for (int i = 0; i < config.GlobalVariblesKey.Length; i++) { string pattern = Parse_r_n(config.GlobalVariblesKeyPattern[i]); Match matchValue = Regex.Match(response, pattern); if (!matchValue.Success) { throw new BaseException("read info value fail"); } string value = matchValue.Groups[1].ToString(); Match matchKey = Regex.Match(config.GlobalVariblesKey[i], this.pattern); if (!matchKey.Success) { throw new BaseException("read info key fail"); } string key = matchKey.Groups[1].ToString(); configGv.Add(key, value); } } } //else if (config.CommandType == AtCommandProperties.EnumCommandType.Hex) //{ // byte[] atCommand = strToToHexByte(config.AtCommand); // //string atCommand = PreTranslateAtCommand(config.AtCommand); // log.Info("AT Commond=" + config.AtCommand); // comDut.DtrEnable = configOpenPhone.Dtr; // comDut.RtsEnable = configOpenPhone.Rts; // comDut.Write(atCommand, 0, atCommand.Length); // log.Info("Tx:" + config.AtCommand); // Thread.Sleep(config.AtCommandInterval); // int length = comDut.ReadBufferSize; // byte[] byteArray = new byte[length]; // comDut.Read(byteArray, 0, length); // string hexStr = byteToHexStr(byteArray); // log.Info("Rx:" + hexStr); // string response = System.Text.Encoding.ASCII.GetString(byteArray); // response = response.Replace("\0", "~"); // //string response = comDut.ReadExisting(); // //byte[] byteArray = System.Text.Encoding.ASCII.GetBytes(response); // configGv.Add("RetBytes", byteArray); // comDut.DtrEnable = false; // comDut.RtsEnable = false; // log.Info("Response:\r\n" + response); // if (!string.IsNullOrEmpty(config.AtCommandError)) // { // if (response.Contains(config.AtCommandError)) // { // throw new BaseException(string.Format("AT response=[{0}] contain error=[{1}]", response, config.AtCommandError)); // } // } // if (!string.IsNullOrEmpty(config.AtCommandOk)) // { // if (!response.Contains(config.AtCommandOk)) // { // throw new BaseException(string.Format("AT response=[{0}] not contain error=[{1}]", response, config.AtCommandOk)); // } // } // if (config.CheckInfo != null) // { // for (int i = 0; i < config.CheckInfo.Length; i++) // { // if (!string.IsNullOrEmpty(config.CheckInfo[i])) // { // string checkInfo = PreTranslateCheckInfo(config.CheckInfo[i]); // if (!response.Contains(checkInfo)) // { // throw new BaseException(string.Format("AT response=[{0}] not contain check info=[{1}]", response, checkInfo)); // } // } // } // } // if (config.GlobalVariblesKey != null && config.GlobalVariblesKeyPattern != null) // { // if (config.GlobalVariblesKey.Length != config.GlobalVariblesKeyPattern.Length) // { // throw new BaseException("请保持GlobalVariblesKey与GlobalVariblesKeyPattern成对存在"); // } // for (int i = 0; i < config.GlobalVariblesKey.Length; i++) // { // string pattern = "-([0-9]{2}) "; // Match matchValue = Regex.Match(response, pattern); // if (!matchValue.Success) // { // throw new BaseException("read info value fail"); // } // string value = matchValue.Groups[1].ToString(); // Match matchKey = Regex.Match(config.GlobalVariblesKey[i], this.pattern); // if (!matchKey.Success) // { // throw new BaseException("read info key fail"); // } // string key = matchKey.Groups[1].ToString(); // configGv.Add(key, value); // } // } //} }
public void Run(IProperties properties, GlobalDic <string, object> globalDic)//virtual { config = properties as ReadMapProperties; ILog log = globalDic[typeof(ILog).ToString()] as ILog; configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles; //int ret = -1; string binFileString = ""; //查询MAC对应的bin文件 //第一种方法 string mac = configGv.Get(GlobalVaribles.MAC); try { var files = Directory.GetFiles(config.BinFolderPath, "*.bin"); foreach (var file in files) { if (file.Contains(mac)) { binFileString = ReadBinery(file); break; } } configGv.Add("BinFileString", binFileString); if (string.IsNullOrEmpty(binFileString)) { throw new Exception(string.Format("读取License文件失败,未读到该MAC:{0}的binFile", mac)); } #region 从服务器download文件下来 http://10.42.1.4:9999/midea_hi3861_license/847C9B7E6287.bin //HttpTools.Download("http://10.42.1.4:9999/midea_hi3861_license/847C9B7E6.bin", "E:/testDownLoadBin/847C9B7E6287.bin"); #endregion } catch (Exception ex) { throw new Exception(string.Format("读取License文件失败,异常:{0}", ex.Message)); } log.Info(string.Format("读取License文件成功:\r\n{0}", binFileString)); //try //{ // binFileString = Read(config.MapFilePath); //} //catch (Exception ex) //{ // throw new Exception(string.Format("读取License文件失败,异常:{0}", ex.Message)); //} //log.Info(string.Format("读取License文件成功:\r\n{0}", binFileString)); ////更新MAP内存中的MAC地址 //string[] splits = { "\r\n" }; //string[] mapFileStringLines = mapFileString.Split(splits, StringSplitOptions.RemoveEmptyEntries); ////IMES获取的MAC*************** //configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles; //string macFromImes = configGv.Get("MAC"); //string reverseMacAddSpace = AddSpaceEachTwoBtye(macFromImes); //string mapFileStringMacUpdate = ""; //for (int i = 0; i < mapFileStringLines.Length; i++) //{ // if (i == 17) // { // //前面固定部分+反转并添加空格的MAC // mapFileStringLines[i] = mapFileStringLines[i].Substring(0, 25) + reverseMacAddSpace; // } // mapFileStringMacUpdate += mapFileStringLines[i] + "\r\n"; //} ////存为byte数组应该会好些,这样可以定位地址,当MAC的偏移地址发生变化时,只需改地址值 //log.Info(string.Format("更新MAP文件中的MAC成功:\r\n{0}", mapFileStringMacUpdate)); //GlobalVaribles configGv1 = globalDic.Get<GlobalVaribles>(); //configGv1.Add("MapFileStringMacUpdate", mapFileStringMacUpdate); }
public void Run(IProperties properties, GlobalDic <string, object> globalDic) { AccessToMacProperties config = properties as AccessToMacProperties; ComDut comDut = globalDic[typeof(ComDut).ToString()] as ComDut; OpenPhoneProperties configOpenPhone = globalDic[typeof(OpenPhoneProperties).ToString()] as OpenPhoneProperties; ILog log = globalDic[typeof(ILog).ToString()] as ILog; configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles; //string moudleBtMac = configGv.Get("MAC_BT"); string endLine = configOpenPhone.EndLine; if (!string.IsNullOrEmpty(endLine)) { endLine = Parse_r_n(endLine); } string atCommand = PreTranslateAtCommand(config.AtCommand); log.Info("AT Commond=" + atCommand); comDut.DtrEnable = configOpenPhone.Dtr; comDut.RtsEnable = configOpenPhone.Rts; comDut.Write(atCommand + endLine); Thread.Sleep(config.AtCommandInterval); string response = comDut.ReadExisting(); comDut.DtrEnable = false; comDut.RtsEnable = false; log.Info("AT Response=" + response); if (!string.IsNullOrEmpty(config.AtCommandError)) { if (response.Contains(config.AtCommandError)) { throw new BaseException(string.Format("AT response=[{0}] contain error=[{1}]", response, config.AtCommandError)); } } if (!string.IsNullOrEmpty(config.AtCommandOk)) { if (!response.Contains(config.AtCommandOk)) { throw new BaseException(string.Format("AT response=[{0}] not contain error=[{1}]", response, config.AtCommandOk)); } } if (config.CheckInfo != null) { for (int i = 0; i < config.CheckInfo.Length; i++) { if (!string.IsNullOrEmpty(config.CheckInfo[i])) { string checkInfo = PreTranslateCheckInfo(config.CheckInfo[i]); if (!response.Contains(checkInfo)) { throw new BaseException(string.Format("AT response=[{0}] not contain check info=[{1}]", response, checkInfo)); } } } } if (!response.Contains("BLE MAC:")) { throw new BaseException("不包含BLE MAC:信息"); } if (!string.IsNullOrEmpty(config.GlobalVariblesKey) && !string.IsNullOrEmpty(config.GlobalVariblesKeyPattern)) { string pattern = Parse_r_n(config.GlobalVariblesKeyPattern); Match matchValue = Regex.Match(response, pattern); if (!matchValue.Success) { //ble mac为空 //log.Info("BLE未写过MAC"); throw new BaseException("BLE未写过MAC,请在前面工序写BLE MAC"); } else { string value = matchValue.Groups[1].ToString(); if (value == "000000000000") { log.Info(string.Format("BLE未写过MAC:{0}", value)); throw new BaseException("BLE未写过MAC,请在前面工序写BLE MAC"); //configGv.Add(GlobalVaribles.MAC_BT, value); } else { log.Info(string.Format("BLE已写过MAC:{0}", value)); //预检查{MoudleBtMac} Match matchKey = Regex.Match(config.GlobalVariblesKey, this.pattern);//this.pattern if (!matchKey.Success) { throw new BaseException("read info key fail"); } string key = matchKey.Groups[1].ToString(); //预检查 MesProcess.PreCheck(value); //赋值BT MAC,WIFI MAC,取消取号 configGv.Add(key, value); //configGv.Add(GlobalVaribles.MAC_BT, value); UInt64 macUInt64 = Convert.ToUInt64(value, 16); string macWifi = string.Format("{0:X}", macUInt64 - 1).PadLeft(12, '0'); configGv.Add(GlobalVaribles.MAC, macWifi); log.Info(string.Format("自动计算WIFI MAC号:{0}", macWifi)); } } } }
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); // } //} }