CheckForm.cs 96 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Text;
  9. using System.Text.RegularExpressions;
  10. using System.Threading;
  11. using System.Windows.Forms;
  12. namespace MOTINOVA_Motor_Factory_Set
  13. {
  14. public partial class CheckForm : Form
  15. {
  16. #region 文件路径
  17. public string LocalCfgFilePath = "";
  18. public string LogSavePath = "";
  19. public string LogSaveFileName = "";
  20. #endregion
  21. #region Boot版本正确标志
  22. bool IsBootVerOK = false;
  23. #endregion
  24. #region 端口设置界面
  25. public static PortSettings portsettings_form = new PortSettings();
  26. #endregion
  27. #region 力矩传感器判断标准
  28. TorqueCheckParam TorqueCheck = new TorqueCheckParam();
  29. #endregion
  30. #region 三个传感器校正系数
  31. List<float> K_array = new List<float>();
  32. #endregion
  33. #region 硬件版本检测判断值
  34. string HW_Version_Check = "";
  35. #endregion
  36. #region 串口缓存
  37. public static List<byte> buffer = new List<byte>(4096);
  38. private byte[] binary_data_1 = new byte[1024];
  39. #endregion
  40. #region MC故障码超时计数
  41. bool MC_ErrorCode_Refresh = false;
  42. ushort MC_ErrorCode_Refresh_Cnt = 0;
  43. #endregion
  44. #region 配置文件信息
  45. ArrayList array_CfgInfo = new ArrayList();
  46. #endregion
  47. #region CRC32校验
  48. static UInt32[] crc32_table = new UInt32[256]
  49. {
  50. 0x00000000, 0x04C11DB7, 0x09823B6E, 0x0D4326D9, 0x130476DC, 0x17C56B6B,
  51. 0x1A864DB2, 0x1E475005, 0x2608EDB8, 0x22C9F00F, 0x2F8AD6D6, 0x2B4BCB61,
  52. 0x350C9B64, 0x31CD86D3, 0x3C8EA00A, 0x384FBDBD, 0x4C11DB70, 0x48D0C6C7,
  53. 0x4593E01E, 0x4152FDA9, 0x5F15ADAC, 0x5BD4B01B, 0x569796C2, 0x52568B75,
  54. 0x6A1936C8, 0x6ED82B7F, 0x639B0DA6, 0x675A1011, 0x791D4014, 0x7DDC5DA3,
  55. 0x709F7B7A, 0x745E66CD, 0x9823B6E0, 0x9CE2AB57, 0x91A18D8E, 0x95609039,
  56. 0x8B27C03C, 0x8FE6DD8B, 0x82A5FB52, 0x8664E6E5, 0xBE2B5B58, 0xBAEA46EF,
  57. 0xB7A96036, 0xB3687D81, 0xAD2F2D84, 0xA9EE3033, 0xA4AD16EA, 0xA06C0B5D,
  58. 0xD4326D90, 0xD0F37027, 0xDDB056FE, 0xD9714B49, 0xC7361B4C, 0xC3F706FB,
  59. 0xCEB42022, 0xCA753D95, 0xF23A8028, 0xF6FB9D9F, 0xFBB8BB46, 0xFF79A6F1,
  60. 0xE13EF6F4, 0xE5FFEB43, 0xE8BCCD9A, 0xEC7DD02D, 0x34867077, 0x30476DC0,
  61. 0x3D044B19, 0x39C556AE, 0x278206AB, 0x23431B1C, 0x2E003DC5, 0x2AC12072,
  62. 0x128E9DCF, 0x164F8078, 0x1B0CA6A1, 0x1FCDBB16, 0x018AEB13, 0x054BF6A4,
  63. 0x0808D07D, 0x0CC9CDCA, 0x7897AB07, 0x7C56B6B0, 0x71159069, 0x75D48DDE,
  64. 0x6B93DDDB, 0x6F52C06C, 0x6211E6B5, 0x66D0FB02, 0x5E9F46BF, 0x5A5E5B08,
  65. 0x571D7DD1, 0x53DC6066, 0x4D9B3063, 0x495A2DD4, 0x44190B0D, 0x40D816BA,
  66. 0xACA5C697, 0xA864DB20, 0xA527FDF9, 0xA1E6E04E, 0xBFA1B04B, 0xBB60ADFC,
  67. 0xB6238B25, 0xB2E29692, 0x8AAD2B2F, 0x8E6C3698, 0x832F1041, 0x87EE0DF6,
  68. 0x99A95DF3, 0x9D684044, 0x902B669D, 0x94EA7B2A, 0xE0B41DE7, 0xE4750050,
  69. 0xE9362689, 0xEDF73B3E, 0xF3B06B3B, 0xF771768C, 0xFA325055, 0xFEF34DE2,
  70. 0xC6BCF05F, 0xC27DEDE8, 0xCF3ECB31, 0xCBFFD686, 0xD5B88683, 0xD1799B34,
  71. 0xDC3ABDED, 0xD8FBA05A, 0x690CE0EE, 0x6DCDFD59, 0x608EDB80, 0x644FC637,
  72. 0x7A089632, 0x7EC98B85, 0x738AAD5C, 0x774BB0EB, 0x4F040D56, 0x4BC510E1,
  73. 0x46863638, 0x42472B8F, 0x5C007B8A, 0x58C1663D, 0x558240E4, 0x51435D53,
  74. 0x251D3B9E, 0x21DC2629, 0x2C9F00F0, 0x285E1D47, 0x36194D42, 0x32D850F5,
  75. 0x3F9B762C, 0x3B5A6B9B, 0x0315D626, 0x07D4CB91, 0x0A97ED48, 0x0E56F0FF,
  76. 0x1011A0FA, 0x14D0BD4D, 0x19939B94, 0x1D528623, 0xF12F560E, 0xF5EE4BB9,
  77. 0xF8AD6D60, 0xFC6C70D7, 0xE22B20D2, 0xE6EA3D65, 0xEBA91BBC, 0xEF68060B,
  78. 0xD727BBB6, 0xD3E6A601, 0xDEA580D8, 0xDA649D6F, 0xC423CD6A, 0xC0E2D0DD,
  79. 0xCDA1F604, 0xC960EBB3, 0xBD3E8D7E, 0xB9FF90C9, 0xB4BCB610, 0xB07DABA7,
  80. 0xAE3AFBA2, 0xAAFBE615, 0xA7B8C0CC, 0xA379DD7B, 0x9B3660C6, 0x9FF77D71,
  81. 0x92B45BA8, 0x9675461F, 0x8832161A, 0x8CF30BAD, 0x81B02D74, 0x857130C3,
  82. 0x5D8A9099, 0x594B8D2E, 0x5408ABF7, 0x50C9B640, 0x4E8EE645, 0x4A4FFBF2,
  83. 0x470CDD2B, 0x43CDC09C, 0x7B827D21, 0x7F436096, 0x7200464F, 0x76C15BF8,
  84. 0x68860BFD, 0x6C47164A, 0x61043093, 0x65C52D24, 0x119B4BE9, 0x155A565E,
  85. 0x18197087, 0x1CD86D30, 0x029F3D35, 0x065E2082, 0x0B1D065B, 0x0FDC1BEC,
  86. 0x3793A651, 0x3352BBE6, 0x3E119D3F, 0x3AD08088, 0x2497D08D, 0x2056CD3A,
  87. 0x2D15EBE3, 0x29D4F654, 0xC5A92679, 0xC1683BCE, 0xCC2B1D17, 0xC8EA00A0,
  88. 0xD6AD50A5, 0xD26C4D12, 0xDF2F6BCB, 0xDBEE767C, 0xE3A1CBC1, 0xE760D676,
  89. 0xEA23F0AF, 0xEEE2ED18, 0xF0A5BD1D, 0xF464A0AA, 0xF9278673, 0xFDE69BC4,
  90. 0x89B8FD09, 0x8D79E0BE, 0x803AC667, 0x84FBDBD0, 0x9ABC8BD5, 0x9E7D9662,
  91. 0x933EB0BB, 0x97FFAD0C, 0xAFB010B1, 0xAB710D06, 0xA6322BDF, 0xA2F33668,
  92. 0xBCB4666D, 0xB8757BDA, 0xB5365D03, 0xB1F740B4
  93. };
  94. static UInt32 crc32_cal(byte[] pData, UInt16 Length)
  95. {
  96. UInt32 nReg;
  97. UInt32 nTemp = 0;
  98. UInt16 i, n;
  99. nReg = 0xFFFFFFFF;
  100. for (n = 0; n < Length; n++)
  101. {
  102. nReg ^= (UInt32)pData[n];
  103. for (i = 0; i < 4; i++)
  104. {
  105. nTemp = crc32_table[((nReg >> 24) & 0xFF)];
  106. nReg <<= 8;
  107. nReg ^= nTemp;
  108. }
  109. }
  110. return nReg;
  111. }
  112. #endregion
  113. #region 命令发送
  114. private void SendCmd(ushort ID, byte Mode, ushort Cmd, byte[] Data)
  115. {
  116. if (!portsettings_form.serialPort1.IsOpen)
  117. {
  118. MessageBox.Show("串口未连接");
  119. return;
  120. }
  121. ushort DataLength = (ushort)(Cmd & 0xFF);
  122. var SendCmdTmp = new byte[DataLength + 13];
  123. //帧头
  124. SendCmdTmp[0] = 0x55;
  125. SendCmdTmp[1] = 0xAA;
  126. //ID
  127. SendCmdTmp[2] = (byte)(ID >> 8);
  128. SendCmdTmp[3] = (byte)(ID & 0xFF);
  129. //MODE
  130. SendCmdTmp[4] = Mode;
  131. //长度
  132. SendCmdTmp[5] = (byte)((Cmd & 0xFF) + 2);
  133. //命令字
  134. SendCmdTmp[6] = (byte)(Cmd >> 8);
  135. SendCmdTmp[7] = (byte)(Cmd & 0xFF);
  136. //数据段
  137. for (UInt16 i = 0; i < (Cmd & 0xFF); i++)
  138. {
  139. SendCmdTmp[8 + i] = Data[i];
  140. }
  141. //校验
  142. UInt32 CRC_Result = crc32_cal(SendCmdTmp, (ushort)(DataLength + 8));
  143. SendCmdTmp[DataLength + 8] = Convert.ToByte(CRC_Result >> 24);
  144. SendCmdTmp[DataLength + 9] = Convert.ToByte((CRC_Result >> 16) % 256);
  145. SendCmdTmp[DataLength + 10] = Convert.ToByte((CRC_Result >> 8) % 256);
  146. SendCmdTmp[DataLength + 11] = Convert.ToByte(CRC_Result % 256);
  147. //帧尾
  148. SendCmdTmp[DataLength + 12] = 0xF0;
  149. //发送数据
  150. portsettings_form.serialPort1.Write(SendCmdTmp, 0, SendCmdTmp.Length);
  151. }
  152. #endregion
  153. #region 串口数据解析
  154. private void Serial_DataReceived_Process()
  155. {
  156. //串口解析
  157. byte DataNum = 0; //记录每条命令数据段的长度
  158. while (buffer.Count >= 13)//当buffer中的数据的个数大于等于4个时,即每一帧的数据长度所在位(第4位)出现时
  159. {
  160. if (buffer[0] == 0x55 && buffer[1] == 0xAA)//判断帧头
  161. {
  162. ushort PackageID;
  163. PackageID = (ushort)(buffer[2] * 256 + buffer[3]);
  164. if ((PackageID == 0x0710) || (PackageID == 0x0715) || (PackageID == 0x0610) || (PackageID == 0x0615) || (PackageID == 0x07FF))
  165. {
  166. int CmdLen = buffer[5];
  167. if (buffer.Count < CmdLen + 11) break;//如果接收到的数据没有达到一帧数据的指定长度, 则执行下次循环
  168. buffer.RemoveRange(0, 6);//数据达到要求长度后删去帧头,ID,模式,和命令长度
  169. DataNum = (byte)(buffer[1]);//命令字的第二个字节的表示数据位的长度
  170. if (DataNum == (CmdLen - 2))
  171. {
  172. for (int i = 0; i < DataNum + 2; i++)
  173. {
  174. binary_data_1[i] = buffer[i];
  175. }
  176. DataCmdProcess(PackageID);//对于不同的命令段,做不同的处理
  177. }
  178. buffer.RemoveRange(0, CmdLen + 5);//解析完成
  179. }
  180. else
  181. {
  182. buffer.RemoveAt(0);//ID不对
  183. }
  184. }
  185. else
  186. {
  187. buffer.RemoveAt(0);//帧头不对,删除帧头高字节
  188. }
  189. }
  190. }
  191. #endregion
  192. #region 故障转换和显示
  193. List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
  194. "马达缺相","NTC故障","","","","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","电路故障","TE故障","TE电路故障","","","","","","","","","",
  195. "",""};
  196. private string ErrorInfoDisplay(UInt32 Code)
  197. {
  198. string Result = "";
  199. if (Code == 0)
  200. {
  201. Result = "无故障";
  202. }
  203. else
  204. {
  205. for (int i = 0; i < 32; i++)
  206. {
  207. if ((Code & 0x01) == 0x01)
  208. {
  209. Result += ErrorInfo[i] + " ";
  210. }
  211. Code >>= 1;
  212. }
  213. }
  214. return Result;
  215. }
  216. #endregion
  217. #region 数据解析处理
  218. private void DataCmdProcess(ushort ID)
  219. {
  220. ushort CmdTemp = (ushort)(binary_data_1[0] * 256 + binary_data_1[1]);
  221. ushort DataTemp;
  222. #region 主控信息
  223. if ((ID == 0x715) || (ID == 0x710))
  224. {
  225. switch (CmdTemp)
  226. {
  227. case 0xC109://Boot 版本
  228. {
  229. unchecked
  230. {
  231. this.Invoke((EventHandler)(delegate
  232. {
  233. if (IsBootVerOK == false)//开机时一般会发送4条,只显示1条
  234. {
  235. richTextBox_TestRecord.AppendText("Bootloader版本:");
  236. string boot_Version = "";
  237. for (ushort i = 0; i < 9; i++)
  238. {
  239. boot_Version += ((char)binary_data_1[2 + i]).ToString();
  240. }
  241. richTextBox_TestRecord.AppendText(boot_Version+" ");
  242. richTextBox_TestRecord.AppendText(boot_Version.Contains("V1") ? "125K" : "250K");
  243. richTextBox_TestRecord.AppendText("\r\n");
  244. }
  245. IsBootVerOK = true;
  246. }));
  247. }
  248. break;
  249. }
  250. case 0x1104://故障码
  251. {
  252. unchecked
  253. {
  254. this.Invoke((EventHandler)(delegate
  255. {
  256. MC_ErrorCode_Refresh = true;
  257. label_error_code.Text =
  258. Convert.ToString(binary_data_1[5], 16).PadLeft(2, '0').ToUpper() +
  259. Convert.ToString(binary_data_1[4], 16).PadLeft(2, '0').ToUpper() +
  260. Convert.ToString(binary_data_1[3], 16).PadLeft(2, '0').ToUpper() +
  261. Convert.ToString(binary_data_1[2], 16).PadLeft(2, '0').ToUpper() +
  262. "H";
  263. label_error_code.BackColor = Color.Red;
  264. }));
  265. }
  266. break;
  267. }
  268. case 0x1240://电机版本信息
  269. {
  270. unchecked
  271. {
  272. this.Invoke((EventHandler)(delegate
  273. {
  274. richTextBox_VerInfo.Text = "";
  275. //电机型号
  276. richTextBox_VerInfo.Text += "型号:";
  277. for (ushort i = 0; i < 16; i++)
  278. {
  279. if (binary_data_1[2 + i] == 0x2E)
  280. {
  281. break;
  282. }
  283. richTextBox_VerInfo.Text += ((char)binary_data_1[2 + i]).ToString();
  284. }
  285. richTextBox_VerInfo.Text += "\r\n";
  286. //电机SN
  287. richTextBox_VerInfo.Text += "序列号:";
  288. for (ushort i = 0; i < 16; i++)
  289. {
  290. if (binary_data_1[18 + i] == 0x2E)
  291. {
  292. break;
  293. }
  294. richTextBox_VerInfo.Text += ((char)binary_data_1[18 + i]).ToString();
  295. }
  296. richTextBox_VerInfo.Text += "\r\n";
  297. //电机HW
  298. richTextBox_VerInfo.Text += "硬件版本:";
  299. for (ushort i = 0; i < 10; i++)//前10位是PCB版号,以'.'结束
  300. {
  301. if (binary_data_1[34 + i] == 0x2E)
  302. {
  303. break;
  304. }
  305. if (binary_data_1[34 + i] == 'r')
  306. {
  307. binary_data_1[34 + i] = (byte)'.';
  308. }
  309. richTextBox_VerInfo.Text += ((char)binary_data_1[34 + i]).ToString();
  310. }
  311. switch (binary_data_1[34 + 10])//第10位代表MCU品牌
  312. {
  313. case (byte)'1':
  314. richTextBox_VerInfo.Text += " " + "ST" + " "; break;
  315. case (byte)'2':
  316. richTextBox_VerInfo.Text += " " + "APM" + " "; break;
  317. case (byte)'3':
  318. richTextBox_VerInfo.Text += " " + "HK" + " "; break;
  319. case (byte)'4':
  320. richTextBox_VerInfo.Text += " " + "GD" + " "; break;
  321. default:
  322. richTextBox_VerInfo.Text += " " + "NULL" + " "; break;
  323. }
  324. for (ushort i = 0; i < 4; i++)//后4位是MCU的ID校验码,用于识别板子的ID
  325. {
  326. richTextBox_VerInfo.Text += Convert.ToString(binary_data_1[46 + i], 16).PadLeft(2, '0').ToUpper();//MCU ID 的CRC32值
  327. }
  328. richTextBox_VerInfo.Text += "\r\n";
  329. //电机FW
  330. richTextBox_VerInfo.Text += "软件版本:";
  331. for (ushort i = 0; i < 16; i++)
  332. {
  333. if (binary_data_1[50 + i] == 0x2E)
  334. {
  335. break;
  336. }
  337. if (binary_data_1[50 + i] == 'r')
  338. {
  339. binary_data_1[50 + i] = (byte)'.';
  340. }
  341. richTextBox_VerInfo.Text += ((char)binary_data_1[50 + i]).ToString();
  342. }
  343. richTextBox_VerInfo.Text += "\r\n";
  344. }));
  345. }
  346. break;
  347. }
  348. case 0x1720://电机程序特性信息
  349. {
  350. unchecked
  351. {
  352. this.Invoke((EventHandler)(delegate
  353. {
  354. //程序特性
  355. richTextBox_VerInfo.Text += "软件属性:";
  356. for (ushort i = 0; i < 32; i++)
  357. {
  358. if (binary_data_1[2 + i] == 0x2E)
  359. {
  360. break;
  361. }
  362. if (binary_data_1[2 + i] == 'r')
  363. {
  364. binary_data_1[2 + i] = (byte)'.';
  365. }
  366. richTextBox_VerInfo.Text += ((char)binary_data_1[2 + i]).ToString();
  367. }
  368. richTextBox_VerInfo.Text += "\r\n";
  369. }));
  370. }
  371. break;
  372. }
  373. case 0xA020://用户参数1
  374. {
  375. unchecked
  376. {
  377. this.Invoke((EventHandler)(delegate
  378. {
  379. richTextBox_ReadCfg.Text += "[用户参数1]" + "\r\n";
  380. richTextBox_ReadCfg.Text += "启动模式," + binary_data_1[3].ToString() + "\r\n";
  381. richTextBox_ReadCfg.Text += "停机时间," + ((ushort)(binary_data_1[5] * 256 + binary_data_1[4])).ToString() + "\r\n";
  382. richTextBox_ReadCfg.Text += "限速值," + binary_data_1[6].ToString() + "\r\n";
  383. richTextBox_ReadCfg.Text += "下降速度," + binary_data_1[7].ToString() + "\r\n";
  384. richTextBox_ReadCfg.Text += "前飞," + binary_data_1[8].ToString() + "\r\n";
  385. richTextBox_ReadCfg.Text += "后飞," + binary_data_1[9].ToString() + "\r\n";
  386. richTextBox_ReadCfg.Text += "限流," + binary_data_1[10].ToString() + "\r\n";
  387. richTextBox_ReadCfg.Text += "温度预警," + (binary_data_1[11] - 40).ToString() + "\r\n";
  388. richTextBox_ReadCfg.Text += "温度保护," + (binary_data_1[12] - 40).ToString() + "\r\n";
  389. richTextBox_ReadCfg.Text += "码表," + binary_data_1[13].ToString()+",";
  390. richTextBox_ReadCfg.Text += ((binary_data_1[13] == 0x55) ? "有" : "无") + "\r\n";
  391. richTextBox_ReadCfg.Text += "轮胎周长," + binary_data_1[14].ToString() + "\r\n";
  392. richTextBox_ReadCfg.Text += "系列号," + binary_data_1[15].ToString() + "\r\n";
  393. richTextBox_ReadCfg.Text += "ECO增益," + binary_data_1[16].ToString() + "\r\n";
  394. richTextBox_ReadCfg.Text += "ECO加速," + binary_data_1[17].ToString() + "\r\n";
  395. richTextBox_ReadCfg.Text += "NORM增益," + binary_data_1[18].ToString() + "\r\n";
  396. richTextBox_ReadCfg.Text += "NORM加速," + binary_data_1[19].ToString() + "\r\n";
  397. richTextBox_ReadCfg.Text += "SPORT增益," + binary_data_1[20].ToString() + "\r\n";
  398. richTextBox_ReadCfg.Text += "SPORT加速," + binary_data_1[21].ToString() + "\r\n";
  399. richTextBox_ReadCfg.Text += "TURBO增益," + binary_data_1[22].ToString() + "\r\n";
  400. richTextBox_ReadCfg.Text += "TURBO加速," + binary_data_1[23].ToString() + "\r\n";
  401. richTextBox_ReadCfg.Text += "SMART增益," + binary_data_1[24].ToString() + "\r\n";
  402. richTextBox_ReadCfg.Text += "SMART加速," + binary_data_1[25].ToString() + "\r\n";
  403. richTextBox_ReadCfg.Text += "车速级数," + binary_data_1[26].ToString() + "\r\n";
  404. richTextBox_ReadCfg.Text += "踏频启动," + binary_data_1[27].ToString() + "\r\n";
  405. richTextBox_ReadCfg.Text += "指拨模式," + binary_data_1[2].ToString() + ",";
  406. richTextBox_ReadCfg.Text += ((binary_data_1[2] == 0x55) ? "不支持" : "支持") + "\r\n";
  407. richTextBox_ReadCfg.Text += "速度信号来源," + binary_data_1[28].ToString() + ",";
  408. richTextBox_ReadCfg.Text += ((binary_data_1[28] == 0x55) ? "传感器" :
  409. (binary_data_1[28] == 0xAA) ? "踏频" :
  410. (binary_data_1[28] == 0xEE) ? "通信" : "") + "\r\n";
  411. richTextBox_ReadCfg.Text += "周长微调," + ((int)binary_data_1[29]).ToString() + "\r\n";
  412. richTextBox_ReadCfg.Text += "低压保护," + ((ushort)(binary_data_1[31] * 256 + binary_data_1[30])).ToString() + "\r\n";
  413. richTextBox_ReadCfg.Text += "推行限速," + binary_data_1[32].ToString() + "\r\n";
  414. richTextBox_ReadCfg.Text += "推行转速," + binary_data_1[33].ToString() + "\r\n";
  415. }));
  416. }
  417. break;
  418. }
  419. case 0xA110://马达参数
  420. {
  421. unchecked
  422. {
  423. this.Invoke((EventHandler)(delegate
  424. {
  425. richTextBox_ReadCfg.Text += "\r\n";
  426. richTextBox_ReadCfg.Text += "[马达参数]" + "\r\n";
  427. richTextBox_ReadCfg.Text += "额定功率," + ((ushort)(binary_data_1[3] * 256 + binary_data_1[2])).ToString() + "\r\n";
  428. richTextBox_ReadCfg.Text += "空载转速," + ((ushort)(binary_data_1[5] * 256 + binary_data_1[4])).ToString() + "\r\n";
  429. richTextBox_ReadCfg.Text += "定子电阻," + ((ushort)(binary_data_1[7] * 256 + binary_data_1[6])).ToString() + "\r\n";
  430. richTextBox_ReadCfg.Text += "定子Lq," + ((ushort)(binary_data_1[9] * 256 + binary_data_1[8])).ToString() + "\r\n";
  431. richTextBox_ReadCfg.Text += "定子Ld," + ((ushort)(binary_data_1[11] * 256 + binary_data_1[10])).ToString() + "\r\n";
  432. richTextBox_ReadCfg.Text += "反电动势," + ((ushort)(binary_data_1[13] * 256 + binary_data_1[12])).ToString() + "\r\n";
  433. richTextBox_ReadCfg.Text += "额定电压," + binary_data_1[14].ToString() + "\r\n";
  434. }));
  435. }
  436. break;
  437. }
  438. case 0xA318://单传感器零点值
  439. {
  440. unchecked
  441. {
  442. this.Invoke((EventHandler)(delegate
  443. {
  444. richTextBox_TQ.Text += "零点:";
  445. for (int i = 0; i < 12; i++)
  446. {
  447. richTextBox_TQ.Text += ((ushort)((binary_data_1[3 + 2 * i] << 8) + binary_data_1[2 + 2 * i])).ToString() + ", ";
  448. }
  449. richTextBox_TQ.Text = richTextBox_TQ.Text.Substring(0, richTextBox_TQ.Text.Length - 2) + "\r\n";
  450. }));
  451. }
  452. break;
  453. }
  454. case 0xA408://校验秘钥
  455. {
  456. unchecked
  457. {
  458. this.Invoke((EventHandler)(delegate
  459. {
  460. richTextBox_ReadCfg.Text += "校验密钥,";
  461. for (int i = 0; i < 8; i++)
  462. {
  463. richTextBox_ReadCfg.Text += ((char)binary_data_1[2+i]).ToString();
  464. }
  465. richTextBox_ReadCfg.Text += "\r\n";
  466. }));
  467. }
  468. break;
  469. }
  470. case 0xA520://生产信息
  471. {
  472. unchecked
  473. {
  474. this.Invoke((EventHandler)(delegate
  475. {
  476. richTextBox_ReadCfg.Text += "\r\n";
  477. richTextBox_ReadCfg.Text += "[其它信息]" + "\r\n";
  478. richTextBox_ReadCfg.Text += "生产商,";
  479. for (int i = 0; i < 8; i++)
  480. {
  481. if (binary_data_1[2 + i] == '.') break;
  482. richTextBox_ReadCfg.Text += ((char)binary_data_1[2 + i]).ToString();
  483. }
  484. richTextBox_ReadCfg.Text += "\r\n";
  485. richTextBox_ReadCfg.Text += "生产地,";
  486. for (int i = 0; i < 8; i++)
  487. {
  488. if (binary_data_1[10 + i] == '.') break;
  489. richTextBox_ReadCfg.Text += ((char)binary_data_1[10 + i]).ToString();
  490. }
  491. richTextBox_ReadCfg.Text += "\r\n";
  492. richTextBox_ReadCfg.Text += "生产日期,";
  493. for (int i = 0; i < 8; i++)
  494. {
  495. if (binary_data_1[18 + i] == '.') break;
  496. richTextBox_ReadCfg.Text += ((char)binary_data_1[18 + i]).ToString();
  497. }
  498. richTextBox_ReadCfg.Text += "\r\n";
  499. }));
  500. }
  501. break;
  502. }
  503. case 0xA610://自定义1
  504. {
  505. unchecked
  506. {
  507. this.Invoke((EventHandler)(delegate
  508. {
  509. richTextBox_ReadCfg.Text += "信息1,";
  510. for (int i = 0; i < 16; i++)
  511. {
  512. if (binary_data_1[2 + i] == '.') break;
  513. richTextBox_ReadCfg.Text += ((char)binary_data_1[2 + i]).ToString();
  514. }
  515. richTextBox_ReadCfg.Text += "\r\n";
  516. }));
  517. }
  518. break;
  519. }
  520. case 0xA710://自定义2
  521. {
  522. unchecked
  523. {
  524. this.Invoke((EventHandler)(delegate
  525. {
  526. richTextBox_ReadCfg.Text += "信息2,";
  527. for (int i = 0; i < 16; i++)
  528. {
  529. if (binary_data_1[2 + i] == '.') break;
  530. richTextBox_ReadCfg.Text += ((char)binary_data_1[2 + i]).ToString();
  531. }
  532. richTextBox_ReadCfg.Text += "\r\n";
  533. }));
  534. }
  535. break;
  536. }
  537. case 0xA810://自定义3
  538. {
  539. unchecked
  540. {
  541. this.Invoke((EventHandler)(delegate
  542. {
  543. richTextBox_ReadCfg.Text += "信息3,";
  544. for (int i = 0; i < 16; i++)
  545. {
  546. if (binary_data_1[2 + i] == '.') break;
  547. richTextBox_ReadCfg.Text += ((char)binary_data_1[2 + i]).ToString();
  548. }
  549. richTextBox_ReadCfg.Text += "\r\n";
  550. }));
  551. }
  552. break;
  553. }
  554. case 0xA903://写入反馈
  555. {
  556. break;
  557. }
  558. case 0xAA04://单传感器校正值
  559. {
  560. unchecked
  561. {
  562. this.Invoke((EventHandler)(delegate
  563. {
  564. richTextBox_TQ.Text += "校正系数:";
  565. richTextBox_TQ.Text += ((float)binary_data_1[4] / 100f).ToString("#0.00") + "\r\n";
  566. richTextBox_TQ.Text += "启动值:";
  567. richTextBox_TQ.Text += ((ushort)((binary_data_1[3] << 8) + binary_data_1[2])).ToString() + "\r\n";
  568. }));
  569. }
  570. break;
  571. }
  572. case 0xAD20://用户参数2
  573. {
  574. unchecked
  575. {
  576. this.Invoke((EventHandler)(delegate
  577. {
  578. richTextBox_ReadCfg.Text += "\r\n";
  579. richTextBox_ReadCfg.Text += "[用户参数2]" + "\r\n";
  580. richTextBox_ReadCfg.Text += "姿态传感器," + binary_data_1[6].ToString() + ",";
  581. richTextBox_ReadCfg.Text += ((binary_data_1[6] == 0x55) ? "不支持" : "支持") + "\r\n";
  582. richTextBox_ReadCfg.Text += "俯仰角零偏," + ((ushort)(binary_data_1[3] * 256 + binary_data_1[2])).ToString() + "\r\n";
  583. richTextBox_ReadCfg.Text += "横滚角零偏," + ((ushort)(binary_data_1[5] * 256 + binary_data_1[4])).ToString() + "\r\n";
  584. richTextBox_ReadCfg.Text += "尾灯模式," + binary_data_1[7].ToString() + "\r\n";
  585. richTextBox_ReadCfg.Text += "前灯电压," + binary_data_1[8].ToString() + ",";
  586. richTextBox_ReadCfg.Text += ((binary_data_1[8] == 0xFF) ? "随电池" : (binary_data_1[8] == 0) ? "硬件配置" : (binary_data_1[8].ToString() + "V")) + "\r\n";
  587. richTextBox_ReadCfg.Text += "尾灯电压," + binary_data_1[9].ToString() + ",";
  588. richTextBox_ReadCfg.Text += ((binary_data_1[9] == 0xFF) ? "随电池" : (binary_data_1[9] == 0) ? "硬件配置" : (binary_data_1[9].ToString() + "V")) + "\r\n";
  589. richTextBox_ReadCfg.Text += "报警阈值," + ((ushort)(binary_data_1[11] * 256 + binary_data_1[10])).ToString() + "\r\n";
  590. richTextBox_ReadCfg.Text += "尾灯脉宽," + ((ushort)(binary_data_1[13] * 256 + binary_data_1[12])).ToString() + "\r\n";
  591. richTextBox_ReadCfg.Text += "尾灯周期," + ((ushort)(binary_data_1[15] * 256 + binary_data_1[14])).ToString() + "\r\n";
  592. richTextBox_ReadCfg.Text += "起始限速," + binary_data_1[16].ToString() + "\r\n";
  593. richTextBox_ReadCfg.Text += "结束限速," + binary_data_1[17].ToString() + "\r\n";
  594. }));
  595. }
  596. break;
  597. }
  598. case 0xAE1A://三传感器零点
  599. {
  600. unchecked
  601. {
  602. this.Invoke((EventHandler)(delegate
  603. {
  604. richTextBox_TQ.Text += "传感器" + binary_data_1[2].ToString() + "零点:";
  605. for (int i = 0; i < 12; i++)
  606. {
  607. richTextBox_TQ.Text += ((ushort)((binary_data_1[4 + 2 * i] << 8) + binary_data_1[3 + 2 * i])).ToString() + ", ";
  608. }
  609. richTextBox_TQ.Text = richTextBox_TQ.Text.Substring(0, richTextBox_TQ.Text.Length - 2) + "\r\n";
  610. }));
  611. }
  612. break;
  613. }
  614. case 0xAF02://三传感器校正系数
  615. {
  616. unchecked
  617. {
  618. this.Invoke((EventHandler)(delegate
  619. {
  620. richTextBox_TQ.Text += "传感器" + binary_data_1[2].ToString() + "校正系数:";
  621. richTextBox_TQ.Text += ((float)binary_data_1[3] / 100f).ToString("#0.00") + "\r\n";
  622. K_array.Add((float)binary_data_1[3] / 100f);
  623. if (K_array.Count >= 3)
  624. {
  625. double avg = (K_array[0] + K_array[1] + K_array[2]) / 3.0f;
  626. double sum = Math.Pow(K_array[0] - avg, 2) + Math.Pow(K_array[1] - avg, 2) + Math.Pow(K_array[2] - avg, 2);
  627. double std = Math.Sqrt(sum / 3.0f);
  628. richTextBox_TQ.Text += "校正系数标准差:" + std.ToString("#0.0000") + "\r\n";
  629. K_array.Clear();
  630. }
  631. }));
  632. }
  633. break;
  634. }
  635. case 0xB002://三传感器启动值
  636. {
  637. unchecked
  638. {
  639. this.Invoke((EventHandler)(delegate
  640. {
  641. richTextBox_TQ.Text += "启动值:";
  642. richTextBox_TQ.Text += ((ushort)((binary_data_1[3] << 8) + binary_data_1[2])).ToString() + "\r\n";
  643. }));
  644. }
  645. break;
  646. }
  647. default: break;
  648. }
  649. }
  650. #endregion
  651. #region TE信息
  652. else if ((ID == 0x615) || (ID == 0x610))
  653. {
  654. switch (CmdTemp)
  655. {
  656. case 0x1240://TE APP版本信息
  657. {
  658. unchecked
  659. {
  660. this.Invoke((EventHandler)(delegate
  661. {
  662. //TE 软件版本
  663. richTextBox_VerInfo.Text += "TE软件版本:";
  664. for (ushort i = 0; i < 16; i++)
  665. {
  666. if (binary_data_1[50 + i] == 0x2E)
  667. {
  668. break;
  669. }
  670. if (binary_data_1[50 + i] == 'r')
  671. {
  672. binary_data_1[50 + i] = (byte)'.';
  673. }
  674. richTextBox_VerInfo.Text += ((char)binary_data_1[50 + i]).ToString();
  675. }
  676. }));
  677. }
  678. break;
  679. }
  680. default: break;
  681. }
  682. #endregion
  683. }
  684. }
  685. #endregion
  686. #region 20ms定时器
  687. private void timer1_Tick(object sender, EventArgs e)
  688. {
  689. //串口数据解析
  690. Serial_DataReceived_Process();
  691. }
  692. #endregion
  693. #region 非独占性延时函数
  694. public static void Delay_ms(int milliSecond)
  695. {
  696. int start = Environment.TickCount;
  697. while (Math.Abs(Environment.TickCount - start) < milliSecond)//毫秒
  698. {
  699. Application.DoEvents();
  700. }
  701. }
  702. #endregion
  703. #region 获取配置文件日期
  704. private void GetDateList(bool DisAll)
  705. {
  706. string[] DateList = { "" };
  707. if (checkBox_LocalFile.Checked == true)//从本地更新日期列表
  708. {
  709. DateList = System.IO.Directory.GetDirectories(LocalCfgFilePath);
  710. }
  711. else//从服务器更新日期列表
  712. {
  713. DateList = StartForm.myFtp.GetDirectoryList(StartForm.myServerCfg.RootPath + "/cfg");
  714. }
  715. comboBox_cfgFileDate.Items.Clear();
  716. //日期列表加载
  717. if (DisAll == true)
  718. {
  719. comboBox_cfgFileDate.Items.Add("显示近期");
  720. comboBox_cfgFileDate.Items.Add("---");
  721. foreach (var file in DateList)
  722. comboBox_cfgFileDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  723. }
  724. else
  725. {
  726. if (DateList.Length > 10)
  727. {
  728. comboBox_cfgFileDate.Items.Add("显示全部");
  729. comboBox_cfgFileDate.Items.Add("---");
  730. }
  731. for (int i = (DateList.Length > 10) ? (DateList.Length - 10) : 0; i < DateList.Length; i++)//显示最近10个日期
  732. comboBox_cfgFileDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  733. }
  734. }
  735. #endregion
  736. #region 获取配置文件列表
  737. private void GetFileListFrom(string date)
  738. {
  739. string[] FileList = { "" };
  740. if (checkBox_LocalFile.Checked == true)//从本地更新文件列表
  741. {
  742. FileList = System.IO.Directory.GetFiles(LocalCfgFilePath + date);
  743. }
  744. else//从服务器更新文件列表
  745. {
  746. FileList = StartForm.myFtp.GetFileNameList(StartForm.myServerCfg.RootPath + "/cfg/" + date);
  747. }
  748. comboBox_File.Items.Clear();
  749. foreach (var file in FileList)
  750. {
  751. if (file.Contains(".ttcfg"))
  752. {
  753. comboBox_File.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  754. }
  755. }
  756. }
  757. #endregion
  758. #region 选择文件日期后更新文件列表
  759. private void comboBox_cfgFileDate_SelectionChangeCommitted(object sender, EventArgs e)
  760. {
  761. if (comboBox_cfgFileDate.SelectedItem.ToString() == "显示全部")
  762. {
  763. GetDateList(true);
  764. }
  765. else if (comboBox_cfgFileDate.SelectedItem.ToString() == "显示近期")
  766. {
  767. GetDateList(false);
  768. }
  769. else
  770. {
  771. comboBox_File.Text = "";
  772. GetFileListFrom(comboBox_cfgFileDate.SelectedItem.ToString());
  773. }
  774. }
  775. #endregion
  776. #region 选择文件后加载文件
  777. private void comboBox_File_SelectionChangeCommitted(object sender, EventArgs e)
  778. {
  779. //清空原来数据
  780. array_CfgInfo.Clear();
  781. string SelectFile = "";
  782. if (checkBox_LocalFile.Checked == false)//从服务器下载文件
  783. {
  784. SelectFile = comboBox_cfgFileDate.SelectedItem.ToString() + "\\" + comboBox_File.SelectedItem.ToString();
  785. if (File.Exists(LocalCfgFilePath + SelectFile))//本地存在选定文件,先删除后再下载
  786. {
  787. File.Delete(LocalCfgFilePath + SelectFile);
  788. }
  789. SelectFile = comboBox_cfgFileDate.SelectedItem.ToString() + "/" + comboBox_File.SelectedItem.ToString();
  790. StartForm.myFtp.DownloadFile(StartForm.myServerCfg.RootPath + "/cfg/" + SelectFile, LocalCfgFilePath + comboBox_cfgFileDate.SelectedItem.ToString());
  791. }
  792. SelectFile = comboBox_cfgFileDate.SelectedItem.ToString() + "\\" + comboBox_File.SelectedItem.ToString();
  793. //打开选中文件
  794. StreamReader objReader = new StreamReader(LocalCfgFilePath + SelectFile);
  795. string sLine = "";
  796. while (sLine != null)
  797. {
  798. sLine = objReader.ReadLine();
  799. array_CfgInfo.Add(sLine);
  800. }
  801. objReader.Close();
  802. //解析显示配置文件
  803. richTextBox_CfgFile.Text = "";
  804. try
  805. {
  806. foreach (string sOutput in array_CfgInfo)
  807. {
  808. if (sOutput.Contains("[测试阈值]"))
  809. {
  810. //删除最后一行,不显示后面内容
  811. richTextBox_CfgFile.Text = richTextBox_CfgFile.Text.Remove(richTextBox_CfgFile.Text.Length - 1);
  812. break;
  813. }
  814. richTextBox_CfgFile.AppendText(sOutput + "\r\n");
  815. }
  816. }
  817. catch (System.Exception)
  818. {
  819. return;
  820. }
  821. //加载力矩传感器判断标准
  822. TorqueCheck.CheckParam_Load(LocalCfgFilePath + SelectFile);
  823. textBox_TQ_Zero.Text = TorqueCheck.Zero_Min.ToString() + " - " + TorqueCheck.Zero_Max.ToString();
  824. textBox_TQ_K.Text = TorqueCheck.Cal_K_Min.ToString("#0.00") + " - " + TorqueCheck.Cal_K_Max.ToString("#0.00");
  825. textBox_TQ_Start.Text = TorqueCheck.Start_Min.ToString() + " - " + TorqueCheck.Start_Max.ToString();
  826. //加载PCBA检测值
  827. try
  828. {
  829. for (int i = 0; i < array_CfgInfo.Count; i++)
  830. {
  831. if (array_CfgInfo[i].ToString().Contains("[其它测试备注信息]"))
  832. {
  833. HW_Version_Check = array_CfgInfo[i + 1].ToString().Split(',')[1];
  834. break;
  835. }
  836. }
  837. }
  838. catch (System.Exception)
  839. {
  840. return;
  841. }
  842. }
  843. #endregion
  844. #region 修改获取文件方式,本地或服务器
  845. private void checkBox_LocalFile_CheckedChanged(object sender, EventArgs e)
  846. {
  847. comboBox_cfgFileDate.Text = "";
  848. comboBox_File.Text = "";
  849. GetDateList(false);
  850. }
  851. #endregion
  852. public CheckForm()
  853. {
  854. InitializeComponent();
  855. System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
  856. }
  857. #region 端口设置
  858. private void toolStripMenuIte_PortSet_Click(object sender, EventArgs e)
  859. {
  860. portsettings_form.Show();
  861. }
  862. #endregion
  863. #region 打开电源
  864. private void 开ToolStripMenuItem_Click(object sender, EventArgs e)
  865. {
  866. byte[] Data = new byte[1];
  867. if (portsettings_form.serialPort1.IsOpen)
  868. {
  869. //开机
  870. Data[0] = 0xF1;
  871. SendCmd(0x7FF, 0x16, 0x2201, Data);
  872. 开ToolStripMenuItem.Checked = true;
  873. 关ToolStripMenuItem.Checked = false;
  874. }
  875. else
  876. {
  877. MessageBox.Show("串口未连接");
  878. return;
  879. }
  880. }
  881. #endregion
  882. #region 关闭电源
  883. private void 关ToolStripMenuItem_Click(object sender, EventArgs e)
  884. {
  885. byte[] Data = new byte[1];
  886. if (portsettings_form.serialPort1.IsOpen)
  887. {
  888. //关机
  889. Data[0] = 0xF0;
  890. SendCmd(0x7FF, 0x16, 0x2201, Data);
  891. 开ToolStripMenuItem.Checked = false;
  892. 关ToolStripMenuItem.Checked = true;
  893. }
  894. else
  895. {
  896. MessageBox.Show("串口未连接");
  897. return;
  898. }
  899. }
  900. #endregion
  901. #region 1s定时器更新时间
  902. private void timer2_Tick(object sender, EventArgs e)
  903. {
  904. label_SystemTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  905. //MC故障信息超时清除
  906. if (MC_ErrorCode_Refresh == false)
  907. {
  908. MC_ErrorCode_Refresh_Cnt++;
  909. if (MC_ErrorCode_Refresh_Cnt > 5)
  910. {
  911. label_error_code.Text = "OK";
  912. label_error_code.BackColor = Color.Green;
  913. MC_ErrorCode_Refresh_Cnt = 0;
  914. }
  915. }
  916. else
  917. {
  918. MC_ErrorCode_Refresh_Cnt = 0;
  919. }
  920. MC_ErrorCode_Refresh = false;
  921. }
  922. #endregion
  923. #region 故障码标签鼠标滑过显示故障内容
  924. private void label_error_code_MouseHover(object sender, EventArgs e)
  925. {
  926. // 创建the ToolTip
  927. ToolTip toolTip1 = new ToolTip();
  928. // 设置显示样式
  929. toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
  930. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  931. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  932. toolTip1.ShowAlways = true;//是否显示提示框
  933. // 设置伴随的对象.
  934. string ErrorCode = this.label_error_code.Text;
  935. UInt32 Code = ErrorCode.Contains("H") ? Convert.ToUInt32(ErrorCode.Split('H')[0], 16) : 0;
  936. toolTip1.SetToolTip(this.label_error_code, ErrorInfoDisplay(Code));//设置故障内容显示
  937. }
  938. #endregion
  939. //创建线程执行一次测试任务
  940. /*
  941. 执行流程如下:
  942. 1、读取BOOT版本信息;
  943. 2、读取电机版本信息 -> 确认SN是否存在为0、确认版本和cfg文件是否一致;
  944. 3、读取力矩传感器标定值 -> 依次判断零点、校正系数、启动值是否在允许范围内,判断零点值差异是否过大;
  945. 4、依次读取配置参数,严格按照cfg文件的顺序读取 -> 对比两个richbox内容是否一致;
  946. 5、显示测试结果;
  947. 6、存储测试结果,上传ftp服务器。
  948. */
  949. private void Thread_Task()
  950. {
  951. //开始测试
  952. richTextBox_TestRecord.Text += "电机信息:" + textBox_PDinfo.Text + "\r\n";
  953. richTextBox_TestRecord.Text += "配置文件:" + comboBox_File.Text + "\r\n";
  954. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n";
  955. label_Result.Text = "不合格";
  956. label_Result.BackColor = Color.Red;
  957. //公有变量
  958. var Code = new byte[32];//发送的指令数据
  959. //检查是否有故障
  960. if (label_error_code.Text != "OK")
  961. {
  962. label_Step.Text = "电机存在故障!";
  963. button_Start.Enabled = true;
  964. textBox_PDinfo.Enabled = true;
  965. //关机
  966. Code[0] = 0xF0;
  967. SendCmd(0x7FF, 0x16, 0x2201, Code);
  968. 开ToolStripMenuItem.Checked = false;
  969. 关ToolStripMenuItem.Checked = true;
  970. Delay_ms(500);
  971. //关闭串口
  972. portsettings_form.closePort();
  973. //存储测试数据
  974. ErrorSaveLog();
  975. return;
  976. }
  977. //开机
  978. Code[0] = 0xF1;
  979. SendCmd(0x7FF, 0x16, 0x2201, Code);
  980. 开ToolStripMenuItem.Checked = true;
  981. 关ToolStripMenuItem.Checked = false;
  982. Delay_ms(2000);
  983. #region 判断BootLoader版本
  984. if (IsBootVerOK == false)
  985. {
  986. //发送系统复位指令
  987. Code[0] = (byte)'R';
  988. Code[1] = (byte)'E';
  989. Code[2] = (byte)'S';
  990. Code[3] = (byte)'E';
  991. Code[4] = (byte)'T';
  992. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  993. Delay_ms(2000);
  994. if (IsBootVerOK == false)
  995. {
  996. label_Step.Text = "Bootloader波特率错误!";
  997. button_Start.Enabled = true;
  998. textBox_PDinfo.Enabled = true;
  999. //关机
  1000. Code[0] = 0xF0;
  1001. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1002. 开ToolStripMenuItem.Checked = false;
  1003. 关ToolStripMenuItem.Checked = true;
  1004. Delay_ms(500);
  1005. //关闭串口
  1006. portsettings_form.closePort();
  1007. //存储测试数据
  1008. ErrorSaveLog();
  1009. return;
  1010. }
  1011. }
  1012. #endregion
  1013. #region 电机运行测试
  1014. if (运行测试执行ToolStripMenuItem.Checked == true)
  1015. {
  1016. label_Step.Text = "电机运行测试 10s";
  1017. Code[0] = 0x01;
  1018. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  1019. Thread.Sleep(200);
  1020. Code[0] = 0x22;
  1021. Code[1] = 0xF0;
  1022. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  1023. int TimeCnt = Environment.TickCount;
  1024. while (Math.Abs(Environment.TickCount - TimeCnt) < 10000)
  1025. {
  1026. if (Math.Abs(Environment.TickCount - TimeCnt) < 1000)
  1027. label_Step.Text = "电机运行测试" + " 10s";
  1028. else if (Math.Abs(Environment.TickCount - TimeCnt) < 2000)
  1029. label_Step.Text = "电机运行测试" + " 9s";
  1030. else if (Math.Abs(Environment.TickCount - TimeCnt) < 3000)
  1031. label_Step.Text = "电机运行测试" + " 8s";
  1032. else if (Math.Abs(Environment.TickCount - TimeCnt) < 4000)
  1033. label_Step.Text = "电机运行测试" + " 7s";
  1034. else if (Math.Abs(Environment.TickCount - TimeCnt) < 5000)
  1035. label_Step.Text = "电机运行测试" + " 6s";
  1036. else if (Math.Abs(Environment.TickCount - TimeCnt) < 6000)
  1037. label_Step.Text = "电机运行测试" + " 5s";
  1038. else if (Math.Abs(Environment.TickCount - TimeCnt) < 7000)
  1039. label_Step.Text = "电机运行测试" + " 4s";
  1040. else if (Math.Abs(Environment.TickCount - TimeCnt) < 8000)
  1041. label_Step.Text = "电机运行测试" + " 3s";
  1042. else if (Math.Abs(Environment.TickCount - TimeCnt) < 9000)
  1043. label_Step.Text = "电机运行测试" + " 2s";
  1044. else if (Math.Abs(Environment.TickCount - TimeCnt) < 10000)
  1045. label_Step.Text = "电机运行测试" + " 1s";
  1046. }
  1047. label_Step.Text = "电机运行测试" + "结束!";
  1048. Code[0] = 0x00;
  1049. Code[1] = 0xF0;
  1050. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  1051. Thread.Sleep(1500);
  1052. Code[0] = 0x00;
  1053. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  1054. }
  1055. #endregion
  1056. #region 版本查询和确认
  1057. label_Step.Text = "检查版本信息";
  1058. Delay_ms(2000);
  1059. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令查询版本信息" + "\r\n";
  1060. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  1061. Delay_ms(500);
  1062. SendCmd((ushort)0x651, (byte)0x11, (ushort)0x1200, null);
  1063. Delay_ms(500);
  1064. string FW_Version_Check = comboBox_File.Text.Split('_')[2] + "_" + comboBox_File.Text.Split('_')[3];
  1065. string FW_Version_Result = "";
  1066. string TE_FW_Ver_Check = comboBox_File.Text.Split('_')[4] + "_" + comboBox_File.Text.Split('_')[5];
  1067. string TE_FW_Ver_Result = "";
  1068. string HW_Version_Result = "";
  1069. try
  1070. {
  1071. HW_Version_Result = richTextBox_VerInfo.Lines[2].Split(':')[1];
  1072. FW_Version_Result = richTextBox_VerInfo.Lines[3].Split(':')[1];
  1073. FW_Version_Result = FW_Version_Result.Split('_')[0] + richTextBox_VerInfo.Lines[4].Split('-')[2].Replace('V', '.') + "_" + FW_Version_Result.Split('_')[1];
  1074. TE_FW_Ver_Result = richTextBox_VerInfo.Lines[5].Split(':')[1];
  1075. }
  1076. catch (System.Exception)
  1077. {
  1078. //label_Step.Text = "软件版本信息不完整!";
  1079. }
  1080. //PCBA版本确认
  1081. if (HW_Version_Result.Contains(HW_Version_Check) == false)//PCBA版号错误,直接结束
  1082. {
  1083. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "PCBA版本错误" + "\r\n";
  1084. label_Step.Text = "PCBA版本错误,测试结束!";
  1085. label_Step.ForeColor = Color.Red;
  1086. button_Start.Enabled = true;
  1087. textBox_PDinfo.Enabled = true;
  1088. ErrorSaveLog();
  1089. //关机
  1090. Code[0] = 0xF0;
  1091. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1092. 开ToolStripMenuItem.Checked = false;
  1093. 关ToolStripMenuItem.Checked = true;
  1094. Delay_ms(500);
  1095. //关闭串口
  1096. portsettings_form.closePort();
  1097. return;
  1098. }
  1099. //主控软件版本检查
  1100. if (string.Equals(FW_Version_Check, FW_Version_Result) == false) //主控版本错误,直接结束
  1101. {
  1102. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "主控版本错误" + "\r\n";
  1103. label_Step.Text = "主控软件版本错误,测试结束!";
  1104. label_Step.ForeColor = Color.Red;
  1105. button_Start.Enabled = true;
  1106. textBox_PDinfo.Enabled = true;
  1107. ErrorSaveLog();
  1108. //关机
  1109. Code[0] = 0xF0;
  1110. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1111. 开ToolStripMenuItem.Checked = false;
  1112. 关ToolStripMenuItem.Checked = true;
  1113. Delay_ms(500);
  1114. //关闭串口
  1115. portsettings_form.closePort();
  1116. return;
  1117. }
  1118. else
  1119. {
  1120. //TE软件版本检查
  1121. if (TE_FW_Ver_Check != "N_A")//单MCU主控板不检测TE版本
  1122. {
  1123. if (string.Equals(TE_FW_Ver_Check, TE_FW_Ver_Result) == false) //TE版本错误,给出提示
  1124. {
  1125. if (MessageBox.Show("TE版本错误,请确认主控板是否为HK?", "TE版本错误", MessageBoxButtons.YesNo) == DialogResult.No)
  1126. {
  1127. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "TE版本错误" + "\r\n";
  1128. label_Step.Text = "TE软件版本错误,测试结束!";
  1129. label_Step.ForeColor = Color.Red;
  1130. button_Start.Enabled = true;
  1131. textBox_PDinfo.Enabled = true;
  1132. ErrorSaveLog();
  1133. //关机
  1134. Code[0] = 0xF0;
  1135. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1136. 开ToolStripMenuItem.Checked = false;
  1137. 关ToolStripMenuItem.Checked = true;
  1138. Delay_ms(500);
  1139. //关闭串口
  1140. portsettings_form.closePort();
  1141. return;
  1142. }
  1143. }
  1144. }
  1145. //型号和SN确认
  1146. try
  1147. {
  1148. string mode1 = "", mode2 = "";
  1149. mode1 = richTextBox_VerInfo.Lines[0].Split(':')[1].Trim();
  1150. mode2 = textBox_PDinfo.Text.Contains("%#") ? textBox_PDinfo.Text.Substring(0, textBox_PDinfo.Text.LastIndexOf('%'))
  1151. : textBox_PDinfo.Text.Substring(0, textBox_PDinfo.Text.LastIndexOf(' ')).Trim();
  1152. if (string.Equals(mode1, mode2) == false)//型号不一致
  1153. {
  1154. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号错误" + "\r\n";
  1155. label_Step.Text = "型号不一致,测试结束!";
  1156. label_Step.ForeColor = Color.Red;
  1157. button_Start.Enabled = true;
  1158. textBox_PDinfo.Enabled = true;
  1159. ErrorSaveLog();
  1160. //关机
  1161. Code[0] = 0xF0;
  1162. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1163. 开ToolStripMenuItem.Checked = false;
  1164. 关ToolStripMenuItem.Checked = true;
  1165. Delay_ms(500);
  1166. //关闭串口
  1167. portsettings_form.closePort();
  1168. return;
  1169. }
  1170. string SN1 = "", SN2 = "";
  1171. SN1 = richTextBox_VerInfo.Lines[1].Split(':')[1].Trim();
  1172. SN2 = textBox_PDinfo.Text.Contains("%#") ? textBox_PDinfo.Text.Remove(0, textBox_PDinfo.Text.LastIndexOf('#') + 1)
  1173. : textBox_PDinfo.Text.Remove(0, textBox_PDinfo.Text.LastIndexOf(' ') + 1);
  1174. if (string.Equals(SN1, SN2) == false)//SN不一致
  1175. {
  1176. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN错误" + "\r\n";
  1177. label_Step.Text = "SN不一致,测试结束!";
  1178. label_Step.ForeColor = Color.Red;
  1179. button_Start.Enabled = true;
  1180. textBox_PDinfo.Enabled = true;
  1181. ErrorSaveLog();
  1182. //关机
  1183. Code[0] = 0xF0;
  1184. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1185. 开ToolStripMenuItem.Checked = false;
  1186. 关ToolStripMenuItem.Checked = true;
  1187. Delay_ms(500);
  1188. //关闭串口
  1189. portsettings_form.closePort();
  1190. return;
  1191. }
  1192. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息正确" + "\r\n";
  1193. }
  1194. catch (Exception)
  1195. {
  1196. label_Step.Text = "电机信息错误,测试结束!";
  1197. label_Step.ForeColor = Color.Red;
  1198. button_Start.Enabled = true;
  1199. textBox_PDinfo.Enabled = true;
  1200. ErrorSaveLog();
  1201. //关机
  1202. Code[0] = 0xF0;
  1203. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1204. 开ToolStripMenuItem.Checked = false;
  1205. 关ToolStripMenuItem.Checked = true;
  1206. Delay_ms(500);
  1207. //关闭串口
  1208. portsettings_form.closePort();
  1209. return;
  1210. }
  1211. }
  1212. #endregion
  1213. #region 判断力矩传感器的标定值是否在允许范围内
  1214. label_Step.Text = "判断力矩传感器";
  1215. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令查询力矩传感器" + "\r\n";
  1216. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2000, null);//单传感器零点
  1217. Delay_ms(200);
  1218. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2900, null);//单传感器校正信息
  1219. Delay_ms(200);
  1220. Code[0] = 1;
  1221. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3201, Code);//传感器1零点
  1222. Delay_ms(200);
  1223. Code[0] = 2;
  1224. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3201, Code);//传感器2零点
  1225. Delay_ms(200);
  1226. Code[0] = 3;
  1227. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3201, Code);//传感器3零点
  1228. Delay_ms(200);
  1229. Code[0] = 1;
  1230. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3301, Code);//传感器1校正系数
  1231. Delay_ms(200);
  1232. Code[0] = 2;
  1233. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3301, Code);//传感器2校正系数
  1234. Delay_ms(200);
  1235. Code[0] = 3;
  1236. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3301, Code);//传感器3校正系数
  1237. Delay_ms(200);
  1238. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3500, null);//三传感器启动值
  1239. Delay_ms(200);
  1240. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "判断力矩传感器" + "\r\n";
  1241. for (int i = 0; i < richTextBox_TQ.Lines.Length; i++)
  1242. {
  1243. switch (richTextBox_TQ.Lines[i].Split(':')[0])
  1244. {
  1245. case "零点": case "传感器1零点": case "传感器2零点": case "传感器3零点":
  1246. {
  1247. string[] zero = richTextBox_TQ.Lines[i].Split(':')[1].Split(new string[] { ", " }, StringSplitOptions.None);
  1248. for (int j = 0; j < zero.Length; j++)
  1249. {
  1250. if ((Convert.ToUInt16(zero[j]) > TorqueCheck.Zero_Max) || (Convert.ToUInt16(zero[j]) < TorqueCheck.Zero_Min))//零点超差
  1251. {
  1252. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "传感器零点超范围" + "\r\n";
  1253. label_Step.Text = "传感器零点超范围,测试结束!";
  1254. label_Step.ForeColor = Color.Red;
  1255. button_Start.Enabled = true;
  1256. textBox_PDinfo.Enabled = true;
  1257. ErrorSaveLog();
  1258. //关机
  1259. Code[0] = 0xF0;
  1260. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1261. 开ToolStripMenuItem.Checked = false;
  1262. 关ToolStripMenuItem.Checked = true;
  1263. Delay_ms(500);
  1264. //关闭串口
  1265. portsettings_form.closePort();
  1266. return;
  1267. }
  1268. }
  1269. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + richTextBox_TQ.Lines[i].Split(':')[0] + "正常" + "\r\n";
  1270. break;
  1271. }
  1272. case "校正系数": case "传感器1校正系数": case "传感器2校正系数": case "传感器3校正系数":
  1273. {
  1274. ushort k = (ushort)(Convert.ToSingle(richTextBox_TQ.Lines[i].Split(':')[1]) * 100);
  1275. if ((k > (ushort)(TorqueCheck.Cal_K_Max * 100f)) || (k < (ushort)(TorqueCheck.Cal_K_Min * 100f)))//校正系数超差
  1276. {
  1277. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "校正系数超范围" + "\r\n";
  1278. label_Step.Text = "校正系数超范围,测试结束!";
  1279. label_Step.ForeColor = Color.Red;
  1280. button_Start.Enabled = true;
  1281. textBox_PDinfo.Enabled = true;
  1282. ErrorSaveLog();
  1283. //关机
  1284. Code[0] = 0xF0;
  1285. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1286. 开ToolStripMenuItem.Checked = false;
  1287. 关ToolStripMenuItem.Checked = true;
  1288. Delay_ms(500);
  1289. //关闭串口
  1290. portsettings_form.closePort();
  1291. return;
  1292. }
  1293. if (k == 100)
  1294. {
  1295. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "传感器未标定" + "\r\n";
  1296. label_Step.Text = "传感器未标定,测试结束!";
  1297. label_Step.ForeColor = Color.Red;
  1298. button_Start.Enabled = true;
  1299. textBox_PDinfo.Enabled = true;
  1300. ErrorSaveLog();
  1301. //关机
  1302. Code[0] = 0xF0;
  1303. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1304. 开ToolStripMenuItem.Checked = false;
  1305. 关ToolStripMenuItem.Checked = true;
  1306. Delay_ms(500);
  1307. //关闭串口
  1308. portsettings_form.closePort();
  1309. return;
  1310. }
  1311. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + richTextBox_TQ.Lines[i].Split(':')[0] + "正常" + "\r\n";
  1312. break;
  1313. }
  1314. case "校正系数标准差":
  1315. {
  1316. double std = Convert.ToDouble(richTextBox_TQ.Lines[i].Split(':')[1]);
  1317. if (std > 0.3f)
  1318. {
  1319. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "校正系数差异大" + "\r\n";
  1320. label_Step.Text = "校正系数标准差超范围,测试结束!";
  1321. label_Step.ForeColor = Color.Red;
  1322. button_Start.Enabled = true;
  1323. textBox_PDinfo.Enabled = true;
  1324. ErrorSaveLog();
  1325. //关机
  1326. Code[0] = 0xF0;
  1327. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1328. 开ToolStripMenuItem.Checked = false;
  1329. 关ToolStripMenuItem.Checked = true;
  1330. Delay_ms(500);
  1331. //关闭串口
  1332. portsettings_form.closePort();
  1333. return;
  1334. }
  1335. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + richTextBox_TQ.Lines[i].Split(':')[0] + "正常" + "\r\n";
  1336. break;
  1337. }
  1338. case "启动值":
  1339. {
  1340. string start = richTextBox_TQ.Lines[i].Split(':')[1];
  1341. if ((Convert.ToUInt16(start) > TorqueCheck.Start_Max) || (Convert.ToUInt16(start) < TorqueCheck.Start_Min))//启动值超差
  1342. {
  1343. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "启动值超范围" + "\r\n";
  1344. label_Step.Text = "启动值超范围,测试结束!";
  1345. label_Step.ForeColor = Color.Red;
  1346. button_Start.Enabled = true;
  1347. textBox_PDinfo.Enabled = true;
  1348. ErrorSaveLog();
  1349. //关机
  1350. Code[0] = 0xF0;
  1351. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1352. 开ToolStripMenuItem.Checked = false;
  1353. 关ToolStripMenuItem.Checked = true;
  1354. Delay_ms(500);
  1355. //关闭串口
  1356. portsettings_form.closePort();
  1357. return;
  1358. }
  1359. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + richTextBox_TQ.Lines[i].Split(':')[0] + "正常" + "\r\n";
  1360. break;
  1361. }
  1362. default:break;
  1363. }
  1364. }
  1365. #endregion
  1366. #region 依次读取配置参数
  1367. label_Step.Text = "判断配置参数";
  1368. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令查询电机配置参数" + "\r\n";
  1369. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1A00, null);//用户参数1
  1370. Delay_ms(200);
  1371. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3000, null);//用户参数2
  1372. Delay_ms(200);
  1373. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1C00, null);//马达参数
  1374. Delay_ms(200);
  1375. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);//生产信息
  1376. Delay_ms(200);
  1377. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);//校验秘钥
  1378. Delay_ms(200);
  1379. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);//自定义1
  1380. Delay_ms(200);
  1381. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);//自定义2
  1382. Delay_ms(200);
  1383. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);//自定义3
  1384. Delay_ms(200);
  1385. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "判断配置参数" + "\r\n";
  1386. for (int line = 0; line < richTextBox_CfgFile.Lines.Length; line++)
  1387. {
  1388. try
  1389. {
  1390. if (richTextBox_ReadCfg.Lines[line].Equals(richTextBox_CfgFile.Lines[line]) == false)
  1391. {
  1392. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + richTextBox_CfgFile.Lines[line].Split(',')[0] + "错误" + "\r\n";
  1393. label_Step.Text = "检查配置参数失败,测试结束!";
  1394. label_Step.ForeColor = Color.Red;
  1395. button_Start.Enabled = true;
  1396. textBox_PDinfo.Enabled = true;
  1397. ErrorSaveLog();
  1398. //关机
  1399. Code[0] = 0xF0;
  1400. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1401. 开ToolStripMenuItem.Checked = false;
  1402. 关ToolStripMenuItem.Checked = true;
  1403. Delay_ms(500);
  1404. //关闭串口
  1405. portsettings_form.closePort();
  1406. return;
  1407. }
  1408. }
  1409. catch (System.Exception)
  1410. {
  1411. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取电机配置参数失败" + "\r\n";
  1412. label_Step.Text = "检查配置参数失败,测试结束!";
  1413. label_Step.ForeColor = Color.Red;
  1414. button_Start.Enabled = true;
  1415. textBox_PDinfo.Enabled = true;
  1416. ErrorSaveLog();
  1417. //关机
  1418. Code[0] = 0xF0;
  1419. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1420. 开ToolStripMenuItem.Checked = false;
  1421. 关ToolStripMenuItem.Checked = true;
  1422. Delay_ms(500);
  1423. //关闭串口
  1424. portsettings_form.closePort();
  1425. return;
  1426. }
  1427. }
  1428. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机配置参数正确" + "\r\n";
  1429. #endregion
  1430. //检查是否有故障
  1431. if (label_error_code.Text != "OK")
  1432. {
  1433. label_Step.Text = "电机存在故障!";
  1434. button_Start.Enabled = true;
  1435. textBox_PDinfo.Enabled = true;
  1436. //关机
  1437. Code[0] = 0xF0;
  1438. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1439. 开ToolStripMenuItem.Checked = false;
  1440. 关ToolStripMenuItem.Checked = true;
  1441. Delay_ms(500);
  1442. //关闭串口
  1443. portsettings_form.closePort();
  1444. //存储测试数据
  1445. ErrorSaveLog();
  1446. return;
  1447. }
  1448. #region 测试结束
  1449. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n";
  1450. label_Step.Text = "测试结束!";
  1451. label_Step.ForeColor = Color.Green;
  1452. label_Result.Text = "合格";
  1453. label_Result.BackColor = Color.Green;
  1454. button_Start.Enabled = true;
  1455. textBox_PDinfo.Enabled = true;
  1456. //关机
  1457. Code[0] = 0xF0;
  1458. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1459. 开ToolStripMenuItem.Checked = false;
  1460. 关ToolStripMenuItem.Checked = true;
  1461. Delay_ms(500);
  1462. //关闭串口
  1463. portsettings_form.closePort();
  1464. //合格计数累加和存储
  1465. label_OK_Count.Text = (Convert.ToInt32(label_OK_Count.Text) + 1).ToString();
  1466. string cfg_file = System.IO.Directory.GetCurrentDirectory() + "\\CheckSerialNum";
  1467. StreamReader objReader = new StreamReader(cfg_file);
  1468. string sLine = "";
  1469. ArrayList arrText = new ArrayList();//创建一个动态数组
  1470. while (sLine != null)
  1471. {
  1472. sLine = objReader.ReadLine();
  1473. arrText.Add(sLine);
  1474. }
  1475. arrText.RemoveAt(arrText.Count - 1);
  1476. objReader.Close();
  1477. arrText[3] = label_OK_Count.Text;
  1478. using (StreamWriter file = new StreamWriter(cfg_file))
  1479. {
  1480. foreach (var entry in arrText)
  1481. {
  1482. file.WriteLine(entry);
  1483. }
  1484. }
  1485. #region 按照产品信息设置测试文件路径
  1486. string ResultPathName = textBox_PDinfo.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_");
  1487. if (System.IO.Directory.Exists(LogSavePath + "log\\" + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ResultPathName) == false)
  1488. System.IO.Directory.CreateDirectory(LogSavePath + "log\\" + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ResultPathName);
  1489. #endregion
  1490. //页面存储
  1491. Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
  1492. Graphics g = Graphics.FromImage(bit);
  1493. g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片
  1494. LogSaveFileName = LogSavePath + "log\\" + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ResultPathName + "\\测试记录" + ".png";
  1495. bit.Save(LogSaveFileName);
  1496. //测试页面上传服务器
  1497. if (StartForm.myFtp.IsNetConnected == true)
  1498. {
  1499. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  1500. if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/qcTest/log/", DateNow) == false)
  1501. {
  1502. StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/qcTest/log/" + DateNow);
  1503. }
  1504. if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/qcTest/log/", DateNow + "/" + ResultPathName) == false)
  1505. {
  1506. StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/qcTest/log/" + DateNow + "/" + ResultPathName);
  1507. }
  1508. bool result = StartForm.myFtp.UploadFile(LogSaveFileName, StartForm.myServerCfg.RootPath + "/qcTest/log/" + DateNow + "/" + ResultPathName);
  1509. if (result == true)
  1510. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  1511. }
  1512. //电机数据存储
  1513. LogSaveFileName = LogSavePath + "\\log\\" + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ResultPathName + "\\电机参数" + ".txt";
  1514. string fileInfo = "";
  1515. fileInfo += "检验记录:\r\n" + richTextBox_TestRecord.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  1516. fileInfo += "电机生产参数:\r\n";
  1517. fileInfo += richTextBox_CfgFile.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  1518. fileInfo += "电机版本信息查询:\r\n";
  1519. fileInfo += richTextBox_VerInfo.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  1520. fileInfo += "力矩传感器标定结果:\r\n";
  1521. fileInfo += richTextBox_TQ.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  1522. fileInfo += "电机参数查询:\r\n";
  1523. fileInfo += richTextBox_ReadCfg.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  1524. fileInfo += "电机故障码:\r\n";
  1525. fileInfo += label_error_code.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  1526. fileInfo += "测试结果:\r\n";
  1527. fileInfo += label_Result.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  1528. System.IO.File.WriteAllText(LogSaveFileName, fileInfo);
  1529. //电机数据上传服务器
  1530. if (StartForm.myFtp.IsNetConnected == true)
  1531. {
  1532. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  1533. if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/qcTest/log/", DateNow) == false)
  1534. {
  1535. StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/qcTest/log/" + DateNow);
  1536. }
  1537. if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/qcTest/log/" + DateNow, ResultPathName) == false)
  1538. {
  1539. StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/qcTest/log/" + DateNow + "/" + ResultPathName);
  1540. }
  1541. bool result = StartForm.myFtp.UploadFile(LogSaveFileName, StartForm.myServerCfg.RootPath + "/qcTest/log/" + DateNow + "/" + ResultPathName);
  1542. if (result == true)
  1543. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机数据上传服务器成功" + "\r\n";
  1544. }
  1545. #endregion
  1546. //测试正常,清空扫码信息
  1547. Delay_ms(1000);
  1548. textBox_PDinfo.Text = "";
  1549. }
  1550. private void CheckForm_Load(object sender, EventArgs e)
  1551. {
  1552. timer1.Enabled = true;
  1553. timer2.Enabled = true;
  1554. //显示测试员信息
  1555. label_TestUser.Text = "测试员:" + StartForm.EnterForm1.comboBox_User.Text;
  1556. //窗口加载时,从FTP服务器或本地获取文件日期列表
  1557. GetDateList(false);
  1558. //装载序列号文件
  1559. string cfg_file = System.IO.Directory.GetCurrentDirectory() + "\\CheckSerialNum";
  1560. StreamReader objReader = new StreamReader(cfg_file);
  1561. string sLine = "";
  1562. ArrayList arrText = new ArrayList();//创建一个动态数组
  1563. while (sLine != null)
  1564. {
  1565. sLine = objReader.ReadLine();
  1566. arrText.Add(sLine);
  1567. }
  1568. objReader.Close();
  1569. label_SerialNum.Text = arrText[1].ToString();//流水号
  1570. label_OK_Count.Text = arrText[3].ToString();//合格计数
  1571. }
  1572. //测试失败存储测试界面
  1573. private void ErrorSaveLog()
  1574. {
  1575. //页面存储
  1576. Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
  1577. Graphics g = Graphics.FromImage(bit);
  1578. g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片
  1579. string LogSaveFileName = LogSavePath + "errorlog\\" + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\";
  1580. if (System.IO.Directory.Exists(LogSaveFileName) == false)
  1581. System.IO.Directory.CreateDirectory(LogSaveFileName);
  1582. LogSaveFileName += textBox_PDinfo.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_测试记录" + ".png";
  1583. bit.Save(LogSaveFileName);
  1584. //测试页面上传服务器
  1585. if (StartForm.myFtp.IsNetConnected == true)
  1586. {
  1587. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  1588. if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/qcTest/errorlog/", DateNow) == false)
  1589. {
  1590. StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/qcTest/errorlog/" + DateNow);
  1591. }
  1592. bool result = StartForm.myFtp.UploadFile(LogSaveFileName, StartForm.myServerCfg.RootPath + "/qcTest/errorlog/" + DateNow);
  1593. if (result == true)
  1594. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试异常页面上传服务器成功" + "\r\n";
  1595. }
  1596. }
  1597. //开始测试按钮点击
  1598. private void button_Start_Click(object sender, EventArgs e)
  1599. {
  1600. TestStart();
  1601. }
  1602. //开始一次测试
  1603. private void TestStart()
  1604. {
  1605. //显示数据清空
  1606. richTextBox_ReadCfg.Text = "";
  1607. richTextBox_TestRecord.Text = "";
  1608. richTextBox_TQ.Text = "";
  1609. richTextBox_VerInfo.Text = "";
  1610. //Boot版本标志复位
  1611. IsBootVerOK = false;
  1612. #region 检查配置文件
  1613. if (comboBox_File.Items.Count == 0) //配置文件目录为空
  1614. {
  1615. label_Step.Text = "无可用配置文件!";
  1616. label_Step.ForeColor = Color.Red;
  1617. return;
  1618. }
  1619. if (comboBox_File.Text.Trim().Length == 0)//未选择配置文件
  1620. {
  1621. label_Step.Text = "请选择配置文件!";
  1622. label_Step.ForeColor = Color.Red;
  1623. return;
  1624. }
  1625. #endregion
  1626. #region 检查产品信息是否符合格式要求
  1627. try
  1628. {
  1629. Regex regex = new Regex(@"^M[12][0-9](0?[1-9]|1[0-2])((0?[1-9])|((1|2)[0-9])|30|31)[A-Z]\d{4}[A-Z][A-Z]?$");
  1630. if (textBox_PDinfo.Text.Contains(" "))
  1631. {
  1632. string Mode = textBox_PDinfo.Text.Split(new string[] { " " }, StringSplitOptions.None)[0];
  1633. string Sn = textBox_PDinfo.Text.Split(new string[] { " " }, StringSplitOptions.None)[1];
  1634. if (regex.IsMatch(Sn) == false)
  1635. {
  1636. label_Step.Text = "SN格式错误!";
  1637. label_Step.ForeColor = Color.Red;
  1638. return;
  1639. }
  1640. }
  1641. else if (textBox_PDinfo.Text.Contains("%#"))
  1642. {
  1643. string Mode = textBox_PDinfo.Text.Split(new string[] { "%#" }, StringSplitOptions.None)[0];
  1644. string Sn = textBox_PDinfo.Text.Split(new string[] { "%#" }, StringSplitOptions.None)[1];
  1645. if (regex.IsMatch(Sn) == false)
  1646. {
  1647. label_Step.Text = "SN格式错误!";
  1648. label_Step.ForeColor = Color.Red;
  1649. return;
  1650. }
  1651. }
  1652. else
  1653. {
  1654. label_Step.Text = "标签格式错误!";
  1655. label_Step.ForeColor = Color.Red;
  1656. return;
  1657. }
  1658. }
  1659. catch (System.Exception)
  1660. {
  1661. label_Step.Text = "标签格式错误!";
  1662. label_Step.ForeColor = Color.Red;
  1663. return;
  1664. }
  1665. #endregion
  1666. #region 检查产品型号和配置文件是否一致
  1667. do
  1668. {
  1669. string cfg_mode = "", pd_mode = "";
  1670. cfg_mode = comboBox_File.Text.Split('_')[0];
  1671. if (textBox_PDinfo.Text.Contains(" "))
  1672. {
  1673. pd_mode = textBox_PDinfo.Text.Split(new string[] { " " }, StringSplitOptions.None)[0];
  1674. }
  1675. else if (textBox_PDinfo.Text.Contains("%#"))
  1676. {
  1677. pd_mode = textBox_PDinfo.Text.Split(new string[] { "%#" }, StringSplitOptions.None)[0];
  1678. }
  1679. if (pd_mode != cfg_mode)
  1680. {
  1681. label_Step.Text = "打标信息与配置文件不一致!";
  1682. label_Step.ForeColor = Color.Red;
  1683. return;
  1684. }
  1685. } while (false);
  1686. #endregion
  1687. //连接串口
  1688. if (portsettings_form.openPort() == false)
  1689. {
  1690. label_Step.Text = "串口连接失败!";
  1691. label_Step.ForeColor = Color.Red;
  1692. return;
  1693. }
  1694. //测试状态更新
  1695. label_Step.Text = "准备开始测试";
  1696. label_Step.ForeColor = Color.Red;
  1697. //流水号累加和存储
  1698. label_SerialNum.Text = (Convert.ToInt32(label_SerialNum.Text) + 1).ToString();
  1699. string cfg_file = System.IO.Directory.GetCurrentDirectory() + "\\CheckSerialNum";
  1700. StreamReader objReader = new StreamReader(cfg_file);
  1701. string sLine = "";
  1702. ArrayList arrText = new ArrayList();//创建一个动态数组
  1703. while (sLine != null)
  1704. {
  1705. sLine = objReader.ReadLine();
  1706. arrText.Add(sLine);
  1707. }
  1708. arrText.RemoveAt(arrText.Count - 1);
  1709. objReader.Close();
  1710. arrText[1] = label_SerialNum.Text;
  1711. using (StreamWriter file = new StreamWriter(cfg_file))
  1712. {
  1713. foreach (var entry in arrText)
  1714. {
  1715. file.WriteLine(entry);
  1716. }
  1717. }
  1718. button_Start.Enabled = false;
  1719. textBox_PDinfo.Enabled = false;
  1720. //创建线程,执行测试任务
  1721. Thread th = new Thread(Thread_Task);
  1722. th.Start();
  1723. }
  1724. //双击清零流水号
  1725. private void label32_DoubleClick(object sender, EventArgs e)
  1726. {
  1727. StartForm.EnterForm1.ShowDialog();
  1728. try
  1729. {
  1730. if (StartForm.EnterForm1.textBox_Passwd.Text == StartForm.EnterForm1.UserAccount[StartForm.EnterForm1.comboBox_User.Text])
  1731. {
  1732. if (StartForm.EnterForm1.comboBox_User.Text == "工程Engineer")
  1733. {
  1734. //流水号清零
  1735. if (MessageBox.Show("流水号清零", "确认清零?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1736. {
  1737. label_SerialNum.Text = "0";
  1738. label_OK_Count.Text = "0";
  1739. //存储
  1740. string cfg_file = System.IO.Directory.GetCurrentDirectory() + "\\CheckSerialNum";
  1741. StreamReader objReader = new StreamReader(cfg_file);
  1742. string sLine = "";
  1743. ArrayList arrText = new ArrayList();//创建一个动态数组
  1744. while (sLine != null)
  1745. {
  1746. sLine = objReader.ReadLine();
  1747. arrText.Add(sLine);
  1748. }
  1749. arrText.RemoveAt(arrText.Count - 1);
  1750. objReader.Close();
  1751. arrText[1] = label_SerialNum.Text;
  1752. arrText[3] = label_OK_Count.Text;
  1753. using (StreamWriter file = new StreamWriter(cfg_file))
  1754. {
  1755. foreach (var entry in arrText)
  1756. {
  1757. file.WriteLine(entry);
  1758. }
  1759. }
  1760. }
  1761. }
  1762. else
  1763. {
  1764. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1765. }
  1766. }
  1767. else
  1768. {
  1769. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1770. }
  1771. }
  1772. catch (Exception)
  1773. {
  1774. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1775. }
  1776. }
  1777. private void textBox_PDinfo_KeyUp(object sender, KeyEventArgs e)
  1778. {
  1779. if (e.KeyCode == Keys.Enter)
  1780. TestStart();
  1781. }
  1782. private void textBox_PDinfo_Click(object sender, EventArgs e)
  1783. {
  1784. textBox_PDinfo.SelectAll();
  1785. }
  1786. private void 屏幕键盘ToolStripMenuItem_Click_1(object sender, EventArgs e)
  1787. {
  1788. System.Diagnostics.Process.Start("osk.exe");
  1789. }
  1790. private void 端口设置ToolStripMenuItem_Click(object sender, EventArgs e)
  1791. {
  1792. portsettings_form.Show();
  1793. }
  1794. private void 合格ToolStripMenuItem_Click(object sender, EventArgs e)
  1795. {
  1796. System.Diagnostics.Process.Start("explorer.exe", LogSavePath + "log\\");
  1797. }
  1798. private void 不合格ToolStripMenuItem_Click(object sender, EventArgs e)
  1799. {
  1800. System.Diagnostics.Process.Start("explorer.exe", LogSavePath + "errorlog\\");
  1801. }
  1802. private void CheckForm_FormClosing(object sender, FormClosingEventArgs e)
  1803. {
  1804. portsettings_form.serialPort1.Close();
  1805. portsettings_form.comboBox_ComIndex.Enabled = true;
  1806. portsettings_form.button_Enter.Text = "确认";
  1807. portsettings_form.g_blnIsOpen = false;
  1808. #if false
  1809. //针对工程和越南账户,直接退出,不执行删除本地配置
  1810. if ((StartForm.EnterForm1.comboBox_User.Text == "越南Vietnam") || (StartForm.EnterForm1.comboBox_User.Text == "工程Engineer"))
  1811. {
  1812. return;
  1813. }
  1814. //关闭前,删除本地所有配置文件
  1815. string path = StartForm.UserPath + "\\cfg\\";
  1816. try
  1817. {
  1818. DirectoryInfo dir = new DirectoryInfo(path);
  1819. FileSystemInfo[] fileinfo = dir.GetFileSystemInfos(); //返回目录中所有文件和子目录
  1820. foreach (FileSystemInfo i in fileinfo)
  1821. {
  1822. if (i is DirectoryInfo) //判断是否文件夹
  1823. {
  1824. DirectoryInfo subdir = new DirectoryInfo(i.FullName);
  1825. subdir.Delete(true); //删除子目录和文件
  1826. }
  1827. else
  1828. {
  1829. File.Delete(i.FullName); //删除指定文件
  1830. }
  1831. }
  1832. //MessageBox.Show("文件清理成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1833. }
  1834. catch (Exception)
  1835. {
  1836. MessageBox.Show("文件清理失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1837. }
  1838. #endif
  1839. }
  1840. private void 运行测试执行ToolStripMenuItem_Click(object sender, EventArgs e)
  1841. {
  1842. 运行测试执行ToolStripMenuItem.Checked = true;
  1843. 运行测试不执行ToolStripMenuItem.Checked = false;
  1844. }
  1845. private void 运行测试不执行ToolStripMenuItem_Click(object sender, EventArgs e)
  1846. {
  1847. 运行测试执行ToolStripMenuItem.Checked = false;
  1848. 运行测试不执行ToolStripMenuItem.Checked = true;
  1849. }
  1850. }
  1851. }