CheckForm.cs 96 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950
  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. textBox_TQ_K_Sqrd.Text = TorqueCheck.Cal_K_Sqrd.ToString("#0.000");
  827. //加载PCBA检测值
  828. try
  829. {
  830. for (int i = 0; i < array_CfgInfo.Count; i++)
  831. {
  832. if (array_CfgInfo[i].ToString().Contains("[其它测试备注信息]"))
  833. {
  834. HW_Version_Check = array_CfgInfo[i + 1].ToString().Split(',')[1];
  835. break;
  836. }
  837. }
  838. }
  839. catch (System.Exception)
  840. {
  841. return;
  842. }
  843. }
  844. #endregion
  845. #region 修改获取文件方式,本地或服务器
  846. private void checkBox_LocalFile_CheckedChanged(object sender, EventArgs e)
  847. {
  848. comboBox_cfgFileDate.Text = "";
  849. comboBox_File.Text = "";
  850. GetDateList(false);
  851. }
  852. #endregion
  853. public CheckForm()
  854. {
  855. InitializeComponent();
  856. System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
  857. }
  858. #region 端口设置
  859. private void toolStripMenuIte_PortSet_Click(object sender, EventArgs e)
  860. {
  861. portsettings_form.Show();
  862. }
  863. #endregion
  864. #region 打开电源
  865. private void 开ToolStripMenuItem_Click(object sender, EventArgs e)
  866. {
  867. byte[] Data = new byte[1];
  868. if (portsettings_form.serialPort1.IsOpen)
  869. {
  870. //开机
  871. Data[0] = 0xF1;
  872. SendCmd(0x7FF, 0x16, 0x2201, Data);
  873. 开ToolStripMenuItem.Checked = true;
  874. 关ToolStripMenuItem.Checked = false;
  875. }
  876. else
  877. {
  878. MessageBox.Show("串口未连接");
  879. return;
  880. }
  881. }
  882. #endregion
  883. #region 关闭电源
  884. private void 关ToolStripMenuItem_Click(object sender, EventArgs e)
  885. {
  886. byte[] Data = new byte[1];
  887. if (portsettings_form.serialPort1.IsOpen)
  888. {
  889. //关机
  890. Data[0] = 0xF0;
  891. SendCmd(0x7FF, 0x16, 0x2201, Data);
  892. 开ToolStripMenuItem.Checked = false;
  893. 关ToolStripMenuItem.Checked = true;
  894. }
  895. else
  896. {
  897. MessageBox.Show("串口未连接");
  898. return;
  899. }
  900. }
  901. #endregion
  902. #region 1s定时器更新时间
  903. private void timer2_Tick(object sender, EventArgs e)
  904. {
  905. label_SystemTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  906. //MC故障信息超时清除
  907. if (MC_ErrorCode_Refresh == false)
  908. {
  909. MC_ErrorCode_Refresh_Cnt++;
  910. if (MC_ErrorCode_Refresh_Cnt > 5)
  911. {
  912. label_error_code.Text = "OK";
  913. label_error_code.BackColor = Color.Green;
  914. MC_ErrorCode_Refresh_Cnt = 0;
  915. }
  916. }
  917. else
  918. {
  919. MC_ErrorCode_Refresh_Cnt = 0;
  920. }
  921. MC_ErrorCode_Refresh = false;
  922. }
  923. #endregion
  924. #region 故障码标签鼠标滑过显示故障内容
  925. private void label_error_code_MouseHover(object sender, EventArgs e)
  926. {
  927. // 创建the ToolTip
  928. ToolTip toolTip1 = new ToolTip();
  929. // 设置显示样式
  930. toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
  931. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  932. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  933. toolTip1.ShowAlways = true;//是否显示提示框
  934. // 设置伴随的对象.
  935. string ErrorCode = this.label_error_code.Text;
  936. UInt32 Code = ErrorCode.Contains("H") ? Convert.ToUInt32(ErrorCode.Split('H')[0], 16) : 0;
  937. toolTip1.SetToolTip(this.label_error_code, ErrorInfoDisplay(Code));//设置故障内容显示
  938. }
  939. #endregion
  940. //创建线程执行一次测试任务
  941. /*
  942. 执行流程如下:
  943. 1、读取BOOT版本信息;
  944. 2、读取电机版本信息 -> 确认SN是否存在为0、确认版本和cfg文件是否一致;
  945. 3、读取力矩传感器标定值 -> 依次判断零点、校正系数、启动值是否在允许范围内,判断零点值差异是否过大;
  946. 4、依次读取配置参数,严格按照cfg文件的顺序读取 -> 对比两个richbox内容是否一致;
  947. 5、显示测试结果;
  948. 6、存储测试结果,上传ftp服务器。
  949. */
  950. private void Thread_Task()
  951. {
  952. //开始测试
  953. richTextBox_TestRecord.Text += "电机信息:" + textBox_PDinfo.Text + "\r\n";
  954. richTextBox_TestRecord.Text += "配置文件:" + comboBox_File.Text + "\r\n";
  955. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n";
  956. label_Result.Text = "不合格";
  957. label_Result.BackColor = Color.Red;
  958. //公有变量
  959. var Code = new byte[32];//发送的指令数据
  960. //检查是否有故障
  961. if (label_error_code.Text != "OK")
  962. {
  963. label_Step.Text = "电机存在故障!";
  964. button_Start.Enabled = true;
  965. textBox_PDinfo.Enabled = true;
  966. //关机
  967. Code[0] = 0xF0;
  968. SendCmd(0x7FF, 0x16, 0x2201, Code);
  969. 开ToolStripMenuItem.Checked = false;
  970. 关ToolStripMenuItem.Checked = true;
  971. Delay_ms(500);
  972. //关闭串口
  973. portsettings_form.closePort();
  974. //存储测试数据
  975. ErrorSaveLog();
  976. return;
  977. }
  978. //开机
  979. Code[0] = 0xF1;
  980. SendCmd(0x7FF, 0x16, 0x2201, Code);
  981. 开ToolStripMenuItem.Checked = true;
  982. 关ToolStripMenuItem.Checked = false;
  983. Delay_ms(2000);
  984. #region 判断BootLoader版本
  985. if (IsBootVerOK == false)
  986. {
  987. //发送系统复位指令
  988. Code[0] = (byte)'R';
  989. Code[1] = (byte)'E';
  990. Code[2] = (byte)'S';
  991. Code[3] = (byte)'E';
  992. Code[4] = (byte)'T';
  993. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  994. Delay_ms(2000);
  995. if (IsBootVerOK == false)
  996. {
  997. label_Step.Text = "Bootloader波特率错误!";
  998. button_Start.Enabled = true;
  999. textBox_PDinfo.Enabled = true;
  1000. //关机
  1001. Code[0] = 0xF0;
  1002. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1003. 开ToolStripMenuItem.Checked = false;
  1004. 关ToolStripMenuItem.Checked = true;
  1005. Delay_ms(500);
  1006. //关闭串口
  1007. portsettings_form.closePort();
  1008. //存储测试数据
  1009. ErrorSaveLog();
  1010. return;
  1011. }
  1012. }
  1013. #endregion
  1014. #region 电机运行测试
  1015. if (运行测试执行ToolStripMenuItem.Checked == true)
  1016. {
  1017. label_Step.Text = "电机运行测试 10s";
  1018. Code[0] = 0x01;
  1019. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  1020. Thread.Sleep(200);
  1021. Code[0] = 0x22;
  1022. Code[1] = 0xF0;
  1023. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  1024. int TimeCnt = Environment.TickCount;
  1025. while (Math.Abs(Environment.TickCount - TimeCnt) < 10000)
  1026. {
  1027. if (Math.Abs(Environment.TickCount - TimeCnt) < 1000)
  1028. label_Step.Text = "电机运行测试" + " 10s";
  1029. else if (Math.Abs(Environment.TickCount - TimeCnt) < 2000)
  1030. label_Step.Text = "电机运行测试" + " 9s";
  1031. else if (Math.Abs(Environment.TickCount - TimeCnt) < 3000)
  1032. label_Step.Text = "电机运行测试" + " 8s";
  1033. else if (Math.Abs(Environment.TickCount - TimeCnt) < 4000)
  1034. label_Step.Text = "电机运行测试" + " 7s";
  1035. else if (Math.Abs(Environment.TickCount - TimeCnt) < 5000)
  1036. label_Step.Text = "电机运行测试" + " 6s";
  1037. else if (Math.Abs(Environment.TickCount - TimeCnt) < 6000)
  1038. label_Step.Text = "电机运行测试" + " 5s";
  1039. else if (Math.Abs(Environment.TickCount - TimeCnt) < 7000)
  1040. label_Step.Text = "电机运行测试" + " 4s";
  1041. else if (Math.Abs(Environment.TickCount - TimeCnt) < 8000)
  1042. label_Step.Text = "电机运行测试" + " 3s";
  1043. else if (Math.Abs(Environment.TickCount - TimeCnt) < 9000)
  1044. label_Step.Text = "电机运行测试" + " 2s";
  1045. else if (Math.Abs(Environment.TickCount - TimeCnt) < 10000)
  1046. label_Step.Text = "电机运行测试" + " 1s";
  1047. }
  1048. label_Step.Text = "电机运行测试" + "结束!";
  1049. Code[0] = 0x00;
  1050. Code[1] = 0xF0;
  1051. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  1052. Thread.Sleep(1500);
  1053. Code[0] = 0x00;
  1054. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  1055. }
  1056. #endregion
  1057. #region 版本查询和确认
  1058. label_Step.Text = "检查版本信息";
  1059. Delay_ms(2000);
  1060. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令查询版本信息" + "\r\n";
  1061. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  1062. Delay_ms(500);
  1063. SendCmd((ushort)0x651, (byte)0x11, (ushort)0x1200, null);
  1064. Delay_ms(500);
  1065. string FW_Version_Check = comboBox_File.Text.Split('_')[2] + "_" + comboBox_File.Text.Split('_')[3];
  1066. string FW_Version_Result = "";
  1067. string TE_FW_Ver_Check = comboBox_File.Text.Split('_')[4] + "_" + comboBox_File.Text.Split('_')[5];
  1068. string TE_FW_Ver_Result = "";
  1069. string HW_Version_Result = "";
  1070. try
  1071. {
  1072. HW_Version_Result = richTextBox_VerInfo.Lines[2].Split(':')[1];
  1073. FW_Version_Result = richTextBox_VerInfo.Lines[3].Split(':')[1];
  1074. FW_Version_Result = FW_Version_Result.Split('_')[0] + richTextBox_VerInfo.Lines[4].Split('-')[2].Replace('V', '.') + "_" + FW_Version_Result.Split('_')[1];
  1075. TE_FW_Ver_Result = richTextBox_VerInfo.Lines[5].Split(':')[1];
  1076. }
  1077. catch (System.Exception)
  1078. {
  1079. //label_Step.Text = "软件版本信息不完整!";
  1080. }
  1081. //PCBA版本确认
  1082. if (HW_Version_Result.Contains(HW_Version_Check) == false)//PCBA版号错误,直接结束
  1083. {
  1084. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "PCBA版本错误" + "\r\n";
  1085. label_Step.Text = "PCBA版本错误,测试结束!";
  1086. label_Step.ForeColor = Color.Red;
  1087. button_Start.Enabled = true;
  1088. textBox_PDinfo.Enabled = true;
  1089. ErrorSaveLog();
  1090. //关机
  1091. Code[0] = 0xF0;
  1092. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1093. 开ToolStripMenuItem.Checked = false;
  1094. 关ToolStripMenuItem.Checked = true;
  1095. Delay_ms(500);
  1096. //关闭串口
  1097. portsettings_form.closePort();
  1098. return;
  1099. }
  1100. //主控软件版本检查
  1101. if (string.Equals(FW_Version_Check, FW_Version_Result) == false) //主控版本错误,直接结束
  1102. {
  1103. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "主控版本错误" + "\r\n";
  1104. label_Step.Text = "主控软件版本错误,测试结束!";
  1105. label_Step.ForeColor = Color.Red;
  1106. button_Start.Enabled = true;
  1107. textBox_PDinfo.Enabled = true;
  1108. ErrorSaveLog();
  1109. //关机
  1110. Code[0] = 0xF0;
  1111. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1112. 开ToolStripMenuItem.Checked = false;
  1113. 关ToolStripMenuItem.Checked = true;
  1114. Delay_ms(500);
  1115. //关闭串口
  1116. portsettings_form.closePort();
  1117. return;
  1118. }
  1119. else
  1120. {
  1121. //TE软件版本检查
  1122. if (TE_FW_Ver_Check != "N_A")//单MCU主控板不检测TE版本
  1123. {
  1124. if (string.Equals(TE_FW_Ver_Check, TE_FW_Ver_Result) == false) //TE版本错误,给出提示
  1125. {
  1126. if (MessageBox.Show("TE版本错误,请确认主控板是否为HK?", "TE版本错误", MessageBoxButtons.YesNo) == DialogResult.No)
  1127. {
  1128. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "TE版本错误" + "\r\n";
  1129. label_Step.Text = "TE软件版本错误,测试结束!";
  1130. label_Step.ForeColor = Color.Red;
  1131. button_Start.Enabled = true;
  1132. textBox_PDinfo.Enabled = true;
  1133. ErrorSaveLog();
  1134. //关机
  1135. Code[0] = 0xF0;
  1136. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1137. 开ToolStripMenuItem.Checked = false;
  1138. 关ToolStripMenuItem.Checked = true;
  1139. Delay_ms(500);
  1140. //关闭串口
  1141. portsettings_form.closePort();
  1142. return;
  1143. }
  1144. }
  1145. }
  1146. //型号和SN确认
  1147. try
  1148. {
  1149. string mode1 = "", mode2 = "";
  1150. mode1 = richTextBox_VerInfo.Lines[0].Split(':')[1].Trim();
  1151. mode2 = textBox_PDinfo.Text.Contains("%#") ? textBox_PDinfo.Text.Substring(0, textBox_PDinfo.Text.LastIndexOf('%'))
  1152. : textBox_PDinfo.Text.Substring(0, textBox_PDinfo.Text.LastIndexOf(' ')).Trim();
  1153. if (string.Equals(mode1, mode2) == false)//型号不一致
  1154. {
  1155. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号错误" + "\r\n";
  1156. label_Step.Text = "型号不一致,测试结束!";
  1157. label_Step.ForeColor = Color.Red;
  1158. button_Start.Enabled = true;
  1159. textBox_PDinfo.Enabled = true;
  1160. ErrorSaveLog();
  1161. //关机
  1162. Code[0] = 0xF0;
  1163. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1164. 开ToolStripMenuItem.Checked = false;
  1165. 关ToolStripMenuItem.Checked = true;
  1166. Delay_ms(500);
  1167. //关闭串口
  1168. portsettings_form.closePort();
  1169. return;
  1170. }
  1171. string SN1 = "", SN2 = "";
  1172. SN1 = richTextBox_VerInfo.Lines[1].Split(':')[1].Trim();
  1173. SN2 = textBox_PDinfo.Text.Contains("%#") ? textBox_PDinfo.Text.Remove(0, textBox_PDinfo.Text.LastIndexOf('#') + 1)
  1174. : textBox_PDinfo.Text.Remove(0, textBox_PDinfo.Text.LastIndexOf(' ') + 1);
  1175. if (string.Equals(SN1, SN2) == false)//SN不一致
  1176. {
  1177. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN错误" + "\r\n";
  1178. label_Step.Text = "SN不一致,测试结束!";
  1179. label_Step.ForeColor = Color.Red;
  1180. button_Start.Enabled = true;
  1181. textBox_PDinfo.Enabled = true;
  1182. ErrorSaveLog();
  1183. //关机
  1184. Code[0] = 0xF0;
  1185. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1186. 开ToolStripMenuItem.Checked = false;
  1187. 关ToolStripMenuItem.Checked = true;
  1188. Delay_ms(500);
  1189. //关闭串口
  1190. portsettings_form.closePort();
  1191. return;
  1192. }
  1193. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息正确" + "\r\n";
  1194. }
  1195. catch (Exception)
  1196. {
  1197. label_Step.Text = "电机信息错误,测试结束!";
  1198. label_Step.ForeColor = Color.Red;
  1199. button_Start.Enabled = true;
  1200. textBox_PDinfo.Enabled = true;
  1201. ErrorSaveLog();
  1202. //关机
  1203. Code[0] = 0xF0;
  1204. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1205. 开ToolStripMenuItem.Checked = false;
  1206. 关ToolStripMenuItem.Checked = true;
  1207. Delay_ms(500);
  1208. //关闭串口
  1209. portsettings_form.closePort();
  1210. return;
  1211. }
  1212. }
  1213. #endregion
  1214. #region 判断力矩传感器的标定值是否在允许范围内
  1215. label_Step.Text = "判断力矩传感器";
  1216. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令查询力矩传感器" + "\r\n";
  1217. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2000, null);//单传感器零点
  1218. Delay_ms(200);
  1219. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2900, null);//单传感器校正信息
  1220. Delay_ms(200);
  1221. Code[0] = 1;
  1222. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3201, Code);//传感器1零点
  1223. Delay_ms(200);
  1224. Code[0] = 2;
  1225. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3201, Code);//传感器2零点
  1226. Delay_ms(200);
  1227. Code[0] = 3;
  1228. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3201, Code);//传感器3零点
  1229. Delay_ms(200);
  1230. Code[0] = 1;
  1231. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3301, Code);//传感器1校正系数
  1232. Delay_ms(200);
  1233. Code[0] = 2;
  1234. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3301, Code);//传感器2校正系数
  1235. Delay_ms(200);
  1236. Code[0] = 3;
  1237. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3301, Code);//传感器3校正系数
  1238. Delay_ms(200);
  1239. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3500, null);//三传感器启动值
  1240. Delay_ms(200);
  1241. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "判断力矩传感器" + "\r\n";
  1242. for (int i = 0; i < richTextBox_TQ.Lines.Length; i++)
  1243. {
  1244. switch (richTextBox_TQ.Lines[i].Split(':')[0])
  1245. {
  1246. case "零点": case "传感器1零点": case "传感器2零点": case "传感器3零点":
  1247. {
  1248. string[] zero = richTextBox_TQ.Lines[i].Split(':')[1].Split(new string[] { ", " }, StringSplitOptions.None);
  1249. for (int j = 0; j < zero.Length; j++)
  1250. {
  1251. if ((Convert.ToUInt16(zero[j]) > TorqueCheck.Zero_Max) || (Convert.ToUInt16(zero[j]) < TorqueCheck.Zero_Min))//零点超差
  1252. {
  1253. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "传感器零点超范围" + "\r\n";
  1254. label_Step.Text = "传感器零点超范围,测试结束!";
  1255. label_Step.ForeColor = Color.Red;
  1256. button_Start.Enabled = true;
  1257. textBox_PDinfo.Enabled = true;
  1258. ErrorSaveLog();
  1259. //关机
  1260. Code[0] = 0xF0;
  1261. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1262. 开ToolStripMenuItem.Checked = false;
  1263. 关ToolStripMenuItem.Checked = true;
  1264. Delay_ms(500);
  1265. //关闭串口
  1266. portsettings_form.closePort();
  1267. return;
  1268. }
  1269. }
  1270. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + richTextBox_TQ.Lines[i].Split(':')[0] + "正常" + "\r\n";
  1271. break;
  1272. }
  1273. case "校正系数": case "传感器1校正系数": case "传感器2校正系数": case "传感器3校正系数":
  1274. {
  1275. ushort k = (ushort)(Convert.ToSingle(richTextBox_TQ.Lines[i].Split(':')[1]) * 100);
  1276. if ((k > (ushort)(TorqueCheck.Cal_K_Max * 100f)) || (k < (ushort)(TorqueCheck.Cal_K_Min * 100f)))//校正系数超差
  1277. {
  1278. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "校正系数超范围" + "\r\n";
  1279. label_Step.Text = "校正系数超范围,测试结束!";
  1280. label_Step.ForeColor = Color.Red;
  1281. button_Start.Enabled = true;
  1282. textBox_PDinfo.Enabled = true;
  1283. ErrorSaveLog();
  1284. //关机
  1285. Code[0] = 0xF0;
  1286. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1287. 开ToolStripMenuItem.Checked = false;
  1288. 关ToolStripMenuItem.Checked = true;
  1289. Delay_ms(500);
  1290. //关闭串口
  1291. portsettings_form.closePort();
  1292. return;
  1293. }
  1294. if (k == 100)
  1295. {
  1296. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "传感器未标定" + "\r\n";
  1297. label_Step.Text = "传感器未标定,测试结束!";
  1298. label_Step.ForeColor = Color.Red;
  1299. button_Start.Enabled = true;
  1300. textBox_PDinfo.Enabled = true;
  1301. ErrorSaveLog();
  1302. //关机
  1303. Code[0] = 0xF0;
  1304. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1305. 开ToolStripMenuItem.Checked = false;
  1306. 关ToolStripMenuItem.Checked = true;
  1307. Delay_ms(500);
  1308. //关闭串口
  1309. portsettings_form.closePort();
  1310. return;
  1311. }
  1312. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + richTextBox_TQ.Lines[i].Split(':')[0] + "正常" + "\r\n";
  1313. break;
  1314. }
  1315. case "校正系数标准差":
  1316. {
  1317. double std = Convert.ToDouble(richTextBox_TQ.Lines[i].Split(':')[1]);
  1318. if (std > TorqueCheck.Cal_K_Sqrd)
  1319. {
  1320. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "校正系数差异大" + "\r\n";
  1321. label_Step.Text = "校正系数标准差超范围,测试结束!";
  1322. label_Step.ForeColor = Color.Red;
  1323. button_Start.Enabled = true;
  1324. textBox_PDinfo.Enabled = true;
  1325. ErrorSaveLog();
  1326. //关机
  1327. Code[0] = 0xF0;
  1328. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1329. 开ToolStripMenuItem.Checked = false;
  1330. 关ToolStripMenuItem.Checked = true;
  1331. Delay_ms(500);
  1332. //关闭串口
  1333. portsettings_form.closePort();
  1334. return;
  1335. }
  1336. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + richTextBox_TQ.Lines[i].Split(':')[0] + "正常" + "\r\n";
  1337. break;
  1338. }
  1339. case "启动值":
  1340. {
  1341. string start = richTextBox_TQ.Lines[i].Split(':')[1];
  1342. if ((Convert.ToUInt16(start) > TorqueCheck.Start_Max) || (Convert.ToUInt16(start) < TorqueCheck.Start_Min))//启动值超差
  1343. {
  1344. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "启动值超范围" + "\r\n";
  1345. label_Step.Text = "启动值超范围,测试结束!";
  1346. label_Step.ForeColor = Color.Red;
  1347. button_Start.Enabled = true;
  1348. textBox_PDinfo.Enabled = true;
  1349. ErrorSaveLog();
  1350. //关机
  1351. Code[0] = 0xF0;
  1352. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1353. 开ToolStripMenuItem.Checked = false;
  1354. 关ToolStripMenuItem.Checked = true;
  1355. Delay_ms(500);
  1356. //关闭串口
  1357. portsettings_form.closePort();
  1358. return;
  1359. }
  1360. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + richTextBox_TQ.Lines[i].Split(':')[0] + "正常" + "\r\n";
  1361. break;
  1362. }
  1363. default:break;
  1364. }
  1365. }
  1366. #endregion
  1367. #region 依次读取配置参数
  1368. label_Step.Text = "判断配置参数";
  1369. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令查询电机配置参数" + "\r\n";
  1370. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1A00, null);//用户参数1
  1371. Delay_ms(200);
  1372. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3000, null);//用户参数2
  1373. Delay_ms(200);
  1374. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1C00, null);//马达参数
  1375. Delay_ms(200);
  1376. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);//生产信息
  1377. Delay_ms(200);
  1378. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);//校验秘钥
  1379. Delay_ms(200);
  1380. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);//自定义1
  1381. Delay_ms(200);
  1382. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);//自定义2
  1383. Delay_ms(200);
  1384. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);//自定义3
  1385. Delay_ms(200);
  1386. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "判断配置参数" + "\r\n";
  1387. for (int line = 0; line < richTextBox_CfgFile.Lines.Length; line++)
  1388. {
  1389. try
  1390. {
  1391. if (richTextBox_ReadCfg.Lines[line].Equals(richTextBox_CfgFile.Lines[line]) == false)
  1392. {
  1393. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + richTextBox_CfgFile.Lines[line].Split(',')[0] + "错误" + "\r\n";
  1394. label_Step.Text = "检查配置参数失败,测试结束!";
  1395. label_Step.ForeColor = Color.Red;
  1396. button_Start.Enabled = true;
  1397. textBox_PDinfo.Enabled = true;
  1398. ErrorSaveLog();
  1399. //关机
  1400. Code[0] = 0xF0;
  1401. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1402. 开ToolStripMenuItem.Checked = false;
  1403. 关ToolStripMenuItem.Checked = true;
  1404. Delay_ms(500);
  1405. //关闭串口
  1406. portsettings_form.closePort();
  1407. return;
  1408. }
  1409. }
  1410. catch (System.Exception)
  1411. {
  1412. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "读取电机配置参数失败" + "\r\n";
  1413. label_Step.Text = "检查配置参数失败,测试结束!";
  1414. label_Step.ForeColor = Color.Red;
  1415. button_Start.Enabled = true;
  1416. textBox_PDinfo.Enabled = true;
  1417. ErrorSaveLog();
  1418. //关机
  1419. Code[0] = 0xF0;
  1420. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1421. 开ToolStripMenuItem.Checked = false;
  1422. 关ToolStripMenuItem.Checked = true;
  1423. Delay_ms(500);
  1424. //关闭串口
  1425. portsettings_form.closePort();
  1426. return;
  1427. }
  1428. }
  1429. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机配置参数正确" + "\r\n";
  1430. #endregion
  1431. //检查是否有故障
  1432. if (label_error_code.Text != "OK")
  1433. {
  1434. label_Step.Text = "电机存在故障!";
  1435. button_Start.Enabled = true;
  1436. textBox_PDinfo.Enabled = true;
  1437. //关机
  1438. Code[0] = 0xF0;
  1439. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1440. 开ToolStripMenuItem.Checked = false;
  1441. 关ToolStripMenuItem.Checked = true;
  1442. Delay_ms(500);
  1443. //关闭串口
  1444. portsettings_form.closePort();
  1445. //存储测试数据
  1446. ErrorSaveLog();
  1447. return;
  1448. }
  1449. #region 测试结束
  1450. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试结束" + "\r\n";
  1451. label_Step.Text = "测试结束!";
  1452. label_Step.ForeColor = Color.Green;
  1453. label_Result.Text = "合格";
  1454. label_Result.BackColor = Color.Green;
  1455. button_Start.Enabled = true;
  1456. textBox_PDinfo.Enabled = true;
  1457. //关机
  1458. Code[0] = 0xF0;
  1459. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1460. 开ToolStripMenuItem.Checked = false;
  1461. 关ToolStripMenuItem.Checked = true;
  1462. Delay_ms(500);
  1463. //关闭串口
  1464. portsettings_form.closePort();
  1465. //合格计数累加和存储
  1466. label_OK_Count.Text = (Convert.ToInt32(label_OK_Count.Text) + 1).ToString();
  1467. string cfg_file = System.IO.Directory.GetCurrentDirectory() + "\\CheckSerialNum";
  1468. StreamReader objReader = new StreamReader(cfg_file);
  1469. string sLine = "";
  1470. ArrayList arrText = new ArrayList();//创建一个动态数组
  1471. while (sLine != null)
  1472. {
  1473. sLine = objReader.ReadLine();
  1474. arrText.Add(sLine);
  1475. }
  1476. arrText.RemoveAt(arrText.Count - 1);
  1477. objReader.Close();
  1478. arrText[3] = label_OK_Count.Text;
  1479. using (StreamWriter file = new StreamWriter(cfg_file))
  1480. {
  1481. foreach (var entry in arrText)
  1482. {
  1483. file.WriteLine(entry);
  1484. }
  1485. }
  1486. #region 按照产品信息设置测试文件路径
  1487. string ResultPathName = textBox_PDinfo.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_");
  1488. if (System.IO.Directory.Exists(LogSavePath + "log\\" + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ResultPathName) == false)
  1489. System.IO.Directory.CreateDirectory(LogSavePath + "log\\" + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ResultPathName);
  1490. #endregion
  1491. //页面存储
  1492. Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
  1493. Graphics g = Graphics.FromImage(bit);
  1494. g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片
  1495. LogSaveFileName = LogSavePath + "log\\" + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ResultPathName + "\\测试记录" + ".png";
  1496. bit.Save(LogSaveFileName);
  1497. //测试页面上传服务器
  1498. if (StartForm.myFtp.IsNetConnected == true)
  1499. {
  1500. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  1501. if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/qcTest/log/", DateNow) == false)
  1502. {
  1503. StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/qcTest/log/" + DateNow);
  1504. }
  1505. if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/qcTest/log/", DateNow + "/" + ResultPathName) == false)
  1506. {
  1507. StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/qcTest/log/" + DateNow + "/" + ResultPathName);
  1508. }
  1509. bool result = StartForm.myFtp.UploadFile(LogSaveFileName, StartForm.myServerCfg.RootPath + "/qcTest/log/" + DateNow + "/" + ResultPathName);
  1510. if (result == true)
  1511. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  1512. }
  1513. //电机数据存储
  1514. LogSaveFileName = LogSavePath + "\\log\\" + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ResultPathName + "\\电机参数" + ".txt";
  1515. string fileInfo = "";
  1516. fileInfo += "检验记录:\r\n" + richTextBox_TestRecord.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  1517. fileInfo += "电机生产参数:\r\n";
  1518. fileInfo += richTextBox_CfgFile.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  1519. fileInfo += "电机版本信息查询:\r\n";
  1520. fileInfo += richTextBox_VerInfo.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  1521. fileInfo += "力矩传感器标定结果:\r\n";
  1522. fileInfo += richTextBox_TQ.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  1523. fileInfo += "电机参数查询:\r\n";
  1524. fileInfo += richTextBox_ReadCfg.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  1525. fileInfo += "电机故障码:\r\n";
  1526. fileInfo += label_error_code.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  1527. fileInfo += "测试结果:\r\n";
  1528. fileInfo += label_Result.Text.Replace("\n", "\r\n") + "\r\n\r\n";
  1529. System.IO.File.WriteAllText(LogSaveFileName, fileInfo);
  1530. //电机数据上传服务器
  1531. if (StartForm.myFtp.IsNetConnected == true)
  1532. {
  1533. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  1534. if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/qcTest/log/", DateNow) == false)
  1535. {
  1536. StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/qcTest/log/" + DateNow);
  1537. }
  1538. if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/qcTest/log/" + DateNow, ResultPathName) == false)
  1539. {
  1540. StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/qcTest/log/" + DateNow + "/" + ResultPathName);
  1541. }
  1542. bool result = StartForm.myFtp.UploadFile(LogSaveFileName, StartForm.myServerCfg.RootPath + "/qcTest/log/" + DateNow + "/" + ResultPathName);
  1543. if (result == true)
  1544. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机数据上传服务器成功" + "\r\n";
  1545. }
  1546. #endregion
  1547. //测试正常,清空扫码信息
  1548. Delay_ms(1000);
  1549. textBox_PDinfo.Text = "";
  1550. }
  1551. private void CheckForm_Load(object sender, EventArgs e)
  1552. {
  1553. timer1.Enabled = true;
  1554. timer2.Enabled = true;
  1555. //显示测试员信息
  1556. label_TestUser.Text = "测试员:" + StartForm.EnterForm1.comboBox_User.Text;
  1557. //窗口加载时,从FTP服务器或本地获取文件日期列表
  1558. GetDateList(false);
  1559. //装载序列号文件
  1560. string cfg_file = System.IO.Directory.GetCurrentDirectory() + "\\CheckSerialNum";
  1561. StreamReader objReader = new StreamReader(cfg_file);
  1562. string sLine = "";
  1563. ArrayList arrText = new ArrayList();//创建一个动态数组
  1564. while (sLine != null)
  1565. {
  1566. sLine = objReader.ReadLine();
  1567. arrText.Add(sLine);
  1568. }
  1569. objReader.Close();
  1570. label_SerialNum.Text = arrText[1].ToString();//流水号
  1571. label_OK_Count.Text = arrText[3].ToString();//合格计数
  1572. }
  1573. //测试失败存储测试界面
  1574. private void ErrorSaveLog()
  1575. {
  1576. //页面存储
  1577. Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
  1578. Graphics g = Graphics.FromImage(bit);
  1579. g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片
  1580. string LogSaveFileName = LogSavePath + "errorlog\\" + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\";
  1581. if (System.IO.Directory.Exists(LogSaveFileName) == false)
  1582. System.IO.Directory.CreateDirectory(LogSaveFileName);
  1583. LogSaveFileName += textBox_PDinfo.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_测试记录" + ".png";
  1584. bit.Save(LogSaveFileName);
  1585. //测试页面上传服务器
  1586. if (StartForm.myFtp.IsNetConnected == true)
  1587. {
  1588. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  1589. if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/qcTest/errorlog/", DateNow) == false)
  1590. {
  1591. StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/qcTest/errorlog/" + DateNow);
  1592. }
  1593. bool result = StartForm.myFtp.UploadFile(LogSaveFileName, StartForm.myServerCfg.RootPath + "/qcTest/errorlog/" + DateNow);
  1594. if (result == true)
  1595. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试异常页面上传服务器成功" + "\r\n";
  1596. }
  1597. }
  1598. //开始测试按钮点击
  1599. private void button_Start_Click(object sender, EventArgs e)
  1600. {
  1601. TestStart();
  1602. }
  1603. //开始一次测试
  1604. private void TestStart()
  1605. {
  1606. //显示数据清空
  1607. richTextBox_ReadCfg.Text = "";
  1608. richTextBox_TestRecord.Text = "";
  1609. richTextBox_TQ.Text = "";
  1610. richTextBox_VerInfo.Text = "";
  1611. //Boot版本标志复位
  1612. IsBootVerOK = false;
  1613. #region 检查配置文件
  1614. if (comboBox_File.Items.Count == 0) //配置文件目录为空
  1615. {
  1616. label_Step.Text = "无可用配置文件!";
  1617. label_Step.ForeColor = Color.Red;
  1618. return;
  1619. }
  1620. if (comboBox_File.Text.Trim().Length == 0)//未选择配置文件
  1621. {
  1622. label_Step.Text = "请选择配置文件!";
  1623. label_Step.ForeColor = Color.Red;
  1624. return;
  1625. }
  1626. #endregion
  1627. #region 检查产品信息是否符合格式要求
  1628. try
  1629. {
  1630. 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]?$");
  1631. if (textBox_PDinfo.Text.Contains(" "))
  1632. {
  1633. string Mode = textBox_PDinfo.Text.Split(new string[] { " " }, StringSplitOptions.None)[0];
  1634. string Sn = textBox_PDinfo.Text.Split(new string[] { " " }, StringSplitOptions.None)[1];
  1635. if (regex.IsMatch(Sn) == false)
  1636. {
  1637. label_Step.Text = "SN格式错误!";
  1638. label_Step.ForeColor = Color.Red;
  1639. return;
  1640. }
  1641. }
  1642. else if (textBox_PDinfo.Text.Contains("%#"))
  1643. {
  1644. string Mode = textBox_PDinfo.Text.Split(new string[] { "%#" }, StringSplitOptions.None)[0];
  1645. string Sn = textBox_PDinfo.Text.Split(new string[] { "%#" }, StringSplitOptions.None)[1];
  1646. if (regex.IsMatch(Sn) == false)
  1647. {
  1648. label_Step.Text = "SN格式错误!";
  1649. label_Step.ForeColor = Color.Red;
  1650. return;
  1651. }
  1652. }
  1653. else
  1654. {
  1655. label_Step.Text = "标签格式错误!";
  1656. label_Step.ForeColor = Color.Red;
  1657. return;
  1658. }
  1659. }
  1660. catch (System.Exception)
  1661. {
  1662. label_Step.Text = "标签格式错误!";
  1663. label_Step.ForeColor = Color.Red;
  1664. return;
  1665. }
  1666. #endregion
  1667. #region 检查产品型号和配置文件是否一致
  1668. do
  1669. {
  1670. string cfg_mode = "", pd_mode = "";
  1671. cfg_mode = comboBox_File.Text.Split('_')[0];
  1672. if (textBox_PDinfo.Text.Contains(" "))
  1673. {
  1674. pd_mode = textBox_PDinfo.Text.Split(new string[] { " " }, StringSplitOptions.None)[0];
  1675. }
  1676. else if (textBox_PDinfo.Text.Contains("%#"))
  1677. {
  1678. pd_mode = textBox_PDinfo.Text.Split(new string[] { "%#" }, StringSplitOptions.None)[0];
  1679. }
  1680. if (pd_mode != cfg_mode)
  1681. {
  1682. label_Step.Text = "打标信息与配置文件不一致!";
  1683. label_Step.ForeColor = Color.Red;
  1684. return;
  1685. }
  1686. } while (false);
  1687. #endregion
  1688. //连接串口
  1689. if (portsettings_form.openPort() == false)
  1690. {
  1691. label_Step.Text = "串口连接失败!";
  1692. label_Step.ForeColor = Color.Red;
  1693. return;
  1694. }
  1695. //测试状态更新
  1696. label_Step.Text = "准备开始测试";
  1697. label_Step.ForeColor = Color.Red;
  1698. //流水号累加和存储
  1699. label_SerialNum.Text = (Convert.ToInt32(label_SerialNum.Text) + 1).ToString();
  1700. string cfg_file = System.IO.Directory.GetCurrentDirectory() + "\\CheckSerialNum";
  1701. StreamReader objReader = new StreamReader(cfg_file);
  1702. string sLine = "";
  1703. ArrayList arrText = new ArrayList();//创建一个动态数组
  1704. while (sLine != null)
  1705. {
  1706. sLine = objReader.ReadLine();
  1707. arrText.Add(sLine);
  1708. }
  1709. arrText.RemoveAt(arrText.Count - 1);
  1710. objReader.Close();
  1711. arrText[1] = label_SerialNum.Text;
  1712. using (StreamWriter file = new StreamWriter(cfg_file))
  1713. {
  1714. foreach (var entry in arrText)
  1715. {
  1716. file.WriteLine(entry);
  1717. }
  1718. }
  1719. button_Start.Enabled = false;
  1720. textBox_PDinfo.Enabled = false;
  1721. //创建线程,执行测试任务
  1722. Thread th = new Thread(Thread_Task);
  1723. th.Start();
  1724. }
  1725. //双击清零流水号
  1726. private void label32_DoubleClick(object sender, EventArgs e)
  1727. {
  1728. StartForm.EnterForm1.ShowDialog();
  1729. try
  1730. {
  1731. if (StartForm.EnterForm1.textBox_Passwd.Text == StartForm.EnterForm1.UserAccount[StartForm.EnterForm1.comboBox_User.Text])
  1732. {
  1733. if (StartForm.EnterForm1.comboBox_User.Text == "工程Engineer")
  1734. {
  1735. //流水号清零
  1736. if (MessageBox.Show("流水号清零", "确认清零?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1737. {
  1738. label_SerialNum.Text = "0";
  1739. label_OK_Count.Text = "0";
  1740. //存储
  1741. string cfg_file = System.IO.Directory.GetCurrentDirectory() + "\\CheckSerialNum";
  1742. StreamReader objReader = new StreamReader(cfg_file);
  1743. string sLine = "";
  1744. ArrayList arrText = new ArrayList();//创建一个动态数组
  1745. while (sLine != null)
  1746. {
  1747. sLine = objReader.ReadLine();
  1748. arrText.Add(sLine);
  1749. }
  1750. arrText.RemoveAt(arrText.Count - 1);
  1751. objReader.Close();
  1752. arrText[1] = label_SerialNum.Text;
  1753. arrText[3] = label_OK_Count.Text;
  1754. using (StreamWriter file = new StreamWriter(cfg_file))
  1755. {
  1756. foreach (var entry in arrText)
  1757. {
  1758. file.WriteLine(entry);
  1759. }
  1760. }
  1761. }
  1762. }
  1763. else
  1764. {
  1765. MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1766. }
  1767. }
  1768. else
  1769. {
  1770. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1771. }
  1772. }
  1773. catch (Exception)
  1774. {
  1775. MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1776. }
  1777. }
  1778. private void textBox_PDinfo_KeyUp(object sender, KeyEventArgs e)
  1779. {
  1780. if (e.KeyCode == Keys.Enter)
  1781. TestStart();
  1782. }
  1783. private void textBox_PDinfo_Click(object sender, EventArgs e)
  1784. {
  1785. textBox_PDinfo.SelectAll();
  1786. }
  1787. private void 屏幕键盘ToolStripMenuItem_Click_1(object sender, EventArgs e)
  1788. {
  1789. System.Diagnostics.Process.Start("osk.exe");
  1790. }
  1791. private void 端口设置ToolStripMenuItem_Click(object sender, EventArgs e)
  1792. {
  1793. portsettings_form.Show();
  1794. }
  1795. private void 合格ToolStripMenuItem_Click(object sender, EventArgs e)
  1796. {
  1797. System.Diagnostics.Process.Start("explorer.exe", LogSavePath + "log\\");
  1798. }
  1799. private void 不合格ToolStripMenuItem_Click(object sender, EventArgs e)
  1800. {
  1801. System.Diagnostics.Process.Start("explorer.exe", LogSavePath + "errorlog\\");
  1802. }
  1803. private void CheckForm_FormClosing(object sender, FormClosingEventArgs e)
  1804. {
  1805. portsettings_form.serialPort1.Close();
  1806. portsettings_form.comboBox_ComIndex.Enabled = true;
  1807. portsettings_form.button_Enter.Text = "确认";
  1808. portsettings_form.g_blnIsOpen = false;
  1809. #if false
  1810. //针对工程和越南账户,直接退出,不执行删除本地配置
  1811. if ((StartForm.EnterForm1.comboBox_User.Text == "越南Vietnam") || (StartForm.EnterForm1.comboBox_User.Text == "工程Engineer"))
  1812. {
  1813. return;
  1814. }
  1815. //关闭前,删除本地所有配置文件
  1816. string path = StartForm.UserPath + "\\cfg\\";
  1817. try
  1818. {
  1819. DirectoryInfo dir = new DirectoryInfo(path);
  1820. FileSystemInfo[] fileinfo = dir.GetFileSystemInfos(); //返回目录中所有文件和子目录
  1821. foreach (FileSystemInfo i in fileinfo)
  1822. {
  1823. if (i is DirectoryInfo) //判断是否文件夹
  1824. {
  1825. DirectoryInfo subdir = new DirectoryInfo(i.FullName);
  1826. subdir.Delete(true); //删除子目录和文件
  1827. }
  1828. else
  1829. {
  1830. File.Delete(i.FullName); //删除指定文件
  1831. }
  1832. }
  1833. //MessageBox.Show("文件清理成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1834. }
  1835. catch (Exception)
  1836. {
  1837. MessageBox.Show("文件清理失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1838. }
  1839. #endif
  1840. }
  1841. private void 运行测试执行ToolStripMenuItem_Click(object sender, EventArgs e)
  1842. {
  1843. 运行测试执行ToolStripMenuItem.Checked = true;
  1844. 运行测试不执行ToolStripMenuItem.Checked = false;
  1845. }
  1846. private void 运行测试不执行ToolStripMenuItem_Click(object sender, EventArgs e)
  1847. {
  1848. 运行测试执行ToolStripMenuItem.Checked = false;
  1849. 运行测试不执行ToolStripMenuItem.Checked = true;
  1850. }
  1851. }
  1852. }