private int DeviceCheck(ThirdPartyTool tool, out string strRet) { int ret = -1; CmdProcess cmdProcess = new CmdProcess(); //cmd类 strRet = cmdProcess.ExeCommand(tool); //"azsphere device wifi show-status" if (strRet.Contains("error: Could not connect to the device.")) { //frmMain.DisplayLog(string.Format("未上电连接上设备,请检查连接或驱动 FAIL\r\n详细:{0} \r\n", strRet)); return(ret); } ret = 0; return(ret); }
/// <summary> /// 任务流 /// </summary> /// <returns></returns> private int TestTaskFlow() { int ret = -1; //string pattern = null; //eidRead = "NULL"; //两种情况进入此处:1、超时跳出了do while,2、按了空格确认上电 if (readWriteIdHandle.IsTimeOut) { frmMain.DisplayLog("测试超时\r\n"); return(ret); } do { frmMain.DisplayLog("测试中...\r\n"); CmdProcess cmdProcess = new CmdProcess(); //cmd类 tool = new ThirdPartyTool() { ToolDirectory = "Microsoft Azure Sphere SDK", ToolName = "InitializeCommandPrompt", Cmd = "azsphere device wifi show-status" }; string strRet; #region //获取OS版本 //strRet = cmdProcess.ExeCommand("", "azsphere device show-ota-status");//"azsphere device wifi show-status" //if (strRet.Contains("error: Could not connect to the device.")) //{ // frmMain.DisplayLog(string.Format("未上电连接上设备,请检查连接或驱动 FAIL\r\n详细:{0} \r\n", strRet)); // break; //} //if (strRet.Contains("is not a valid value")) //{ // frmMain.DisplayLog(string.Format("未claim设备 获取OS版本失败 FAIL\r\n详细:{0} \r\n", strRet)); // break; //} #endregion //对比模块MAC地址-标签MAC地址 strRet = cmdProcess.ExeCommand("", "azsphere device wifi show-status");//"azsphere device wifi show-status" if (strRet.Contains("error: Could not connect to the device.")) { frmMain.DisplayLog(string.Format("未上电连接上设备,请检查连接或驱动 FAIL\r\n详细:{0} \r\n", strRet)); break; } //ret = DeviceCheck(tool, out strRet); //if (ret!=0) //{ // frmMain.DisplayLog(string.Format("未上电连接上设备,请检查连接或驱动 FAIL\r\n详细:{0} \r\n", strRet)); // break; //} string mouduleMac = cmdProcess.GetValueByKeyword(strRet, "MAC Address"); if (mouduleMac != labelSn) { frmMain.DisplayLog(string.Format("MAC检查:模块{0},标签{1} 对比不一致 FAIL\r\n", mouduleMac, labelSn)); break; } frmMain.DisplayLog(string.Format("MAC检查:模块{0},标签{1} 对比一致 PASS\r\n", mouduleMac, labelSn)); //检查是否有测试程序 //azsphere device sideload show-status //azsphere device sideload delete //azsphere device sideload deploy -p mt_app.img //删除当前程序 frmMain.DisplayLog("当前程序删除中...\r\n"); strRet = cmdProcess.ExeCommand("", "azsphere device sideload delete");//"azsphere device wifi show-status" if (strRet.Contains("error: Could not connect to the device.")) { frmMain.DisplayLog(string.Format("未上电连接上设备,请检查连接或驱动 FAIL\r\n详细:{0} \r\n", strRet)); break; } if (!strRet.Contains("Command completed successfully")) { frmMain.DisplayLog(string.Format("当前程序删除: 失败 FAIL\r\n详细:{0} \r\n", strRet)); break; } frmMain.DisplayLog("当前程序删除:成功 PASS\r\n"); Thread.Sleep(500); //Side load(加载测试固件) frmMain.DisplayLog("测试固件加载中...\r\n"); strRet = cmdProcess.ExeCommand("", string.Format("azsphere device sideload deploy -p ../app/{0}", TestAppName));//"azsphere device wifi show-status" if (strRet.Contains("error: Could not connect to the device.")) { frmMain.DisplayLog(string.Format("未上电连接上设备,请检查连接或驱动 FAIL\r\n详细:{0} \r\n", strRet)); break; } //tool.Cmd = "azsphere device sideload deploy -p mt_app.img"; //ret = DeviceCheck(tool, out strRet); //if (ret != 0) //{ // frmMain.DisplayLog(string.Format("未上电连接上设备,请检查连接或驱动 FAIL\r\n详细:{0} \r\n", strRet)); // break; //} if (!strRet.Contains("Command completed successfully")) { frmMain.DisplayLog(string.Format("加载测试固件:失败 FAIL\r\n详细:{0} \r\n", strRet)); break; } frmMain.DisplayLog(string.Format("加载测试固件:成功 PASS\r\n", strRet)); string pinTestRetinfo; //Socket复位 frmMain.DisplayLog("复位测试中...\r\n"); //成功 为有效信息 bool pinTestRet = PinTestBySocket("reset_tests", out pinTestRetinfo); frmMain.DisplayLog(pinTestRetinfo + "\r\n"); //失败 为错误信息 if (!pinTestRet) { frmMain.DisplayLog("复位测试:失败 FAIL\r\n");//失败 为错误信息 break; } frmMain.DisplayLog("复位测试:合格 PASS\r\n");//成功 为有效信息 //Socket GPIO检查 frmMain.DisplayLog("GPIO测试中...\r\n"); pinTestRet = PinTestBySocket("get_gpios", out pinTestRetinfo); frmMain.DisplayLog(pinTestRetinfo + "\r\n");//失败 为错误信息 if (!pinTestRet) { frmMain.DisplayLog("GPIO测试:测试失败 FAIL\r\n");//失败 为错误信息 break; } string errorStr; bool gpioRet = GetGIPOResultBySocketRet(pinTestRetinfo, out errorStr); //展示返回的GPIO数据 //strRet = strRet.Replace("P", "PASS").Replace("F", "FAIL") + "\r\n"; //frmMain.DisplayLog(strRet); //GPIO结果显示 if (!gpioRet) { frmMain.DisplayLog("GPIO测试: 不合格 FAIL \r\n"); break; } frmMain.DisplayLog("GPIO测试:合格 PASS\r\n");//成功 为有效信息 #region 串口测试 复位和GPIO ////串口发送Reset System\r\n //strRet = readWriteIdHandle.Read(ATReadCmd.ReadIdType.Reset); //if (string.IsNullOrEmpty(strRet)) //{ // frmMain.DisplayLog(string.Format("复位命令未得到回应 串口失败 FAIL\r\n详细:{0} \r\n", strRet)); // break; //} ////if (!strRet.Contains("Get RST command")) ////{ //// frmMain.DisplayLog(string.Format("复位未得到回应 串口失败 FAIL\r\n详细:{0} \r\n", strRet)); //// break; ////} ////复位命令得到回应 //frmMain.DisplayLog(string.Format("复位中... \r\n")); ////跳出循环说明复位成功 //readWriteIdHandle.ReadRestInfo("init completed"); //frmMain.DisplayLog(string.Format("复位成功 PASS\r\n")); ////GPIO测试 ////串口发送Reset System\r\n //Thread.Sleep(1000); //strRet = readWriteIdHandle.Read(ATReadCmd.ReadIdType.GPIOTest); //if (string.IsNullOrEmpty(strRet)) //{ // frmMain.DisplayLog("GPIO测试命令未得到回应 串口失败 FAIL\r\n"); // break; //} ////GPIO测试命令得到回应 ////frmMain.DisplayLog("GPIO测试中... \r\n"); ////string errorInfo; ////bool gpioRet = checkGIPOResult(strRet, out errorInfo); //////展示返回的GPIO数据 ////strRet = strRet.Replace("P", "PASS").Replace("F", "FAIL") + "\r\n"; ////frmMain.DisplayLog(strRet); //////GPIO结果显示 ////if (!gpioRet) ////{ //// frmMain.DisplayLog(string.Format("GPIO测试:失败 FAIL \r\n详细:{0}\r\n", errorInfo)); //// break; ////} ////frmMain.DisplayLog("GPIO测试:成功 PASS\r\n"); #endregion //删除APPtest frmMain.DisplayLog("测试固件删除中...\r\n"); strRet = cmdProcess.ExeCommand("", "azsphere device sideload delete");//"azsphere device wifi show-status" if (strRet.Contains("error: Could not connect to the device.")) { frmMain.DisplayLog(string.Format("未上电连接上设备,请检查连接或驱动 FAIL\r\n详细:{0} \r\n", strRet)); break; } //tool.Cmd = "azsphere device sideload deploy -p mt_app.img"; //ret = DeviceCheck(tool, out strRet); //if (ret != 0) //{ // frmMain.DisplayLog(string.Format("未上电连接上设备,请检查连接或驱动 FAIL\r\n详细:{0} \r\n", strRet)); // break; //} if (!strRet.Contains("Command completed successfully")) { frmMain.DisplayLog(string.Format("测试固件删除:失败 FAIL\r\n详细:{0} \r\n", strRet)); break; } frmMain.DisplayLog("测试固件删除:成功 PASS\r\n"); frmMain.DisplayLog("Wifi列表网络检查中...\r\n"); //检查网络 wifi表 strRet = cmdProcess.ExeCommand("", "azsphere device wifi list");//"azsphere device wifi show-status" if (strRet.Contains("error: Could not connect to the device.")) { frmMain.DisplayLog(string.Format("未上电连接上设备,请检查连接或驱动 FAIL\r\n详细:{0} \r\n", strRet)); break; } if (!strRet.Contains("No networks found") && strRet.Contains("ID")) { //Get ID string[] wifiIdList = cmdProcess.GetListByKeyword(strRet, "ID").ToArray(); foreach (var item in wifiIdList) { frmMain.DisplayLog("WIFI列表检查:含有WIFI列表ID,删除中...\r\n"); //不为空 if (!string.IsNullOrEmpty(item)) { //删除ID strRet = cmdProcess.ExeCommand("", string.Format("azsphere device wifi delete –i {0}", item));//"azsphere device wifi show-status" if (strRet.Contains("error: Could not connect to the device.")) { frmMain.DisplayLog(string.Format("未上电连接上设备,请检查连接或驱动 FAIL\r\n详细:{0} \r\n", strRet)); return(ret); } //不包含成功信息且不包含 if (!strRet.Contains("Successfully removed network") && !strRet.Contains("Command completed successfully")) { frmMain.DisplayLog(string.Format("WIFI列表ID删除:失败 FAIL\r\n详细:{0} \r\n", strRet)); return(ret); } } } } frmMain.DisplayLog("WIFI列表检查:PASS\r\n"); //性能测试 frmMain.DisplayLog("capabilties测试中...\r\n"); Capability: strRet = cmdProcess.ExeCommand("", "azsphere device capability show-attached");//"azsphere device wifi show-status" if (strRet.Contains("error: Could not connect to the device.")) { frmMain.DisplayLog(string.Format("未上电连接上设备,请检查连接或驱动 FAIL\r\n详细:{0} \r\n", strRet)); break; } if (!strRet.Contains("Command completed successfully")) { frmMain.DisplayLog(string.Format("capabilties测试:失败 FAIL\r\n详细:{0} \r\n", strRet)); break; } List <string> capabilitiesList = cmdProcess.GetListCapabilitiesKeyword(strRet, "Enable"); if (capabilitiesList.Count > 0) { //manufacture set complete status,只能设置一次,设置后就不能够RF测试和校准了,测试阶段不要轻易尝试。 #region if (IsManufactureComplete == 1) { strRet = cmdProcess.ExeCommand("", "manufacture set complete status");//"azsphere device wifi show-status" if (strRet.Contains("error: Could not connect to the device.")) { frmMain.DisplayLog(string.Format("未上电连接上设备,请检查连接或驱动 FAIL\r\n详细:{0} \r\n", strRet)); break; } frmMain.DisplayLog(string.Format("已设置制作完成状态,继续测试capabilties中... \r\n详细:{0} \r\n", strRet)); goto Capability; } #endregion frmMain.DisplayLog(string.Format("capabilties测试:失败 FAIL\r\n详细:{0} \r\n", strRet)); break; } frmMain.DisplayLog("capabilties测试:PASS\r\n"); //E-fuse测试 tool = new ThirdPartyTool() { ToolDirectory = "RFToolCli", Cmd = string.Format("RfSettingsTool check --expected ../bin/{0}", EfuseBin) }; //strRet = cmdProcess.ExeCommand(tool);//"azsphere device wifi show-status" //if (strRet.Contains("error")) //{ // frmMain.DisplayLog(string.Format("E-fuse测试:失败 FAIL\r\n详细:{0} \r\n", strRet)); // break; //} //python //tool.Cmd = "python RunHeaderTest.py ";//reset_system //tool.ToolDirectory = "PC"; //strRet = cmdProcess.ExeCommand(tool, ""); //if (strRet.Contains("error")) //{ // frmMain.DisplayLog(string.Format("E-fuse测试:失败 FAIL\r\n详细:{0} \r\n", strRet)); // break; //} //E-fuse具体测试内容 frmMain.DisplayLog("e-fuse测试中...\r\n"); strRet = cmdProcess.ExeCommand(tool, ""); string hasReadFlag = "Comparing configurations."; string startFlag = "Reading configuration data from device."; string erroInfo = StringHelp.SubCentre(strRet, startFlag, "\r\n\r\n"); if (!strRet.Contains(hasReadFlag)) { frmMain.DisplayLog(string.Format("E-fuse测试:命令失败 \r\n详细:{0} \r\n", erroInfo)); break; } strRet = StringHelp.SubCentre(strRet, hasReadFlag, "\r\n\r\n"); frmMain.DisplayLog(strRet + "\r\n"); if (strRet.Contains("ERROR") || strRet.Contains("异常")) { frmMain.DisplayLog("E-fuse测试结果: FAIL \r\n"); break; } frmMain.DisplayLog("E-fuse测试:PASS\r\n"); ret = 0; //cd RFToolCli //List<string> listValue = readWriteIdHandle.ReadId(); //if (listValue.Count <= 3) //{ // break; //} ////多组:1,1,01,01,,,40,0*61 //int sum = 0; //string[] arryData; //try //{ // foreach (string strData in listValue) // { // arryData = strData.Split(','); // 应滤除其他可视卫星 // int cn0Value = int.Parse(arryData[6]); // sum += cn0Value; // } //} //catch (Exception ex) //{ // frmMain.DisplayLog(string.Format("数据解析错误:{0}\r\n", ex.Message)); // break; //} //int argVale = sum / listValue.Count; //frmMain.DisplayLog(string.Format("获取C/N0值:{0}\r\n", argVale)); //if (argVale < StandardCN01) //{ // frmMain.DisplayLog(string.Format("C/N0值:{0},小于设定范围{1} FAIL\r\n", argVale, StandardCN01)); // break; //} //frmMain.DisplayLog(string.Format("C/N0值:{0},大于设定范围{1} PASS\r\n", argVale,StandardCN01)); //ret = 0; ////从芯片获取eid ////eidRead = "081603FFFFF35293" + eidlast.ToString("X").PadLeft(4,'0'); //eidRead = readWriteIdHandle.ReadId(ATReadCmd.ReadIdType.EidRead); //pattern = @"[0-9A-Z]{20}"; //if (string.IsNullOrEmpty(eidRead) || !Regex.IsMatch(eidRead, pattern)) //{ // frmMain.DisplayLog("EID读取失败\r\n"); // break; //} //frmMain.DisplayLog(string.Format("已获取模块EID:{0}\r\n", eidRead)); //frmMain.SetText(AllForms.EnumControlWidget.txtEid.ToString(), eidRead, false); } while (false); ProductionInfo.SystemType systemType = ProductionInfo.Type; //使用do..while(false)的原因,是为了当测试流程为fail时,使用break跳出该结构,仍然执行结果上报 return(ret); }
private int TestTaskFlow() { int ret = -1; try { #region //离线查重MAC if (ProductionInfo.Type == ProductionInfo.SystemType.Offline) { JiaHao.ExcelHelp.ExcelHelper excel = JiaHao.ExcelHelp.ExcelHelper.GetExcelHelperInstance(); int retCheck = excel.SearchImei(txtMac.Text); if (retCheck != 0) { DisplayLog(string.Format("MAC查重: {0} 重复 FAIL\r\n", txtMac.Text)); //return ret; //stopWatcher1.Stop(); return(retCheck); } else { DisplayLog(string.Format("MAC查重: {0} 本机查重 PASS\r\n", txtMac.Text)); } } //分配SN JiaHao.ExcelHelp.ExcelHelper snExcel = JiaHao.ExcelHelp.ExcelHelper.GetExcelHelperInstance(true); string sn = snExcel.GetSn();//读最后一行 if (string.IsNullOrEmpty(sn)) { DisplayLog(string.Format("分配SN: MAC:{0}分配SN失败 FAIL\r\n", txtMac.Text)); ret = -1; return(ret); } DisplayLog(string.Format("分配SN: {0}成功 PASS\r\n", sn)); SetText(EnumControlWidget.txtSn.ToString(), sn, false); //txtSn.Text = sn; //txtSn.Refresh(); string strTimeNow = DateTime.Now.ToString("yyyyMMdd_HHmmss"); string strBinFilePath = strBinPath + txtSn.Text.ToUpper() + "_" + strTimeNow + ".bin"; FileStream fs = new FileStream(strBinFilePath, FileMode.Create);//@"C:\Users\ZJH\Desktop\test2.bin" BinaryWriter bw = new BinaryWriter(fs); //byte[] byteArray = StringToHex(textSN.Text); // byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(txtSn.Text); for (int i = 0; i < byteArray.Length; i++) { bw.Write((byte)byteArray[i]); } bw.Close(); fs.Close(); StringBuilder SN = new StringBuilder(256); string path; IntPtr ptrTestSoftFormMain = FindWindow(espApplicationPath); IntPtr ptrChild1 = Win32API.FindWindowEx(ptrTestSoftFormMain, IntPtr.Zero, null, null);// Win32API.SendMessage(ptrChild1, Win32API.WM_GETTEXT, 100, SN); path = SN.ToString(); IntPtr ptrChild1_1 = Win32API.FindWindowEx(ptrChild1, IntPtr.Zero, null, null);// Win32API.SendMessage(ptrChild1_1, Win32API.WM_GETTEXT, 100, SN); path = SN.ToString(); IntPtr ptrChild1_2 = Win32API.FindWindowEx(ptrChild1, ptrChild1_1, null, null);// Win32API.SendMessage(ptrChild1_2, Win32API.WM_GETTEXT, 100, SN); path = SN.ToString(); IntPtr ptrChild1_3S = Win32API.FindWindowEx(ptrChild1, ptrChild1_2, null, null); // IntPtr ptrChild1_3S_1 = Win32API.FindWindowEx(ptrChild1_3S, IntPtr.Zero, null, null); // IntPtr ptrChild1_3S_1_1 = Win32API.FindWindowEx(ptrChild1_3S_1, IntPtr.Zero, null, null); // IntPtr ptrChild1_3S_1_1_1 = Win32API.FindWindowEx(ptrChild1_3S_1_1, IntPtr.Zero, null, null); // IntPtr ptrChild3S_1_1_1_1text = Win32API.FindWindowEx(ptrChild1_3S_1_1_1, IntPtr.Zero, null, null); // if (ptrChild3S_1_1_1_1text.Equals(IntPtr.Zero)) { DisplayLog("烧录软件检查: 无法抓取到烧录软件路径栏 Edit FAIL\r\n"); return(ret); } Win32API.SendMessage(ptrChild3S_1_1_1_1text, Win32API.WM_SETTEXT, 0, strBinFilePath); //抓取Button IntPtr ptrChild1_3S_3 = Win32API.FindWindowEx(ptrChild1_3S, IntPtr.Zero, null, "ESP FLASH DOWNLOAD TOOL V0.9.7");// Win32API.SendMessage(ptrChild1_3S_3, Win32API.WM_GETTEXT, 100, SN); path = SN.ToString(); IntPtr ptrChild1_3S_3_1 = Win32API.FindWindowEx(ptrChild1_3S_3, IntPtr.Zero, null, null);// Win32API.SendMessage(ptrChild1_3S_3_1, Win32API.WM_GETTEXT, 100, SN); path = SN.ToString(); IntPtr ptrChild1_3S_3_1_1 = Win32API.FindWindowEx(ptrChild1_3S_3_1, IntPtr.Zero, null, null);// Win32API.SendMessage(ptrChild1_3S_3_1_1, Win32API.WM_GETTEXT, 100, SN); path = SN.ToString(); IntPtr ptrChild1_3S_3_1_1_5start = Win32API.FindWindowEx(ptrChild1_3S_3_1_1, IntPtr.Zero, null, "START");// Win32API.SendMessage(ptrChild1_3S_3_1_1_5start, Win32API.WM_GETTEXT, 100, SN); path = SN.ToString(); if (ptrChild1_3S_3_1_1_5start.Equals(IntPtr.Zero)) { //MessageBox.Show("未抓取到START按键"); DisplayLog("烧录软件检查: 无法抓取到START按键 FAIL\r\n"); return(ret); } if (CheckSn == 1) { DisplayLog(string.Format("等待{0}s ....,请上电进入下载模式 进行查询SN\r\n", WaitintTime / 1000)); //扫码等待5s后,查询SN Thread.Sleep(WaitintTime); #region 查询产品是否有SN // 读取SN生产bin文件 string strCmdReturn1; DisplayLog("开始读取芯片0xc1000地址...\r\n"); int retCmd1 = cmdProcess.ExeCommand(ReadToolFolderName, ReadToolAppName, ComPort, out strCmdReturn1); //使用工具读取addr并生成bin成功 if (retCmd1 != 0) { Process[] processes = Process.GetProcesses(); //创建并实例化一个操作进程的类:Process foreach (var item in processes) { if (item.ProcessName == "read_bin_addr") { item.Close(); //item.Kill(); break; } } DisplayLog("SN查询:读取地址失败 FAIL,提示:超过等待时间,设备需3次进入下载模式\r\n"); return(retCmd1); //goto END;//END 处理收尾:显示烧写结果,清空 } DisplayLog("读取芯片0xc1000地址生成bin成功\r\n"); DisplayLog("开始读取bin中的SN...\r\n"); //获取bin文件路径 int po; string idKeySubstr1 = "save data to : "; if ((po = strCmdReturn1.IndexOf(idKeySubstr1)) >= 0) { string createdBinPath = strCmdReturn1.Substring(po + idKeySubstr1.Length); //读取bin文件,前7个字节 createdBinPath = createdBinPath.Replace("./", "./" + ReadToolFolderName + "/"); byte[] readHex = ReadFile(createdBinPath); //将读取与写入对比,一致则写入成功 string strRead = Encoding.UTF8.GetString(readHex); //if (strRead != "") //{ //} DisplayLog("读取bin中的SN成功\r\n"); for (int i = 0; i < readHex.Length; i++) { if (readHex[i] != 0xFF) { hasSn = true; } } if (hasSn) { hasSn = false; DisplayLog("SN查询:" + string.Format("产品中已有SN:{0} FAIL\r\n", strRead)); return(ret); } DisplayLog("SN查询:" + "产品中未写过SN PASS\r\n"); } #endregion } DisplayLog(string.Format("等待{0}s ....,请上电进入下载模式,进行下载\r\n", WaitintTime / 1000)); //扫码等待5s后点击Start按键 Thread.Sleep(WaitintTime); //点击START按键 Win32API.SendMessage(ptrChild1_3S_3_1_1_5start, Win32API.BM_CLICK, 0, "0"); //需等烧录完成后,并按板子进入烧录模式,再启动读取软件,读取数据 DisplayLog(string.Format("等待{0}s ....,请在下载完成后再次上电进入下载模式,进行校验\r\n", WaitintTime / 1000)); Thread.Sleep(WaitintTime); // 读取SN生产bin文件 #region DisplayLog("开始读取芯片0xc1000地址...\r\n"); string strCmdReturn; int retCmd = cmdProcess.ExeCommand(ReadToolFolderName, ReadToolAppName, ComPort, out strCmdReturn); //使用工具读取addr并生成bin成功 if (retCmd != 0) { Process[] processes = Process.GetProcesses(); //创建并实例化一个操作进程的类:Process foreach (var item in processes) { if (item.ProcessName == "read_bin_addr") { item.Close(); //item.Kill(); break; } } DisplayLog("SN校验:校验失败,提示:超过等待时间,设备需2次进入下载模式\r\n"); return(retCmd); //goto END;//END 处理收尾:显示烧写结果,清空 } DisplayLog("读取芯片0xc1000地址生成bin成功\r\n"); DisplayLog("开始读取bin中的SN...\r\n"); #endregion //获取bin文件路径 int positon; string idKeySubstr = "save data to : "; if ((positon = strCmdReturn.IndexOf(idKeySubstr)) >= 0) { string createdBinPath = strCmdReturn.Substring(positon + idKeySubstr.Length); //读取bin文件,前7个字节 createdBinPath = createdBinPath.Replace("./", "./" + ReadToolFolderName + "/"); byte[] readHex = ReadFile(createdBinPath); //将读取与写入对比,一致则写入成功 for (int i = 0; i < readHex.Length; i++) { if (readHex[i] != byteArray[i]) { isDiff = true; } } DisplayLog("读取bin中的SN成功\r\n"); if (isDiff) { isDiff = false; DisplayLog("SN校验:" + txtSn.Text + " 写入错误,写入失败 FAIL\r\n"); return(ret); } DisplayLog("SN校验:" + txtSn.Text + " 写入正确 PASS\r\n"); #region 离线 记录到Excel if (ProductionInfo.Type == ProductionInfo.SystemType.Offline) { JiaHao.ExcelHelp.ExcelHelper excel = JiaHao.ExcelHelp.ExcelHelper.GetExcelHelperInstance(); excel.ExportExcelOneByOne(new JiaHao.ExcelHelp.ExcelHelper.TrayInfoInExcel() { num = 1, mac = txtMac.Text, sn = txtSn.Text, cuatomerName = "厦门阳光" }); //Log添加 写入Excel成功 DisplayLog("写入过站记录表: MAC:" + txtMac.Text + " SN:" + txtSn.Text + " PASS\r\n"); //删除最后一行SN ret = snExcel.DeleteLastRow(); if (ret != 0) { DisplayLog(string.Format("删除SN: MAC({0})删除最后一行SN失败 FAIL\r\n", txtMac.Text)); return(ret); } else { DisplayLog(string.Format("删除SN: MAC({0})删除最后一行SN成功 PASS\r\n", txtMac.Text)); } } #endregion ret = 0; } #endregion } catch (Exception ex) { MessageBox.Show(txtSn.Text + ex.Message); //txtSn.Text = ""; return(ret); } return(ret); }