ImportForm.cs 132 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO.Ports;
  10. using System.Collections;
  11. using System.Threading;
  12. using System.Text.RegularExpressions;
  13. namespace MOTINOVA_Motor_Factory_Set
  14. {
  15. public partial class ImportForm : Form
  16. {
  17. #region 文件路径
  18. string LogSaveFileName = "";
  19. public string LogSavePath = "";
  20. public string LocalCfgFilePath = "";
  21. #endregion
  22. #region 测试参数配置
  23. //以下值在根据电机测试的配置文件中更改
  24. ushort MotorRadeSpeed = 1200; //空载转速
  25. ushort RateCadence = 120; //最高踏频
  26. ushort RateVoltage = 36000; //额定电压
  27. bool GasModeTest = true; //转把模式检测开关
  28. bool SpeedSensorTest = true; //速度传感器检测开关
  29. //以下值在软件测试文件params.cfg文件中修改
  30. ushort No_load_Current = 1000; //空载电流
  31. ushort SpeedSensorThData = 60; //车速传感器判断阈值
  32. ushort GasModeSpeed = 1200; //指拨模式测试转速
  33. #endregion
  34. #region 配置文件信息
  35. ArrayList array_CfgInfo = new ArrayList();
  36. #endregion
  37. #region 端口设置界面
  38. public static PortSettings portsettings_form = new PortSettings();
  39. #endregion
  40. #region 串口缓存
  41. public static List<byte> buffer = new List<byte>(4096);
  42. private byte[] binary_data_1 = new byte[1024];
  43. #endregion
  44. #region MC运行信息超时计数
  45. bool MC_RunInfo_Refresh = false;
  46. ushort MC_RunInfo_Refresh_Cnt = 0;
  47. #endregion
  48. #region MC故障码超时计数
  49. bool MC_ErrorCode_Refresh = false;
  50. ushort MC_ErrorCode_Refresh_Cnt = 0;
  51. #endregion
  52. #region 执行步骤
  53. public enum TestStep_Enum
  54. {
  55. Step_Init = 0,
  56. Step_SysClear = 1, //系统清除
  57. Step_Write = 2, //参数写入
  58. Step_Light = 3, //灯电压测试
  59. Step_Walk = 4, //推行测试
  60. Step_GasMode = 5, //转把测试
  61. Step_CheckVer = 6, //版本查询和确认
  62. Step_Save = 7 //数据读取和存储
  63. }
  64. TestStep_Enum TestStep;
  65. #endregion
  66. #region 反馈指令判断计时
  67. bool Ack_Flag = true;
  68. ushort Ack_Cnt = 0;
  69. #endregion
  70. #region 单步测试标志
  71. public enum StepTestResult_Enum
  72. {
  73. StepTestResult_Ready = 0,
  74. StepTestResult_Testing = 1,
  75. StepTestResult_OK = 2,
  76. StepTestResult_Fail = 3
  77. }
  78. StepTestResult_Enum StepTestFlag = StepTestResult_Enum.StepTestResult_Ready;
  79. #endregion
  80. #region 推行/转把测试计时
  81. ushort WalkProcess_Cnt = 0;
  82. ushort OK_cnt = 0;
  83. #endregion
  84. public ImportForm()
  85. {
  86. InitializeComponent();
  87. System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
  88. //加载用户路径
  89. LogSavePath = StartForm.UserPath;
  90. LocalCfgFilePath = StartForm.UserPath;
  91. }
  92. #region 获取配置文件日期
  93. private void GetDateList(bool DisAll)
  94. {
  95. string[] DateList = { "" };
  96. if (checkBox_LocalFile.Checked == true)//从本地更新日期列表
  97. {
  98. DateList = System.IO.Directory.GetDirectories(LocalCfgFilePath);
  99. }
  100. else//从服务器更新日期列表
  101. {
  102. DateList = StartForm.myFtp.GetDirectoryList(StartForm.myServerCfg.RootPath + "/cfg");
  103. }
  104. comboBox_cfgFileDate.Items.Clear();
  105. //日期列表加载
  106. if (DisAll == true)
  107. {
  108. comboBox_cfgFileDate.Items.Add("显示近期");
  109. comboBox_cfgFileDate.Items.Add("---");
  110. foreach (var file in DateList)
  111. comboBox_cfgFileDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  112. }
  113. else
  114. {
  115. if (DateList.Length > 10)
  116. {
  117. comboBox_cfgFileDate.Items.Add("显示全部");
  118. comboBox_cfgFileDate.Items.Add("---");
  119. }
  120. for (int i = (DateList.Length > 10) ? (DateList.Length - 10) : 0; i < DateList.Length; i++)//显示最近10个日期
  121. comboBox_cfgFileDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
  122. }
  123. }
  124. #endregion
  125. #region 获取配置文件列表
  126. private void GetFileListFrom(string date)
  127. {
  128. string[] FileList = { "" };
  129. if (checkBox_LocalFile.Checked == true)//从本地更新文件列表
  130. {
  131. FileList = System.IO.Directory.GetFiles(LocalCfgFilePath + date);
  132. }
  133. else//从服务器更新文件列表
  134. {
  135. FileList = StartForm.myFtp.GetFileNameList(StartForm.myServerCfg.RootPath + "/cfg/" + date);
  136. }
  137. comboBox_File.Items.Clear();
  138. foreach (var file in FileList)
  139. {
  140. comboBox_File.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
  141. }
  142. }
  143. #endregion
  144. #region 选择文件日期后更新文件列表
  145. private void comboBox_cfgFileDate_SelectionChangeCommitted(object sender, EventArgs e)
  146. {
  147. if (comboBox_cfgFileDate.SelectedItem.ToString() == "显示全部")
  148. {
  149. GetDateList(true);
  150. }
  151. else if (comboBox_cfgFileDate.SelectedItem.ToString() == "显示近期")
  152. {
  153. GetDateList(false);
  154. }
  155. else
  156. {
  157. comboBox_File.Text = "";
  158. GetFileListFrom(comboBox_cfgFileDate.SelectedItem.ToString());
  159. }
  160. }
  161. #endregion
  162. #region 选择文件后加载文件
  163. private void comboBox_File_SelectionChangeCommitted(object sender, EventArgs e)
  164. {
  165. //清空原来数据
  166. array_CfgInfo.Clear();
  167. string SelectFile = "";
  168. if (checkBox_LocalFile.Checked == false)//非本地模式从服务器下载文件
  169. {
  170. SelectFile = comboBox_cfgFileDate.SelectedItem.ToString() + "\\" + comboBox_File.SelectedItem.ToString();
  171. if (!File.Exists(LocalCfgFilePath + SelectFile))//检查本地是否存在选定文件
  172. {
  173. SelectFile = comboBox_cfgFileDate.SelectedItem.ToString() + "/" + comboBox_File.SelectedItem.ToString();
  174. StartForm.myFtp.DownloadFile(StartForm.myServerCfg.RootPath + "/cfg/" + SelectFile, LocalCfgFilePath + comboBox_cfgFileDate.SelectedItem.ToString());
  175. }
  176. }
  177. SelectFile = comboBox_cfgFileDate.SelectedItem.ToString() + "\\" + comboBox_File.SelectedItem.ToString();
  178. //打开选中文件
  179. StreamReader objReader = new StreamReader(LocalCfgFilePath + SelectFile);
  180. string sLine = "";
  181. while (sLine != null)
  182. {
  183. sLine = objReader.ReadLine();
  184. array_CfgInfo.Add(sLine);
  185. }
  186. objReader.Close();
  187. //解析显示配置文件
  188. richTextBox_CfgFile.Text = "";
  189. try
  190. {
  191. foreach (string sOutput in array_CfgInfo)
  192. {
  193. richTextBox_CfgFile.AppendText(sOutput + "\r\n");
  194. }
  195. }
  196. catch (System.Exception)
  197. {
  198. return;
  199. }
  200. //更新推行模式测试判断标准
  201. MotorRadeSpeed = Convert.ToUInt16(array_CfgInfo[42].ToString().Split(',')[1]);
  202. //RateCadence = (ushort)(MotorRadeSpeed / 11U);
  203. RateVoltage = (ushort)(Convert.ToByte(array_CfgInfo[47].ToString().Split(',')[1]) * 1000);
  204. //更新指拨和速度传感器测试标志
  205. byte temp = Convert.ToByte(array_CfgInfo[25].ToString().Split(',')[1]);
  206. GasModeTest = temp == 0x55 ? false : temp == 0xAA ? true : false;
  207. temp = Convert.ToByte(array_CfgInfo[26].ToString().Split(',')[1]);
  208. SpeedSensorTest = temp == 0x55 || (temp == 0xAA ? false : temp == 0xEE ? false : false);
  209. //更新空载电流和车速传感器判断阈值
  210. if (array_CfgInfo.Count > 56)//旧版本无改配置项,采用默认值
  211. {
  212. No_load_Current = Convert.ToUInt16(array_CfgInfo[59].ToString().Split(',')[1]);
  213. SpeedSensorThData = Convert.ToUInt16(array_CfgInfo[60].ToString().Split(',')[1]);
  214. GasModeSpeed = Convert.ToUInt16(array_CfgInfo[61].ToString().Split(',')[1]);
  215. }
  216. }
  217. #endregion
  218. #region 修改获取文件方式,本地或服务器
  219. private void checkBox_LocalFile_CheckedChanged(object sender, EventArgs e)
  220. {
  221. comboBox_cfgFileDate.Text = "";
  222. comboBox_File.Text = "";
  223. richTextBox_CfgFile.Text = "";
  224. GetDateList(false);
  225. }
  226. #endregion
  227. private void ImportForm_Load(object sender, EventArgs e)
  228. {
  229. timer1.Enabled = true;
  230. timer2.Enabled = true;
  231. //装载配置文件
  232. GetDateList(false);
  233. //装载序列号文件
  234. string cfg_file = System.IO.Directory.GetCurrentDirectory() + "\\SerialNum";
  235. StreamReader objReader = new StreamReader(cfg_file);
  236. string sLine = "";
  237. ArrayList arrText = new ArrayList();//创建一个动态数组
  238. while (sLine != null)
  239. {
  240. sLine = objReader.ReadLine();
  241. arrText.Add(sLine);
  242. }
  243. objReader.Close();
  244. label_SerialNum.Text = arrText[1].ToString();//流水号
  245. }
  246. private void toolStripMenuIte_PortSet_Click(object sender, EventArgs e)
  247. {
  248. portsettings_form.Show();
  249. }
  250. #region CRC32校验
  251. static UInt32[] crc32_table = new UInt32[256]
  252. {
  253. 0x00000000, 0x04C11DB7, 0x09823B6E, 0x0D4326D9, 0x130476DC, 0x17C56B6B,
  254. 0x1A864DB2, 0x1E475005, 0x2608EDB8, 0x22C9F00F, 0x2F8AD6D6, 0x2B4BCB61,
  255. 0x350C9B64, 0x31CD86D3, 0x3C8EA00A, 0x384FBDBD, 0x4C11DB70, 0x48D0C6C7,
  256. 0x4593E01E, 0x4152FDA9, 0x5F15ADAC, 0x5BD4B01B, 0x569796C2, 0x52568B75,
  257. 0x6A1936C8, 0x6ED82B7F, 0x639B0DA6, 0x675A1011, 0x791D4014, 0x7DDC5DA3,
  258. 0x709F7B7A, 0x745E66CD, 0x9823B6E0, 0x9CE2AB57, 0x91A18D8E, 0x95609039,
  259. 0x8B27C03C, 0x8FE6DD8B, 0x82A5FB52, 0x8664E6E5, 0xBE2B5B58, 0xBAEA46EF,
  260. 0xB7A96036, 0xB3687D81, 0xAD2F2D84, 0xA9EE3033, 0xA4AD16EA, 0xA06C0B5D,
  261. 0xD4326D90, 0xD0F37027, 0xDDB056FE, 0xD9714B49, 0xC7361B4C, 0xC3F706FB,
  262. 0xCEB42022, 0xCA753D95, 0xF23A8028, 0xF6FB9D9F, 0xFBB8BB46, 0xFF79A6F1,
  263. 0xE13EF6F4, 0xE5FFEB43, 0xE8BCCD9A, 0xEC7DD02D, 0x34867077, 0x30476DC0,
  264. 0x3D044B19, 0x39C556AE, 0x278206AB, 0x23431B1C, 0x2E003DC5, 0x2AC12072,
  265. 0x128E9DCF, 0x164F8078, 0x1B0CA6A1, 0x1FCDBB16, 0x018AEB13, 0x054BF6A4,
  266. 0x0808D07D, 0x0CC9CDCA, 0x7897AB07, 0x7C56B6B0, 0x71159069, 0x75D48DDE,
  267. 0x6B93DDDB, 0x6F52C06C, 0x6211E6B5, 0x66D0FB02, 0x5E9F46BF, 0x5A5E5B08,
  268. 0x571D7DD1, 0x53DC6066, 0x4D9B3063, 0x495A2DD4, 0x44190B0D, 0x40D816BA,
  269. 0xACA5C697, 0xA864DB20, 0xA527FDF9, 0xA1E6E04E, 0xBFA1B04B, 0xBB60ADFC,
  270. 0xB6238B25, 0xB2E29692, 0x8AAD2B2F, 0x8E6C3698, 0x832F1041, 0x87EE0DF6,
  271. 0x99A95DF3, 0x9D684044, 0x902B669D, 0x94EA7B2A, 0xE0B41DE7, 0xE4750050,
  272. 0xE9362689, 0xEDF73B3E, 0xF3B06B3B, 0xF771768C, 0xFA325055, 0xFEF34DE2,
  273. 0xC6BCF05F, 0xC27DEDE8, 0xCF3ECB31, 0xCBFFD686, 0xD5B88683, 0xD1799B34,
  274. 0xDC3ABDED, 0xD8FBA05A, 0x690CE0EE, 0x6DCDFD59, 0x608EDB80, 0x644FC637,
  275. 0x7A089632, 0x7EC98B85, 0x738AAD5C, 0x774BB0EB, 0x4F040D56, 0x4BC510E1,
  276. 0x46863638, 0x42472B8F, 0x5C007B8A, 0x58C1663D, 0x558240E4, 0x51435D53,
  277. 0x251D3B9E, 0x21DC2629, 0x2C9F00F0, 0x285E1D47, 0x36194D42, 0x32D850F5,
  278. 0x3F9B762C, 0x3B5A6B9B, 0x0315D626, 0x07D4CB91, 0x0A97ED48, 0x0E56F0FF,
  279. 0x1011A0FA, 0x14D0BD4D, 0x19939B94, 0x1D528623, 0xF12F560E, 0xF5EE4BB9,
  280. 0xF8AD6D60, 0xFC6C70D7, 0xE22B20D2, 0xE6EA3D65, 0xEBA91BBC, 0xEF68060B,
  281. 0xD727BBB6, 0xD3E6A601, 0xDEA580D8, 0xDA649D6F, 0xC423CD6A, 0xC0E2D0DD,
  282. 0xCDA1F604, 0xC960EBB3, 0xBD3E8D7E, 0xB9FF90C9, 0xB4BCB610, 0xB07DABA7,
  283. 0xAE3AFBA2, 0xAAFBE615, 0xA7B8C0CC, 0xA379DD7B, 0x9B3660C6, 0x9FF77D71,
  284. 0x92B45BA8, 0x9675461F, 0x8832161A, 0x8CF30BAD, 0x81B02D74, 0x857130C3,
  285. 0x5D8A9099, 0x594B8D2E, 0x5408ABF7, 0x50C9B640, 0x4E8EE645, 0x4A4FFBF2,
  286. 0x470CDD2B, 0x43CDC09C, 0x7B827D21, 0x7F436096, 0x7200464F, 0x76C15BF8,
  287. 0x68860BFD, 0x6C47164A, 0x61043093, 0x65C52D24, 0x119B4BE9, 0x155A565E,
  288. 0x18197087, 0x1CD86D30, 0x029F3D35, 0x065E2082, 0x0B1D065B, 0x0FDC1BEC,
  289. 0x3793A651, 0x3352BBE6, 0x3E119D3F, 0x3AD08088, 0x2497D08D, 0x2056CD3A,
  290. 0x2D15EBE3, 0x29D4F654, 0xC5A92679, 0xC1683BCE, 0xCC2B1D17, 0xC8EA00A0,
  291. 0xD6AD50A5, 0xD26C4D12, 0xDF2F6BCB, 0xDBEE767C, 0xE3A1CBC1, 0xE760D676,
  292. 0xEA23F0AF, 0xEEE2ED18, 0xF0A5BD1D, 0xF464A0AA, 0xF9278673, 0xFDE69BC4,
  293. 0x89B8FD09, 0x8D79E0BE, 0x803AC667, 0x84FBDBD0, 0x9ABC8BD5, 0x9E7D9662,
  294. 0x933EB0BB, 0x97FFAD0C, 0xAFB010B1, 0xAB710D06, 0xA6322BDF, 0xA2F33668,
  295. 0xBCB4666D, 0xB8757BDA, 0xB5365D03, 0xB1F740B4
  296. };
  297. static UInt32 crc32_cal(byte[] pData, UInt16 Length)
  298. {
  299. UInt32 nReg;
  300. UInt32 nTemp = 0;
  301. UInt16 i, n;
  302. nReg = 0xFFFFFFFF;
  303. for (n = 0; n < Length; n++)
  304. {
  305. nReg ^= (UInt32)pData[n];
  306. for (i = 0; i < 4; i++)
  307. {
  308. nTemp = crc32_table[((nReg >> 24) & 0xFF)];
  309. nReg <<= 8;
  310. nReg ^= nTemp;
  311. }
  312. }
  313. return nReg;
  314. }
  315. #endregion
  316. #region 命令发送
  317. private void SendCmd(ushort ID, byte Mode, ushort Cmd, byte[] Data)
  318. {
  319. if (!portsettings_form.serialPort1.IsOpen)
  320. {
  321. MessageBox.Show("串口未连接");
  322. return;
  323. }
  324. ushort DataLength = (ushort)(Cmd & 0xFF);
  325. var SendCmdTmp = new byte[DataLength + 13];
  326. //帧头
  327. SendCmdTmp[0] = 0x55;
  328. SendCmdTmp[1] = 0xAA;
  329. //ID
  330. SendCmdTmp[2] = (byte)(ID >> 8);
  331. SendCmdTmp[3] = (byte)(ID & 0xFF);
  332. //MODE
  333. SendCmdTmp[4] = Mode;
  334. //长度
  335. SendCmdTmp[5] = (byte)((Cmd & 0xFF) + 2);
  336. //命令字
  337. SendCmdTmp[6] = (byte)(Cmd >> 8);
  338. SendCmdTmp[7] = (byte)(Cmd & 0xFF);
  339. //数据段
  340. for (UInt16 i = 0; i < (Cmd & 0xFF); i++)
  341. {
  342. SendCmdTmp[8 + i] = Data[i];
  343. }
  344. //校验
  345. UInt32 CRC_Result = crc32_cal(SendCmdTmp, (ushort)(DataLength + 8));
  346. SendCmdTmp[DataLength + 8] = Convert.ToByte(CRC_Result >> 24);
  347. SendCmdTmp[DataLength + 9] = Convert.ToByte((CRC_Result >> 16) % 256);
  348. SendCmdTmp[DataLength + 10] = Convert.ToByte((CRC_Result >> 8) % 256);
  349. SendCmdTmp[DataLength + 11] = Convert.ToByte(CRC_Result % 256);
  350. //帧尾
  351. SendCmdTmp[DataLength + 12] = 0xF0;
  352. //发送数据
  353. portsettings_form.serialPort1.Write(SendCmdTmp, 0, SendCmdTmp.Length);
  354. }
  355. #endregion
  356. #region 串口数据解析
  357. private void Serial_DataReceived_Process()
  358. {
  359. //串口解析
  360. byte DataNum = 0; //记录每条命令数据段的长度
  361. while (buffer.Count >= 13)//当buffer中的数据的个数大于等于4个时,即每一帧的数据长度所在位(第4位)出现时
  362. {
  363. if (buffer[0] == 0x55 && buffer[1] == 0xAA)//判断帧头
  364. {
  365. ushort PackageID;
  366. PackageID = (ushort)(buffer[2] * 256 + buffer[3]);
  367. if ((PackageID == 0x0710) || (PackageID == 0x0715) ||
  368. (PackageID == 0x0610) || (PackageID == 0x0615) ||
  369. (PackageID == 0x07FF) ||
  370. (PackageID == 0x0725) || (PackageID == 0x0720))
  371. {
  372. int CmdLen = buffer[5];
  373. if (buffer.Count < CmdLen + 11) break;//如果接收到的数据没有达到一帧数据的指定长度, 则执行下次循环
  374. buffer.RemoveRange(0, 6);//数据达到要求长度后删去帧头,ID,模式,和命令长度
  375. DataNum = (byte)(buffer[1]);//命令字的第二个字节的表示数据位的长度
  376. if (DataNum == (CmdLen - 2))
  377. {
  378. for (int i = 0; i < DataNum + 2; i++)
  379. {
  380. binary_data_1[i] = buffer[i];
  381. }
  382. if (TestStep == TestStep_Enum.Step_Save)
  383. {
  384. //数据存储
  385. var RecData = new byte[CmdLen];
  386. Array.Copy(binary_data_1, RecData, CmdLen);
  387. if ((PackageID == 0x0710) || (PackageID == 0x0715) ||
  388. (PackageID == 0x0610) || (PackageID == 0x0615) ||
  389. (PackageID == 0x07FF))
  390. {
  391. DataSave(RecData);
  392. }
  393. }
  394. DataCmdProcess(PackageID);//对于不同的命令段,做不同的处理
  395. }
  396. buffer.RemoveRange(0, CmdLen + 5);//解析完成
  397. }
  398. else
  399. {
  400. buffer.RemoveAt(0);//ID不对
  401. }
  402. }
  403. else
  404. {
  405. buffer.RemoveAt(0);//帧头不对,删除帧头高字节
  406. }
  407. }
  408. }
  409. #endregion
  410. #region 数据存储
  411. private void DataSave(byte[] Data)
  412. {
  413. string SaveData = "";
  414. //数据存储
  415. for (int i = 0; i < Data.Length; i++)
  416. {
  417. SaveData += Convert.ToString(Data[i], 16).PadLeft(2, '0').ToUpper() + " ";
  418. }
  419. SaveData += "\r\n";
  420. System.IO.File.AppendAllText(LogSaveFileName, SaveData);
  421. }
  422. #endregion
  423. //故障转换和显示
  424. List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
  425. "马达缺相","NTC故障","","","","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","电路故障","TE故障","TE电路故障","","","","","","","","","",
  426. "",""};
  427. private void ErrorInfoDisplay(UInt32 Code)
  428. {
  429. label_ErrorInfo.Text = "";
  430. if (Code == 0)
  431. {
  432. label_ErrorInfo.Text = "无故障";
  433. label_ErrorInfo.ForeColor = Color.Green;
  434. }
  435. else
  436. {
  437. label_ErrorInfo.ForeColor = Color.Red;
  438. for (int i = 0; i < 32; i++)
  439. {
  440. if ((Code & 0x01) == 0x01)
  441. {
  442. label_ErrorInfo.Text += ErrorInfo[i] + " ";
  443. }
  444. Code >>= 1;
  445. }
  446. }
  447. }
  448. #region 数据解析处理
  449. private void DataCmdProcess(ushort ID)
  450. {
  451. ushort CmdTemp = (ushort)(binary_data_1[0] * 256 + binary_data_1[1]);
  452. ushort DataTemp;
  453. #region 主控信息
  454. if ((ID == 0x715) || (ID == 0x710))
  455. {
  456. switch (CmdTemp)
  457. {
  458. case 0x1020://电机运行信息
  459. {
  460. unchecked
  461. {
  462. this.Invoke((EventHandler)(delegate
  463. {
  464. MC_RunInfo_Refresh = true;
  465. //车速
  466. DataTemp = (ushort)(binary_data_1[3] * 256 + binary_data_1[2]);
  467. textBox_BikeSpeed.Text = ((float)DataTemp / 10f).ToString("0.0");
  468. //输出转速
  469. DataTemp = (ushort)(binary_data_1[5] * 256 + binary_data_1[4]);
  470. textBox_MotorSpeed.Text = Convert.ToString(DataTemp);
  471. //母线电压
  472. DataTemp = (ushort)(binary_data_1[9] * 256 + binary_data_1[8]);
  473. textBox_Vol.Text = Convert.ToString(DataTemp);
  474. //母线电流
  475. DataTemp = (ushort)(binary_data_1[11] * 256 + binary_data_1[10]);
  476. textBox_Cur.Text = Convert.ToString(DataTemp);
  477. //踏频
  478. DataTemp = (ushort)(binary_data_1[12]);
  479. textBox_Cadence.Text = Convert.ToString(DataTemp);
  480. //踩踏力矩
  481. DataTemp = (ushort)(binary_data_1[13]);
  482. textBox_Torque.Text = Convert.ToString(DataTemp);
  483. //踩踏方向
  484. DataTemp = (ushort)(binary_data_1[14]);
  485. if (DataTemp == 0)
  486. {
  487. textBox_Dir.Text = "正向";
  488. }
  489. else if (DataTemp == 1)
  490. {
  491. textBox_Dir.Text = "反向";
  492. }
  493. else if (DataTemp == 2)
  494. {
  495. textBox_Dir.Text = "停止";
  496. }
  497. //PCB温度
  498. DataTemp = (ushort)(binary_data_1[23]);
  499. textBox_PCB.Text = Convert.ToString((int)(DataTemp - 40));
  500. //绕组温度
  501. DataTemp = (ushort)(binary_data_1[24]);
  502. textBox_Coil.Text = Convert.ToString((int)(DataTemp - 40));
  503. //MCU温度
  504. DataTemp = (ushort)(binary_data_1[25]);
  505. textBox_MCU.Text = Convert.ToString((int)(DataTemp - 40));
  506. }));
  507. }
  508. break;
  509. }
  510. case 0x1104://故障码
  511. {
  512. unchecked
  513. {
  514. this.Invoke((EventHandler)(delegate
  515. {
  516. MC_ErrorCode_Refresh = true;
  517. label_error_code.Text =
  518. Convert.ToString(binary_data_1[5], 16).PadLeft(2, '0').ToUpper() +
  519. Convert.ToString(binary_data_1[4], 16).PadLeft(2, '0').ToUpper() +
  520. Convert.ToString(binary_data_1[3], 16).PadLeft(2, '0').ToUpper() +
  521. Convert.ToString(binary_data_1[2], 16).PadLeft(2, '0').ToUpper() +
  522. "H";
  523. label_error_code.BackColor = Color.Red;
  524. UInt32 ErrorCode = (UInt32)((binary_data_1[5] << 24) + (binary_data_1[4] << 16) + (binary_data_1[3] << 8) + binary_data_1[2]);
  525. ErrorInfoDisplay(ErrorCode);
  526. }));
  527. }
  528. break;
  529. }
  530. case 0x1240://电机版本信息
  531. {
  532. unchecked
  533. {
  534. this.Invoke((EventHandler)(delegate
  535. {
  536. richTextBox_Ver.Text += "";
  537. //电机型号
  538. richTextBox_Ver.Text += "型号:";
  539. for (ushort i = 0; i < 16; i++)
  540. {
  541. if (binary_data_1[2 + i] == 0x2E)
  542. {
  543. break;
  544. }
  545. richTextBox_Ver.Text += ((char)binary_data_1[2 + i]).ToString();
  546. }
  547. richTextBox_Ver.Text += "\r\n";
  548. //电机SN
  549. richTextBox_Ver.Text += "序列号:";
  550. for (ushort i = 0; i < 16; i++)
  551. {
  552. if (binary_data_1[18 + i] == 0x2E)
  553. {
  554. break;
  555. }
  556. richTextBox_Ver.Text += ((char)binary_data_1[18 + i]).ToString();
  557. }
  558. richTextBox_Ver.Text += "\r\n";
  559. //电机HW
  560. richTextBox_Ver.Text += "硬件版本:";
  561. for (ushort i = 0; i < 10; i++)//前10位是PCB版号,以'.'结束
  562. {
  563. if (binary_data_1[34 + i] == 0x2E)
  564. {
  565. break;
  566. }
  567. if (binary_data_1[34 + i] == 'r')
  568. {
  569. binary_data_1[34 + i] = (byte)'.';
  570. }
  571. richTextBox_Ver.Text += ((char)binary_data_1[34 + i]).ToString();
  572. }
  573. switch (binary_data_1[34 + 10])//第10位代表MCU品牌
  574. {
  575. case (byte)'1':
  576. richTextBox_Ver.Text += " " + "ST" + " "; break;
  577. case (byte)'2':
  578. richTextBox_Ver.Text += " " + "APM" + " "; break;
  579. case (byte)'3':
  580. richTextBox_Ver.Text += " " + "HK" + " "; break;
  581. case (byte)'4':
  582. richTextBox_Ver.Text += " " + "GD" + " "; break;
  583. default:
  584. richTextBox_Ver.Text += " " + "NULL" + " "; break;
  585. }
  586. for (ushort i = 0; i < 4; i++)//后4位是MCU的ID校验码,用于识别板子的ID
  587. {
  588. richTextBox_Ver.Text += Convert.ToString(binary_data_1[46 + i], 16).PadLeft(2, '0').ToUpper();//MCU ID 的CRC32值
  589. }
  590. richTextBox_Ver.Text += "\r\n";
  591. //电机FW
  592. richTextBox_Ver.Text += "软件版本:";
  593. for (ushort i = 0; i < 16; i++)
  594. {
  595. if (binary_data_1[50 + i] == 0x2E)
  596. {
  597. break;
  598. }
  599. if (binary_data_1[50 + i] == 'r')
  600. {
  601. binary_data_1[50 + i] = (byte)'.';
  602. }
  603. richTextBox_Ver.Text += ((char)binary_data_1[50 + i]).ToString();
  604. }
  605. richTextBox_Ver.Text += "\r\n";
  606. }));
  607. }
  608. break;
  609. }
  610. case 0x1720://电机程序特性信息
  611. {
  612. unchecked
  613. {
  614. this.Invoke((EventHandler)(delegate
  615. {
  616. //程序特性
  617. for (ushort i = 0; i < 32; i++)
  618. {
  619. if (binary_data_1[2 + i] == 0x2E)
  620. {
  621. break;
  622. }
  623. if (binary_data_1[2 + i] == 'r')
  624. {
  625. binary_data_1[2 + i] = (byte)'.';
  626. }
  627. richTextBox_Ver.Text += ((char)binary_data_1[2 + i]).ToString();
  628. }
  629. richTextBox_Ver.Text += "\r\n";
  630. }));
  631. }
  632. break;
  633. }
  634. case 0xA903://反馈指令
  635. {
  636. unchecked
  637. {
  638. this.Invoke((EventHandler)(delegate
  639. {
  640. Ack_Flag = true;
  641. StepTestFlag = StepTestResult_Enum.StepTestResult_OK;
  642. }));
  643. }
  644. break;
  645. }
  646. default: break;
  647. }
  648. }
  649. #endregion
  650. #region TE
  651. else if ((ID == 0x615) || (ID == 0x610))
  652. {
  653. switch (CmdTemp)
  654. {
  655. case 0x1240://TE APP版本信息
  656. {
  657. unchecked
  658. {
  659. this.Invoke((EventHandler)(delegate
  660. {
  661. //TE 软件版本
  662. richTextBox_Ver.Text += "TE软件版本:";
  663. for (ushort i = 0; i < 16; i++)
  664. {
  665. if (binary_data_1[50 + i] == 0x2E)
  666. {
  667. break;
  668. }
  669. if (binary_data_1[50 + i] == 'r')
  670. {
  671. binary_data_1[50 + i] = (byte)'.';
  672. }
  673. richTextBox_Ver.Text += ((char)binary_data_1[50 + i]).ToString();
  674. }
  675. }));
  676. }
  677. break;
  678. }
  679. default: break;
  680. }
  681. }
  682. #endregion
  683. #region //电池信息
  684. else if ((ID == 0x725) || (ID == 0x720))
  685. {
  686. label_BMS_COM.BackColor = Color.Green;
  687. label_BMS_COM.Text = "OK";
  688. }
  689. #endregion
  690. }
  691. #endregion
  692. //20ms定时器
  693. private void timer1_Tick(object sender, EventArgs e)
  694. {
  695. //串口数据解析
  696. Serial_DataReceived_Process();
  697. }
  698. #region 非独占性延时函数
  699. public static void Delay_ms(int milliSecond)
  700. {
  701. int start = Environment.TickCount;
  702. while (Math.Abs(Environment.TickCount - start) < milliSecond)//毫秒
  703. {
  704. Application.DoEvents();
  705. }
  706. }
  707. #endregion
  708. //电机运行信息清除
  709. private void MC_RunInfo_Clear()
  710. {
  711. foreach (Control c in groupBox9.Controls)
  712. {
  713. if (c is TextBox)
  714. {
  715. c.Text = "---";
  716. }
  717. }
  718. }
  719. private void ImportForm_FormClosing(object sender, FormClosingEventArgs e)
  720. {
  721. portsettings_form.serialPort1.Close();
  722. portsettings_form.comboBox_ComIndex.Enabled = true;
  723. portsettings_form.button_Enter.Text = "确认";
  724. portsettings_form.g_blnIsOpen = false;
  725. }
  726. //开关灯
  727. private void LightProcess()
  728. {
  729. var CtrlCode = new byte[2];
  730. CtrlCode[0] = 0x00;
  731. if (button_LightCtl.Text == "开灯")
  732. {
  733. button_LightCtl.Text = "关灯";
  734. CtrlCode[1] = 0xF1;
  735. button_LightCtl.BackColor = Color.Yellow;
  736. button_LightCtl.ForeColor = Color.Black;
  737. }
  738. else
  739. {
  740. button_LightCtl.Text = "开灯";
  741. CtrlCode[1] = 0xF0;
  742. button_LightCtl.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
  743. button_LightCtl.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(113)))), ((int)(((byte)(185)))));
  744. }
  745. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  746. }
  747. //开关灯按钮
  748. private void button_LightCtl_Click(object sender, EventArgs e)
  749. {
  750. LightProcess();
  751. }
  752. //电机启动/停止控制
  753. private void Walk_Process(byte GearSt)
  754. {
  755. var Code = new byte[2];
  756. if (button_Walk.Text == "启动")
  757. {
  758. button_Walk.Text = "停止";
  759. //发送指令使电机进入配置模式
  760. Code[0] = 0x01;
  761. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  762. Thread.Sleep(200);
  763. //发送指令进入设定档位
  764. Code[0] = GearSt;
  765. if (button_LightCtl.Text == "关灯")
  766. Code[1] = 0xF1;
  767. else
  768. Code[1] = 0xF0;
  769. button_Walk.BackColor = Color.Yellow;
  770. button_Walk.ForeColor = Color.Black;
  771. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  772. }
  773. else
  774. {
  775. button_Walk.Text = "启动";
  776. //发送指令关闭档位模式
  777. Code[0] = 0x00;
  778. if (button_LightCtl.Text == "关灯")
  779. Code[1] = 0xF1;
  780. else
  781. Code[1] = 0xF0;
  782. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
  783. Thread.Sleep(200);
  784. //发送指令使电机退出配置模式
  785. Code[0] = 0x00;
  786. button_Walk.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
  787. button_Walk.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(113)))), ((int)(((byte)(185)))));
  788. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
  789. }
  790. }
  791. //电机启动/停止按钮
  792. private void button_Walk_Click(object sender, EventArgs e)
  793. {
  794. Walk_Process(0x22);
  795. }
  796. //查询版本信息
  797. private void button_Check_Ver_Click(object sender, EventArgs e)
  798. {
  799. richTextBox_Ver.Text = "";
  800. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  801. Delay_ms(200);
  802. SendCmd((ushort)0x651, (byte)0x11, (ushort)0x1200, null);
  803. }
  804. //按钮初始化
  805. private void label_Init()
  806. {
  807. radioButton_Light_OK.Checked = false;//灯电压确认按钮
  808. radioButton_Light_OK.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
  809. radioButton_Light_OK.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(113)))), ((int)(((byte)(185)))));
  810. radioButton_Light_NG.Checked = false;
  811. radioButton_Light_NG.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
  812. radioButton_Light_NG.ForeColor= System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(113)))), ((int)(((byte)(185)))));
  813. label_error_code.BackColor = Color.Green;//故障码
  814. label_error_code.Text = "OK";
  815. label_Sta_Clear.BackColor = Color.Red;//系统清除
  816. label_Sta_Clear.Text = "NG";
  817. label_Sta_Write.BackColor = Color.Red;//参数写入
  818. label_Sta_Write.Text = "NG";
  819. label_sta_light.BackColor = Color.Red;//灯电压
  820. label_sta_light.Text = "NG";
  821. label_sensor_vol.BackColor = Color.Red;//电压检测
  822. label_sensor_vol.Text = "NG";
  823. label_sensor_cur.BackColor = Color.Red;//电流检测
  824. label_sensor_cur.Text = "NG";
  825. label_sensor_speed.BackColor = Color.Red;//车速检测
  826. label_sensor_speed.Text = "NG";
  827. label_sensor_cadence.BackColor = Color.Red;//踏频检测
  828. label_sensor_cadence.Text = "NG";
  829. label_sensor_motor.BackColor = Color.Red;//电机转速检测
  830. label_sensor_motor.Text = "NG";
  831. label_sensor_PCB_temp.BackColor = Color.Red;//PCB温度检测
  832. label_sensor_PCB_temp.Text = "NG";
  833. label_sensor_coil_temp.BackColor = Color.Red;//绕组温度检测
  834. label_sensor_coil_temp.Text = "NG";
  835. label_sensor_MCU_temp.BackColor = Color.Red;//MCU温度检测
  836. label_sensor_MCU_temp.Text = "NG";
  837. label_Sensor_Break1.BackColor = Color.Red;//断电刹把
  838. label_Sensor_Break1.Text = "NG";
  839. label_Sensor_Break2.BackColor = Color.Red;//断电刹把
  840. label_Sensor_Break2.Text = "NG";
  841. label_Sensor_Gas.BackColor = Color.Red;//转把
  842. label_Sensor_Gas.Text = "NG";
  843. label_FW_Version.BackColor = Color.Red;//版本信息
  844. label_FW_Version.Text = "NG";
  845. label_BMS_COM.BackColor = Color.Red;//BMS通信
  846. label_BMS_COM.Text = "NG";
  847. label_Result.BackColor = Color.Red;//测试结果
  848. label_Result.Text = "不合格";
  849. richTextBox_Ver.Text = "";//版本信息
  850. richTextBox_TestRecord.Text = "";//测试过程记录
  851. }
  852. //测试失败存储测试界面
  853. private void ErrorSaveLog()
  854. {
  855. //页面存储
  856. Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
  857. Graphics g = Graphics.FromImage(bit);
  858. g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片
  859. LogSaveFileName = LogSavePath + "\\errorlog\\" + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\";
  860. if (System.IO.Directory.Exists(LogSaveFileName) == false)
  861. System.IO.Directory.CreateDirectory(LogSaveFileName);
  862. LogSaveFileName += textBox_PDinfo.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_测试记录" + ".png";
  863. bit.Save(LogSaveFileName);
  864. //测试页面上传服务器
  865. if (StartForm.myFtp.IsNetConnected == true)
  866. {
  867. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  868. if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/walkTest/errorlog/", DateNow) == false)
  869. {
  870. StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/walkTest/errorlog/" + DateNow);
  871. }
  872. bool result = StartForm.myFtp.UploadFile(LogSaveFileName, StartForm.myServerCfg.RootPath + "/walkTest/errorlog/" + DateNow);
  873. if (result == true)
  874. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试异常页面上传服务器成功" + "\r\n";
  875. }
  876. }
  877. //执行一次测试任务
  878. private void Thread_Task()
  879. {
  880. //开始测试
  881. richTextBox_TestRecord.Text += "电机信息:" + textBox_PDinfo.Text + "\r\n";
  882. richTextBox_TestRecord.Text += "配置文件:" + comboBox_File.Text + "\r\n";
  883. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n";
  884. //公有变量
  885. var Code = new byte[32];//发送的指令数据
  886. ushort DataTemp;
  887. short DataTemp_Int16;
  888. string ResultPathName = "";
  889. //开机
  890. Code[0] = 0xF1;
  891. SendCmd(0x7FF, 0x16, 0x2201, Code);
  892. 开ToolStripMenuItem.Checked = true;
  893. 关ToolStripMenuItem.Checked = false;
  894. Delay_ms(500);
  895. //检查是否有故障
  896. if (label_error_code.Text != "OK")
  897. {
  898. label_Step.Text = "电机存在故障!";
  899. button_Start.Enabled = true;
  900. //关机
  901. Code[0] = 0xF0;
  902. SendCmd(0x7FF, 0x16, 0x2201, Code);
  903. 开ToolStripMenuItem.Checked = false;
  904. 关ToolStripMenuItem.Checked = true;
  905. Delay_ms(500);
  906. //关闭串口
  907. portsettings_form.closePort();
  908. //存储测试数据
  909. ErrorSaveLog();
  910. return;
  911. }
  912. #region Step1:发送指令,系统清除
  913. if (系统清除执行ToolStripMenuItem.Checked == true)
  914. {
  915. TestStep = TestStep_Enum.Step_SysClear;
  916. label_Step.Text = "系统清除,请等待!";
  917. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送系统清除指令" + "\r\n";
  918. Array.Clear(Code, 0, 32);
  919. Code[0] = (byte)'C';
  920. Code[1] = (byte)'L';
  921. Code[2] = (byte)'E';
  922. Code[3] = (byte)'A';
  923. Code[4] = (byte)'R';
  924. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  925. Ack_Flag = false;
  926. Ack_Cnt = 0;
  927. StepTestFlag = StepTestResult_Enum.StepTestResult_Testing;
  928. while (StepTestFlag == StepTestResult_Enum.StepTestResult_Testing) ;//等待测试结束
  929. if (StepTestFlag == StepTestResult_Enum.StepTestResult_OK)//成功
  930. {
  931. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n";
  932. label_Sta_Clear.BackColor = Color.Green;
  933. label_Sta_Clear.Text = "OK";
  934. }
  935. else//失败
  936. {
  937. label_Step.Text = "系统清除失败,测试结束!";
  938. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除失败,测试结束" + "\r\n";
  939. button_Start.Enabled = true;
  940. //关机
  941. Code[0] = 0xF0;
  942. SendCmd(0x7FF, 0x16, 0x2201, Code);
  943. 开ToolStripMenuItem.Checked = false;
  944. 关ToolStripMenuItem.Checked = true;
  945. Delay_ms(500);
  946. //关闭串口
  947. portsettings_form.closePort();
  948. //存储测试数据
  949. ErrorSaveLog();
  950. return;
  951. }
  952. //系统清除完成后会重启,等待3s
  953. Delay_ms(2000);
  954. }
  955. else if (系统清除不执行ToolStripMenuItem.Checked == true)
  956. {
  957. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "不执行系统清除" + "\r\n";
  958. label_Sta_Clear.BackColor = Color.Yellow;
  959. label_Sta_Clear.Text = "N/A";
  960. }
  961. #endregion
  962. #region Step2:发送指令,依次写入参数
  963. TestStep = TestStep_Enum.Step_Write;
  964. label_Step.Text = "参数写入中,请等待!";
  965. #region Step2.1:写入电机型号和序列号
  966. string Mode = textBox_PDinfo.Text.Contains("%#") ? textBox_PDinfo.Text.Substring(0, textBox_PDinfo.Text.LastIndexOf('%'))
  967. : textBox_PDinfo.Text.Substring(0, textBox_PDinfo.Text.LastIndexOf(' ')).Trim();
  968. string SN = textBox_PDinfo.Text.Contains("%#") ? textBox_PDinfo.Text.Remove(0, textBox_PDinfo.Text.LastIndexOf('#') + 1)
  969. : textBox_PDinfo.Text.Remove(0, textBox_PDinfo.Text.LastIndexOf(' ') + 1);
  970. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入电机型号" + "\r\n";
  971. Array.Clear(Code, 0, 32);
  972. for (ushort i = 0; i < ((Mode.Length > 16) ? 16 : Mode.Length); i++)
  973. {
  974. Code[i] = (byte)Mode[i];
  975. }
  976. if (Mode.Length < 16)
  977. {
  978. Code[Mode.Length] = (byte)'.';
  979. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  980. {
  981. Code[Mode.Length + 1 + i] = 0x20;
  982. }
  983. }
  984. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, Code);
  985. Ack_Flag = false;
  986. Ack_Cnt = 0;
  987. StepTestFlag = StepTestResult_Enum.StepTestResult_Testing;
  988. while (StepTestFlag == StepTestResult_Enum.StepTestResult_Testing) ;//等待测试结束
  989. if (StepTestFlag == StepTestResult_Enum.StepTestResult_OK)//成功
  990. {
  991. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机型号写入成功" + "\r\n";
  992. }
  993. else//失败
  994. {
  995. label_Step.Text = "参数写入失败,测试结束!";
  996. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机型号写入失败,测试结束" + "\r\n";
  997. //关机
  998. Code[0] = 0xF0;
  999. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1000. 开ToolStripMenuItem.Checked = false;
  1001. 关ToolStripMenuItem.Checked = true;
  1002. button_Start.Enabled = true;
  1003. Delay_ms(500);
  1004. //关闭串口
  1005. portsettings_form.closePort();
  1006. //存储测试数据
  1007. ErrorSaveLog();
  1008. return;
  1009. }
  1010. Delay_ms(200);
  1011. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入电机序列号" + "\r\n";
  1012. Array.Clear(Code, 0, 32);
  1013. for (ushort i = 0; i < ((SN.Length > 16) ? 16 : SN.Length); i++)
  1014. {
  1015. Code[i] = (byte)SN[i];
  1016. }
  1017. if (SN.Length < 16)
  1018. {
  1019. Code[SN.Length] = (byte)'.';
  1020. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  1021. {
  1022. Code[SN.Length + 1 + i] = 0x20;
  1023. }
  1024. }
  1025. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, Code);
  1026. Ack_Flag = false;
  1027. Ack_Cnt = 0;
  1028. StepTestFlag = StepTestResult_Enum.StepTestResult_Testing;
  1029. while (StepTestFlag == StepTestResult_Enum.StepTestResult_Testing) ;//等待测试结束
  1030. if (StepTestFlag == StepTestResult_Enum.StepTestResult_OK)//成功
  1031. {
  1032. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机序列号写入成功" + "\r\n";
  1033. }
  1034. else//失败
  1035. {
  1036. label_Step.Text = "参数写入失败,测试结束!";
  1037. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机序列号写入失败,测试结束" + "\r\n";
  1038. //关机
  1039. Code[0] = 0xF0;
  1040. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1041. 开ToolStripMenuItem.Checked = false;
  1042. 关ToolStripMenuItem.Checked = true;
  1043. button_Start.Enabled = true;
  1044. Delay_ms(500);
  1045. //关闭串口
  1046. portsettings_form.closePort();
  1047. //存储测试数据
  1048. ErrorSaveLog();
  1049. return;
  1050. }
  1051. #endregion
  1052. #region Step2.2:写入用户参数1
  1053. Delay_ms(200);
  1054. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入用户参数1" + "\r\n";
  1055. Array.Clear(Code, 0, 32);
  1056. //指拨模式
  1057. Code[0] = Convert.ToByte(array_CfgInfo[25].ToString().Split(',')[1]);
  1058. //启动模式
  1059. Code[1] = Convert.ToByte(array_CfgInfo[1].ToString().Split(',')[1]);
  1060. //停机时间
  1061. DataTemp = Convert.ToUInt16(array_CfgInfo[2].ToString().Split(',')[1]);
  1062. Code[2] = (byte)(DataTemp & 0xFF);
  1063. Code[3] = (byte)(DataTemp >> 8);
  1064. //限速
  1065. Code[4] = Convert.ToByte(array_CfgInfo[3].ToString().Split(',')[1]);
  1066. //下降速度
  1067. Code[5] = Convert.ToByte(array_CfgInfo[4].ToString().Split(',')[1]);
  1068. //前飞
  1069. Code[6] = Convert.ToByte(array_CfgInfo[5].ToString().Split(',')[1]);
  1070. //后飞
  1071. Code[7] = Convert.ToByte(array_CfgInfo[6].ToString().Split(',')[1]);
  1072. //限流
  1073. Code[8] = Convert.ToByte(array_CfgInfo[7].ToString().Split(',')[1]);
  1074. //温度预警
  1075. Code[9] = (byte)(Convert.ToByte(array_CfgInfo[8].ToString().Split(',')[1]) + 40);
  1076. //温度保护
  1077. Code[10] = (byte)(Convert.ToByte(array_CfgInfo[9].ToString().Split(',')[1]) + 40);
  1078. //无PBU
  1079. Code[11] = Convert.ToByte(array_CfgInfo[10].ToString().Split(',')[1]);
  1080. //轮胎周长
  1081. Code[12] = Convert.ToByte(array_CfgInfo[11].ToString().Split(',')[1]);
  1082. //电机系列号
  1083. Code[13] = Convert.ToByte(array_CfgInfo[12].ToString().Split(',')[1]);
  1084. //ECO助力增益
  1085. Code[14] = Convert.ToByte(array_CfgInfo[13].ToString().Split(',')[1]);
  1086. //ECO加速
  1087. Code[15] = Convert.ToByte(array_CfgInfo[14].ToString().Split(',')[1]);
  1088. //NORM助力增益
  1089. Code[16] = Convert.ToByte(array_CfgInfo[15].ToString().Split(',')[1]);
  1090. //NORM加速
  1091. Code[17] = Convert.ToByte(array_CfgInfo[16].ToString().Split(',')[1]);
  1092. //SPORT助力增益
  1093. Code[18] = Convert.ToByte(array_CfgInfo[17].ToString().Split(',')[1]);
  1094. //SPORT加速
  1095. Code[19] = Convert.ToByte(array_CfgInfo[18].ToString().Split(',')[1]);
  1096. //TURBO助力增益
  1097. Code[20] = Convert.ToByte(array_CfgInfo[19].ToString().Split(',')[1]);
  1098. //TURBO加速
  1099. Code[21] = Convert.ToByte(array_CfgInfo[20].ToString().Split(',')[1]);
  1100. //SMART助力增益
  1101. Code[22] = Convert.ToByte(array_CfgInfo[21].ToString().Split(',')[1]);
  1102. //SMART加速
  1103. Code[23] = Convert.ToByte(array_CfgInfo[22].ToString().Split(',')[1]);
  1104. //速度传感器信号个数
  1105. Code[24] = Convert.ToByte(array_CfgInfo[23].ToString().Split(',')[1]);
  1106. //踏频启动信号个数
  1107. Code[25] = Convert.ToByte(array_CfgInfo[24].ToString().Split(',')[1]);
  1108. //速度传感器
  1109. Code[26] = Convert.ToByte(array_CfgInfo[26].ToString().Split(',')[1]);
  1110. //周长微调
  1111. Code[27] = (byte)Convert.ToInt16(array_CfgInfo[27].ToString().Split(',')[1]);
  1112. //低压保护阈值
  1113. DataTemp = Convert.ToUInt16(array_CfgInfo[28].ToString().Split(',')[1]);
  1114. Code[28] = (byte)(DataTemp & 0xFF);
  1115. Code[29] = (byte)(DataTemp >> 8);
  1116. //推行限速
  1117. DataTemp = Convert.ToByte(array_CfgInfo[29].ToString().Split(',')[1]);
  1118. Code[30] = (byte)Convert.ToByte(DataTemp);
  1119. //推行马达转速
  1120. Code[31] = (byte)Convert.ToByte(array_CfgInfo[30].ToString().Split(',')[1]);
  1121. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1B20, Code);
  1122. Ack_Flag = false;
  1123. Ack_Cnt = 0;
  1124. StepTestFlag = StepTestResult_Enum.StepTestResult_Testing;
  1125. while (StepTestFlag == StepTestResult_Enum.StepTestResult_Testing) ;//等待测试结束
  1126. if (StepTestFlag == StepTestResult_Enum.StepTestResult_OK)//成功
  1127. {
  1128. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "用户参数1写入成功" + "\r\n";
  1129. }
  1130. else//失败
  1131. {
  1132. label_Step.Text = "参数写入失败,测试结束!";
  1133. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "用户参数1写入失败,测试结束" + "\r\n";
  1134. //关机
  1135. Code[0] = 0xF0;
  1136. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1137. 开ToolStripMenuItem.Checked = false;
  1138. 关ToolStripMenuItem.Checked = true;
  1139. button_Start.Enabled = true;
  1140. Delay_ms(500);
  1141. //关闭串口
  1142. portsettings_form.closePort();
  1143. //存储测试数据
  1144. ErrorSaveLog();
  1145. return;
  1146. }
  1147. #endregion
  1148. #region Step2.3:写入用户参数2
  1149. Delay_ms(200);
  1150. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入用户参数2" + "\r\n";
  1151. Array.Clear(Code, 0, 32);
  1152. //俯仰角零偏
  1153. DataTemp_Int16 = (short)(decimal.Parse(array_CfgInfo[34].ToString().Split(',')[1]) * 10);
  1154. Code[0] = (byte)(DataTemp_Int16 & 0xFF);
  1155. Code[1] = (byte)(DataTemp_Int16 >> 8);
  1156. //横滚角零偏
  1157. DataTemp_Int16 = (short)(decimal.Parse(array_CfgInfo[35].ToString().Split(',')[1]) * 10);
  1158. Code[2] = (byte)(DataTemp_Int16 & 0xFF);
  1159. Code[3] = (byte)(DataTemp_Int16 >> 8);
  1160. //支持姿态传感器
  1161. Code[4] = Convert.ToByte(array_CfgInfo[33].ToString().Split(',')[1]);
  1162. //尾灯模式
  1163. Code[5] = Convert.ToByte(array_CfgInfo[36].ToString().Split(',')[1]);
  1164. //前灯电压
  1165. Code[6] = Convert.ToByte(array_CfgInfo[37].ToString().Split(',')[1]);
  1166. //后灯电压
  1167. Code[7] = Convert.ToByte(array_CfgInfo[38].ToString().Split(',')[1]);
  1168. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3120, Code);
  1169. Ack_Flag = false;
  1170. Ack_Cnt = 0;
  1171. StepTestFlag = StepTestResult_Enum.StepTestResult_Testing;
  1172. while (StepTestFlag == StepTestResult_Enum.StepTestResult_Testing) ;//等待测试结束
  1173. if (StepTestFlag == StepTestResult_Enum.StepTestResult_OK)//成功
  1174. {
  1175. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "用户参数2写入成功" + "\r\n";
  1176. }
  1177. else//失败
  1178. {
  1179. label_Step.Text = "参数写入失败,测试结束!";
  1180. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "用户参数2写入失败,测试结束" + "\r\n";
  1181. //关机
  1182. Code[0] = 0xF0;
  1183. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1184. 开ToolStripMenuItem.Checked = false;
  1185. 关ToolStripMenuItem.Checked = true;
  1186. button_Start.Enabled = true;
  1187. Delay_ms(500);
  1188. //关闭串口
  1189. portsettings_form.closePort();
  1190. //存储测试数据
  1191. ErrorSaveLog();
  1192. return;
  1193. }
  1194. #endregion
  1195. #region Step2.4:写入马达参数
  1196. Delay_ms(200);
  1197. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入马达参数" + "\r\n";
  1198. Array.Clear(Code, 0, 32);
  1199. //额定功率
  1200. DataTemp = Convert.ToUInt16(array_CfgInfo[41].ToString().Split(',')[1]);
  1201. Code[0] = (byte)(DataTemp & 0xFF);
  1202. Code[1] = (byte)(DataTemp >> 8);
  1203. //额定转速
  1204. DataTemp = Convert.ToUInt16(array_CfgInfo[42].ToString().Split(',')[1]);
  1205. Code[2] = (byte)(DataTemp & 0xFF);
  1206. Code[3] = (byte)(DataTemp >> 8);
  1207. //定子电阻
  1208. DataTemp = Convert.ToUInt16(array_CfgInfo[43].ToString().Split(',')[1]);
  1209. Code[4] = (byte)(DataTemp & 0xFF);
  1210. Code[5] = (byte)(DataTemp >> 8);
  1211. //Lq
  1212. DataTemp = Convert.ToUInt16(array_CfgInfo[44].ToString().Split(',')[1]);
  1213. Code[6] = (byte)(DataTemp & 0xFF);
  1214. Code[7] = (byte)(DataTemp >> 8);
  1215. //Ld
  1216. DataTemp = Convert.ToUInt16(array_CfgInfo[45].ToString().Split(',')[1]);
  1217. Code[8] = (byte)(DataTemp & 0xFF);
  1218. Code[9] = (byte)(DataTemp >> 8);
  1219. //反电动势
  1220. DataTemp = Convert.ToUInt16(array_CfgInfo[46].ToString().Split(',')[1]);
  1221. Code[10] = (byte)(DataTemp & 0xFF);
  1222. Code[11] = (byte)(DataTemp >> 8);
  1223. //额定电压
  1224. Code[12] = Convert.ToByte(array_CfgInfo[47].ToString().Split(',')[1]);
  1225. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1D10, Code);
  1226. Ack_Flag = false;
  1227. Ack_Cnt = 0;
  1228. StepTestFlag = StepTestResult_Enum.StepTestResult_Testing;
  1229. while (StepTestFlag == StepTestResult_Enum.StepTestResult_Testing) ;//等待测试结束
  1230. if (StepTestFlag == StepTestResult_Enum.StepTestResult_OK)//成功
  1231. {
  1232. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "马达参数写入成功" + "\r\n";
  1233. }
  1234. else//失败
  1235. {
  1236. label_Step.Text = "参数写入失败,测试结束!";
  1237. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "马达参数写入失败,测试结束" + "\r\n";
  1238. //关机
  1239. Code[0] = 0xF0;
  1240. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1241. 开ToolStripMenuItem.Checked = false;
  1242. 关ToolStripMenuItem.Checked = true;
  1243. button_Start.Enabled = true;
  1244. Delay_ms(500);
  1245. //关闭串口
  1246. portsettings_form.closePort();
  1247. //存储测试数据
  1248. ErrorSaveLog();
  1249. return;
  1250. }
  1251. #endregion
  1252. #region Step2.5:写入生产信息
  1253. Delay_ms(200);
  1254. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入生产信息" + "\r\n";
  1255. Array.Clear(Code, 0, 32);
  1256. string MAC_Info = array_CfgInfo[50].ToString().Split(',')[1];
  1257. for (ushort i = 0; i < ((MAC_Info.Length > 8) ? 8 : MAC_Info.Length); i++)
  1258. {
  1259. Code[i] = (byte)MAC_Info[i];
  1260. }
  1261. MAC_Info = array_CfgInfo[51].ToString().Split(',')[1];
  1262. for (ushort i = 0; i < ((MAC_Info.Length > 8) ? 8 : MAC_Info.Length); i++)
  1263. {
  1264. Code[8 + i] = (byte)MAC_Info[i];
  1265. }
  1266. MAC_Info = array_CfgInfo[52].ToString().Split(',')[1];
  1267. for (ushort i = 0; i < ((MAC_Info.Length > 8) ? 8 : MAC_Info.Length); i++)
  1268. {
  1269. Code[16 + i] = (byte)MAC_Info[i];
  1270. }
  1271. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, Code);
  1272. Ack_Flag = false;
  1273. Ack_Cnt = 0;
  1274. StepTestFlag = StepTestResult_Enum.StepTestResult_Testing;
  1275. while (StepTestFlag == StepTestResult_Enum.StepTestResult_Testing) ;//等待测试结束
  1276. if (StepTestFlag == StepTestResult_Enum.StepTestResult_OK)//成功
  1277. {
  1278. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "生产信息写入成功" + "\r\n";
  1279. }
  1280. else//失败
  1281. {
  1282. label_Step.Text = "参数写入失败,测试结束!";
  1283. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "生产信息写入失败,测试结束" + "\r\n";
  1284. //关机
  1285. Code[0] = 0xF0;
  1286. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1287. 开ToolStripMenuItem.Checked = false;
  1288. 关ToolStripMenuItem.Checked = true;
  1289. button_Start.Enabled = true;
  1290. Delay_ms(500);
  1291. //关闭串口
  1292. portsettings_form.closePort();
  1293. //存储测试数据
  1294. ErrorSaveLog();
  1295. return;
  1296. }
  1297. #endregion
  1298. #region Step2.6:写入校验密钥
  1299. Delay_ms(200);
  1300. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入校验密钥" + "\r\n";
  1301. Array.Clear(Code, 0, 32);
  1302. if (array_CfgInfo[53].ToString().EndsWith(",") == false)
  1303. {
  1304. string KeyString = array_CfgInfo[53].ToString().Split(',')[1];
  1305. for (ushort i = 0; i < ((KeyString.Length > 8) ? 8 : KeyString.Length); i++)
  1306. {
  1307. Code[i] = (byte)KeyString[i];
  1308. }
  1309. }
  1310. else
  1311. {
  1312. Code.Initialize();
  1313. }
  1314. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1108, Code);
  1315. Ack_Flag = false;
  1316. Ack_Cnt = 0;
  1317. StepTestFlag = StepTestResult_Enum.StepTestResult_Testing;
  1318. while (StepTestFlag == StepTestResult_Enum.StepTestResult_Testing) ;//等待测试结束
  1319. if (StepTestFlag == StepTestResult_Enum.StepTestResult_OK)//成功
  1320. {
  1321. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "校验密钥写入成功" + "\r\n";
  1322. }
  1323. else//失败
  1324. {
  1325. label_Step.Text = "参数写入失败,测试结束!";
  1326. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "校验密钥写入失败,测试结束" + "\r\n";
  1327. //关机
  1328. Code[0] = 0xF0;
  1329. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1330. 开ToolStripMenuItem.Checked = false;
  1331. 关ToolStripMenuItem.Checked = true;
  1332. button_Start.Enabled = true;
  1333. Delay_ms(500);
  1334. //关闭串口
  1335. portsettings_form.closePort();
  1336. //存储测试数据
  1337. ErrorSaveLog();
  1338. return;
  1339. }
  1340. #endregion
  1341. #region Step2.7:写入自定义信息1、2、3
  1342. //自定义信息1
  1343. Delay_ms(200);
  1344. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入自定义信息1" + "\r\n";
  1345. Array.Clear(Code, 0, 32);
  1346. if (array_CfgInfo[54].ToString().EndsWith(",") == false)
  1347. {
  1348. string UserInfo1String = array_CfgInfo[54].ToString().Split(',')[1];
  1349. for (ushort i = 0; i < (UserInfo1String.Length > 16 ? 16 : UserInfo1String.Length); i++)
  1350. {
  1351. Code[i] = (byte)UserInfo1String[i];
  1352. }
  1353. }
  1354. else
  1355. {
  1356. Array.Clear(Code, 0, 16);
  1357. }
  1358. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1410, Code);
  1359. Ack_Flag = false;
  1360. Ack_Cnt = 0;
  1361. StepTestFlag = StepTestResult_Enum.StepTestResult_Testing;
  1362. while (StepTestFlag == StepTestResult_Enum.StepTestResult_Testing) ;//等待测试结束
  1363. if (StepTestFlag == StepTestResult_Enum.StepTestResult_OK)//成功
  1364. {
  1365. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "自定义信息1写入成功" + "\r\n";
  1366. }
  1367. else//失败
  1368. {
  1369. label_Step.Text = "参数写入失败,测试结束!";
  1370. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "自定义信息1写入失败,测试结束" + "\r\n";
  1371. //关机
  1372. Code[0] = 0xF0;
  1373. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1374. 开ToolStripMenuItem.Checked = false;
  1375. 关ToolStripMenuItem.Checked = true;
  1376. button_Start.Enabled = true;
  1377. Delay_ms(500);
  1378. //关闭串口
  1379. portsettings_form.closePort();
  1380. //存储测试数据
  1381. ErrorSaveLog();
  1382. return;
  1383. }
  1384. //自定义信息2
  1385. Delay_ms(200);
  1386. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入自定义信息2" + "\r\n";
  1387. Array.Clear(Code, 0, 32);
  1388. if (array_CfgInfo[55].ToString().EndsWith(",") == false)
  1389. {
  1390. string UserInfo2String = array_CfgInfo[55].ToString().Split(',')[1];
  1391. for (ushort i = 0; i < (UserInfo2String.Length > 16 ? 16 : UserInfo2String.Length); i++)
  1392. {
  1393. Code[i] = (byte)UserInfo2String[i];
  1394. }
  1395. }
  1396. else
  1397. {
  1398. Array.Clear(Code, 0, 16);
  1399. }
  1400. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1610, Code);
  1401. Ack_Flag = false;
  1402. Ack_Cnt = 0;
  1403. StepTestFlag = StepTestResult_Enum.StepTestResult_Testing;
  1404. while (StepTestFlag == StepTestResult_Enum.StepTestResult_Testing) ;//等待测试结束
  1405. if (StepTestFlag == StepTestResult_Enum.StepTestResult_OK)//成功
  1406. {
  1407. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "自定义信息2写入成功" + "\r\n";
  1408. }
  1409. else//失败
  1410. {
  1411. label_Step.Text = "参数写入失败,测试结束!";
  1412. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "自定义信息2写入失败,测试结束" + "\r\n";
  1413. //关机
  1414. Code[0] = 0xF0;
  1415. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1416. 开ToolStripMenuItem.Checked = false;
  1417. 关ToolStripMenuItem.Checked = true;
  1418. button_Start.Enabled = true;
  1419. Delay_ms(500);
  1420. //关闭串口
  1421. portsettings_form.closePort();
  1422. //存储测试数据
  1423. ErrorSaveLog();
  1424. return;
  1425. }
  1426. //自定义信息3
  1427. Delay_ms(200);
  1428. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入自定义信息3" + "\r\n";
  1429. Array.Clear(Code, 0, 32);
  1430. if (array_CfgInfo[56].ToString().EndsWith(",") == false)
  1431. {
  1432. string UserInfo3String = array_CfgInfo[56].ToString().Split(',')[1];
  1433. for (ushort i = 0; i < (UserInfo3String.Length > 16 ? 16 : UserInfo3String.Length); i++)
  1434. {
  1435. Code[i] = (byte)UserInfo3String[i];
  1436. }
  1437. }
  1438. else
  1439. {
  1440. Array.Clear(Code, 0, 16);
  1441. }
  1442. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1810, Code);
  1443. Ack_Flag = false;
  1444. Ack_Cnt = 0;
  1445. StepTestFlag = StepTestResult_Enum.StepTestResult_Testing;
  1446. while (StepTestFlag == StepTestResult_Enum.StepTestResult_Testing) ;//等待测试结束
  1447. if (StepTestFlag == StepTestResult_Enum.StepTestResult_OK)//成功
  1448. {
  1449. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "自定义信息3写入成功" + "\r\n";
  1450. }
  1451. else//失败
  1452. {
  1453. label_Step.Text = "参数写入失败,测试结束!";
  1454. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "自定义信息3写入失败,测试结束" + "\r\n";
  1455. //关机
  1456. Code[0] = 0xF0;
  1457. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1458. 开ToolStripMenuItem.Checked = false;
  1459. 关ToolStripMenuItem.Checked = true;
  1460. button_Start.Enabled = true;
  1461. Delay_ms(500);
  1462. //关闭串口
  1463. portsettings_form.closePort();
  1464. //存储测试数据
  1465. ErrorSaveLog();
  1466. return;
  1467. }
  1468. #endregion
  1469. //参数写入完成
  1470. label_Sta_Write.BackColor = Color.Green;
  1471. label_Sta_Write.Text = "OK";
  1472. #endregion
  1473. if (推行测试执行ToolStripMenuItem.Checked == true)
  1474. {
  1475. #region Step3:灯电压测试
  1476. TestStep = TestStep_Enum.Step_Light;
  1477. label_Step.Text = "灯电压测试,请确认电压!";
  1478. button_LightCtl.Text = "开灯";
  1479. LightProcess();
  1480. radioButton_Light_OK.Checked = false;
  1481. radioButton_Light_OK.BackColor = Color.Green;
  1482. radioButton_Light_OK.ForeColor = Color.White;
  1483. radioButton_Light_OK.Enabled = true;
  1484. radioButton_Light_NG.Checked = false;
  1485. radioButton_Light_NG.Enabled = true;
  1486. radioButton_Light_NG.BackColor = Color.Red;
  1487. radioButton_Light_NG.ForeColor = Color.White;
  1488. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开灯指令,请确认灯电压是否正确……" + "\r\n";
  1489. while ((radioButton_Light_OK.Checked == false) && (radioButton_Light_NG.Checked == false)) ;
  1490. if (radioButton_Light_OK.Checked == true)
  1491. {
  1492. label_sta_light.BackColor = Color.Green;
  1493. radioButton_Light_NG.BackColor = Color.Gray;
  1494. label_sta_light.Text = "OK";
  1495. radioButton_Light_OK.Enabled = false;
  1496. radioButton_Light_NG.Enabled = false;
  1497. }
  1498. else if (radioButton_Light_NG.Checked == true)
  1499. {
  1500. label_sta_light.BackColor = Color.Red;
  1501. radioButton_Light_OK.BackColor = Color.Gray;
  1502. label_sta_light.Text = "NG";
  1503. label_Step.Text = "灯电压错误,测试结束!";
  1504. button_LightCtl.Text = "关灯";
  1505. LightProcess();
  1506. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "灯电压错误,测试结束" + "\r\n";
  1507. //关机
  1508. Code[0] = 0xF0;
  1509. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1510. 开ToolStripMenuItem.Checked = false;
  1511. 关ToolStripMenuItem.Checked = true;
  1512. button_Start.Enabled = true;
  1513. radioButton_Light_OK.Enabled = false;
  1514. radioButton_Light_NG.Enabled = false;
  1515. Delay_ms(500);
  1516. //关闭串口
  1517. portsettings_form.closePort();
  1518. //存储测试数据
  1519. ErrorSaveLog();
  1520. return;
  1521. }
  1522. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "灯电压确认完成" + "\r\n";
  1523. button_LightCtl.Text = "关灯";
  1524. LightProcess();
  1525. #endregion
  1526. #region Step4:推行测试
  1527. TestStep = TestStep_Enum.Step_Walk;
  1528. //判断母线电压
  1529. label_Step.Text = "母线电压检测!";
  1530. button_Walk.Text = "启动";
  1531. Walk_Process(0x00);
  1532. Delay_ms(500);
  1533. try
  1534. {
  1535. DataTemp = Convert.ToUInt16(textBox_Vol.Text);
  1536. }
  1537. catch (System.Exception ex)
  1538. {
  1539. MessageBox.Show(ex.Message);
  1540. label_Step.Text = "母线电压测试异常,测试结束!";
  1541. //关机
  1542. Code[0] = 0xF0;
  1543. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1544. 开ToolStripMenuItem.Checked = false;
  1545. 关ToolStripMenuItem.Checked = true;
  1546. button_Start.Enabled = true;
  1547. Delay_ms(500);
  1548. //关闭串口
  1549. portsettings_form.closePort();
  1550. //存储测试数据
  1551. ErrorSaveLog();
  1552. return;
  1553. }
  1554. if ((DataTemp > (RateVoltage - 1000)) && (DataTemp < (RateVoltage + 1000)))
  1555. {
  1556. if (label_sensor_vol.BackColor == Color.Red)
  1557. {
  1558. label_sensor_vol.BackColor = Color.Green;
  1559. label_sensor_vol.Text = "OK";
  1560. }
  1561. }
  1562. else
  1563. {
  1564. label_Step.Text = "母线电压异常,测试结束!";
  1565. //关机
  1566. Code[0] = 0xF0;
  1567. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1568. 开ToolStripMenuItem.Checked = false;
  1569. 关ToolStripMenuItem.Checked = true;
  1570. button_Start.Enabled = true;
  1571. Delay_ms(500);
  1572. //关闭串口
  1573. portsettings_form.closePort();
  1574. //存储测试数据
  1575. ErrorSaveLog();
  1576. return;
  1577. }
  1578. //传感器判断
  1579. label_Step.Text = "推行测试,电机开始自动运转!";
  1580. button_Walk.Text = "启动";
  1581. Walk_Process(0x22);
  1582. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机进入推行模式,请注意安全!" + "\r\n";
  1583. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "传感器自动检测开始" + "\r\n";
  1584. OK_cnt = 0;
  1585. WalkProcess_Cnt = 0;
  1586. while (WalkProcess_Cnt < 20)//开始判断传感器,超时20s
  1587. {
  1588. //车速传感器 1
  1589. if (SpeedSensorTest == false)
  1590. {
  1591. if (label_sensor_speed.BackColor == Color.Red)
  1592. {
  1593. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过车速传感器测试" + "\r\n";
  1594. label_sensor_speed.BackColor = Color.Green;
  1595. label_sensor_speed.Text = "OK";
  1596. OK_cnt++;
  1597. }
  1598. }
  1599. else
  1600. {
  1601. try
  1602. {
  1603. DataTemp = (ushort)(Convert.ToDecimal(textBox_BikeSpeed.Text) * 10);
  1604. }
  1605. catch (System.Exception ex)
  1606. {
  1607. MessageBox.Show(ex.Message);
  1608. label_Step.Text = "推行测试异常,测试结束!";
  1609. //关机
  1610. Code[0] = 0xF0;
  1611. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1612. 开ToolStripMenuItem.Checked = false;
  1613. 关ToolStripMenuItem.Checked = true;
  1614. button_Start.Enabled = true;
  1615. Delay_ms(500);
  1616. //关闭串口
  1617. portsettings_form.closePort();
  1618. //存储测试数据
  1619. ErrorSaveLog();
  1620. return;
  1621. }
  1622. if ((DataTemp > (SpeedSensorThData - 50)) && (DataTemp < (SpeedSensorThData + 50)))
  1623. {
  1624. if (label_sensor_speed.BackColor == Color.Red)
  1625. {
  1626. label_sensor_speed.BackColor = Color.Green;
  1627. label_sensor_speed.Text = "OK";
  1628. OK_cnt++;
  1629. }
  1630. }
  1631. }
  1632. //马达转速 2
  1633. try
  1634. {
  1635. DataTemp = Convert.ToUInt16(textBox_MotorSpeed.Text);
  1636. }
  1637. catch (System.Exception ex)
  1638. {
  1639. MessageBox.Show(ex.Message);
  1640. label_Step.Text = "推行测试异常,测试结束!";
  1641. //关机
  1642. Code[0] = 0xF0;
  1643. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1644. 开ToolStripMenuItem.Checked = false;
  1645. 关ToolStripMenuItem.Checked = true;
  1646. button_Start.Enabled = true;
  1647. Delay_ms(500);
  1648. //关闭串口
  1649. portsettings_form.closePort();
  1650. //存储测试数据
  1651. ErrorSaveLog();
  1652. return;
  1653. }
  1654. if ((DataTemp > (MotorRadeSpeed - 200)) && (DataTemp < (MotorRadeSpeed + 200)))
  1655. {
  1656. if (label_sensor_motor.BackColor == Color.Red)
  1657. {
  1658. label_sensor_motor.BackColor = Color.Green;
  1659. label_sensor_motor.Text = "OK";
  1660. OK_cnt++;
  1661. }
  1662. }
  1663. ////母线电压
  1664. //try
  1665. //{
  1666. // DataTemp = Convert.ToUInt16(textBox_Vol.Text);
  1667. //}
  1668. //catch (System.Exception ex)
  1669. //{
  1670. // MessageBox.Show(ex.Message);
  1671. // label_Step.Text = "推行测试异常,测试结束!";
  1672. // //关机
  1673. // Code[0] = 0xF0;
  1674. // SendCmd(0x7FF, 0x16, 0x2201, Code);
  1675. // 开ToolStripMenuItem.Checked = false;
  1676. // 关ToolStripMenuItem.Checked = true;
  1677. // button_Start.Enabled = true;
  1678. // Delay_ms(500);
  1679. // //关闭串口
  1680. // portsettings_form.closePort();
  1681. // //存储测试数据
  1682. // ErrorSaveLog();
  1683. // return;
  1684. //}
  1685. //if ((DataTemp > (RateVoltage - 1000)) && (DataTemp < (RateVoltage + 1000)))
  1686. //{
  1687. // if (label_sensor_vol.BackColor == Color.Red)
  1688. // {
  1689. // label_sensor_vol.BackColor = Color.Green;
  1690. // label_sensor_vol.Text = "OK";
  1691. // OK_cnt++;
  1692. // }
  1693. //}
  1694. //母线电流 3
  1695. try
  1696. {
  1697. DataTemp = Convert.ToUInt16(textBox_Cur.Text);
  1698. }
  1699. catch (System.Exception ex)
  1700. {
  1701. MessageBox.Show(ex.Message);
  1702. label_Step.Text = "推行测试异常,测试结束!";
  1703. //关机
  1704. Code[0] = 0xF0;
  1705. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1706. 开ToolStripMenuItem.Checked = false;
  1707. 关ToolStripMenuItem.Checked = true;
  1708. button_Start.Enabled = true;
  1709. Delay_ms(500);
  1710. //关闭串口
  1711. portsettings_form.closePort();
  1712. //存储测试数据
  1713. ErrorSaveLog();
  1714. return;
  1715. }
  1716. if ((DataTemp > No_load_Current - 500) && (DataTemp < No_load_Current + 500))
  1717. {
  1718. if (label_sensor_cur.BackColor == Color.Red)
  1719. {
  1720. label_sensor_cur.BackColor = Color.Green;
  1721. label_sensor_cur.Text = "OK";
  1722. OK_cnt++;
  1723. }
  1724. }
  1725. //踏频 4
  1726. try
  1727. {
  1728. DataTemp = Convert.ToUInt16(textBox_Cadence.Text);
  1729. }
  1730. catch (System.Exception ex)
  1731. {
  1732. MessageBox.Show(ex.Message);
  1733. label_Step.Text = "推行测试异常,测试结束!";
  1734. //关机
  1735. Code[0] = 0xF0;
  1736. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1737. 开ToolStripMenuItem.Checked = false;
  1738. 关ToolStripMenuItem.Checked = true;
  1739. button_Start.Enabled = true;
  1740. Delay_ms(500);
  1741. //关闭串口
  1742. portsettings_form.closePort();
  1743. //存储测试数据
  1744. ErrorSaveLog();
  1745. return;
  1746. }
  1747. if ((DataTemp > (RateCadence - 40)) && (DataTemp < (RateCadence + 40)))
  1748. {
  1749. if (label_sensor_cadence.BackColor == Color.Red)
  1750. {
  1751. label_sensor_cadence.BackColor = Color.Green;
  1752. label_sensor_cadence.Text = "OK";
  1753. OK_cnt++;
  1754. }
  1755. }
  1756. //PCB温度 5
  1757. try
  1758. {
  1759. DataTemp_Int16 = Convert.ToInt16(textBox_PCB.Text);
  1760. }
  1761. catch (System.Exception ex)
  1762. {
  1763. MessageBox.Show(ex.Message);
  1764. label_Step.Text = "推行测试异常,测试结束!";
  1765. //关机
  1766. Code[0] = 0xF0;
  1767. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1768. 开ToolStripMenuItem.Checked = false;
  1769. 关ToolStripMenuItem.Checked = true;
  1770. button_Start.Enabled = true;
  1771. Delay_ms(500);
  1772. //关闭串口
  1773. portsettings_form.closePort();
  1774. //存储测试数据
  1775. ErrorSaveLog();
  1776. return;
  1777. }
  1778. if ((DataTemp_Int16 > -20) && (DataTemp_Int16 < 60))
  1779. {
  1780. if (label_sensor_PCB_temp.BackColor == Color.Red)
  1781. {
  1782. label_sensor_PCB_temp.BackColor = Color.Green;
  1783. label_sensor_PCB_temp.Text = "OK";
  1784. OK_cnt++;
  1785. }
  1786. }
  1787. //绕组温度 6
  1788. try
  1789. {
  1790. DataTemp_Int16 = Convert.ToInt16(textBox_Coil.Text);
  1791. }
  1792. catch (System.Exception ex)
  1793. {
  1794. MessageBox.Show(ex.Message);
  1795. label_Step.Text = "推行测试异常,测试结束!";
  1796. //关机
  1797. Code[0] = 0xF0;
  1798. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1799. 开ToolStripMenuItem.Checked = false;
  1800. 关ToolStripMenuItem.Checked = true;
  1801. button_Start.Enabled = true;
  1802. Delay_ms(500);
  1803. //关闭串口
  1804. portsettings_form.closePort();
  1805. //存储测试数据
  1806. ErrorSaveLog();
  1807. return;
  1808. }
  1809. if ((DataTemp_Int16 > -20) && (DataTemp_Int16 < 60))
  1810. {
  1811. if (label_sensor_coil_temp.BackColor == Color.Red)
  1812. {
  1813. label_sensor_coil_temp.BackColor = Color.Green;
  1814. label_sensor_coil_temp.Text = "OK";
  1815. OK_cnt++;
  1816. }
  1817. }
  1818. //MCU温度 7
  1819. try
  1820. {
  1821. DataTemp_Int16 = Convert.ToInt16(textBox_MCU.Text);
  1822. }
  1823. catch (System.Exception ex)
  1824. {
  1825. MessageBox.Show(ex.Message);
  1826. label_Step.Text = "推行测试异常,测试结束!";
  1827. //关机
  1828. Code[0] = 0xF0;
  1829. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1830. 开ToolStripMenuItem.Checked = false;
  1831. 关ToolStripMenuItem.Checked = true;
  1832. button_Start.Enabled = true;
  1833. Delay_ms(500);
  1834. //关闭串口
  1835. portsettings_form.closePort();
  1836. //存储测试数据
  1837. ErrorSaveLog();
  1838. return;
  1839. }
  1840. if ((DataTemp_Int16 > -20) && (DataTemp_Int16 < 60))
  1841. {
  1842. if (label_sensor_MCU_temp.BackColor == Color.Red)
  1843. {
  1844. label_sensor_MCU_temp.BackColor = Color.Green;
  1845. label_sensor_MCU_temp.Text = "OK";
  1846. OK_cnt++;
  1847. }
  1848. }
  1849. //测试完成,退出
  1850. if (OK_cnt == 7)
  1851. {
  1852. break;
  1853. }
  1854. }
  1855. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "传感器自动检测结束" + "\r\n";
  1856. //断电开关1
  1857. label_Step.Text = "请在10s内捏下断电刹把 1!";
  1858. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "断电刹把 1 检测开始,请捏下断电刹把 1" + "\r\n";
  1859. WalkProcess_Cnt = 0;
  1860. while (WalkProcess_Cnt < 15)//10s内判断电机是否停止
  1861. {
  1862. try
  1863. {
  1864. DataTemp = Convert.ToUInt16(textBox_MotorSpeed.Text);
  1865. }
  1866. catch (System.Exception ex)
  1867. {
  1868. MessageBox.Show(ex.Message);
  1869. label_Step.Text = "推行测试异常,测试结束!";
  1870. //关机
  1871. Code[0] = 0xF0;
  1872. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1873. 开ToolStripMenuItem.Checked = false;
  1874. 关ToolStripMenuItem.Checked = true;
  1875. button_Start.Enabled = true;
  1876. Delay_ms(500);
  1877. //关闭串口
  1878. portsettings_form.closePort();
  1879. //存储测试数据
  1880. ErrorSaveLog();
  1881. return;
  1882. }
  1883. if (DataTemp < 100)
  1884. {
  1885. if (label_Sensor_Break1.BackColor == Color.Red)
  1886. {
  1887. label_Sensor_Break1.BackColor = Color.Green;
  1888. label_Sensor_Break1.Text = "OK";
  1889. OK_cnt++;
  1890. }
  1891. break;
  1892. }
  1893. }
  1894. label_Step.Text = "请松开断电刹把 1";
  1895. WalkProcess_Cnt = 0;
  1896. while (WalkProcess_Cnt < 10)//等待电机再次启动,如果超时提示错误
  1897. {
  1898. try
  1899. {
  1900. DataTemp = Convert.ToUInt16(textBox_MotorSpeed.Text);
  1901. }
  1902. catch (System.Exception ex)
  1903. {
  1904. MessageBox.Show(ex.Message);
  1905. label_Step.Text = "推行测试异常,测试结束!";
  1906. //关机
  1907. Code[0] = 0xF0;
  1908. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1909. 开ToolStripMenuItem.Checked = false;
  1910. 关ToolStripMenuItem.Checked = true;
  1911. button_Start.Enabled = true;
  1912. Delay_ms(500);
  1913. //关闭串口
  1914. portsettings_form.closePort();
  1915. //存储测试数据
  1916. ErrorSaveLog();
  1917. return;
  1918. }
  1919. if (DataTemp > 300)//电机转速超过300rpm,再次启动测试
  1920. break;
  1921. }
  1922. if (WalkProcess_Cnt >= 10)//表示超时退出,电机未启动
  1923. {
  1924. label_Step.Text = "推行测试异常,测试结束!";
  1925. //关机
  1926. Code[0] = 0xF0;
  1927. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1928. 开ToolStripMenuItem.Checked = false;
  1929. 关ToolStripMenuItem.Checked = true;
  1930. button_Start.Enabled = true;
  1931. Delay_ms(500);
  1932. //关闭串口
  1933. portsettings_form.closePort();
  1934. //存储测试数据
  1935. ErrorSaveLog();
  1936. return;
  1937. }
  1938. //断电开关2
  1939. label_Step.Text = "请在10s内捏下断电刹把 2!";
  1940. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "断电刹把 2 检测开始,请捏下断电刹把 2" + "\r\n";
  1941. WalkProcess_Cnt = 0;
  1942. while (WalkProcess_Cnt < 15)//10s内判断电机是否停止
  1943. {
  1944. try
  1945. {
  1946. DataTemp = Convert.ToUInt16(textBox_MotorSpeed.Text);
  1947. }
  1948. catch (System.Exception ex)
  1949. {
  1950. MessageBox.Show(ex.Message);
  1951. label_Step.Text = "推行测试异常,测试结束!";
  1952. //关机
  1953. Code[0] = 0xF0;
  1954. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1955. 开ToolStripMenuItem.Checked = false;
  1956. 关ToolStripMenuItem.Checked = true;
  1957. button_Start.Enabled = true;
  1958. Delay_ms(500);
  1959. //关闭串口
  1960. portsettings_form.closePort();
  1961. //存储测试数据
  1962. ErrorSaveLog();
  1963. return;
  1964. }
  1965. if (DataTemp < 100)
  1966. {
  1967. if (label_Sensor_Break2.BackColor == Color.Red)
  1968. {
  1969. label_Sensor_Break2.BackColor = Color.Green;
  1970. label_Sensor_Break2.Text = "OK";
  1971. OK_cnt++;
  1972. }
  1973. break;
  1974. }
  1975. }
  1976. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "断电刹把检测结束" + "\r\n";
  1977. label_Step.Text = "请松开断电刹把 2!";
  1978. button_Walk.Text = "停止";
  1979. Walk_Process(0x00);
  1980. Delay_ms(1000);
  1981. //判断测试结果
  1982. if (OK_cnt < 9)
  1983. {
  1984. label_Step.Text = "推行测试异常,测试结束!";
  1985. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "推行测试失败,测试结束" + "\r\n";
  1986. //关机
  1987. Code[0] = 0xF0;
  1988. SendCmd(0x7FF, 0x16, 0x2201, Code);
  1989. 开ToolStripMenuItem.Checked = false;
  1990. 关ToolStripMenuItem.Checked = true;
  1991. button_Start.Enabled = true;
  1992. Delay_ms(500);
  1993. //关闭串口
  1994. portsettings_form.closePort();
  1995. //存储测试数据
  1996. ErrorSaveLog();
  1997. return;
  1998. }
  1999. //判断BMS通信是否正常
  2000. if (BMS检测执行ToolStripMenuItem1.Checked == true)
  2001. {
  2002. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检测BMS通信状态" + "\r\n";
  2003. if (label_BMS_COM.Text != "OK")
  2004. {
  2005. label_Step.Text = "BMS通信异常,测试结束!";
  2006. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "推行测试失败,测试结束" + "\r\n";
  2007. //关机
  2008. Code[0] = 0xF0;
  2009. SendCmd(0x7FF, 0x16, 0x2201, Code);
  2010. 开ToolStripMenuItem.Checked = false;
  2011. 关ToolStripMenuItem.Checked = true;
  2012. button_Start.Enabled = true;
  2013. Delay_ms(500);
  2014. //关闭串口
  2015. portsettings_form.closePort();
  2016. //存储测试数据
  2017. ErrorSaveLog();
  2018. return;
  2019. }
  2020. }
  2021. else if (BMS检测不执行ToolStripMenuItem1.Checked == true)
  2022. {
  2023. label_BMS_COM.BackColor = Color.Yellow;
  2024. label_BMS_COM.Text = "N/A";
  2025. }
  2026. #endregion
  2027. #region Step5:转把模式测试(非必需)
  2028. if (GasModeTest == false)
  2029. {
  2030. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过指拨模式测试" + "\r\n";
  2031. label_Sensor_Gas.BackColor = Color.Green;
  2032. label_Sensor_Gas.Text = "OK";
  2033. }
  2034. else
  2035. {
  2036. TestStep = TestStep_Enum.Step_GasMode;
  2037. label_Step.Text = "指拨模式测试,请在10s内转动指拨!";
  2038. button_Walk.Text = "启动";
  2039. Walk_Process(0x04);
  2040. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "指拨模式测试开始,请转动指拨" + "\r\n";
  2041. OK_cnt = 0;
  2042. WalkProcess_Cnt = 0;
  2043. while (WalkProcess_Cnt < 10)//10s内判断电机是否启动
  2044. {
  2045. try
  2046. {
  2047. DataTemp = Convert.ToUInt16(textBox_MotorSpeed.Text);
  2048. }
  2049. catch (System.Exception ex)
  2050. {
  2051. MessageBox.Show(ex.Message);
  2052. label_Step.Text = "推行测试异常,测试结束!";
  2053. //关机
  2054. Code[0] = 0xF0;
  2055. SendCmd(0x7FF, 0x16, 0x2201, Code);
  2056. 开ToolStripMenuItem.Checked = false;
  2057. 关ToolStripMenuItem.Checked = true;
  2058. button_Start.Enabled = true;
  2059. Delay_ms(500);
  2060. //关闭串口
  2061. portsettings_form.closePort();
  2062. //存储测试数据
  2063. ErrorSaveLog();
  2064. return;
  2065. }
  2066. if ((DataTemp > (GasModeSpeed - 100)) && (DataTemp < (GasModeSpeed + 100)))
  2067. {
  2068. label_Sensor_Gas.BackColor = Color.Green;
  2069. label_Sensor_Gas.Text = "OK";
  2070. OK_cnt++;
  2071. break;
  2072. }
  2073. }
  2074. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "指拨模式测试结束" + "\r\n";
  2075. Delay_ms(1000);
  2076. button_Walk.Text = "停止";
  2077. Walk_Process(0x00);
  2078. //判断测试结果
  2079. if (OK_cnt < 1)
  2080. {
  2081. label_Step.Text = "指拨模式测试异常,测试结束!";
  2082. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "指拨模式测试失败,测试结束" + "\r\n";
  2083. //关机
  2084. Code[0] = 0xF0;
  2085. SendCmd(0x7FF, 0x16, 0x2201, Code);
  2086. 开ToolStripMenuItem.Checked = false;
  2087. 关ToolStripMenuItem.Checked = true;
  2088. button_Start.Enabled = true;
  2089. Delay_ms(500);
  2090. //关闭串口
  2091. portsettings_form.closePort();
  2092. //存储测试数据
  2093. ErrorSaveLog();
  2094. return;
  2095. }
  2096. }
  2097. #endregion
  2098. }
  2099. else
  2100. {
  2101. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "不执行推行测试" + "\r\n";
  2102. label_sta_light.BackColor = Color.Yellow;
  2103. label_sta_light.Text = "N/A";
  2104. label_sensor_cadence.BackColor = Color.Yellow;
  2105. label_sensor_cadence.Text = "N/A";
  2106. label_sensor_cur.BackColor = Color.Yellow;
  2107. label_sensor_cur.Text = "N/A";
  2108. label_sensor_vol.BackColor = Color.Yellow;
  2109. label_sensor_vol.Text = "N/A";
  2110. label_sensor_motor.BackColor = Color.Yellow;
  2111. label_sensor_motor.Text = "N/A";
  2112. label_sensor_coil_temp.BackColor = Color.Yellow;
  2113. label_sensor_coil_temp.Text = "N/A";
  2114. label_sensor_MCU_temp.BackColor = Color.Yellow;
  2115. label_sensor_MCU_temp.Text = "N/A";
  2116. label_sensor_PCB_temp.BackColor = Color.Yellow;
  2117. label_sensor_PCB_temp.Text = "N/A";
  2118. label_sensor_speed.BackColor = Color.Yellow;
  2119. label_sensor_speed.Text = "N/A";
  2120. label_Sensor_Gas.BackColor = Color.Yellow;
  2121. label_Sensor_Gas.Text = "N/A";
  2122. label_Sensor_Break1.BackColor = Color.Yellow;
  2123. label_Sensor_Break1.Text = "N/A";
  2124. label_Sensor_Break2.BackColor = Color.Yellow;
  2125. label_Sensor_Break2.Text = "N/A";
  2126. label_BMS_COM.BackColor = Color.Yellow;
  2127. label_BMS_COM.Text = "N/A";
  2128. }
  2129. #region Step6:版本查询和确认
  2130. TestStep = TestStep_Enum.Step_CheckVer;
  2131. label_Step.Text = "版本查询和确认";
  2132. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令查询版本信息" + "\r\n";
  2133. richTextBox_Ver.Text = "";
  2134. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  2135. Delay_ms(200);
  2136. SendCmd((ushort)0x651, (byte)0x11, (ushort)0x1200, null);
  2137. Delay_ms(200);
  2138. string FW_Version_Check = comboBox_File.Text.Split('_')[2] + "_" + comboBox_File.Text.Split('_')[3];
  2139. string FW_Version_Result = "";
  2140. string TE_FW_Ver_Check = comboBox_File.Text.Split('_')[4] + "_" + comboBox_File.Text.Split('_')[5];
  2141. string TE_FW_Ver_Result = "";
  2142. try
  2143. {
  2144. FW_Version_Result = richTextBox_Ver.Lines[3].Split(':')[1];
  2145. FW_Version_Result = FW_Version_Result.Split('_')[0] + richTextBox_Ver.Lines[4].Split('-')[2].Replace('V', '.') + "_" + FW_Version_Result.Split('_')[1];
  2146. TE_FW_Ver_Result = richTextBox_Ver.Lines[5].Split(':')[1];
  2147. }
  2148. catch (System.Exception)
  2149. {
  2150. label_Step.Text = "软件版本信息不完整!";
  2151. }
  2152. if (string.Equals(FW_Version_Check, FW_Version_Result) == false) //主控版本错误,直接结束
  2153. {
  2154. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息错误" + "\r\n";
  2155. label_Step.Text = "软件版本错误,测试结束!";
  2156. //关机
  2157. Code[0] = 0xF0;
  2158. SendCmd(0x7FF, 0x16, 0x2201, Code);
  2159. 开ToolStripMenuItem.Checked = false;
  2160. 关ToolStripMenuItem.Checked = true;
  2161. button_Start.Enabled = true;
  2162. Delay_ms(500);
  2163. //关闭串口
  2164. portsettings_form.closePort();
  2165. //存储测试数据
  2166. ErrorSaveLog();
  2167. return;
  2168. }
  2169. else
  2170. {
  2171. if (string.Equals(TE_FW_Ver_Check, TE_FW_Ver_Result) == false) //TE版本错误,给出提示
  2172. {
  2173. if (MessageBox.Show("TE版本错误,请确认主控板是否为HK?", "TE版本错误", MessageBoxButtons.YesNo) == DialogResult.No)
  2174. {
  2175. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "TE软件版本错误" + "\r\n";
  2176. label_Step.Text = "TE软件版本错误,测试结束!";
  2177. //关机
  2178. Code[0] = 0xF0;
  2179. SendCmd(0x7FF, 0x16, 0x2201, Code);
  2180. 开ToolStripMenuItem.Checked = false;
  2181. 关ToolStripMenuItem.Checked = true;
  2182. button_Start.Enabled = true;
  2183. Delay_ms(500);
  2184. //关闭串口
  2185. portsettings_form.closePort();
  2186. //存储测试数据
  2187. ErrorSaveLog();
  2188. return;
  2189. }
  2190. }
  2191. label_FW_Version.BackColor = Color.Green;
  2192. label_FW_Version.Text = "OK";
  2193. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息正确" + "\r\n";
  2194. }
  2195. Delay_ms(1000);
  2196. #endregion
  2197. #region 按照产品信息设置测试文件路径
  2198. ResultPathName = textBox_PDinfo.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_");
  2199. if (System.IO.Directory.Exists(LogSavePath + "log\\" + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ResultPathName) == false)
  2200. System.IO.Directory.CreateDirectory(LogSavePath + "log\\" + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ResultPathName);
  2201. #endregion
  2202. #region Step7:参数查询和保存
  2203. TestStep = TestStep_Enum.Step_Save;
  2204. label_Step.Text = "参数导出";
  2205. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始导出电机内部参数" + "\r\n";
  2206. LogSaveFileName = LogSavePath + "log\\" + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ResultPathName + "\\ParamsLog" + ".ttlog";
  2207. //开始发送指令
  2208. byte[] SendData = new byte[32];
  2209. //查询校验密钥
  2210. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);
  2211. Delay_ms(100);
  2212. //查询版本信息
  2213. //SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  2214. //Delay_ms(100);
  2215. //SendCmd((ushort)0x651, (byte)0x11, (ushort)0x1200, null);
  2216. //Delay_ms(100);
  2217. //查询用户字符串1
  2218. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);
  2219. Delay_ms(100);
  2220. //查询用户字符串2
  2221. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);
  2222. Delay_ms(100);
  2223. //查询用户字符串3
  2224. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);
  2225. Delay_ms(100);
  2226. //查询用户参数1
  2227. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1A00, null);
  2228. Delay_ms(100);
  2229. //查询马达参数
  2230. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1C00, null);
  2231. Delay_ms(100);
  2232. //查询历史信息
  2233. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
  2234. Delay_ms(100);
  2235. //查询生产信息
  2236. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);
  2237. Delay_ms(100);
  2238. //查询力矩传感器零点 Volans
  2239. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2000, null);
  2240. Delay_ms(100);
  2241. //查询运行信息
  2242. SendData[0] = 0x00;
  2243. SendData[1] = 0xF0;
  2244. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, SendData);
  2245. Delay_ms(100);
  2246. SendData[0] = 0x01;
  2247. SendData[1] = 0xF0;
  2248. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, SendData);
  2249. Delay_ms(100);
  2250. SendData[0] = 0x02;
  2251. SendData[1] = 0xF0;
  2252. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, SendData);
  2253. Delay_ms(100);
  2254. SendData[0] = 0x03;
  2255. SendData[1] = 0xF0;
  2256. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, SendData);
  2257. Delay_ms(100);
  2258. SendData[0] = 0x04;
  2259. SendData[1] = 0xF0;
  2260. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, SendData);
  2261. Delay_ms(100);
  2262. SendData[0] = 0x33;
  2263. SendData[1] = 0xF0;
  2264. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, SendData);
  2265. Delay_ms(100);
  2266. //查询力矩传感器校正信息 Volans
  2267. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2900, null);
  2268. Delay_ms(100);
  2269. //导出故障日志
  2270. UInt32 Address_Begin;
  2271. UInt32 Addres_End;
  2272. Address_Begin = 0x0801F800;
  2273. Addres_End = 0x0801FBFF;
  2274. UInt32 ReadCount = 0;
  2275. ReadCount = (Addres_End - Address_Begin + 1) / 128;
  2276. for (ushort i = 0; i < ReadCount; i++)
  2277. {
  2278. var SendByte = new byte[8];
  2279. UInt32 Address_Temp_Begin;
  2280. UInt32 Address_Temp_End;
  2281. Address_Temp_Begin = Address_Begin + 128 * (UInt32)i;
  2282. SendByte[0] = (byte)(Address_Temp_Begin >> 24);
  2283. SendByte[1] = (byte)(Address_Temp_Begin >> 16);
  2284. SendByte[2] = (byte)(Address_Temp_Begin >> 8);
  2285. SendByte[3] = (byte)(Address_Temp_Begin);
  2286. Address_Temp_End = Address_Temp_Begin + 127;
  2287. SendByte[4] = (byte)(Address_Temp_End >> 24);
  2288. SendByte[5] = (byte)(Address_Temp_End >> 16);
  2289. SendByte[6] = (byte)(Address_Temp_End >> 8);
  2290. SendByte[7] = (byte)(Address_Temp_End);
  2291. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  2292. Delay_ms(100);
  2293. }
  2294. //查询骑行信息
  2295. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2E00, null);
  2296. Delay_ms(100);
  2297. //查询用户参数2
  2298. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3000, null);
  2299. Delay_ms(100);
  2300. //查询力矩传感器零点值 Pegasi
  2301. SendData[0] = 1;
  2302. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3201, SendData);
  2303. Delay_ms(100);
  2304. SendData[0] = 2;
  2305. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3201, SendData);
  2306. Delay_ms(100);
  2307. SendData[0] = 3;
  2308. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3201, SendData);
  2309. Delay_ms(100);
  2310. //查询校正系数 Pegasi
  2311. SendData[0] = 1;
  2312. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3301, SendData);
  2313. Delay_ms(100);
  2314. SendData[0] = 2;
  2315. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3301, SendData);
  2316. Delay_ms(100);
  2317. SendData[0] = 3;
  2318. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3301, SendData);
  2319. Delay_ms(100);
  2320. //查询启动值 Pegasi
  2321. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3500, null);
  2322. Delay_ms(100);
  2323. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机参数导出完成" + "\r\n";
  2324. #endregion
  2325. //检查是否有故障
  2326. if (label_error_code.Text != "OK")
  2327. {
  2328. label_Step.Text = "电机存在故障!";
  2329. //关机
  2330. Code[0] = 0xF0;
  2331. SendCmd(0x7FF, 0x16, 0x2201, Code);
  2332. 开ToolStripMenuItem.Checked = false;
  2333. 关ToolStripMenuItem.Checked = true;
  2334. button_Start.Enabled = true;
  2335. Delay_ms(500);
  2336. //关闭串口
  2337. portsettings_form.closePort();
  2338. //存储测试数据
  2339. ErrorSaveLog();
  2340. return;
  2341. }
  2342. //显示测试结果
  2343. label_Result.BackColor = Color.Green;
  2344. label_Result.Text = "合格";
  2345. label_Step.Text = "合格,测试结束!";
  2346. label_Step.ForeColor = Color.Green;
  2347. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "合格,测试结束" + "\r\n";
  2348. //关机
  2349. Code[0] = 0xF0;
  2350. SendCmd(0x7FF, 0x16, 0x2201, Code);
  2351. 开ToolStripMenuItem.Checked = false;
  2352. 关ToolStripMenuItem.Checked = true;
  2353. button_Start.Enabled = true;
  2354. Delay_ms(500);
  2355. //关闭串口
  2356. portsettings_form.closePort();
  2357. //导出的参数上传服务器
  2358. if (StartForm.myFtp.IsNetConnected == true)
  2359. {
  2360. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  2361. if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/walkTest/log/", DateNow) == false)
  2362. {
  2363. StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow);
  2364. }
  2365. if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow, ResultPathName) == false)
  2366. {
  2367. StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow + "/" + ResultPathName);
  2368. }
  2369. bool result = StartForm.myFtp.UploadFile(LogSaveFileName, StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow + "/" + ResultPathName);
  2370. if (result == true)
  2371. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机配置参数上传服务器成功" + "\r\n";
  2372. }
  2373. //保存测试信息
  2374. //页面存储
  2375. Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
  2376. Graphics g = Graphics.FromImage(bit);
  2377. g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片
  2378. LogSaveFileName = LogSavePath + "log\\" + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ResultPathName + "\\测试页面" + ".png";
  2379. bit.Save(LogSaveFileName);
  2380. //测试页面上传服务器
  2381. if (StartForm.myFtp.IsNetConnected == true)
  2382. {
  2383. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  2384. if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/walkTest/log/", DateNow) == false)
  2385. {
  2386. StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow);
  2387. }
  2388. if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow, ResultPathName) == false)
  2389. {
  2390. StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow + "/" + ResultPathName);
  2391. }
  2392. bool result = StartForm.myFtp.UploadFile(LogSaveFileName, StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow + "/" + ResultPathName);
  2393. if (result == true)
  2394. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
  2395. }
  2396. //保存测试记录
  2397. LogSaveFileName = LogSavePath + "log\\" + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ResultPathName + "\\测试记录" + ".txt";
  2398. richTextBox_TestRecord.SaveFile(LogSaveFileName, RichTextBoxStreamType.PlainText);
  2399. //测试记录上传服务器
  2400. if (StartForm.myFtp.IsNetConnected == true)
  2401. {
  2402. string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
  2403. if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/walkTest/log/", DateNow) == false)
  2404. {
  2405. StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow);
  2406. }
  2407. if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow, ResultPathName) == false)
  2408. {
  2409. StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow + "/" + ResultPathName);
  2410. }
  2411. bool result = StartForm.myFtp.UploadFile(LogSaveFileName, StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow + "/" + ResultPathName);
  2412. if (result == true)
  2413. richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
  2414. }
  2415. //测试正常,清空扫码信息
  2416. textBox_PDinfo.Text = "";
  2417. }
  2418. //开始测试
  2419. private void button_Start_Click(object sender, EventArgs e)
  2420. {
  2421. TestStart();
  2422. }
  2423. //测试子函数
  2424. private void TestStart()
  2425. {
  2426. //标签初始化
  2427. label_Init();
  2428. //检查设置
  2429. if ((推行测试执行ToolStripMenuItem.Checked == false) && (推行测试不执行ToolStripMenuItem.Checked == false))
  2430. {
  2431. label_Step.Text = "请先选择是否执行\"推行测试\"!";
  2432. label_Step.ForeColor = Color.Red;
  2433. return;
  2434. }
  2435. if ((系统清除执行ToolStripMenuItem.Checked == false) && (系统清除不执行ToolStripMenuItem.Checked == false))
  2436. {
  2437. label_Step.Text = "请先选择是否执行\"系统清除\"!";
  2438. label_Step.ForeColor = Color.Red;
  2439. return;
  2440. }
  2441. if ((BMS检测执行ToolStripMenuItem1.Checked == false) && (BMS检测不执行ToolStripMenuItem1.Checked == false))
  2442. {
  2443. label_Step.Text = "请先选择是否执行\"BMS通信检测\"!";
  2444. label_Step.ForeColor = Color.Red;
  2445. return;
  2446. }
  2447. #region 检查配置文件
  2448. if (comboBox_File.Items.Count == 0) //配置文件目录为空
  2449. {
  2450. label_Step.Text = "无可用配置文件!";
  2451. label_Step.ForeColor = Color.Red;
  2452. return;
  2453. }
  2454. if (comboBox_File.Text.Trim().Length == 0)//未选择配置文件
  2455. {
  2456. label_Step.Text = "请选择配置文件!";
  2457. return;
  2458. }
  2459. #endregion
  2460. #region 检查产品信息是否符合格式要求
  2461. try
  2462. {
  2463. 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]$");
  2464. if (textBox_PDinfo.Text.Contains(" "))
  2465. {
  2466. string Mode = textBox_PDinfo.Text.Split(new string[] { " " }, StringSplitOptions.None)[0];
  2467. string Sn = textBox_PDinfo.Text.Split(new string[] { " " }, StringSplitOptions.None)[1];
  2468. if (regex.IsMatch(Sn) == false)
  2469. {
  2470. label_Step.Text = "SN格式错误!";
  2471. label_Step.ForeColor = Color.Red;
  2472. return;
  2473. }
  2474. }
  2475. else if (textBox_PDinfo.Text.Contains("%#"))
  2476. {
  2477. string Mode = textBox_PDinfo.Text.Split(new string[] { "%#" }, StringSplitOptions.None)[0];
  2478. string Sn = textBox_PDinfo.Text.Split(new string[] { "%#" }, StringSplitOptions.None)[1];
  2479. if (regex.IsMatch(Sn) == false)
  2480. {
  2481. label_Step.Text = "SN格式错误!";
  2482. label_Step.ForeColor = Color.Red;
  2483. return;
  2484. }
  2485. }
  2486. else
  2487. {
  2488. label_Step.Text = "标签格式错误!";
  2489. label_Step.ForeColor = Color.Red;
  2490. return;
  2491. }
  2492. }
  2493. catch (System.Exception)
  2494. {
  2495. label_Step.Text = "标签格式错误!";
  2496. label_Step.ForeColor = Color.Red;
  2497. return;
  2498. }
  2499. #endregion
  2500. //连接串口
  2501. if (portsettings_form.openPort() == false)
  2502. {
  2503. label_Step.Text = "串口连接失败!";
  2504. label_Step.ForeColor = Color.Red;
  2505. return;
  2506. }
  2507. //测试状态更新
  2508. TestStep = TestStep_Enum.Step_Init;
  2509. label_Step.Text = "准备开始测试";
  2510. label_Step.ForeColor = Color.Red;
  2511. //流水号累加和存储
  2512. label_SerialNum.Text = (Convert.ToInt32(label_SerialNum.Text) + 1).ToString();
  2513. string cfg_file = System.IO.Directory.GetCurrentDirectory() + "\\SerialNum";
  2514. StreamReader objReader = new StreamReader(cfg_file);
  2515. string sLine = "";
  2516. ArrayList arrText = new ArrayList();//创建一个动态数组
  2517. while (sLine != null)
  2518. {
  2519. sLine = objReader.ReadLine();
  2520. arrText.Add(sLine);
  2521. }
  2522. arrText.RemoveAt(arrText.Count - 1);
  2523. objReader.Close();
  2524. arrText[1] = label_SerialNum.Text;
  2525. using (StreamWriter file = new StreamWriter(cfg_file))
  2526. {
  2527. foreach (var entry in arrText)
  2528. {
  2529. file.WriteLine(entry);
  2530. }
  2531. }
  2532. button_Start.Enabled = false;
  2533. //创建线程,执行测试任务
  2534. Thread th = new Thread(Thread_Task);
  2535. th.Start();
  2536. }
  2537. //1s计时
  2538. private void timer2_Tick(object sender, EventArgs e)
  2539. {
  2540. label_SystemTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2541. //MC故障信息超时清除
  2542. if (MC_ErrorCode_Refresh == false)
  2543. {
  2544. MC_ErrorCode_Refresh_Cnt++;
  2545. if (MC_ErrorCode_Refresh_Cnt > 5)
  2546. {
  2547. label_error_code.Text = "OK";
  2548. label_error_code.BackColor = Color.Green;
  2549. label_ErrorInfo.Text = "无故障";
  2550. label_ErrorInfo.ForeColor = Color.Green;
  2551. MC_ErrorCode_Refresh_Cnt = 0;
  2552. }
  2553. }
  2554. else
  2555. {
  2556. MC_ErrorCode_Refresh_Cnt = 0;
  2557. }
  2558. MC_ErrorCode_Refresh = false;
  2559. //MC_RunInfo超时清除
  2560. if (MC_RunInfo_Refresh == false)
  2561. {
  2562. MC_RunInfo_Refresh_Cnt++;
  2563. if (MC_RunInfo_Refresh_Cnt > 5)
  2564. {
  2565. MC_RunInfo_Clear();
  2566. MC_RunInfo_Refresh_Cnt = 0;
  2567. }
  2568. }
  2569. else
  2570. {
  2571. MC_RunInfo_Refresh_Cnt = 0;
  2572. }
  2573. MC_RunInfo_Refresh = false;
  2574. //等待反馈指令
  2575. if (Ack_Flag == false)
  2576. {
  2577. Ack_Cnt++;
  2578. if (Ack_Cnt > 2)
  2579. {
  2580. Ack_Flag = true;
  2581. StepTestFlag = StepTestResult_Enum.StepTestResult_Fail;
  2582. }
  2583. }
  2584. //推行测试计时
  2585. if ((TestStep == TestStep_Enum.Step_Walk) || (TestStep == TestStep_Enum.Step_GasMode))
  2586. {
  2587. WalkProcess_Cnt++;
  2588. }
  2589. }
  2590. //打开系统开关
  2591. private void 开ToolStripMenuItem_Click(object sender, EventArgs e)
  2592. {
  2593. byte[] Data = new byte[1];
  2594. if (portsettings_form.serialPort1.IsOpen)
  2595. {
  2596. //开机
  2597. Data[0] = 0xF1;
  2598. SendCmd(0x7FF, 0x16, 0x2201, Data);
  2599. 开ToolStripMenuItem.Checked = true;
  2600. 关ToolStripMenuItem.Checked = false;
  2601. }
  2602. else
  2603. {
  2604. MessageBox.Show("串口未连接");
  2605. return;
  2606. }
  2607. }
  2608. //关闭系统开关
  2609. private void 关ToolStripMenuItem_Click(object sender, EventArgs e)
  2610. {
  2611. byte[] Data = new byte[1];
  2612. if (portsettings_form.serialPort1.IsOpen)
  2613. {
  2614. //关机
  2615. Data[0] = 0xF0;
  2616. SendCmd(0x7FF, 0x16, 0x2201, Data);
  2617. 开ToolStripMenuItem.Checked = false;
  2618. 关ToolStripMenuItem.Checked = true;
  2619. }
  2620. else
  2621. {
  2622. MessageBox.Show("串口未连接");
  2623. return;
  2624. }
  2625. }
  2626. //清除流水号
  2627. private void label8_DoubleClick(object sender, EventArgs e)
  2628. {
  2629. //流水号清零
  2630. if (MessageBox.Show("流水号清零", "确认清零?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2631. {
  2632. label_SerialNum.Text = "0";
  2633. //存储
  2634. string cfg_file = System.IO.Directory.GetCurrentDirectory() + "\\SerialNum";
  2635. StreamReader objReader = new StreamReader(cfg_file);
  2636. string sLine = "";
  2637. ArrayList arrText = new ArrayList();//创建一个动态数组
  2638. while (sLine != null)
  2639. {
  2640. sLine = objReader.ReadLine();
  2641. arrText.Add(sLine);
  2642. }
  2643. arrText.RemoveAt(arrText.Count - 1);
  2644. objReader.Close();
  2645. arrText[1] = label_SerialNum.Text;
  2646. using (StreamWriter file = new StreamWriter(cfg_file))
  2647. {
  2648. foreach (var entry in arrText)
  2649. {
  2650. file.WriteLine(entry);
  2651. }
  2652. }
  2653. }
  2654. }
  2655. private void richTextBox_TestRecord_TextChanged(object sender, EventArgs e)
  2656. {
  2657. richTextBox_TestRecord.SelectionStart = richTextBox_TestRecord.Text.Length;
  2658. richTextBox_TestRecord.ScrollToCaret();
  2659. }
  2660. private void textBox_PDinfo_Click(object sender, EventArgs e)
  2661. {
  2662. textBox_PDinfo.SelectAll();
  2663. }
  2664. private void textBox_PDinfo_KeyUp(object sender, KeyEventArgs e)
  2665. {
  2666. if (e.KeyCode == Keys.Enter)
  2667. {
  2668. TestStart();
  2669. }
  2670. }
  2671. private void 屏幕键盘ToolStripMenuItem_Click(object sender, EventArgs e)
  2672. {
  2673. System.Diagnostics.Process.Start("osk.exe");
  2674. }
  2675. private void 端口选择ToolStripMenuItem_Click(object sender, EventArgs e)
  2676. {
  2677. portsettings_form.Show();
  2678. }
  2679. private void BMS检测执行ToolStripMenuItem1_Click(object sender, EventArgs e)
  2680. {
  2681. BMS检测执行ToolStripMenuItem1.Checked = true;
  2682. BMS检测不执行ToolStripMenuItem1.Checked = false;
  2683. label_TestFunsUpdate();
  2684. }
  2685. private void BMS检测不执行ToolStripMenuItem1_Click(object sender, EventArgs e)
  2686. {
  2687. StartForm.EnterForm1.ShowDialog();
  2688. if ((StartForm.EnterForm1.textBox_User.Text == "PT") && (StartForm.EnterForm1.textBox_Passwd.Text == "123456"))
  2689. {
  2690. BMS检测不执行ToolStripMenuItem1.Checked = true;
  2691. BMS检测执行ToolStripMenuItem1.Checked = false;
  2692. label_TestFunsUpdate();
  2693. }
  2694. else
  2695. {
  2696. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2697. }
  2698. }
  2699. private void 推行测试执行ToolStripMenuItem_Click(object sender, EventArgs e)
  2700. {
  2701. 推行测试执行ToolStripMenuItem.Checked = true;
  2702. 推行测试不执行ToolStripMenuItem.Checked = false;
  2703. label_TestFunsUpdate();
  2704. }
  2705. private void 推行测试不执行ToolStripMenuItem_Click(object sender, EventArgs e)
  2706. {
  2707. StartForm.EnterForm1.ShowDialog();
  2708. if ((StartForm.EnterForm1.textBox_User.Text == "PT") && (StartForm.EnterForm1.textBox_Passwd.Text == "123456"))
  2709. {
  2710. 推行测试不执行ToolStripMenuItem.Checked = true;
  2711. 推行测试执行ToolStripMenuItem.Checked = false;
  2712. label_TestFunsUpdate();
  2713. }
  2714. else
  2715. {
  2716. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2717. }
  2718. }
  2719. private void 系统清除执行ToolStripMenuItem_Click(object sender, EventArgs e)
  2720. {
  2721. 系统清除执行ToolStripMenuItem.Checked = true;
  2722. 系统清除不执行ToolStripMenuItem.Checked = false;
  2723. label_TestFunsUpdate();
  2724. }
  2725. private void 系统清除不执行ToolStripMenuItem_Click(object sender, EventArgs e)
  2726. {
  2727. StartForm.EnterForm1.ShowDialog();
  2728. if ((StartForm.EnterForm1.textBox_User.Text == "PT") && (StartForm.EnterForm1.textBox_Passwd.Text == "123456"))
  2729. {
  2730. 系统清除执行ToolStripMenuItem.Checked = false;
  2731. 系统清除不执行ToolStripMenuItem.Checked = true;
  2732. label_TestFunsUpdate();
  2733. }
  2734. else
  2735. {
  2736. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2737. }
  2738. }
  2739. private void label_TestFunsUpdate()
  2740. {
  2741. label_TestFun.Text = "测试功能:";
  2742. if (系统清除执行ToolStripMenuItem.Checked == true)
  2743. label_TestFun.Text += "系统清除 ";
  2744. label_TestFun.Text += "参数写入 ";
  2745. if(推行测试执行ToolStripMenuItem.Checked==true)
  2746. label_TestFun.Text += "推行测试 ";
  2747. if(BMS检测执行ToolStripMenuItem1.Checked==true)
  2748. label_TestFun.Text += "BMS通信检测 ";
  2749. }
  2750. private void 只写入参数ToolStripMenuItem_Click(object sender, EventArgs e)
  2751. {
  2752. if (只写入参数ToolStripMenuItem.Checked == true)
  2753. {
  2754. 系统清除不执行ToolStripMenuItem.Checked = false;
  2755. 系统清除执行ToolStripMenuItem.Checked = true;
  2756. 推行测试不执行ToolStripMenuItem.Checked = false;
  2757. 推行测试执行ToolStripMenuItem.Checked = true;
  2758. BMS检测不执行ToolStripMenuItem1.Checked = false;
  2759. BMS检测执行ToolStripMenuItem1.Checked = true;
  2760. 只写入参数ToolStripMenuItem.Checked = false;
  2761. 推行测试ToolStripMenuItem.Enabled = true;
  2762. bMS通信检测ToolStripMenuItem.Enabled = true;
  2763. 系统清除ToolStripMenuItem.Enabled = true;
  2764. label_TestFunsUpdate();
  2765. }
  2766. else
  2767. {
  2768. StartForm.EnterForm1.ShowDialog();
  2769. if ((StartForm.EnterForm1.textBox_User.Text == "PT") && (StartForm.EnterForm1.textBox_Passwd.Text == "123456"))
  2770. {
  2771. 系统清除执行ToolStripMenuItem.Checked = false;
  2772. 系统清除不执行ToolStripMenuItem.Checked = true;
  2773. 推行测试执行ToolStripMenuItem.Checked = false;
  2774. 推行测试不执行ToolStripMenuItem.Checked = true;
  2775. BMS检测执行ToolStripMenuItem1.Checked = false;
  2776. BMS检测不执行ToolStripMenuItem1.Checked = true;
  2777. 只写入参数ToolStripMenuItem.Checked = true;
  2778. 推行测试ToolStripMenuItem.Enabled = false;
  2779. bMS通信检测ToolStripMenuItem.Enabled = false;
  2780. 系统清除ToolStripMenuItem.Enabled = false;
  2781. label_TestFunsUpdate();
  2782. }
  2783. else
  2784. {
  2785. MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2786. }
  2787. }
  2788. }
  2789. private void 合格ToolStripMenuItem_Click(object sender, EventArgs e)
  2790. {
  2791. System.Diagnostics.Process.Start("explorer.exe", LogSavePath + "log\\");
  2792. }
  2793. private void 不合格ToolStripMenuItem_Click(object sender, EventArgs e)
  2794. {
  2795. System.Diagnostics.Process.Start("explorer.exe", LogSavePath + "errorlog\\");
  2796. }
  2797. }
  2798. }