ImportForm.cs 163 KB

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