ImportForm.cs 142 KB

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