ImportForm.cs 145 KB

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