ImportForm.cs 150 KB

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