Form1.cs 158 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Threading;
  5. using System.Windows.Forms;
  6. namespace Welling_Motor_Debug_Tool
  7. {
  8. public partial class Form1 : Form
  9. {
  10. #region 变量定义
  11. //串口实例
  12. Serial_Process mySerialProcess = new Serial_Process();
  13. //MC运行信息超时计数
  14. bool MC_RunInfo_Refresh = false;
  15. ushort MC_RunInfo_Refresh_Cnt = 0;
  16. //MC故障码超时计数
  17. bool MC_ErrorCode_Refresh = false;
  18. ushort MC_ErrorCode_Refresh_Cnt = 0;
  19. //配置参数实例
  20. Params myParams = new Params();
  21. //记录文件名称
  22. string SaveFilename = "";
  23. //BMS运行信息超时计数
  24. bool BMS_RunInfo_Refresh = false;
  25. ushort BMS_RunInfo_Refresh_Cnt = 0;
  26. //生产模式关机指令反馈装
  27. bool PowerOffAckStatus = false;
  28. #endregion
  29. public Form1()
  30. {
  31. InitializeComponent();
  32. }
  33. #region 非独占性延时函数
  34. public static void Delay_ms(int milliSecond)
  35. {
  36. int start = Environment.TickCount;
  37. while (Math.Abs(Environment.TickCount - start) < milliSecond)//毫秒
  38. {
  39. Application.DoEvents();
  40. }
  41. }
  42. #endregion
  43. private void Form1_Load(object sender, System.EventArgs e)
  44. {
  45. //页面初始化
  46. label_BuildTime.Text= "编译时间:"+ System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString();
  47. //下拉控件初始值设定
  48. comboBox_WorkMode.SelectedIndex = 0;
  49. comboBox_GearSt.SelectedIndex = 0;
  50. comboBox_LightSwitch.SelectedIndex = 1;
  51. comboBox_OBC_SetGearST.SelectedIndex = 0;
  52. comboBox_OBC_LightSw.SelectedIndex = 1;
  53. comboBox_AssistTorque.SelectedIndex = 0;
  54. comboBox_AssistCadence.SelectedIndex = 0;
  55. //combobox事件定义
  56. this.comboBox_WorkMode.SelectedIndexChanged += new System.EventHandler(this.comboBox_WorkMode_SelectedIndexChanged);
  57. this.comboBox_GearSt.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  58. this.comboBox_LightSwitch.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
  59. this.comboBox_OBC_SetGearST.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  60. this.comboBox_OBC_LightSw.SelectedIndexChanged += new System.EventHandler(this.comboBox_OBC_SetGearST_SelectedIndexChanged);
  61. //端口设置
  62. mySerialProcess.Init();
  63. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  64. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
  65. toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf("115200");
  66. //创建线程,定时解析数据
  67. Thread th = new Thread(Task_SerialProcess);
  68. th.IsBackground = true;
  69. th.Start();
  70. }
  71. #region 串口数据解析线程
  72. /// <summary>
  73. /// 串口数据解析线程
  74. /// </summary>
  75. private void Task_SerialProcess()
  76. {
  77. //创建定时器,定时读取串口数据
  78. System.Timers.Timer timer_ReadSerial = new System.Timers.Timer();
  79. timer_ReadSerial.Enabled = true;
  80. timer_ReadSerial.Interval = 20;
  81. timer_ReadSerial.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_ReadSerial_Tick);
  82. timer_ReadSerial.Start();
  83. while (true)
  84. {
  85. Thread.Sleep(1);
  86. };
  87. }
  88. /// <summary>
  89. /// 串口解析定时器
  90. /// </summary>
  91. /// <param name="sender"></param>
  92. /// <param name="e"></param>
  93. private void timer_ReadSerial_Tick(object sender, EventArgs e)
  94. {
  95. //串口解析
  96. Serial_process(mySerialProcess.buffer);
  97. }
  98. #endregion
  99. #region 数据解析
  100. public void Serial_process(List<byte> buffer)
  101. {
  102. byte DataNum = 0; //记录每条命令数据段的长度
  103. ushort PackageID, Cmd;
  104. byte[] Data = new byte[1024];
  105. while (buffer.Count >= 13)//当buffer中的数据的个数大于等于4个时,即每一帧的数据长度所在位(第4位)出现时
  106. {
  107. if (buffer[0] == 0x55 && buffer[1] == 0xAA)//判断帧头
  108. {
  109. PackageID = (ushort)(buffer[2] * 256 + buffer[3]);
  110. if ((PackageID == 0x0710) || (PackageID == 0x0715) || (PackageID == 0x07FF) || (PackageID == 0x0720) || (PackageID == 0x0713))
  111. {
  112. int CmdLen = buffer[5];
  113. if (buffer.Count < CmdLen + 11) break;//如果接收到的数据没有达到一帧数据的指定长度, 则执行下次循环
  114. buffer.RemoveRange(0, 6);//数据达到要求长度后删去帧头,ID,模式,和命令长度
  115. while (CmdLen > 0) //读取命令段
  116. {
  117. Cmd = (ushort)(buffer[0] * 256 + buffer[1]);
  118. DataNum = (byte)(buffer[1]);//命令字的第二个字节的表示数据位的长度
  119. if (DataNum <= (CmdLen - 2))
  120. {
  121. for (int i = 0; i < DataNum; i++)
  122. {
  123. Data[i] = buffer[i + 2];
  124. }
  125. DataCmdProcess(PackageID, Cmd, Data);//对于不同的命令段,做不同的处理
  126. buffer.RemoveRange(0, DataNum);//移除处理过的数据段
  127. CmdLen -= (DataNum + 2);
  128. if (CmdLen < 2)
  129. {
  130. buffer.RemoveRange(0, CmdLen + 2);
  131. return;
  132. }
  133. }
  134. else
  135. {
  136. buffer.RemoveRange(0, CmdLen + 11);
  137. }
  138. }
  139. }
  140. else
  141. {
  142. buffer.RemoveAt(0);//ID不对
  143. }
  144. }
  145. else
  146. {
  147. buffer.RemoveAt(0);//帧头不对,删除帧头高字节
  148. }
  149. }
  150. }
  151. private void DataCmdProcess(ushort ID, ushort CmdTemp, byte[] Data)
  152. {
  153. int DataTemp;
  154. ushort uData16;
  155. unchecked
  156. {
  157. this.Invoke((EventHandler)(delegate { label_RecCount.Text = Convert.ToString(Convert.ToInt32(label_RecCount.Text) + 1); }));
  158. }
  159. #region 解析发送给CDL的指令
  160. if (ID == 0x7FF)
  161. {
  162. switch (CmdTemp)
  163. {
  164. case 0x1100://
  165. {
  166. unchecked
  167. {
  168. this.Invoke((EventHandler)(delegate
  169. {
  170. //CDL连接成功
  171. mySerialProcess.CDL_Online_Flag = true;
  172. MessageBox.Show("连接成功!", "提示");
  173. }));
  174. }
  175. break;
  176. }
  177. default: break;
  178. }
  179. }
  180. #endregion
  181. #region 解析电机的命令
  182. else if ((ID == 0x715) || (ID == 0x710))
  183. {
  184. switch (CmdTemp)
  185. {
  186. case 0x1020://电机运行信息
  187. {
  188. unchecked
  189. {
  190. this.Invoke((EventHandler)(delegate
  191. {
  192. MC_RunInfo_Refresh = true;
  193. //车速
  194. DataTemp = (int)(Data[1] * 256 + Data[0]);
  195. textBox_RunInfo_BikeSpeed.Text = ((float)DataTemp / 10f).ToString("0.0") + " km/h";
  196. //输出转速
  197. DataTemp = (ushort)(Data[3] * 256 + Data[2]);
  198. textBox_RunInfo_MotorSpeed.Text = Convert.ToString(DataTemp) + " rpm";
  199. Class_MotorSpeed.String = textBox_RunInfo_MotorSpeed.Text;
  200. Class_MotorSpeed.Data = DataTemp;
  201. //电功率
  202. DataTemp = (ushort)(Data[5] * 256 + Data[4]);
  203. textBox_RunInfo_Power.Text = Convert.ToString(DataTemp) + " W";
  204. //母线电压
  205. DataTemp = (ushort)(Data[7] * 256 + Data[6]);
  206. textBox_RunInfo_Vol.Text = Convert.ToString(DataTemp) + " mV";
  207. //textBox_RunInfo_Vol.Text = (DataTemp / 1000f).ToString("0.0") + " V";
  208. //母线电流
  209. DataTemp = (short)(Data[9] * 256 + Data[8]);
  210. textBox_RunInfo_Current.Text = Convert.ToString(DataTemp) + " mA";
  211. //textBox_RunInfo_Current.Text = (DataTemp / 1000f).ToString("0.0") + " A";
  212. Class_CurrentData.String = textBox_RunInfo_Current.Text;
  213. Class_CurrentData.Data = DataTemp;
  214. //踏频
  215. DataTemp = (ushort)(Data[10]);
  216. textBox_RunInfo_Cadence.Text = Convert.ToString(DataTemp) + " rpm";
  217. Class_CadenceData.String = textBox_RunInfo_Cadence.Text;
  218. Class_CadenceData.Data = DataTemp;
  219. //踩踏力矩
  220. DataTemp = (ushort)(Data[11]);
  221. textBox_RunInfo_Torque.Text = Convert.ToString(DataTemp) + " N.m";
  222. Class_TorqueData.String = textBox_RunInfo_Torque.Text;
  223. Class_TorqueData.Data = DataTemp;
  224. //踩踏方向
  225. DataTemp = (ushort)(Data[12]);
  226. if (DataTemp == 0)
  227. {
  228. textBox_RunInfo_Dir.Text = "正向";
  229. }
  230. else if (DataTemp == 1)
  231. {
  232. textBox_RunInfo_Dir.Text = "反向";
  233. }
  234. else if (DataTemp == 2)
  235. {
  236. textBox_RunInfo_Dir.Text = "停止";
  237. }
  238. //助力档位
  239. DataTemp = (ushort)(Data[13]);
  240. if (DataTemp == 0x33)
  241. {
  242. textBox_RunInfo_GearSt.Text = "SMART";
  243. //comboBox_GearSt.SelectedIndex = 5;
  244. //comboBox_OBC_SetGearST.SelectedIndex = 5;
  245. }
  246. else if (DataTemp == 0x22)
  247. {
  248. textBox_RunInfo_GearSt.Text = "WALK";
  249. //comboBox_GearSt.SelectedIndex = 6;
  250. //comboBox_OBC_SetGearST.SelectedIndex = 6;
  251. }
  252. else
  253. {
  254. string[] Gears = new string[5] { "OFF", "ECO", "NORM", "SPORT", "TURBO" };
  255. textBox_RunInfo_GearSt.Text = Gears[DataTemp];
  256. //comboBox_GearSt.SelectedIndex = DataTemp;
  257. //comboBox_OBC_SetGearST.SelectedIndex = DataTemp;
  258. }
  259. //大灯状态
  260. DataTemp = (ushort)(Data[14]);
  261. if (DataTemp == 0xF0)
  262. {
  263. textBox_RunInfo_LightSwitch.Text = "OFF";
  264. //comboBox_LightSwitch.SelectedIndex = 1;
  265. //comboBox_OBC_LightSw.SelectedIndex = 1;
  266. }
  267. else if (DataTemp == 0xF1)
  268. {
  269. textBox_RunInfo_LightSwitch.Text = "ON";
  270. //comboBox_LightSwitch.SelectedIndex = 0;
  271. //comboBox_OBC_LightSw.SelectedIndex = 0;
  272. }
  273. //剩余电量
  274. DataTemp = (ushort)(Data[15]);
  275. textBox_RunInfo_SOC.Text = Convert.ToString(DataTemp) + " %";
  276. //剩余续航里程
  277. DataTemp = (ushort)(Data[17] * 256 + Data[16]);
  278. if ((DataTemp == 0xEEEE) || (DataTemp == 0xFFFF))
  279. {
  280. textBox_RunInfo_Range.Text = "---";
  281. }
  282. else
  283. {
  284. textBox_RunInfo_Range.Text = Convert.ToString(DataTemp) + " km";
  285. }
  286. //预留(显示力矩Reg),空2bytes
  287. DataTemp = (ushort)(Data[19] * 256 + Data[18]);
  288. textBox_TorqueReg.Text = Convert.ToString(DataTemp);
  289. //平均功耗
  290. DataTemp = (ushort)(Data[20]);
  291. textBox_RunInfo_AvgPower.Text = Convert.ToString(DataTemp * 10) + " mAh/km";
  292. //PCB温度
  293. DataTemp = (ushort)(Data[21]);
  294. textBox_RunInfo_T_PCB.Text = Convert.ToString((int)(DataTemp - 40))+" ℃";
  295. Class_MotorTemp.String = textBox_RunInfo_T_PCB.Text;
  296. Class_MotorTemp.Data = DataTemp - 40;
  297. //绕组温度
  298. DataTemp = (ushort)(Data[22]);
  299. textBox_RunInfo_T_Coil.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  300. //MCU温度
  301. DataTemp = (ushort)(Data[23]);
  302. textBox_RunInfo_T_MCU.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
  303. //单次里程
  304. DataTemp = (ushort)(Data[25] * 256 + Data[24]);
  305. textBox_RunInfo_Trip.Text = ((float)DataTemp / 10f).ToString("0.0") + " km";
  306. //单次时间
  307. DataTemp = (ushort)(Data[27] * 256 + Data[26]);
  308. textBox_RunInfo_Trip_Time.Text = Convert.ToString(DataTemp) + " s";
  309. //数据保存
  310. DataAutoSave();
  311. }));
  312. }
  313. break;
  314. }
  315. case 0x1104://故障码
  316. {
  317. unchecked
  318. {
  319. this.Invoke((EventHandler)(delegate
  320. {
  321. MC_ErrorCode_Refresh = true;
  322. textBox_ErrorCode.Text =
  323. Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() +
  324. Convert.ToString(Data[2], 16).PadLeft(2, '0').ToUpper() +
  325. Convert.ToString(Data[1], 16).PadLeft(2, '0').ToUpper() +
  326. Convert.ToString(Data[0], 16).PadLeft(2, '0').ToUpper() +
  327. "H";
  328. }));
  329. }
  330. break;
  331. }
  332. case 0xA903://反馈指令
  333. {
  334. unchecked
  335. {
  336. this.Invoke((EventHandler)(delegate
  337. {
  338. timer_1s.Enabled = false;
  339. MessageBox.Show("OK", "反馈指令", MessageBoxButtons.OK, MessageBoxIcon.Information);
  340. timer_1s.Enabled = true;
  341. //关机反馈
  342. PowerOffAckStatus = true;
  343. }));
  344. }
  345. break;
  346. }
  347. case 0xB226://马达参数
  348. {
  349. unchecked
  350. {
  351. this.Invoke((EventHandler)(delegate
  352. {
  353. richTextBox_MotorParam.Clear();
  354. for (int i = 0; i < myParams.MotorParma.Count; i++)
  355. {
  356. richTextBox_MotorParam.AppendText(myParams.MotorParma[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  357. }
  358. richTextBox_MotorParam.Text = richTextBox_MotorParam.Text.Substring(0, richTextBox_MotorParam.Text.Length - 2);
  359. }));
  360. }
  361. break;
  362. }
  363. case 0xB31A://整车信息
  364. {
  365. unchecked
  366. {
  367. this.Invoke((EventHandler)(delegate
  368. {
  369. richTextBox_BikeParam.Clear();
  370. for (int i = 0; i < myParams.BikeParma.Count; i++)
  371. {
  372. richTextBox_BikeParam.AppendText(myParams.BikeParma[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  373. }
  374. richTextBox_BikeParam.Text = richTextBox_BikeParam.Text.Substring(0, richTextBox_BikeParam.Text.Length - 2);
  375. //更新生产模式中整车参数
  376. textBox_FacModeWheelSize.Text = (Data[1] * 256 + Data[0]).ToString();//周长
  377. textBox_FacModeSpeedLimit.Text= (Data[5] * 256 + Data[4]).ToString();//限速
  378. DataTemp = (int)(Data[13] * 256 + Data[12]);//助力方案1
  379. if (DataTemp == 0) comboBox_FacModeAssist1.SelectedIndex = 0;
  380. else if (DataTemp == 341) comboBox_FacModeAssist1.SelectedIndex = 1;
  381. else if (DataTemp == 682) comboBox_FacModeAssist1.SelectedIndex = 2;
  382. else comboBox_FacModeAssist1.SelectedIndex = 3;
  383. DataTemp = (int)(Data[15] * 256 + Data[14]);//助力方案2
  384. if (DataTemp == 0) comboBox_FacModeAssist2.SelectedIndex = 0;
  385. else if (DataTemp == 341) comboBox_FacModeAssist2.SelectedIndex = 1;
  386. else if (DataTemp == 682) comboBox_FacModeAssist2.SelectedIndex = 2;
  387. else comboBox_FacModeAssist2.SelectedIndex = 3;
  388. DataTemp = (int)(Data[17] * 256 + Data[16]);//灯压
  389. if (DataTemp == 6) comboBox_FacModeLightVol.SelectedIndex = 0;
  390. else if (DataTemp == 12) comboBox_FacModeLightVol.SelectedIndex = 1;
  391. else comboBox_FacModeLightVol.SelectedIndex = 2;
  392. DataTemp = (int)(Data[21] * 256 + Data[20]);//启动模式
  393. if (DataTemp == 1) comboBox_FacModeStartMode.SelectedIndex = 0;
  394. else if (DataTemp == 3) comboBox_FacModeStartMode.SelectedIndex = 2;
  395. else comboBox_FacModeStartMode.SelectedIndex = 1;
  396. }));
  397. }
  398. break;
  399. }
  400. case 0xB420://控制器参数
  401. {
  402. unchecked
  403. {
  404. this.Invoke((EventHandler)(delegate
  405. {
  406. richTextBox_ControlParam.Clear();
  407. for (int i = 0; i < myParams.ControlParma.Count; i++)
  408. {
  409. richTextBox_ControlParam.AppendText(myParams.ControlParma[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  410. }
  411. richTextBox_ControlParam.Text = richTextBox_ControlParam.Text.Substring(0, richTextBox_ControlParam.Text.Length - 2);
  412. }));
  413. }
  414. break;
  415. }
  416. case 0xB528://传感器参数
  417. {
  418. unchecked
  419. {
  420. this.Invoke((EventHandler)(delegate
  421. {
  422. richTextBox_SensorParam.Clear();
  423. for (int i = 0; i < myParams.SensorParam.Count; i++)
  424. {
  425. richTextBox_SensorParam.AppendText(myParams.SensorParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  426. }
  427. richTextBox_SensorParam.Text = richTextBox_SensorParam.Text.Substring(0, richTextBox_SensorParam.Text.Length - 2);
  428. //更新生产模式页面传感器零点和标定值
  429. textBox_FacModeSensorADC0.Text = (Data[1] * 256 + Data[0]).ToString();
  430. textBox_FacModeSensorADC1.Text = (Data[15] * 256 + Data[14]).ToString();
  431. textBox_FacModeSensorADC2.Text = (Data[19] * 256 + Data[18]).ToString();
  432. textBox_FacModeSensorADC3.Text = (Data[23] * 256 + Data[22]).ToString();
  433. textBox_FacModeSensorADC4.Text = (Data[27] * 256 + Data[26]).ToString();
  434. }));
  435. }
  436. break;
  437. }
  438. case 0xB64C://助力参数
  439. {
  440. unchecked
  441. {
  442. this.Invoke((EventHandler)(delegate
  443. {
  444. richTextBox_AssistParam.Clear();
  445. int index_1 = myParams.AssistParam.IndexOf("转矩曲线.a");
  446. int index_2 = myParams.AssistParam.IndexOf("踏频曲线.d");
  447. for (int i = 0; i < myParams.AssistParam.Count; i++)
  448. {
  449. if (i < index_1) //数据占用2bytes
  450. {
  451. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  452. }
  453. else if (i <= index_2) //数据占用4bytes
  454. {
  455. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((long)((Data[4 * i - 5] << 24) + (Data[4 * i - 6] << 16) + (Data[4 * i - 7] << 8) + Data[4 * i - 8])) + ", ");
  456. }
  457. else //数据占用2bytes
  458. {
  459. richTextBox_AssistParam.AppendText(myParams.AssistParam[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 17] * 256 + Data[2 * i + 16])) + ", ");
  460. }
  461. }
  462. richTextBox_AssistParam.Text = richTextBox_AssistParam.Text.Substring(0, richTextBox_AssistParam.Text.Length - 2);
  463. //更新生产模式中助力参数
  464. textBox_FacModeStartGain.Text = (Data[1] * 256 + Data[0]).ToString();//零速增益
  465. textBox_FacModeCircuitK.Text = (Data[45] * 256 + Data[44]).ToString();//电流阶梯
  466. textBox_FacModeFltCounter.Text = (Data[49] * 256 + Data[48]).ToString();//滤波脉冲
  467. textBox_FacModeSpeedLimitTh.Text = (Data[55] * 256 + Data[54]).ToString();//限速启动
  468. textBox_FacModeSpeedLimitEnd.Text = (Data[57] * 256 + Data[56]).ToString();//限速停止
  469. textBox_FacModeCadencePer.Text = (Data[59] * 256 + Data[58]).ToString();//踏频占比
  470. }));
  471. }
  472. break;
  473. }
  474. case 0xB74C://历史记录
  475. {
  476. unchecked
  477. {
  478. this.Invoke((EventHandler)(delegate
  479. {
  480. richTextBox_Record.Clear();
  481. for (int i = 0; i < myParams.Record.Count; i++)
  482. {
  483. richTextBox_Record.AppendText(myParams.Record[i] + "=" + Convert.ToString(Data[2 * i + 1] * 256 + Data[2 * i]) + ", ");
  484. }
  485. richTextBox_Record.Text = richTextBox_Record.Text.Substring(0, richTextBox_Record.Text.Length - 2);
  486. }));
  487. }
  488. break;
  489. }
  490. case 0xB83A://调试参数
  491. {
  492. unchecked
  493. {
  494. this.Invoke((EventHandler)(delegate
  495. {
  496. richTextBox_DebugParam.Clear();
  497. for (int i = 0; i < myParams.DebugParam.Count; i++)
  498. {
  499. richTextBox_DebugParam.AppendText(myParams.DebugParam[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
  500. }
  501. richTextBox_DebugParam.Text = richTextBox_DebugParam.Text.Substring(0, richTextBox_DebugParam.Text.Length - 2);
  502. }));
  503. }
  504. break;
  505. }
  506. case 0xB904://存储标志
  507. {
  508. unchecked
  509. {
  510. this.Invoke((EventHandler)(delegate
  511. {
  512. ushort Flag = 0;
  513. Flag = (ushort)(Data[1] * 256 + Data[0]);//EEPROM存储标志
  514. if (Flag == 0)
  515. {
  516. radioButton_EE_SaveNo.Checked = true;
  517. radioButton_EE_SaveYes.Checked = false;
  518. }
  519. else
  520. {
  521. radioButton_EE_SaveNo.Checked = false;
  522. radioButton_EE_SaveYes.Checked = true;
  523. }
  524. Flag = (ushort)(Data[3] * 256 + Data[2]);//SIP偏移校准存储标志
  525. if (Flag == 0)
  526. {
  527. radioButton_SIP_SaveNo.Checked = true;
  528. radioButton_SIP_SaveYes.Checked = false;
  529. }
  530. else
  531. {
  532. radioButton_SIP_SaveNo.Checked = false;
  533. radioButton_SIP_SaveYes.Checked = true;
  534. }
  535. }));
  536. }
  537. break;
  538. }
  539. case 0x1240://电机版本信息
  540. {
  541. unchecked
  542. {
  543. this.Invoke((EventHandler)(delegate
  544. {
  545. //电机型号
  546. textBox_Model.Text = "";
  547. textBox_OBC_ReadModel.Text = "";
  548. textBox_FacModeName.Text = "";
  549. for (ushort i = 0; i < 16; i++)
  550. {
  551. if (Data[i] == 0x2E)
  552. {
  553. break;
  554. }
  555. textBox_Model.Text += ((char)Data[i]).ToString();
  556. textBox_OBC_ReadModel.Text += ((char)Data[i]).ToString();
  557. textBox_FacModeName.Text += ((char)Data[i]).ToString();
  558. }
  559. Class_Motor_Ver.Mode = textBox_Model.Text;
  560. //电机SN
  561. textBox_SN.Text = "";
  562. textBox_OBC_ReadSN.Text = "";
  563. textBox_FacModeNum.Text = "";
  564. for (ushort i = 0; i < 16; i++)
  565. {
  566. if (Data[16 + i] == 0x2E)
  567. {
  568. break;
  569. }
  570. textBox_SN.Text += ((char)Data[16 + i]).ToString();
  571. textBox_OBC_ReadSN.Text += ((char)Data[16 + i]).ToString();
  572. textBox_FacModeNum.Text += ((char)Data[16 + i]).ToString();
  573. }
  574. Class_Motor_Ver.SN = textBox_SN.Text;
  575. //电机HW
  576. textBox_HW.Text = "";
  577. textBox_OBC_ReadHW.Text = "";
  578. textBox_FacModeHW.Text = "";
  579. for (ushort i = 0; i < 16; i++)
  580. {
  581. if (Data[32 + i] == 0x2E)
  582. {
  583. break;
  584. }
  585. textBox_HW.Text += ((char)Data[32 + i]).ToString();
  586. textBox_OBC_ReadHW.Text += ((char)Data[32 + i]).ToString();
  587. textBox_FacModeHW.Text += ((char)Data[32 + i]).ToString();
  588. }
  589. Class_Motor_Ver.HW = textBox_HW.Text;
  590. //电机FW
  591. textBox_FW.Text = "";
  592. textBox_OBC_ReadFW.Text = "";
  593. textBox_FacModeFW.Text = "";
  594. for (ushort i = 0; i < 16; i++)
  595. {
  596. if (Data[48 + i] == 0x2E)
  597. {
  598. break;
  599. }
  600. if (Data[48 + i] == 'r')
  601. {
  602. Data[48 + i] = (byte)'.';
  603. }
  604. textBox_FW.Text += ((char)Data[48 + i]).ToString();
  605. textBox_OBC_ReadFW.Text += ((char)Data[48 + i]).ToString();
  606. textBox_FacModeFW.Text += ((char)Data[48 + i]).ToString();
  607. }
  608. Class_Motor_Ver.FW = textBox_FW.Text;
  609. }));
  610. }
  611. break;
  612. }
  613. case 0xA610://自定义1
  614. {
  615. unchecked
  616. {
  617. this.Invoke((EventHandler)(delegate
  618. {
  619. textBox_User1.Text = "";
  620. for (ushort i = 0; i < 16; i++)
  621. {
  622. if (Data[i] == 0x2E)
  623. {
  624. break;
  625. }
  626. textBox_User1.Text += ((char)Data[i]).ToString();
  627. }
  628. }));
  629. }
  630. break;
  631. }
  632. case 0xA710://自定义2
  633. {
  634. unchecked
  635. {
  636. this.Invoke((EventHandler)(delegate
  637. {
  638. textBox_User2.Text = "";
  639. for (ushort i = 0; i < 16; i++)
  640. {
  641. if (Data[i] == 0x2E)
  642. {
  643. break;
  644. }
  645. textBox_User2.Text += ((char)Data[i]).ToString();
  646. }
  647. }));
  648. }
  649. break;
  650. }
  651. case 0xA810://自定义1
  652. {
  653. unchecked
  654. {
  655. this.Invoke((EventHandler)(delegate
  656. {
  657. textBox_User3.Text = "";
  658. for (ushort i = 0; i < 16; i++)
  659. {
  660. if (Data[i] == 0x2E)
  661. {
  662. break;
  663. }
  664. textBox_User3.Text += ((char)Data[i]).ToString();
  665. }
  666. }));
  667. }
  668. break;
  669. }
  670. case 0xA520://生产信息
  671. {
  672. unchecked
  673. {
  674. this.Invoke((EventHandler)(delegate
  675. {
  676. //生产商
  677. textBox_MAC.Text = "";
  678. for (ushort i = 0; i < 8; i++)
  679. {
  680. if (Data[i] == 0x2E)
  681. {
  682. break;
  683. }
  684. textBox_MAC.Text += ((char)Data[i]).ToString();
  685. }
  686. //生产地
  687. textBox_MACAdd.Text = "";
  688. for (ushort i = 0; i < 8; i++)
  689. {
  690. if (Data[8 + i] == 0x2E)
  691. {
  692. break;
  693. }
  694. textBox_MACAdd.Text += ((char)Data[8 + i]).ToString();
  695. }
  696. //生产日期
  697. textBox_MACDate.Text = "";
  698. for (ushort i = 0; i < 8; i++)
  699. {
  700. if (Data[16 + i] == 0x2E)
  701. {
  702. break;
  703. }
  704. textBox_MACDate.Text += ((char)Data[16 + i]).ToString();
  705. }
  706. //品牌信息
  707. textBox_PP.Text = "";
  708. for (ushort i = 0; i < 8; i++)
  709. {
  710. if (Data[24 + i] == 0x2E)
  711. {
  712. break;
  713. }
  714. textBox_PP.Text += ((char)Data[24 + i]).ToString();
  715. }
  716. }));
  717. }
  718. break;
  719. }
  720. case 0xA408://密钥
  721. {
  722. unchecked
  723. {
  724. this.Invoke((EventHandler)(delegate
  725. {
  726. textBox_Key.Text = "";
  727. for (ushort i = 0; i < 8; i++)
  728. {
  729. textBox_Key.Text += ((char)Data[i]).ToString();
  730. }
  731. }));
  732. }
  733. break;
  734. }
  735. case 0x1401://在线检测结果
  736. {
  737. unchecked
  738. {
  739. this.Invoke((EventHandler)(delegate
  740. {
  741. textBox_Online.Text = Convert.ToString(Data[3], 16).PadLeft(2, '0').ToUpper() + "H";
  742. }));
  743. }
  744. break;
  745. }
  746. case 0x1510://骑行历史信息
  747. {
  748. unchecked
  749. {
  750. this.Invoke((EventHandler)(delegate
  751. {
  752. long DataTemp32;
  753. //ODO里程
  754. DataTemp32 = (long)((Data[3] << 24) + (Data[2] << 16) + (Data[1] << 8) + Data[0]);
  755. textBox_OBC_ODO_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  756. //ODO时间
  757. DataTemp32 = (long)((Data[7] << 24) + (Data[6] << 16) + (Data[5] << 8) + Data[4]);
  758. if (DataTemp32 >= 60 * 100000)
  759. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  760. else
  761. textBox_OBC_ODO_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  762. //TRIP里程
  763. DataTemp32 = (long)((Data[11] << 24) + (Data[10] << 16) + (Data[9] << 8) + Data[8]);
  764. textBox_OBC_TRIP_KM.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  765. //TRIP时间
  766. DataTemp32 = (long)((Data[15] << 24) + (Data[14] << 16) + (Data[13] << 8) + Data[12]);
  767. if (DataTemp32 >= 60 * 100000)
  768. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h";
  769. else
  770. textBox_OBC_TRIP_TIME.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  771. }));
  772. }
  773. break;
  774. }
  775. case 0x1720://客户信息
  776. {
  777. unchecked
  778. {
  779. this.Invoke((EventHandler)(delegate
  780. {
  781. //程序特性
  782. textBox_SP.Text = "";
  783. textBox_OBC_ReadSP.Text = "";
  784. textBox_FacModeSP.Text = "";
  785. for (ushort i = 0; i < 32; i++)
  786. {
  787. if (Data[i] == 0x2E)
  788. {
  789. break;
  790. }
  791. textBox_SP.Text += ((char)Data[i]).ToString();
  792. textBox_OBC_ReadSP.Text += ((char)Data[i]).ToString();
  793. textBox_FacModeSP.Text += ((char)Data[i]).ToString(); ;
  794. }
  795. Class_Motor_Ver.Special = textBox_SP.Text;
  796. }));
  797. }
  798. break;
  799. }
  800. default:
  801. {
  802. unchecked
  803. {
  804. if ((CmdTemp & 0xFF00) == 0xAB00) //返回指定地址存储器数据
  805. {
  806. this.Invoke((EventHandler)(delegate
  807. {
  808. long ByteNum = 0;
  809. ByteNum = ((Data[4] << 24) + (Data[5] << 16) + (Data[6] << 8) + Data[7]) - ((Data[0] << 24) + (Data[1] << 16) + (Data[2] << 8) + Data[3]) + 1;
  810. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  811. {
  812. for (int i = 0; i < ByteNum; i++)
  813. {
  814. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  815. }
  816. }
  817. else //根据设置自动转换10进制显示
  818. {
  819. if (checkBox_ReadRanFlash_ChangeFormat.Checked == true) //10进制显示
  820. {
  821. switch (ByteNum)
  822. {
  823. case 1:
  824. {
  825. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8]) + ", ");
  826. break;
  827. }
  828. case 2:
  829. {
  830. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8)) + ", ");
  831. break;
  832. }
  833. case 3:
  834. {
  835. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16)) + ", ");
  836. break;
  837. }
  838. case 4:
  839. {
  840. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24)) + ", ");
  841. break;
  842. }
  843. default:
  844. {
  845. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  846. break;
  847. }
  848. }
  849. }
  850. else //16进制显示
  851. {
  852. switch (ByteNum)
  853. {
  854. case 1:
  855. {
  856. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8], 16).PadLeft(2, '0').ToUpper() + ", ");
  857. break;
  858. }
  859. case 2:
  860. {
  861. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8), 16).PadLeft(4, '0').ToUpper() + ", ");
  862. break;
  863. }
  864. case 3:
  865. {
  866. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16), 16).PadLeft(6, '0').ToUpper() + ", ");
  867. break;
  868. }
  869. case 4:
  870. {
  871. richTextBox_RamFlasgData.AppendText("0x" + Convert.ToString(Data[8] + (Data[9] << 8) + (Data[10] << 16) + (Data[11] << 24), 16).PadLeft(8, '0').ToUpper() + ", ");
  872. break;
  873. }
  874. default:
  875. {
  876. richTextBox_RamFlasgData.AppendText("无效数据" + ", ");
  877. break;
  878. }
  879. }
  880. }
  881. }
  882. }));
  883. }
  884. }
  885. break;
  886. }
  887. }
  888. }
  889. #endregion
  890. #region 解析BMS广播的命令
  891. else if (ID == 0x720)
  892. {
  893. switch (CmdTemp)
  894. {
  895. case 0x1010://BMS运行信息
  896. {
  897. unchecked
  898. {
  899. this.Invoke((EventHandler)(delegate
  900. {
  901. BMS_RunInfo_Refresh = true;
  902. richTextBox_OBC_BMS_RunInfo.Clear();
  903. //电压
  904. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  905. richTextBox_OBC_BMS_RunInfo.AppendText("电压:" + Convert.ToString(uData16) + " mV" + "\r\n");
  906. //电流
  907. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  908. richTextBox_OBC_BMS_RunInfo.AppendText("电流:" + Convert.ToString(uData16) + " mA" + "\r\n");
  909. //剩余容量
  910. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  911. richTextBox_OBC_BMS_RunInfo.AppendText("剩余容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  912. //满充容量
  913. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  914. richTextBox_OBC_BMS_RunInfo.AppendText("满充容量:" + Convert.ToString(uData16) + " mV" + "\r\n");
  915. //电芯温度
  916. richTextBox_OBC_BMS_RunInfo.AppendText("电芯温度:" + Convert.ToString((int)(Data[8] - 40) + " ℃" + "\r\n"));
  917. //剩余电量
  918. richTextBox_OBC_BMS_RunInfo.AppendText("剩余电量:" + Convert.ToString(Data[9]) + " %" + "\r\n");
  919. //电池状态
  920. richTextBox_OBC_BMS_RunInfo.AppendText("电池状态:" + Convert.ToString(Data[10], 16).PadLeft(2, '0').ToUpper() + " H" + "\r\n");
  921. //SOH
  922. richTextBox_OBC_BMS_RunInfo.AppendText("电池寿命:" + Convert.ToString(Data[11]) + " %");
  923. }));
  924. }
  925. break;
  926. }
  927. default: break;
  928. }
  929. }
  930. #endregion
  931. #region 解析电机发送OBC的命令
  932. else if (ID == 0x713)
  933. {
  934. switch (CmdTemp)
  935. {
  936. case 0x5408://电机用户参数
  937. {
  938. unchecked
  939. {
  940. this.Invoke((EventHandler)(delegate
  941. {
  942. richTextBox_OBC_ReadUserInfo.Clear();
  943. //默认周长
  944. richTextBox_OBC_ReadUserInfo.AppendText("默认周长:" + Convert.ToString((int)Data[0]) + " cm" + "\r\n");
  945. //启动模式
  946. richTextBox_OBC_ReadUserInfo.AppendText("启动模式:" + ((Data[1] == 0x01) ? "柔和" : (Data[1] == 0x02) ? "正常" : (Data[1] == 0x03) ? "强劲" : "无效") + "\r\n");
  947. comboBox_OBC_StartMode.SelectedIndex = Data[1] - 1;
  948. //限速
  949. richTextBox_OBC_ReadUserInfo.AppendText("限速:" + Convert.ToString(Data[2]) + " km/h" + "\r\n");
  950. //周长微调
  951. numericUpDown_OBC_WheelAdj.Value = (int)(Data[3] > 128 ? (Data[3] - 256) : Data[3]);
  952. richTextBox_OBC_ReadUserInfo.AppendText("周长微调:" + Convert.ToString(numericUpDown_OBC_WheelAdj.Value) + " cm" + "\r\n");
  953. //助力方案
  954. richTextBox_OBC_ReadUserInfo.AppendText("助力方案:" + Convert.ToString(Data[4]) + "\r\n");
  955. comboBox_OBC_AssistFunc.SelectedIndex = Data[4] - 1;
  956. //关机时间
  957. richTextBox_OBC_ReadUserInfo.AppendText("关机时间:" + Convert.ToString(Data[5]) + " min" + "\r\n");
  958. numericUpDown_OBC_OffTime.Value = (int)Data[5];
  959. }));
  960. }
  961. break;
  962. }
  963. case 0x5303://电机应答反馈
  964. {
  965. unchecked
  966. {
  967. this.Invoke((EventHandler)(delegate
  968. {
  969. timer_1s.Enabled = false;
  970. MessageBox.Show("OK", "反馈指令", MessageBoxButtons.OK, MessageBoxIcon.Information);
  971. timer_1s.Enabled = true;
  972. }));
  973. }
  974. break;
  975. }
  976. default: break;
  977. }
  978. }
  979. #endregion
  980. }
  981. #endregion
  982. /// <summary>
  983. /// 端口连接事件
  984. /// </summary>
  985. /// <param name="sender"></param>
  986. /// <param name="e"></param>
  987. private void 连接ToolStripMenuItem_Click(object sender, System.EventArgs e)
  988. {
  989. bool result = false;
  990. if (连接ToolStripMenuItem.Text == "连接")
  991. {
  992. result = mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text);
  993. if (result)
  994. {
  995. toolStripComboBox_ComNum.Enabled = false;
  996. toolStripComboBox_Baudrate.Enabled = false;
  997. 刷新ToolStripMenuItem.Enabled = false;
  998. 连接ToolStripMenuItem.Text = "断开";
  999. 连接ToolStripMenuItem.Checked = true;
  1000. label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
  1001. }
  1002. }
  1003. else if (连接ToolStripMenuItem.Text == "断开")
  1004. {
  1005. checkBox_OBC_StartSetGearSt.Checked = false;
  1006. mySerialProcess.SerialClose();
  1007. toolStripComboBox_ComNum.Enabled = true;
  1008. toolStripComboBox_Baudrate.Enabled = true;
  1009. 刷新ToolStripMenuItem.Enabled = true;
  1010. 连接ToolStripMenuItem.Text = "连接";
  1011. 连接ToolStripMenuItem.Checked = false;
  1012. label_COM_Sta.Text = "连接状态:未连接";
  1013. }
  1014. }
  1015. /// <summary>
  1016. /// 端口号刷新事件
  1017. /// </summary>
  1018. /// <param name="sender"></param>
  1019. /// <param name="e"></param>
  1020. private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
  1021. {
  1022. toolStripComboBox_ComNum.Items.Clear();
  1023. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  1024. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
  1025. }
  1026. /// <summary>
  1027. /// 转速调节事件
  1028. /// </summary>
  1029. /// <param name="sender"></param>
  1030. /// <param name="e"></param>
  1031. private void numericUpDown_SpeedAdj_ValueChanged(object sender, EventArgs e)
  1032. {
  1033. //生产模式转速设置值更新
  1034. trackBar_FacModeMotorSpeedAdj.Value = (int)numericUpDown_SpeedAdj.Value;
  1035. label_FacModeMotorSpeedSet.Text = trackBar_FacModeMotorSpeedAdj.Value.ToString() + "%";
  1036. //设置转速百分比
  1037. var Data = new byte[1];
  1038. Data[0] = (byte)numericUpDown_SpeedAdj.Value;
  1039. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  1040. }
  1041. /// <summary>
  1042. /// 存储标志修改事件
  1043. /// </summary>
  1044. /// <param name="sender"></param>
  1045. /// <param name="e"></param>
  1046. private void 写入存储ToolStripMenuItem_Click(object sender, EventArgs e)
  1047. {
  1048. 写入存储ToolStripMenuItem.Checked = !写入存储ToolStripMenuItem.Checked;
  1049. }
  1050. /// <summary>
  1051. /// 1s定时器
  1052. /// </summary>
  1053. /// <param name="sender"></param>
  1054. /// <param name="e"></param>
  1055. private void timer_1s_Tick(object sender, EventArgs e)
  1056. {
  1057. //时间更新
  1058. label_SystemTime.Text = "系统时间:" + DateTime.Now.ToString();
  1059. //MC_Runinfo超时清除
  1060. if (MC_RunInfo_Refresh == false)
  1061. {
  1062. MC_RunInfo_Refresh_Cnt++;
  1063. if (MC_RunInfo_Refresh_Cnt > 10)//5s
  1064. {
  1065. MC_RunInfo_Clear();
  1066. MC_RunInfo_Refresh_Cnt = 0;
  1067. }
  1068. }
  1069. else
  1070. {
  1071. MC_RunInfo_Refresh_Cnt = 0;
  1072. }
  1073. MC_RunInfo_Refresh = false;
  1074. //BMS_RunInfo超时清除
  1075. if (BMS_RunInfo_Refresh == false)
  1076. {
  1077. BMS_RunInfo_Refresh_Cnt++;
  1078. if (BMS_RunInfo_Refresh_Cnt > 10)//5s
  1079. {
  1080. richTextBox_OBC_BMS_RunInfo.Clear();
  1081. BMS_RunInfo_Refresh_Cnt = 0;
  1082. }
  1083. }
  1084. else
  1085. {
  1086. BMS_RunInfo_Refresh_Cnt = 0;
  1087. }
  1088. BMS_RunInfo_Refresh = false;
  1089. //故障码超时清除
  1090. if (MC_ErrorCode_Refresh == false)
  1091. {
  1092. MC_ErrorCode_Refresh_Cnt++;
  1093. if (MC_ErrorCode_Refresh_Cnt > 10)//5s
  1094. {
  1095. textBox_ErrorCode.Text = "---";
  1096. MC_ErrorCode_Refresh_Cnt = 0;
  1097. }
  1098. }
  1099. else
  1100. {
  1101. MC_ErrorCode_Refresh_Cnt = 0;
  1102. }
  1103. MC_ErrorCode_Refresh = false;
  1104. //CDL连接超时
  1105. #if false
  1106. if (mySerialProcess.CDL_Online_Flag == false)
  1107. {
  1108. mySerialProcess.CDL_OnlineCheck_Cnt++;
  1109. if (mySerialProcess.CDL_OnlineCheck_Cnt > 3)//3s
  1110. {
  1111. timer_1s.Enabled = false;
  1112. MessageBox.Show("连接失败!", "提示");
  1113. timer_1s.Enabled = true;
  1114. //关闭串口
  1115. mySerialProcess.SerialClose();
  1116. toolStripComboBox_ComNum.Enabled = true;
  1117. toolStripComboBox_Baudrate.Enabled = true;
  1118. 刷新ToolStripMenuItem.Enabled = true;
  1119. 连接ToolStripMenuItem.Text = "连接";
  1120. 连接ToolStripMenuItem.Checked = false;
  1121. label_COM_Sta.Text = "连接状态:未连接";
  1122. }
  1123. }
  1124. #endif
  1125. //OBC定时发送设置档位
  1126. if (checkBox_OBC_StartSetGearSt.Checked == true)
  1127. {
  1128. var CtrlCode = new byte[2];
  1129. if (comboBox_OBC_SetGearST.SelectedIndex == 5)//档位
  1130. CtrlCode[0] = 0x33;
  1131. else if (comboBox_OBC_SetGearST.SelectedIndex == 6)//档位
  1132. CtrlCode[0] = 0x22;
  1133. else
  1134. CtrlCode[0] = (byte)comboBox_OBC_SetGearST.SelectedIndex;
  1135. if (comboBox_OBC_LightSw.SelectedIndex == 0)//车灯
  1136. CtrlCode[1] = 0xF1;
  1137. else
  1138. CtrlCode[1] = 0xF0;
  1139. if (!mySerialProcess.SendCmdWithoutNotice((ushort)0x731, (byte)0x0C, (ushort)0x3002, CtrlCode))
  1140. {
  1141. checkBox_OBC_StartSetGearSt.Checked = false;
  1142. }
  1143. }
  1144. //OBC定时发送查询电池
  1145. if (checkBox_OBC_StartReadBMS.Checked == true)
  1146. {
  1147. if (!mySerialProcess.SendCmd((ushort)0x732, (byte)0x11, (ushort)0x5000, null))
  1148. {
  1149. checkBox_OBC_StartReadBMS.Checked = false;
  1150. }
  1151. }
  1152. //定时读取存储器
  1153. if (checkBox_ReadRanFlash_AutoSW.Checked == true)
  1154. {
  1155. var Address = new byte[4];
  1156. UInt32 Address_Begin;
  1157. UInt32 Addres_End;
  1158. if (checkBox_ReadRanFlash_AutoClear.Checked == true)
  1159. richTextBox_RamFlasgData.Clear();
  1160. do
  1161. {
  1162. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  1163. {
  1164. checkBox_ReadRanFlash_AutoSW.Checked = false;
  1165. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  1166. continue;
  1167. }
  1168. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  1169. {
  1170. checkBox_ReadRanFlash_AutoSW.Checked = false;
  1171. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  1172. continue;
  1173. }
  1174. else
  1175. {
  1176. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  1177. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  1178. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  1179. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  1180. if (Addres_End < Address_Begin)
  1181. {
  1182. checkBox_ReadRanFlash_AutoSW.Checked = false;
  1183. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  1184. continue;
  1185. }
  1186. else
  1187. {
  1188. var SendByte = new byte[8];
  1189. SendByte[0] = (byte)(Address_Begin >> 24);
  1190. SendByte[1] = (byte)(Address_Begin >> 16);
  1191. SendByte[2] = (byte)(Address_Begin >> 8);
  1192. SendByte[3] = (byte)(Address_Begin);
  1193. SendByte[4] = (byte)(Addres_End >> 24);
  1194. SendByte[5] = (byte)(Addres_End >> 16);
  1195. SendByte[6] = (byte)(Addres_End >> 8);
  1196. SendByte[7] = (byte)(Addres_End);
  1197. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  1198. }
  1199. }
  1200. } while (false);
  1201. }
  1202. }
  1203. /// <summary>
  1204. /// 运行信息清除
  1205. /// </summary>
  1206. private void MC_RunInfo_Clear()
  1207. {
  1208. foreach (Control c in groupBox2.Controls)
  1209. {
  1210. if ((c is TextBox))
  1211. {
  1212. if(c.Name != textBox_ErrorCode.ToString())
  1213. c.Text = "---";
  1214. }
  1215. }
  1216. }
  1217. /// <summary>
  1218. /// 读取马达参数
  1219. /// </summary>
  1220. /// <param name="sender"></param>
  1221. /// <param name="e"></param>
  1222. private void button_Read_MotorParam_Click(object sender, EventArgs e)
  1223. {
  1224. richTextBox_MotorParam.Clear();
  1225. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null);
  1226. }
  1227. /// <summary>
  1228. /// 写入马达参数
  1229. /// </summary>
  1230. /// <param name="sender"></param>
  1231. /// <param name="e"></param>
  1232. private void button_Write_Click(object sender, EventArgs e)
  1233. {
  1234. var ConfigParam = new byte[40];
  1235. for (int i = 0; i < 40; i++)
  1236. ConfigParam[i] = 0;
  1237. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  1238. short wDataTemp = 0;
  1239. string[] strDataTemp = richTextBox_MotorParam.Text.Split(new string[] { ", "},StringSplitOptions.None);
  1240. try
  1241. {
  1242. for (int i = 0; i < strDataTemp.Length; i++)
  1243. {
  1244. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  1245. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  1246. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  1247. }
  1248. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B28, ConfigParam);
  1249. }
  1250. catch (Exception)
  1251. {
  1252. timer_1s.Enabled = false;
  1253. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1254. timer_1s.Enabled = true;
  1255. }
  1256. }
  1257. /// <summary>
  1258. /// 读取整车信息
  1259. /// </summary>
  1260. /// <param name="sender"></param>
  1261. /// <param name="e"></param>
  1262. private void button_ReadBikeParam_Click(object sender, EventArgs e)
  1263. {
  1264. richTextBox_BikeParam.Clear();
  1265. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
  1266. }
  1267. /// <summary>
  1268. /// 写入整车信息
  1269. /// </summary>
  1270. /// <param name="sender"></param>
  1271. /// <param name="e"></param>
  1272. private void button_WriteBikeParam_Click(object sender, EventArgs e)
  1273. {
  1274. var ConfigParam = new byte[28];
  1275. for (int i = 0; i < 28; i++)
  1276. ConfigParam[i] = 0;
  1277. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  1278. short wDataTemp = 0;
  1279. string[] strDataTemp = richTextBox_BikeParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  1280. try
  1281. {
  1282. for (int i = 0; i < strDataTemp.Length; i++)
  1283. {
  1284. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  1285. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  1286. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  1287. }
  1288. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1C, ConfigParam);
  1289. }
  1290. catch (Exception)
  1291. {
  1292. timer_1s.Enabled = false;
  1293. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1294. timer_1s.Enabled = true;
  1295. }
  1296. }
  1297. /// <summary>
  1298. /// 读取控制器参数
  1299. /// </summary>
  1300. /// <param name="sender"></param>
  1301. /// <param name="e"></param>
  1302. private void button_ReadControlParam_Click(object sender, EventArgs e)
  1303. {
  1304. richTextBox_ControlParam.Clear();
  1305. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  1306. }
  1307. /// <summary>
  1308. /// 写入控制器参数
  1309. /// </summary>
  1310. /// <param name="sender"></param>
  1311. /// <param name="e"></param>
  1312. private void button_WriteControlParam_Click(object sender, EventArgs e)
  1313. {
  1314. var ConfigParam = new byte[34];
  1315. for (int i = 0; i < 34; i++)
  1316. ConfigParam[i] = 0;
  1317. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  1318. ushort uwDataTemp = 0;
  1319. string[] strDataTemp = richTextBox_ControlParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  1320. try
  1321. {
  1322. for (int i = 0; i < strDataTemp.Length; i++)
  1323. {
  1324. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  1325. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  1326. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  1327. }
  1328. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3F22, ConfigParam);
  1329. }
  1330. catch (Exception)
  1331. {
  1332. timer_1s.Enabled = false;
  1333. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1334. timer_1s.Enabled = true;
  1335. }
  1336. }
  1337. /// <summary>
  1338. /// 读取助力参数
  1339. /// </summary>
  1340. /// <param name="sender"></param>
  1341. /// <param name="e"></param>
  1342. private void button_ReadAssistParam_Click(object sender, EventArgs e)
  1343. {
  1344. var ConfigParam = new byte[4];
  1345. int AssistNum = 0;
  1346. try
  1347. {
  1348. AssistNum = Convert.ToInt32(comboBox_AssistTorque.Text);
  1349. ConfigParam[0] = (byte)(AssistNum & 0xFF);
  1350. ConfigParam[1] = (byte)(AssistNum >> 8);
  1351. AssistNum = Convert.ToInt32(comboBox_AssistCadence.Text);
  1352. ConfigParam[2] = (byte)(AssistNum & 0xFF);
  1353. ConfigParam[3] = (byte)(AssistNum >> 8);
  1354. richTextBox_AssistParam.Clear();
  1355. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
  1356. }
  1357. catch (Exception)
  1358. {
  1359. timer_1s.Enabled = false;
  1360. MessageBox.Show("请选择助力参数编号!","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
  1361. timer_1s.Enabled = true;
  1362. }
  1363. }
  1364. /// <summary>
  1365. /// 写入助力参数
  1366. /// </summary>
  1367. /// <param name="sender"></param>
  1368. /// <param name="e"></param>
  1369. private void button_WriteAssistParam_Click(object sender, EventArgs e)
  1370. {
  1371. var ConfigParam = new byte[80];
  1372. for (int i = 0; i < 80; i++)
  1373. ConfigParam[i] = 0;
  1374. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  1375. long lDataTemp = 0;
  1376. string[] strDataTemp = richTextBox_AssistParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  1377. int index_1 = 0, index_2 = 0;
  1378. try
  1379. {
  1380. for (int i = 0; i < strDataTemp.Length; i++)
  1381. {
  1382. if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
  1383. {
  1384. index_1 = i;
  1385. break;
  1386. }
  1387. }
  1388. for (int i = 0; i < strDataTemp.Length; i++)
  1389. {
  1390. if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
  1391. {
  1392. index_2 = i;
  1393. break;
  1394. }
  1395. }
  1396. for (int i = 0; i < strDataTemp.Length; i++)
  1397. {
  1398. lDataTemp = Convert.ToInt32(strDataTemp[i].Split('=')[1]);
  1399. if (i < index_1)
  1400. {
  1401. ConfigParam[2 * i + 4] = (byte)lDataTemp;
  1402. ConfigParam[2 * i + 5] = (byte)(lDataTemp >> 8);
  1403. }
  1404. else if (i <= index_2)
  1405. {
  1406. ConfigParam[4 * i - 4] = (byte)lDataTemp;
  1407. ConfigParam[4 * i - 3] = (byte)(lDataTemp >> 8);
  1408. ConfigParam[4 * i - 2] = (byte)(lDataTemp >> 16);
  1409. ConfigParam[4 * i - 1] = (byte)(lDataTemp >> 24);
  1410. }
  1411. else
  1412. {
  1413. ConfigParam[2 * i + 20] = (byte)lDataTemp;
  1414. ConfigParam[2 * i + 21] = (byte)(lDataTemp >> 8);
  1415. }
  1416. }
  1417. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
  1418. }
  1419. catch (Exception)
  1420. {
  1421. timer_1s.Enabled = false;
  1422. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1423. timer_1s.Enabled = true;
  1424. }
  1425. }
  1426. /// <summary>
  1427. /// 读取调试参数
  1428. /// </summary>
  1429. /// <param name="sender"></param>
  1430. /// <param name="e"></param>
  1431. private void button_ReadDebugParam_Click(object sender, EventArgs e)
  1432. {
  1433. richTextBox_DebugParam.Clear();
  1434. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  1435. }
  1436. /// <summary>
  1437. /// 写入调试参数
  1438. /// </summary>
  1439. /// <param name="sender"></param>
  1440. /// <param name="e"></param>
  1441. private void button_WriteDebugParam_Click(object sender, EventArgs e)
  1442. {
  1443. var ConfigParam = new byte[60];
  1444. for (int i = 0; i < 60; i++)
  1445. ConfigParam[i] = 0;
  1446. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  1447. ushort uwDataTemp = 0;
  1448. string[] strDataTemp = richTextBox_DebugParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  1449. try
  1450. {
  1451. for (int i = 0; i < strDataTemp.Length; i++)
  1452. {
  1453. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  1454. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  1455. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  1456. }
  1457. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam);
  1458. }
  1459. catch (Exception)
  1460. {
  1461. timer_1s.Enabled = false;
  1462. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1463. timer_1s.Enabled = true;
  1464. }
  1465. }
  1466. /// <summary>
  1467. /// 读取历史
  1468. /// </summary>
  1469. /// <param name="sender"></param>
  1470. /// <param name="e"></param>
  1471. private void button_ReadRecord_Click(object sender, EventArgs e)
  1472. {
  1473. richTextBox_Record.Clear();
  1474. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
  1475. }
  1476. /// <summary>
  1477. /// 读取传感器参数
  1478. /// </summary>
  1479. /// <param name="sender"></param>
  1480. /// <param name="e"></param>
  1481. private void button_ReadSensorParam_Click(object sender, EventArgs e)
  1482. {
  1483. richTextBox_SensorParam.Clear();
  1484. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  1485. }
  1486. /// <summary>
  1487. /// 写入力矩传感器标定值
  1488. /// </summary>
  1489. /// <param name="sender"></param>
  1490. /// <param name="e"></param>
  1491. private void button_Write_Cal_Click(object sender, EventArgs e)
  1492. {
  1493. var ConfigParam = new byte[4];
  1494. for (int i = 0; i < 4; i++)
  1495. ConfigParam[i] = 0;
  1496. ushort uwDataTemp = 0;
  1497. try
  1498. {
  1499. uwDataTemp = Convert.ToUInt16(comboBox_TorqueSet.Text);//负载序号
  1500. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  1501. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  1502. uwDataTemp = (ushort)(decimal.Parse(textBox_Load.Text) * 10); ;//负载值0.1Nm
  1503. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  1504. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  1505. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  1506. }
  1507. catch (Exception)
  1508. {
  1509. timer_1s.Enabled = false;
  1510. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1511. timer_1s.Enabled = true;
  1512. }
  1513. }
  1514. /// <summary>
  1515. /// 写入传感器参数
  1516. /// </summary>
  1517. /// <param name="sender"></param>
  1518. /// <param name="e"></param>
  1519. private void button_WriteSensorParam_Click(object sender, EventArgs e)
  1520. {
  1521. var ConfigParam = new byte[14];
  1522. for (int i = 0; i < 14; i++)
  1523. ConfigParam[i] = 0;
  1524. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  1525. ushort uwDataTemp = 0;
  1526. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  1527. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  1528. int index = 0;
  1529. try
  1530. {
  1531. for (int i = 0; i < strDataTemp.Length; i++)
  1532. {
  1533. if (strDataTemp[i].Split('=')[0] == "踏频传感器一圈脉冲数")
  1534. {
  1535. index = i;
  1536. break;
  1537. }
  1538. }
  1539. for (int i = 0; i < (strDataTemp.Length - index); i++)
  1540. {
  1541. uwDataTemp = Convert.ToUInt16(strDataTemp[i + index].Split('=')[1]);
  1542. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  1543. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  1544. }
  1545. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x420E, ConfigParam);
  1546. }
  1547. catch (Exception)
  1548. {
  1549. timer_1s.Enabled = false;
  1550. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1551. timer_1s.Enabled = true;
  1552. }
  1553. }
  1554. /// <summary>
  1555. /// 写入型号
  1556. /// </summary>
  1557. /// <param name="sender"></param>
  1558. /// <param name="e"></param>
  1559. private void button_WriteModel_Click(object sender, EventArgs e)
  1560. {
  1561. string Mode = textBox_Model.Text;
  1562. var ModeArray = new byte[16];
  1563. for (ushort i = 0; i < Mode.Length; i++)
  1564. {
  1565. ModeArray[i] = (byte)Mode[i];
  1566. }
  1567. if (Mode.Length < 16)
  1568. {
  1569. ModeArray[Mode.Length] = (byte)'.';
  1570. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  1571. {
  1572. ModeArray[Mode.Length + 1 + i] = 0x20;
  1573. }
  1574. }
  1575. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  1576. }
  1577. /// <summary>
  1578. /// 写入SN
  1579. /// </summary>
  1580. /// <param name="sender"></param>
  1581. /// <param name="e"></param>
  1582. private void button_WriteSN_Click(object sender, EventArgs e)
  1583. {
  1584. string SN = textBox_SN.Text;
  1585. var SNArray = new byte[16];
  1586. for (ushort i = 0; i < SN.Length; i++)
  1587. {
  1588. SNArray[i] = (byte)SN[i];
  1589. }
  1590. if (SN.Length < 16)
  1591. {
  1592. SNArray[SN.Length] = (byte)'.';
  1593. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  1594. {
  1595. SNArray[SN.Length + 1 + i] = 0x20;
  1596. }
  1597. }
  1598. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  1599. }
  1600. /// <summary>
  1601. /// 查询版本信息
  1602. /// </summary>
  1603. /// <param name="sender"></param>
  1604. /// <param name="e"></param>
  1605. private void button_ReadVersion_Click(object sender, EventArgs e)
  1606. {
  1607. textBox_Model.Text = "---";
  1608. textBox_SN.Text = "---";
  1609. textBox_HW.Text = "---";
  1610. textBox_FW.Text = "---";
  1611. textBox_SP.Text = "---";
  1612. textBox_OBC_ReadModel.Text = "---";
  1613. textBox_OBC_ReadSN.Text = "---";
  1614. textBox_OBC_ReadHW.Text = "---";
  1615. textBox_OBC_ReadFW.Text = "---";
  1616. textBox_OBC_ReadSP.Text = "---";
  1617. textBox_FacModeName.Text = "---";
  1618. textBox_FacModeNum.Text = "---";
  1619. textBox_FacModeHW.Text = "---";
  1620. textBox_FacModeFW.Text = "---";
  1621. textBox_FacModeSP.Text = "---";
  1622. Class_Motor_Ver.Mode = "---";
  1623. Class_Motor_Ver.SN = "---";
  1624. Class_Motor_Ver.HW = "---";
  1625. Class_Motor_Ver.FW = "---";
  1626. Class_Motor_Ver.Special = "---";
  1627. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  1628. }
  1629. /// <summary>
  1630. /// 查询自定义1
  1631. /// </summary>
  1632. /// <param name="sender"></param>
  1633. /// <param name="e"></param>
  1634. private void button_ReadUser1_Click(object sender, EventArgs e)
  1635. {
  1636. textBox_User1.Text = "---";
  1637. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);
  1638. }
  1639. /// <summary>
  1640. /// 查询自定义2
  1641. /// </summary>
  1642. /// <param name="sender"></param>
  1643. /// <param name="e"></param>
  1644. private void button_ReadUser2_Click(object sender, EventArgs e)
  1645. {
  1646. textBox_User2.Text = "---";
  1647. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);
  1648. }
  1649. /// <summary>
  1650. /// 查询自定义3
  1651. /// </summary>
  1652. /// <param name="sender"></param>
  1653. /// <param name="e"></param>
  1654. private void button_ReadUser3_Click(object sender, EventArgs e)
  1655. {
  1656. textBox_User3.Text = "---";
  1657. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);
  1658. }
  1659. /// <summary>
  1660. /// 写入自定义字符串1
  1661. /// </summary>
  1662. /// <param name="sender"></param>
  1663. /// <param name="e"></param>
  1664. private void button_WriteUser1_Click(object sender, EventArgs e)
  1665. {
  1666. string User = textBox_User1.Text;
  1667. var UserArray = new byte[16];
  1668. for (ushort i = 0; i < User.Length; i++)
  1669. {
  1670. UserArray[i] = (byte)User[i];
  1671. }
  1672. if (User.Length < 16)
  1673. {
  1674. UserArray[User.Length] = (byte)'.';
  1675. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  1676. {
  1677. UserArray[User.Length + 1 + i] = 0x20;
  1678. }
  1679. }
  1680. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1410, UserArray);
  1681. }
  1682. /// <summary>
  1683. /// 写入自定义字符串2
  1684. /// </summary>
  1685. /// <param name="sender"></param>
  1686. /// <param name="e"></param>
  1687. private void button_WriteUser2_Click(object sender, EventArgs e)
  1688. {
  1689. string User = textBox_User2.Text;
  1690. var UserArray = new byte[16];
  1691. for (ushort i = 0; i < User.Length; i++)
  1692. {
  1693. UserArray[i] = (byte)User[i];
  1694. }
  1695. if (User.Length < 16)
  1696. {
  1697. UserArray[User.Length] = (byte)'.';
  1698. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  1699. {
  1700. UserArray[User.Length + 1 + i] = 0x20;
  1701. }
  1702. }
  1703. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1610, UserArray);
  1704. }
  1705. /// <summary>
  1706. /// 写入自定义字符串3
  1707. /// </summary>
  1708. /// <param name="sender"></param>
  1709. /// <param name="e"></param>
  1710. private void button_WriteUser3_Click(object sender, EventArgs e)
  1711. {
  1712. string User = textBox_User3.Text;
  1713. var UserArray = new byte[16];
  1714. for (ushort i = 0; i < User.Length; i++)
  1715. {
  1716. UserArray[i] = (byte)User[i];
  1717. }
  1718. if (User.Length < 16)
  1719. {
  1720. UserArray[User.Length] = (byte)'.';
  1721. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  1722. {
  1723. UserArray[User.Length + 1 + i] = 0x20;
  1724. }
  1725. }
  1726. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1810, UserArray);
  1727. }
  1728. /// <summary>
  1729. /// 查询生产信息
  1730. /// </summary>
  1731. /// <param name="sender"></param>
  1732. /// <param name="e"></param>
  1733. private void button_ReadMAC_Click(object sender, EventArgs e)
  1734. {
  1735. textBox_MAC.Text = "---";
  1736. textBox_MACAdd.Text = "---";
  1737. textBox_MACDate.Text = "---";
  1738. textBox_PP.Text = "---";
  1739. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);
  1740. }
  1741. /// <summary>
  1742. /// 写入生产信息
  1743. /// </summary>
  1744. /// <param name="sender"></param>
  1745. /// <param name="e"></param>
  1746. private void button_WriteMac_Click(object sender, EventArgs e)
  1747. {
  1748. var MACArray = new byte[32];
  1749. //填入生产商
  1750. for (ushort i = 0; i < textBox_MAC.Text.Length; i++)
  1751. {
  1752. MACArray[i] = (byte)textBox_MAC.Text[i];
  1753. }
  1754. if (textBox_MAC.Text.Length < 8)
  1755. {
  1756. MACArray[textBox_MAC.Text.Length] = (byte)'.';
  1757. for (ushort i = 0; i < 8 - textBox_MAC.Text.Length - 1; i++)
  1758. {
  1759. MACArray[textBox_MAC.Text.Length + 1 + i] = 0x20;
  1760. }
  1761. }
  1762. //填入生产地
  1763. for (ushort i = 0; i < textBox_MACAdd.Text.Length; i++)
  1764. {
  1765. MACArray[8 + i] = (byte)textBox_MACAdd.Text[i];
  1766. }
  1767. if (textBox_MACAdd.Text.Length < 8)
  1768. {
  1769. MACArray[textBox_MACAdd.Text.Length + 8] = (byte)'.';
  1770. for (ushort i = 0; i < 8 - textBox_MACAdd.Text.Length - 1; i++)
  1771. {
  1772. MACArray[textBox_MACAdd.Text.Length + 1 + i + 8] = 0x20;
  1773. }
  1774. }
  1775. //填入生产日期
  1776. for (ushort i = 0; i < textBox_MACDate.Text.Length; i++)
  1777. {
  1778. MACArray[16 + i] = (byte)textBox_MACDate.Text[i];
  1779. }
  1780. if (textBox_MACDate.Text.Length < 8)
  1781. {
  1782. MACArray[textBox_MACDate.Text.Length + 16] = (byte)'.';
  1783. for (ushort i = 0; i < 8 - textBox_MACDate.Text.Length - 1; i++)
  1784. {
  1785. MACArray[textBox_MACDate.Text.Length + 1 + i + 16] = 0x20;
  1786. }
  1787. }
  1788. //填入品牌
  1789. for (ushort i = 0; i < textBox_PP.Text.Length; i++)
  1790. {
  1791. MACArray[24 + i] = (byte)textBox_PP.Text[i];
  1792. }
  1793. if (textBox_PP.Text.Length < 8)
  1794. {
  1795. MACArray[textBox_PP.Text.Length + 24] = (byte)'.';
  1796. for (ushort i = 0; i < 8 - textBox_PP.Text.Length - 1; i++)
  1797. {
  1798. MACArray[textBox_PP.Text.Length + 1 + i + 24] = 0x20;
  1799. }
  1800. }
  1801. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  1802. }
  1803. /// <summary>
  1804. /// 查询密钥
  1805. /// </summary>
  1806. /// <param name="sender"></param>
  1807. /// <param name="e"></param>
  1808. private void button_ReadKey_Click(object sender, EventArgs e)
  1809. {
  1810. textBox_Key.Text = "---";
  1811. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);
  1812. }
  1813. /// <summary>
  1814. /// 写入校验密钥
  1815. /// </summary>
  1816. /// <param name="sender"></param>
  1817. /// <param name="e"></param>
  1818. private void button_WriteKey_Click(object sender, EventArgs e)
  1819. {
  1820. string Key = textBox_Key.Text;
  1821. var KeyArray = new byte[8];
  1822. if (Key.Length != 8)
  1823. {
  1824. timer_1s.Enabled = false;
  1825. MessageBox.Show("请检查字符长度是否为8", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1826. timer_1s.Enabled = true;
  1827. return;
  1828. }
  1829. for (ushort i = 0; i < Key.Length; i++)
  1830. {
  1831. KeyArray[i] = (byte)Key[i];
  1832. }
  1833. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1108, KeyArray);
  1834. }
  1835. /// <summary>
  1836. /// 查询在线检测结果
  1837. /// </summary>
  1838. /// <param name="sender"></param>
  1839. /// <param name="e"></param>
  1840. private void button_ReadOnLine_Click(object sender, EventArgs e)
  1841. {
  1842. textBox_Online.Text = "---";
  1843. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2100, null);
  1844. }
  1845. /// <summary>
  1846. /// 系统清除
  1847. /// </summary>
  1848. /// <param name="sender"></param>
  1849. /// <param name="e"></param>
  1850. private void button_SystemClear_Click(object sender, EventArgs e)
  1851. {
  1852. var Code = new byte[5];
  1853. Code[0] = (byte)'C';
  1854. Code[1] = (byte)'L';
  1855. Code[2] = (byte)'E';
  1856. Code[3] = (byte)'A';
  1857. Code[4] = (byte)'R';
  1858. timer_1s.Enabled = false;
  1859. if (MessageBox.Show("系统清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1860. {
  1861. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1862. {
  1863. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1864. {
  1865. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  1866. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  1867. }
  1868. }
  1869. }
  1870. timer_1s.Enabled = true;
  1871. }
  1872. /// <summary>
  1873. /// 参数还原
  1874. /// </summary>
  1875. /// <param name="sender"></param>
  1876. /// <param name="e"></param>
  1877. private void button_Recovery_Click(object sender, EventArgs e)
  1878. {
  1879. var Code = new byte[8];
  1880. Code[0] = (byte)'R';
  1881. Code[1] = (byte)'E';
  1882. Code[2] = (byte)'C';
  1883. Code[3] = (byte)'O';
  1884. Code[4] = (byte)'V';
  1885. Code[5] = (byte)'E';
  1886. Code[6] = (byte)'R';
  1887. Code[7] = (byte)'Y';
  1888. timer_1s.Enabled = false;
  1889. if (MessageBox.Show("参数还原后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1890. {
  1891. if (MessageBox.Show("请再次确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1892. {
  1893. if (MessageBox.Show("请最后确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1894. {
  1895. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2708, Code);
  1896. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  1897. }
  1898. }
  1899. }
  1900. timer_1s.Enabled = true;
  1901. }
  1902. /// <summary>
  1903. /// 系统复位
  1904. /// </summary>
  1905. /// <param name="sender"></param>
  1906. /// <param name="e"></param>
  1907. private void button_Reset_Click(object sender, EventArgs e)
  1908. {
  1909. var Code = new byte[5];
  1910. Code[0] = (byte)'O';
  1911. Code[1] = (byte)'F';
  1912. Code[2] = (byte)'F';
  1913. Code[3] = (byte)'.';
  1914. Code[4] = (byte)'.';
  1915. timer_1s.Enabled = false;
  1916. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1917. {
  1918. timer_1s.Enabled = true;
  1919. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  1920. PowerOffAckStatus = false;
  1921. Delay_ms(250);
  1922. int TryCnt = 3;
  1923. while ((TryCnt--) >= 0)
  1924. {
  1925. if (!PowerOffAckStatus)
  1926. {
  1927. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  1928. PowerOffAckStatus = false;
  1929. Delay_ms(250);
  1930. }
  1931. else break;
  1932. }
  1933. if (PowerOffAckStatus)
  1934. {
  1935. timer_1s.Enabled = false;
  1936. MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  1937. timer_1s.Enabled = true;
  1938. }
  1939. else
  1940. {
  1941. timer_1s.Enabled = false;
  1942. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1943. timer_1s.Enabled = true;
  1944. }
  1945. }
  1946. timer_1s.Enabled = true;
  1947. }
  1948. /// <summary>
  1949. /// 记录清除
  1950. /// </summary>
  1951. /// <param name="sender"></param>
  1952. /// <param name="e"></param>
  1953. private void button_ClearLog_Click(object sender, EventArgs e)
  1954. {
  1955. var Code = new byte[9];
  1956. Code[0] = (byte)'L';
  1957. Code[1] = (byte)'O';
  1958. Code[2] = (byte)'G';
  1959. Code[3] = (byte)' ';
  1960. Code[4] = (byte)'C';
  1961. Code[5] = (byte)'L';
  1962. Code[6] = (byte)'E';
  1963. Code[7] = (byte)'A';
  1964. Code[8] = (byte)'R';
  1965. timer_1s.Enabled = false;
  1966. if (MessageBox.Show("历史记录信息清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1967. {
  1968. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1969. {
  1970. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1971. {
  1972. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3909, Code);
  1973. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  1974. }
  1975. }
  1976. }
  1977. timer_1s.Enabled = true;
  1978. }
  1979. /// <summary>
  1980. /// 打开系统计算器
  1981. /// </summary>
  1982. /// <param name="sender"></param>
  1983. /// <param name="e"></param>
  1984. private void 计算器ToolStripMenuItem_Click(object sender, EventArgs e)
  1985. {
  1986. System.Diagnostics.Process.Start("calc.exe");
  1987. }
  1988. /// <summary>
  1989. ///故障转换和显示
  1990. /// </summary>
  1991. List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
  1992. "马达缺相","NTC故障","BMS校验失败","","OBC校验失败","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","","","","","","","","","","","","",
  1993. "",""};
  1994. private string ErrorInfoDisplay(UInt32 Code)
  1995. {
  1996. string Result = "";
  1997. if (Code == 0)
  1998. {
  1999. Result = "无故障";
  2000. }
  2001. else
  2002. {
  2003. for (int i = 0; i < 32; i++)
  2004. {
  2005. if ((Code & 0x01) == 0x01)
  2006. {
  2007. Result += ErrorInfo[i] + " ";
  2008. }
  2009. Code >>= 1;
  2010. }
  2011. }
  2012. return Result;
  2013. }
  2014. /// <summary>
  2015. /// 鼠标滑过故障码显示具体内容
  2016. /// </summary>
  2017. /// <param name="sender"></param>
  2018. /// <param name="e"></param>
  2019. private void textBox_ErrorCode_MouseHover(object sender, EventArgs e)
  2020. {
  2021. // 创建the ToolTip
  2022. ToolTip toolTip1 = new ToolTip();
  2023. // 设置显示样式
  2024. toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
  2025. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  2026. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  2027. toolTip1.ShowAlways = true;//是否显示提示框
  2028. // 设置伴随的对象.
  2029. string ErrorCode = this.textBox_ErrorCode.Text;
  2030. UInt32 Code = ErrorCode.Contains("H") ? Convert.ToUInt32(ErrorCode.Split('H')[0], 16) : 0;
  2031. toolTip1.SetToolTip(this.textBox_ErrorCode, ErrorInfoDisplay(Code));//设置故障内容显示
  2032. }
  2033. /// <summary>
  2034. /// 数据记录
  2035. /// </summary>
  2036. private void DataAutoSave()
  2037. {
  2038. if (记录数据ToolStripMenuItem.Checked == true)
  2039. {
  2040. if (SaveFilename == string.Empty)
  2041. {
  2042. return;
  2043. }
  2044. string SaveData = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace(" ", "_") + " ";
  2045. foreach (Control c in groupBox3.Controls)
  2046. {
  2047. if (c is TextBox)
  2048. {
  2049. SaveData += c.Text + " , ";
  2050. }
  2051. }
  2052. SaveData += "\r\n";
  2053. System.IO.File.AppendAllText(SaveFilename, SaveData);//sb.ToString());
  2054. }
  2055. }
  2056. /// <summary>
  2057. /// 打开或关闭数据记录
  2058. /// </summary>
  2059. /// <param name="sender"></param>
  2060. /// <param name="e"></param>
  2061. private void 记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  2062. {
  2063. if (记录数据ToolStripMenuItem.Checked == false)
  2064. {
  2065. if (mySerialProcess.mySerial.IsOpen == true)
  2066. {
  2067. SaveFilename = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_运行信息" + ".txt";
  2068. timer_1s.Enabled = false;
  2069. MessageBox.Show("开始记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  2070. timer_1s.Enabled = true;
  2071. 记录数据ToolStripMenuItem.Checked = true;
  2072. }
  2073. else
  2074. {
  2075. timer_1s.Enabled = false;
  2076. MessageBox.Show("请连接电机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  2077. timer_1s.Enabled = true;
  2078. }
  2079. }
  2080. else
  2081. {
  2082. 记录数据ToolStripMenuItem.Checked = false;
  2083. timer_1s.Enabled = false;
  2084. MessageBox.Show("停止记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  2085. timer_1s.Enabled = true;
  2086. }
  2087. }
  2088. /// <summary>
  2089. /// 仪表启动控制档位开关事件
  2090. /// </summary>
  2091. /// <param name="sender"></param>
  2092. /// <param name="e"></param>
  2093. private void checkBox_OBC_StartSetGearSt_CheckedChanged(object sender, EventArgs e)
  2094. {
  2095. if (checkBox_OBC_StartSetGearSt.Checked == true)
  2096. {
  2097. //检查串口是否打开
  2098. if (!mySerialProcess.mySerial.IsOpen)
  2099. {
  2100. timer_1s.Enabled = false;
  2101. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2102. timer_1s.Enabled = true;
  2103. checkBox_OBC_StartSetGearSt.Checked = false;
  2104. return;
  2105. }
  2106. //检查是否选择档位和打开车灯
  2107. if ((comboBox_OBC_SetGearST.SelectedIndex == -1) || (comboBox_OBC_LightSw.SelectedIndex == -1))
  2108. {
  2109. timer_1s.Enabled = false;
  2110. MessageBox.Show("请检查档位设置和大灯开关!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2111. timer_1s.Enabled = true;
  2112. checkBox_OBC_StartSetGearSt.Checked = false;
  2113. return;
  2114. }
  2115. }
  2116. }
  2117. /// <summary>
  2118. /// OBC查询电机用户参数
  2119. /// </summary>
  2120. /// <param name="sender"></param>
  2121. /// <param name="e"></param>
  2122. private void button_OBC_ReadUserInfo_Click(object sender, EventArgs e)
  2123. {
  2124. richTextBox_OBC_ReadUserInfo.Clear();
  2125. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3300, null);
  2126. }
  2127. /// <summary>
  2128. /// OBC设置电机用户参数
  2129. /// </summary>
  2130. /// <param name="sender"></param>
  2131. /// <param name="e"></param>
  2132. private void button_OBC_WriteUserInfo_Click(object sender, EventArgs e)
  2133. {
  2134. var UserInfoCode = new byte[8];
  2135. for (int i = 0; i < UserInfoCode.Length; i++)
  2136. UserInfoCode[i] = 0;
  2137. if (comboBox_OBC_StartMode.SelectedIndex == -1)//检查数据有效性
  2138. {
  2139. timer_1s.Enabled = false;
  2140. MessageBox.Show("请选择启动模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2141. timer_1s.Enabled = true;
  2142. return;
  2143. }
  2144. if (comboBox_OBC_AssistFunc.SelectedIndex == -1)//检查数据有效性
  2145. {
  2146. timer_1s.Enabled = false;
  2147. MessageBox.Show("请选择助力方案!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2148. timer_1s.Enabled = true;
  2149. return;
  2150. }
  2151. UserInfoCode[0] = (byte)(int)numericUpDown_OBC_WheelAdj.Value;
  2152. UserInfoCode[1] = (byte)(comboBox_OBC_StartMode.SelectedIndex + 1);
  2153. UserInfoCode[2] = (byte)(comboBox_OBC_AssistFunc.SelectedIndex + 1);
  2154. UserInfoCode[3] = (byte)(uint)numericUpDown_OBC_OffTime.Value;
  2155. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3408, UserInfoCode);
  2156. }
  2157. /// <summary>
  2158. /// OBC查询电机版本信息
  2159. /// </summary>
  2160. /// <param name="sender"></param>
  2161. /// <param name="e"></param>
  2162. private void button_OBC_ReadVerInfo_Click(object sender, EventArgs e)
  2163. {
  2164. textBox_Model.Text = "---";
  2165. textBox_SN.Text = "---";
  2166. textBox_HW.Text = "---";
  2167. textBox_FW.Text = "---";
  2168. textBox_SP.Text = "---";
  2169. textBox_OBC_ReadModel.Text = "---";
  2170. textBox_OBC_ReadSN.Text = "---";
  2171. textBox_OBC_ReadHW.Text = "---";
  2172. textBox_OBC_ReadFW.Text = "---";
  2173. textBox_OBC_ReadSP.Text = "---";
  2174. textBox_FacModeName.Text = "---";
  2175. textBox_FacModeNum.Text = "---";
  2176. textBox_FacModeHW.Text = "---";
  2177. textBox_FacModeFW.Text = "---";
  2178. textBox_FacModeSP.Text = "---";
  2179. Class_Motor_Ver.Mode = "---";
  2180. Class_Motor_Ver.SN = "---";
  2181. Class_Motor_Ver.HW = "---";
  2182. Class_Motor_Ver.FW = "---";
  2183. Class_Motor_Ver.Special = "---";
  2184. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  2185. }
  2186. /// <summary>
  2187. /// OBC读取骑行历史
  2188. /// </summary>
  2189. /// <param name="sender"></param>
  2190. /// <param name="e"></param>
  2191. private void button_OBC_ReadRideInfo_Click(object sender, EventArgs e)
  2192. {
  2193. textBox_OBC_TRIP_KM.Text = "";
  2194. textBox_OBC_TRIP_TIME.Text = "";
  2195. textBox_OBC_ODO_KM.Text = "";
  2196. textBox_OBC_ODO_TIME.Text = "";
  2197. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3500, null);
  2198. }
  2199. /// <summary>
  2200. /// OBC清除TRIP里程
  2201. /// </summary>
  2202. /// <param name="sender"></param>
  2203. /// <param name="e"></param>
  2204. private void button_OBC_ClearTrip_Click(object sender, EventArgs e)
  2205. {
  2206. var Code = new byte[5];
  2207. Code[0] = (byte)'C';
  2208. Code[1] = (byte)'L';
  2209. Code[2] = (byte)'E';
  2210. Code[3] = (byte)'A';
  2211. Code[4] = (byte)'R';
  2212. timer_1s.Enabled = false;
  2213. if (MessageBox.Show("TRIP清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2214. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3605, Code);
  2215. timer_1s.Enabled = true;
  2216. }
  2217. private void checkBox_OBC_StartReadBMS_CheckedChanged(object sender, EventArgs e)
  2218. {
  2219. if (checkBox_OBC_StartReadBMS.Checked == true)
  2220. {
  2221. //检查串口是否打开
  2222. if (!mySerialProcess.mySerial.IsOpen)
  2223. {
  2224. timer_1s.Enabled = false;
  2225. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2226. timer_1s.Enabled = true;
  2227. checkBox_OBC_StartReadBMS.Checked = false;
  2228. return;
  2229. }
  2230. }
  2231. }
  2232. /// <summary>
  2233. /// 写入力矩传感器参数
  2234. /// </summary>
  2235. /// <param name="sender"></param>
  2236. /// <param name="e"></param>
  2237. private void button_WriteTqSensorParam_Click(object sender, EventArgs e)
  2238. {
  2239. var ConfigParam = new byte[46];
  2240. for (int i = 0; i < 14; i++)
  2241. ConfigParam[i] = 0;
  2242. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2243. ushort uwDataTemp = 0;
  2244. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  2245. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2246. int index = 0;
  2247. try
  2248. {
  2249. for (int i = 0; i < strDataTemp.Length; i++)
  2250. {
  2251. if (strDataTemp[i].Split('=')[0] == "第四阶段转矩点采集值")
  2252. {
  2253. index = i;
  2254. break;
  2255. }
  2256. }
  2257. for (int i = 0; i < (index + 1); i++)
  2258. {
  2259. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2260. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2261. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2262. }
  2263. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x472E, ConfigParam);
  2264. }
  2265. catch (Exception)
  2266. {
  2267. timer_1s.Enabled = false;
  2268. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2269. timer_1s.Enabled = true;
  2270. }
  2271. }
  2272. /// <summary>
  2273. /// 查询存储标志
  2274. /// </summary>
  2275. /// <param name="sender"></param>
  2276. /// <param name="e"></param>
  2277. private void button_ReadSaveFlag_Click(object sender, EventArgs e)
  2278. {
  2279. radioButton_EE_SaveYes.Checked = false;
  2280. radioButton_EE_SaveNo.Checked = false;
  2281. radioButton_SIP_SaveYes.Checked = false;
  2282. radioButton_SIP_SaveNo.Checked = false;
  2283. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null);
  2284. }
  2285. /// <summary>
  2286. /// 写入存储标志
  2287. /// </summary>
  2288. /// <param name="sender"></param>
  2289. /// <param name="e"></param>
  2290. private void button_WriteSaveFlag_Click(object sender, EventArgs e)
  2291. {
  2292. var SaveFlag = new byte[6];
  2293. for (int i = 0; i < 6; i++)
  2294. SaveFlag[i] = 0;
  2295. if ((radioButton_EE_SaveYes.Checked == false) && (radioButton_EE_SaveNo.Checked == false))
  2296. {
  2297. timer_1s.Enabled = false;
  2298. MessageBox.Show("请选择EEPROM存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2299. timer_1s.Enabled = true;
  2300. return;
  2301. }
  2302. if ((radioButton_SIP_SaveYes.Checked == false) && (radioButton_SIP_SaveNo.Checked == false))
  2303. {
  2304. timer_1s.Enabled = false;
  2305. MessageBox.Show("请选择SIP校验存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2306. timer_1s.Enabled = true;
  2307. return;
  2308. }
  2309. SaveFlag[0] = (byte)((checkBox_SaveYes.Checked) ? 0x01 : 0x00);
  2310. SaveFlag[2] = (byte)(radioButton_EE_SaveYes.Checked ? 0x01 : 0x00);
  2311. SaveFlag[3] = 0;
  2312. SaveFlag[4] = (byte)(radioButton_SIP_SaveYes.Checked ? 0x01 : 0x00);
  2313. SaveFlag[5] = 0;
  2314. timer_1s.Enabled = false;
  2315. if (MessageBox.Show("确认修改存储标志?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2316. {
  2317. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4906, SaveFlag);
  2318. }
  2319. timer_1s.Enabled = true;
  2320. }
  2321. /// <summary>
  2322. /// 读取指定地址数据
  2323. /// </summary>
  2324. /// <param name="sender"></param>
  2325. /// <param name="e"></param>
  2326. private void button_ReadRamFlash_Click(object sender, EventArgs e)
  2327. {
  2328. var Address = new byte[4];
  2329. UInt32 Address_Begin;
  2330. UInt32 Addres_End;
  2331. if(checkBox_ReadRanFlash_AutoClear.Checked == true)
  2332. richTextBox_RamFlasgData.Clear();
  2333. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  2334. {
  2335. timer_1s.Enabled = false;
  2336. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2337. timer_1s.Enabled = true;
  2338. return;
  2339. }
  2340. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  2341. {
  2342. timer_1s.Enabled = false;
  2343. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2344. timer_1s.Enabled = true;
  2345. return;
  2346. }
  2347. else
  2348. {
  2349. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  2350. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2351. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  2352. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2353. if (Addres_End < Address_Begin)
  2354. {
  2355. timer_1s.Enabled = false;
  2356. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2357. timer_1s.Enabled = true;
  2358. return;
  2359. }
  2360. else
  2361. {
  2362. var SendByte = new byte[8];
  2363. SendByte[0] = (byte)(Address_Begin >> 24);
  2364. SendByte[1] = (byte)(Address_Begin >> 16);
  2365. SendByte[2] = (byte)(Address_Begin >> 8);
  2366. SendByte[3] = (byte)(Address_Begin);
  2367. SendByte[4] = (byte)(Addres_End >> 24);
  2368. SendByte[5] = (byte)(Addres_End >> 16);
  2369. SendByte[6] = (byte)(Addres_End >> 8);
  2370. SendByte[7] = (byte)(Addres_End);
  2371. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  2372. }
  2373. }
  2374. }
  2375. /// <summary>
  2376. /// 工作模式选择
  2377. /// </summary>
  2378. /// <param name="sender"></param>
  2379. /// <param name="e"></param>
  2380. private void comboBox_WorkMode_SelectedIndexChanged(object sender, EventArgs e)
  2381. {
  2382. var RunMode = new byte[1];
  2383. if (comboBox_WorkMode.Text == "配置模式")
  2384. RunMode[0] = 0x01;
  2385. else
  2386. RunMode[0] = 0x00;
  2387. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  2388. }
  2389. /// <summary>
  2390. /// 助力档位选择
  2391. /// </summary>
  2392. /// <param name="sender"></param>
  2393. /// <param name="e"></param>
  2394. private void comboBox_GearSt_SelectedIndexChanged(object sender, EventArgs e)
  2395. {
  2396. var CtrlCode = new byte[2];
  2397. if (comboBox_GearSt.SelectedIndex == 5)//档位
  2398. CtrlCode[0] = 0x33;
  2399. else if (comboBox_GearSt.SelectedIndex == 6)//档位
  2400. CtrlCode[0] = 0x22;
  2401. else
  2402. CtrlCode[0] = (byte)comboBox_GearSt.SelectedIndex;
  2403. if (comboBox_LightSwitch.SelectedIndex == 0)//车灯
  2404. CtrlCode[1] = 0xF1;
  2405. else
  2406. CtrlCode[1] = 0xF0;
  2407. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  2408. comboBox_OBC_SetGearST.SelectedIndex = comboBox_GearSt.SelectedIndex;
  2409. comboBox_OBC_LightSw.SelectedIndex = comboBox_LightSwitch.SelectedIndex;
  2410. }
  2411. /// <summary>
  2412. /// 仪表档位选择
  2413. /// </summary>
  2414. /// <param name="sender"></param>
  2415. /// <param name="e"></param>
  2416. private void comboBox_OBC_SetGearST_SelectedIndexChanged(object sender, EventArgs e)
  2417. {
  2418. comboBox_GearSt.SelectedIndex = comboBox_OBC_SetGearST.SelectedIndex;
  2419. comboBox_LightSwitch.SelectedIndex = comboBox_OBC_LightSw.SelectedIndex;
  2420. }
  2421. /// <summary>
  2422. /// 生产模式初始化
  2423. /// </summary>
  2424. /// <param name="sender"></param>
  2425. /// <param name="e"></param>
  2426. private void button_FacModeInit_Click(object sender, EventArgs e)
  2427. {
  2428. var Code = new byte[5];
  2429. Code[0] = (byte)'C';
  2430. Code[1] = (byte)'L';
  2431. Code[2] = (byte)'E';
  2432. Code[3] = (byte)'A';
  2433. Code[4] = (byte)'R';
  2434. timer_1s.Enabled = false;
  2435. if (MessageBox.Show("电机即将初始化!", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2436. {
  2437. if (MessageBox.Show("请再次确认", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2438. {
  2439. timer_1s.Enabled = true;
  2440. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  2441. PowerOffAckStatus = false;
  2442. Delay_ms(250);
  2443. int TryCnt = 3;
  2444. while ((TryCnt--) >= 0)
  2445. {
  2446. if (!PowerOffAckStatus)
  2447. {
  2448. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  2449. PowerOffAckStatus = false;
  2450. Delay_ms(250);
  2451. }
  2452. else break;
  2453. }
  2454. if (PowerOffAckStatus)
  2455. {
  2456. timer_1s.Enabled = false;
  2457. MessageBox.Show("系统已关机,请保持无负载重新开机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  2458. timer_1s.Enabled = true;
  2459. }
  2460. else
  2461. {
  2462. timer_1s.Enabled = false;
  2463. MessageBox.Show("初始化失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2464. timer_1s.Enabled = true;
  2465. }
  2466. timer_1s.Enabled = true;
  2467. }
  2468. }
  2469. timer_1s.Enabled = true;
  2470. //清除历史测试记录
  2471. textBox_FacModeSensorADC0.Text = "";
  2472. textBox_FacModeSensorADC1.Text = "";
  2473. textBox_FacModeSensorADC2.Text = "";
  2474. textBox_FacModeSensorADC3.Text = "";
  2475. textBox_FacModeSensorADC4.Text = "";
  2476. checkBox_FacModeCheckBikeSpeed.Checked = false;
  2477. checkBox_FacModeCheckCadence.Checked = false;
  2478. checkBox_FacModeCheckNTC.Checked = false;
  2479. checkBox_FacModeCheckVol.Checked = false;
  2480. LightSwitchStatus = false;
  2481. MotorRunStatus = false;
  2482. trackBar_FacModeMotorSpeedAdj.Value = 5;
  2483. textBox_FacModeWheelSize.Text = "";
  2484. textBox_FacModeSpeedLimit.Text = "";
  2485. comboBox_FacModeAssist1.SelectedIndex = -1;
  2486. comboBox_FacModeAssist2.SelectedIndex = -1;
  2487. comboBox_FacModeLightVol.SelectedIndex = -1;
  2488. comboBox_FacModeStartMode.SelectedIndex = -1;
  2489. textBox_FacModeStartGain.Text = "";
  2490. textBox_FacModeCircuitK.Text = "";
  2491. textBox_FacModeFltCounter.Text = "";
  2492. textBox_FacModeSpeedLimitTh.Text = "";
  2493. textBox_FacModeSpeedLimitEnd.Text = "";
  2494. textBox_FacModeCadencePer.Text = "";
  2495. textBox_FacModeName.Text = "";
  2496. textBox_FacModeNum.Text = "";
  2497. textBox_FacModeHW.Text = "";
  2498. textBox_FacModeFW.Text = "";
  2499. }
  2500. /// <summary>
  2501. /// 生产模式读取传感器参数
  2502. /// </summary>
  2503. /// <param name="sender"></param>
  2504. /// <param name="e"></param>
  2505. private void button_FacModeSensorRead_Click(object sender, EventArgs e)
  2506. {
  2507. richTextBox_SensorParam.Clear();
  2508. textBox_FacModeSensorADC0.Text = "";
  2509. textBox_FacModeSensorADC1.Text = "";
  2510. textBox_FacModeSensorADC2.Text = "";
  2511. textBox_FacModeSensorADC3.Text = "";
  2512. textBox_FacModeSensorADC4.Text = "";
  2513. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  2514. }
  2515. /// <summary>
  2516. /// 生产模式传感器标定1
  2517. /// </summary>
  2518. /// <param name="sender"></param>
  2519. /// <param name="e"></param>
  2520. private void buttonFacModeSet1_Click(object sender, EventArgs e)
  2521. {
  2522. var ConfigParam = new byte[4];
  2523. for (int i = 0; i < 4; i++)
  2524. ConfigParam[i] = 0;
  2525. ushort uwDataTemp = 0;
  2526. try
  2527. {
  2528. uwDataTemp = 1;//负载序号
  2529. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  2530. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  2531. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal1.Text) * 10); ;//负载值0.1Nm
  2532. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  2533. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  2534. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  2535. Delay_ms(200);
  2536. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  2537. }
  2538. catch (Exception)
  2539. {
  2540. timer_1s.Enabled = false;
  2541. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2542. timer_1s.Enabled = true;
  2543. }
  2544. }
  2545. /// <summary>
  2546. /// 生产模式传感器标定2
  2547. /// </summary>
  2548. /// <param name="sender"></param>
  2549. /// <param name="e"></param>
  2550. private void buttonFacModeSet2_Click(object sender, EventArgs e)
  2551. {
  2552. var ConfigParam = new byte[4];
  2553. for (int i = 0; i < 4; i++)
  2554. ConfigParam[i] = 0;
  2555. ushort uwDataTemp = 0;
  2556. try
  2557. {
  2558. uwDataTemp = 2;//负载序号
  2559. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  2560. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  2561. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal2.Text) * 10); ;//负载值0.1Nm
  2562. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  2563. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  2564. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  2565. Delay_ms(200);
  2566. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  2567. }
  2568. catch (Exception)
  2569. {
  2570. timer_1s.Enabled = false;
  2571. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2572. timer_1s.Enabled = true;
  2573. }
  2574. }
  2575. /// <summary>
  2576. /// 生产模式传感器标定3
  2577. /// </summary>
  2578. /// <param name="sender"></param>
  2579. /// <param name="e"></param>
  2580. private void buttonFacModeSet3_Click(object sender, EventArgs e)
  2581. {
  2582. var ConfigParam = new byte[4];
  2583. for (int i = 0; i < 4; i++)
  2584. ConfigParam[i] = 0;
  2585. ushort uwDataTemp = 0;
  2586. try
  2587. {
  2588. uwDataTemp = 3;//负载序号
  2589. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  2590. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  2591. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal3.Text) * 10); ;//负载值0.1Nm
  2592. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  2593. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  2594. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  2595. Delay_ms(200);
  2596. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  2597. }
  2598. catch (Exception)
  2599. {
  2600. timer_1s.Enabled = false;
  2601. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2602. timer_1s.Enabled = true;
  2603. }
  2604. }
  2605. /// <summary>
  2606. /// 生产模式传感器标定3
  2607. /// </summary>
  2608. /// <param name="sender"></param>
  2609. /// <param name="e"></param>
  2610. private void buttonFacModeSet4_Click(object sender, EventArgs e)
  2611. {
  2612. var ConfigParam = new byte[4];
  2613. for (int i = 0; i < 4; i++)
  2614. ConfigParam[i] = 0;
  2615. ushort uwDataTemp = 0;
  2616. try
  2617. {
  2618. uwDataTemp = 4;//负载序号
  2619. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  2620. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  2621. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal4.Text) * 10); ;//负载值0.1Nm
  2622. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  2623. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  2624. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  2625. Delay_ms(200);
  2626. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  2627. }
  2628. catch (Exception)
  2629. {
  2630. timer_1s.Enabled = false;
  2631. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2632. timer_1s.Enabled = true;
  2633. }
  2634. }
  2635. /// <summary>
  2636. /// 生产模式采集按钮
  2637. /// </summary>
  2638. /// <param name="sender"></param>
  2639. /// <param name="e"></param>
  2640. private void button_FacModeWorkMode_Click(object sender, EventArgs e)
  2641. {
  2642. var RunMode = new byte[1];
  2643. if (button_FacModeWorkMode.Text == "开始")
  2644. {
  2645. RunMode[0] = 0x01;
  2646. if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode))
  2647. {
  2648. button_FacModeWorkMode.Text = "停止";
  2649. button_FacModeWorkMode.BackColor = Color.Yellow;
  2650. }
  2651. }
  2652. else if (button_FacModeWorkMode.Text == "停止")
  2653. {
  2654. RunMode[0] = 0x00;
  2655. if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode))
  2656. {
  2657. button_FacModeWorkMode.Text = "开始";
  2658. button_FacModeWorkMode.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
  2659. }
  2660. }
  2661. }
  2662. /// <summary>
  2663. /// 生产模式开关灯
  2664. /// </summary>
  2665. /// <param name="sender"></param>
  2666. /// <param name="e"></param>
  2667. bool LightSwitchStatus = false;
  2668. private void button_FacModeLightSW_Click(object sender, EventArgs e)
  2669. {
  2670. var CtrlCode = new byte[2];
  2671. CtrlCode[0] = 0x00;
  2672. if (LightSwitchStatus)
  2673. {
  2674. CtrlCode[1] = 0xF0;
  2675. button_FacModeLightSW.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128)))));
  2676. }
  2677. else
  2678. {
  2679. CtrlCode[1] = 0xF1;
  2680. button_FacModeLightSW.BackColor = Color.Yellow;
  2681. }
  2682. if(mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode))
  2683. {
  2684. LightSwitchStatus = !LightSwitchStatus;
  2685. comboBox_LightSwitch.SelectedIndex = LightSwitchStatus ? 0 : 1;
  2686. comboBox_OBC_LightSw.SelectedIndex = LightSwitchStatus ? 0 : 1;
  2687. }
  2688. }
  2689. /// <summary>
  2690. /// 生产模式电机控制
  2691. /// </summary>
  2692. /// <param name="sender"></param>
  2693. /// <param name="e"></param>
  2694. bool MotorRunStatus = false;
  2695. private void button_FacModeMotorRun_Click(object sender, EventArgs e)
  2696. {
  2697. string DebugDefaultInfo = "整体运行模式=4, 位置获取模式=1, 采样模式=2, 旋转方向=1, 定位电流=1000, 拖拽电压=18, 拖拽电流=1000, 拖拽频率=20, 加速斜率=500, 减速斜率=100, 转速环控制器带宽=15, 转速环控制器m=4, 电流环控制器带宽=300, 电流环控制器m=1, 磁链观测器带宽=10, 磁链观测器m=10, 锁相环带宽=150, 锁相环m=2, 惯量=300, PWM 最大占空比=900, PWM七段式切五段式阈值=700, 功率限幅值=6500, 功率Error=500, 功率限幅Kp=20, 功率限幅Ki=3000";
  2698. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  2699. var ConfigParam = new byte[60];
  2700. for (int i = 0; i < 60; i++)
  2701. ConfigParam[i] = 0;
  2702. ConfigParam[0] = 0x00;
  2703. ushort uwDataTemp = 0;
  2704. if (!MotorRunStatus) //停止状态
  2705. {
  2706. //设置电机系列
  2707. if (radioButton_FacModeDriverCity.Checked == true)
  2708. {
  2709. strDataTemp[0] = "整体运行模式=3";
  2710. strDataTemp[3] = "旋转方向=1";
  2711. strDataTemp[18] = "惯量=300";
  2712. }
  2713. else if (radioButton_FacModeDriverMtb.Checked == true)
  2714. {
  2715. strDataTemp[0] = "整体运行模式=3";
  2716. strDataTemp[3] = "旋转方向=0";
  2717. strDataTemp[18] = "惯量=500";
  2718. }
  2719. else
  2720. {
  2721. timer_1s.Enabled = false;
  2722. MessageBox.Show("请选择电机类型!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2723. timer_1s.Enabled = true;
  2724. return;
  2725. }
  2726. //设置带载类型
  2727. if (label_Load.Text == "空载")
  2728. {
  2729. strDataTemp[10] = "转速环控制器带宽=3";
  2730. }
  2731. else if (label_Load.Text == "带载")
  2732. {
  2733. strDataTemp[10] = "转速环控制器带宽=15";
  2734. }
  2735. else
  2736. {
  2737. timer_1s.Enabled = false;
  2738. MessageBox.Show("请选择带载类型!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2739. timer_1s.Enabled = true;
  2740. return;
  2741. }
  2742. //选择位置模式
  2743. if (label_MotorSensor.Text == "有感")
  2744. {
  2745. strDataTemp[1] = "位置获取模式=1";
  2746. }
  2747. else if (label_MotorSensor.Text == "无感")
  2748. {
  2749. strDataTemp[1] = "位置获取模式=0";
  2750. }
  2751. else
  2752. {
  2753. timer_1s.Enabled = false;
  2754. MessageBox.Show("请选择位置模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2755. timer_1s.Enabled = true;
  2756. return;
  2757. }
  2758. //发送数据
  2759. try
  2760. {
  2761. for (int i = 0; i < strDataTemp.Length; i++)
  2762. {
  2763. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2764. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2765. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2766. }
  2767. if(!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  2768. return;
  2769. }
  2770. catch (Exception)
  2771. {
  2772. timer_1s.Enabled = false;
  2773. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2774. timer_1s.Enabled = true;
  2775. }
  2776. //设置转速百分比100%
  2777. trackBar_FacModeMotorSpeedAdj.Value = 100;
  2778. MotorRunStatus = !MotorRunStatus;
  2779. button_FacModeMotorRun.BackColor = Color.Yellow;
  2780. //电机进入配置模式
  2781. var RunMode = new byte[1];
  2782. RunMode[0] = 0x01;
  2783. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  2784. button_FacModeWorkMode.Text = "停止";
  2785. button_FacModeWorkMode.BackColor = Color.Yellow;
  2786. }
  2787. else //运转状态
  2788. {
  2789. //设置电机调试参数
  2790. if (radioButton_FacModeDriverCity.Checked == true)
  2791. {
  2792. strDataTemp[0] = "整体运行模式=4";
  2793. strDataTemp[1] = "位置获取模式=1";
  2794. strDataTemp[3] = "旋转方向=1";
  2795. strDataTemp[10] = "转速环控制器带宽=15";
  2796. strDataTemp[18] = "惯量=300";
  2797. }
  2798. else if (radioButton_FacModeDriverMtb.Checked == true)
  2799. {
  2800. strDataTemp[0] = "整体运行模式=5";
  2801. strDataTemp[1] = "位置获取模式=1";
  2802. strDataTemp[3] = "旋转方向=0";
  2803. strDataTemp[10] = "转速环控制器带宽=15";
  2804. strDataTemp[18] = "惯量=500";
  2805. }
  2806. else
  2807. {
  2808. timer_1s.Enabled = false;
  2809. MessageBox.Show("请选择电机类型!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2810. timer_1s.Enabled = true;
  2811. return;
  2812. }
  2813. try
  2814. {
  2815. for (int i = 0; i < strDataTemp.Length; i++)
  2816. {
  2817. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2818. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2819. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2820. }
  2821. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  2822. return;
  2823. }
  2824. catch (Exception)
  2825. {
  2826. timer_1s.Enabled = false;
  2827. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2828. timer_1s.Enabled = true;
  2829. }
  2830. //设置转速百分比2%
  2831. trackBar_FacModeMotorSpeedAdj.Value = 2;
  2832. MotorRunStatus = !MotorRunStatus;
  2833. button_FacModeMotorRun.BackColor = Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
  2834. //电机退出配置模式
  2835. var RunMode = new byte[1];
  2836. RunMode[0] = 0x00;
  2837. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  2838. button_FacModeWorkMode.Text = "开始";
  2839. button_FacModeWorkMode.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
  2840. }
  2841. }
  2842. /// <summary>
  2843. /// 生产模式转速调节
  2844. /// </summary>
  2845. /// <param name="sender"></param>
  2846. /// <param name="e"></param>
  2847. private void trackBar_FacModeMotorSpeedAdj_ValueChanged(object sender, EventArgs e)
  2848. {
  2849. //转速百分比更新
  2850. label_FacModeMotorSpeedSet.Text = trackBar_FacModeMotorSpeedAdj.Value.ToString() + "%";
  2851. numericUpDown_SpeedAdj.Value = trackBar_FacModeMotorSpeedAdj.Value;
  2852. }
  2853. /// <summary>
  2854. /// 生产模式读取整车参数
  2855. /// </summary>
  2856. /// <param name="sender"></param>
  2857. /// <param name="e"></param>
  2858. private void button_FacModeBikeParaRead_Click(object sender, EventArgs e)
  2859. {
  2860. textBox_FacModeWheelSize.Text = "";
  2861. textBox_FacModeSpeedLimit.Text = "";
  2862. comboBox_FacModeAssist1.SelectedIndex = -1;
  2863. comboBox_FacModeAssist2.SelectedIndex = -1;
  2864. comboBox_FacModeLightVol.SelectedIndex = -1;
  2865. comboBox_FacModeStartMode.SelectedIndex = -1;
  2866. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
  2867. }
  2868. /// <summary>
  2869. /// 生产模式写入整车参数
  2870. /// </summary>
  2871. /// <param name="sender"></param>
  2872. /// <param name="e"></param>
  2873. private void button_FacModeBikeParaSet_Click(object sender, EventArgs e)
  2874. {
  2875. string BikeDefaultInfo = "轮胎周长=219, 电控传动比=35, 助力最大限速=25, 推行模式限速=6, 前牙盘T数=38, 后牙盘T数=11, 助力方案1=341, 助力方案2=682, 前后灯电压=6, 轮胎周长微调=0, 启动模式=2, 自动关机时间=15";
  2876. var ConfigParam = new byte[28];
  2877. for (int i = 0; i < 28; i++)
  2878. ConfigParam[i] = 0;
  2879. ConfigParam[0] = (byte)(0x01);
  2880. ushort uwDataTemp = 0;
  2881. string[] strDataTemp = BikeDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  2882. try
  2883. {
  2884. for (int i = 0; i < strDataTemp.Length; i++)
  2885. {
  2886. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2887. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2888. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2889. }
  2890. //周长
  2891. uwDataTemp = Convert.ToUInt16(textBox_FacModeWheelSize.Text);
  2892. ConfigParam[2] = (byte)uwDataTemp;
  2893. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  2894. //限速
  2895. uwDataTemp = Convert.ToUInt16(textBox_FacModeSpeedLimit.Text);
  2896. ConfigParam[6] = (byte)uwDataTemp;
  2897. ConfigParam[7] = (byte)(uwDataTemp >> 8);
  2898. //助力方案1
  2899. if (comboBox_FacModeAssist1.SelectedIndex == 0) uwDataTemp = 0;
  2900. else if (comboBox_FacModeAssist1.SelectedIndex == 1) uwDataTemp = 341;
  2901. else if (comboBox_FacModeAssist1.SelectedIndex == 2) uwDataTemp = 682;
  2902. else
  2903. {
  2904. timer_1s.Enabled = false;
  2905. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2906. timer_1s.Enabled = true;
  2907. return;
  2908. }
  2909. ConfigParam[14] = (byte)uwDataTemp;
  2910. ConfigParam[15] = (byte)(uwDataTemp >> 8);
  2911. //助力方案2
  2912. if(comboBox_FacModeAssist2.SelectedIndex == 0) uwDataTemp = 0;
  2913. else if (comboBox_FacModeAssist2.SelectedIndex == 1) uwDataTemp = 341;
  2914. else if (comboBox_FacModeAssist2.SelectedIndex == 2) uwDataTemp = 682;
  2915. else
  2916. {
  2917. timer_1s.Enabled = false;
  2918. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2919. timer_1s.Enabled = true;
  2920. return;
  2921. }
  2922. ConfigParam[16] = (byte)uwDataTemp;
  2923. ConfigParam[17] = (byte)(uwDataTemp >> 8);
  2924. //灯压
  2925. if(comboBox_FacModeLightVol.SelectedIndex == 0) uwDataTemp = 6;
  2926. else if (comboBox_FacModeLightVol.SelectedIndex == 1) uwDataTemp = 12;
  2927. else
  2928. {
  2929. timer_1s.Enabled = false;
  2930. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2931. timer_1s.Enabled = true;
  2932. return;
  2933. }
  2934. ConfigParam[18] = (byte)uwDataTemp;
  2935. ConfigParam[19] = (byte)(uwDataTemp >> 8);
  2936. //启动模式
  2937. if (comboBox_FacModeStartMode.SelectedIndex == 0) uwDataTemp = 1;
  2938. else if (comboBox_FacModeStartMode.SelectedIndex == 2) uwDataTemp = 3;
  2939. else uwDataTemp = 2;
  2940. ConfigParam[22] = (byte)uwDataTemp;
  2941. ConfigParam[23] = (byte)(uwDataTemp >> 8);
  2942. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1C, ConfigParam);
  2943. }
  2944. catch (Exception)
  2945. {
  2946. timer_1s.Enabled = false;
  2947. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2948. timer_1s.Enabled = true;
  2949. }
  2950. }
  2951. /// <summary>
  2952. /// 生产模式读取助力参数
  2953. /// </summary>
  2954. /// <param name="sender"></param>
  2955. /// <param name="e"></param>
  2956. private void button_FacModeAssistParaRead_Click(object sender, EventArgs e)
  2957. {
  2958. var ConfigParam = new byte[4];
  2959. textBox_FacModeStartGain.Text = "";
  2960. textBox_FacModeCircuitK.Text = "";
  2961. textBox_FacModeFltCounter.Text = "";
  2962. textBox_FacModeSpeedLimitTh.Text ="";
  2963. textBox_FacModeSpeedLimitEnd.Text = "";
  2964. textBox_FacModeCadencePer.Text = "";
  2965. ConfigParam[0] = (byte)(1 & 0xFF);
  2966. ConfigParam[1] = (byte)(1 >> 8);
  2967. ConfigParam[2] = (byte)(1 & 0xFF);
  2968. ConfigParam[3] = (byte)(1 >> 8);
  2969. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
  2970. }
  2971. /// <summary>
  2972. /// 生产模式写入助力参数
  2973. /// </summary>
  2974. /// <param name="sender"></param>
  2975. /// <param name="e"></param>
  2976. private void button_FacModeAssistParaSet_Click(object sender, EventArgs e)
  2977. {
  2978. string AssistDefaultInfo = "零速启动增益=4096, 巡航启动增益=4096, 助力转矩曲线编号=1, 助力踏频曲线编号=1, 转矩曲线.a=0, 转矩曲线.b=0, 转矩曲线.c=2048, 转矩曲线.d=137, 踏频曲线.a=0, 踏频曲线.b=0, 踏频曲线.c=35000, 踏频曲线.d=0, 助力启动阈值=80, 助力停止阈值=40, 启动时电流增长阶梯=10, 启动对应踏频脉冲数=32, 转矩滤波对应踏频脉冲数=45, 待速转速=0, 待速最大电流=500, 车速限幅启动阈值=25, 车速限幅停止阈值=27, 踏频占比=1229";
  2979. var ConfigParam = new byte[80];
  2980. for (int i = 0; i < 80; i++)
  2981. ConfigParam[i] = 0;
  2982. ConfigParam[0] = (byte)(0x01);
  2983. ushort uwDataTemp = 0;
  2984. ulong ulDataTemp = 0;
  2985. int index_1 = 0, index_2 = 0;
  2986. string[] strDataTemp = AssistDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  2987. try
  2988. {
  2989. //因数据类型不同,预处理
  2990. for (int i = 0; i < strDataTemp.Length; i++)
  2991. {
  2992. if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
  2993. {
  2994. index_1 = i;
  2995. break;
  2996. }
  2997. }
  2998. for (int i = 0; i < strDataTemp.Length; i++)
  2999. {
  3000. if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
  3001. {
  3002. index_2 = i;
  3003. break;
  3004. }
  3005. }
  3006. for (int i = 0; i < strDataTemp.Length; i++)
  3007. {
  3008. ulDataTemp = Convert.ToUInt32(strDataTemp[i].Split('=')[1]);
  3009. if (i < index_1)
  3010. {
  3011. ConfigParam[2 * i + 4] = (byte)ulDataTemp;
  3012. ConfigParam[2 * i + 5] = (byte)(ulDataTemp >> 8);
  3013. }
  3014. else if (i <= index_2)
  3015. {
  3016. ConfigParam[4 * i - 4] = (byte)ulDataTemp;
  3017. ConfigParam[4 * i - 3] = (byte)(ulDataTemp >> 8);
  3018. ConfigParam[4 * i - 2] = (byte)(ulDataTemp >> 16);
  3019. ConfigParam[4 * i - 1] = (byte)(ulDataTemp >> 24);
  3020. }
  3021. else
  3022. {
  3023. ConfigParam[2 * i + 20] = (byte)ulDataTemp;
  3024. ConfigParam[2 * i + 21] = (byte)(ulDataTemp >> 8);
  3025. }
  3026. }
  3027. //零速增益
  3028. uwDataTemp = Convert.ToUInt16(textBox_FacModeStartGain.Text);
  3029. ConfigParam[4] = (byte)uwDataTemp;
  3030. ConfigParam[5] = (byte)(uwDataTemp >> 8);
  3031. //电流阶梯
  3032. uwDataTemp = Convert.ToUInt16(textBox_FacModeCircuitK.Text);
  3033. ConfigParam[48] = (byte)uwDataTemp;
  3034. ConfigParam[49] = (byte)(uwDataTemp >> 8);
  3035. //滤波脉冲
  3036. uwDataTemp = Convert.ToUInt16(textBox_FacModeFltCounter.Text);
  3037. ConfigParam[52] = (byte)uwDataTemp;
  3038. ConfigParam[53] = (byte)(uwDataTemp >> 8);
  3039. //限速启动
  3040. uwDataTemp = Convert.ToUInt16(textBox_FacModeSpeedLimitTh.Text);
  3041. ConfigParam[58] = (byte)uwDataTemp;
  3042. ConfigParam[59] = (byte)(uwDataTemp >> 8);
  3043. //限速停止
  3044. uwDataTemp = Convert.ToUInt16(textBox_FacModeSpeedLimitEnd.Text);
  3045. ConfigParam[60] = (byte)uwDataTemp;
  3046. ConfigParam[61] = (byte)(uwDataTemp >> 8);
  3047. //踏频占比
  3048. uwDataTemp = Convert.ToUInt16(textBox_FacModeCadencePer.Text);
  3049. ConfigParam[62] = (byte)uwDataTemp;
  3050. ConfigParam[63] = (byte)(uwDataTemp >> 8);
  3051. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
  3052. }
  3053. catch (Exception)
  3054. {
  3055. timer_1s.Enabled = false;
  3056. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3057. timer_1s.Enabled = true;
  3058. }
  3059. }
  3060. /// <summary>
  3061. /// 生产模式写入型号
  3062. /// </summary>
  3063. /// <param name="sender"></param>
  3064. /// <param name="e"></param>
  3065. private void button_FacModeSetName_Click(object sender, EventArgs e)
  3066. {
  3067. string Mode = textBox_FacModeName.Text;
  3068. var ModeArray = new byte[16];
  3069. for (ushort i = 0; i < Mode.Length; i++)
  3070. {
  3071. ModeArray[i] = (byte)Mode[i];
  3072. }
  3073. if (Mode.Length < 16)
  3074. {
  3075. ModeArray[Mode.Length] = (byte)'.';
  3076. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  3077. {
  3078. ModeArray[Mode.Length + 1 + i] = 0x20;
  3079. }
  3080. }
  3081. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  3082. }
  3083. /// <summary>
  3084. /// 生产模式写入SN
  3085. /// </summary>
  3086. /// <param name="sender"></param>
  3087. /// <param name="e"></param>
  3088. private void Button_FacModeSetNum_Click(object sender, EventArgs e)
  3089. {
  3090. string SN = textBox_FacModeNum.Text;
  3091. var SNArray = new byte[16];
  3092. for (ushort i = 0; i < SN.Length; i++)
  3093. {
  3094. SNArray[i] = (byte)SN[i];
  3095. }
  3096. if (SN.Length < 16)
  3097. {
  3098. SNArray[SN.Length] = (byte)'.';
  3099. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  3100. {
  3101. SNArray[SN.Length + 1 + i] = 0x20;
  3102. }
  3103. }
  3104. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  3105. }
  3106. /// <summary>
  3107. /// 生产模式读取版本信息
  3108. /// </summary>
  3109. /// <param name="sender"></param>
  3110. /// <param name="e"></param>
  3111. private void Button_FacModeReadVer_Click_1(object sender, EventArgs e)
  3112. {
  3113. textBox_Model.Text = "---";
  3114. textBox_SN.Text = "---";
  3115. textBox_HW.Text = "---";
  3116. textBox_FW.Text = "---";
  3117. textBox_SP.Text = "---";
  3118. textBox_OBC_ReadModel.Text = "---";
  3119. textBox_OBC_ReadSN.Text = "---";
  3120. textBox_OBC_ReadHW.Text = "---";
  3121. textBox_OBC_ReadFW.Text = "---";
  3122. textBox_OBC_ReadSP.Text = "---";
  3123. textBox_FacModeName.Text = "---";
  3124. textBox_FacModeNum.Text = "---";
  3125. textBox_FacModeHW.Text = "---";
  3126. textBox_FacModeFW.Text = "---";
  3127. textBox_FacModeSP.Text = "---";
  3128. Class_Motor_Ver.Mode = "---";
  3129. Class_Motor_Ver.SN = "---";
  3130. Class_Motor_Ver.HW = "---";
  3131. Class_Motor_Ver.FW = "---";
  3132. Class_Motor_Ver.Special = "---";
  3133. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  3134. }
  3135. /// <summary>
  3136. /// 生产模式写入生产信息
  3137. /// </summary>
  3138. /// <param name="sender"></param>
  3139. /// <param name="e"></param>
  3140. private void Button_FacModeSetMacDate_Click(object sender, EventArgs e)
  3141. {
  3142. var MACArray = new byte[32];
  3143. string MacDefaultInfo = "TTIUM";
  3144. string MacAddDefaultInfo = "WUHAN";
  3145. string MacDateDefaultInfo = DateTime.Now.ToString("yyyyMMdd");
  3146. string MacPPDefaultInfo = "MM_MC1";
  3147. //填入生产商
  3148. for (ushort i = 0; i < MacDefaultInfo.Length; i++)
  3149. {
  3150. MACArray[i] = (byte)MacDefaultInfo[i];
  3151. }
  3152. if (MacDefaultInfo.Length < 8)
  3153. {
  3154. MACArray[MacDefaultInfo.Length] = (byte)'.';
  3155. for (ushort i = 0; i < 8 - MacDefaultInfo.Length - 1; i++)
  3156. {
  3157. MACArray[MacDefaultInfo.Length + 1 + i] = 0x20;
  3158. }
  3159. }
  3160. //填入生产地
  3161. for (ushort i = 0; i < MacAddDefaultInfo.Length; i++)
  3162. {
  3163. MACArray[8 + i] = (byte)MacAddDefaultInfo[i];
  3164. }
  3165. if (MacAddDefaultInfo.Length < 8)
  3166. {
  3167. MACArray[MacAddDefaultInfo.Length + 8] = (byte)'.';
  3168. for (ushort i = 0; i < 8 - MacAddDefaultInfo.Length - 1; i++)
  3169. {
  3170. MACArray[MacAddDefaultInfo.Length + 1 + i + 8] = 0x20;
  3171. }
  3172. }
  3173. //填入生产日期
  3174. for (ushort i = 0; i < MacDateDefaultInfo.Length; i++)
  3175. {
  3176. MACArray[16 + i] = (byte)MacDateDefaultInfo[i];
  3177. }
  3178. if (MacDateDefaultInfo.Length < 8)
  3179. {
  3180. MACArray[MacDateDefaultInfo.Length + 16] = (byte)'.';
  3181. for (ushort i = 0; i < 8 - MacDateDefaultInfo.Length - 1; i++)
  3182. {
  3183. MACArray[MacDateDefaultInfo.Length + 1 + i + 16] = 0x20;
  3184. }
  3185. }
  3186. //填入产品标识
  3187. for (ushort i = 0; i < MacPPDefaultInfo.Length; i++)
  3188. {
  3189. MACArray[24 + i] = (byte)MacPPDefaultInfo[i];
  3190. }
  3191. if (MacPPDefaultInfo.Length < 8)
  3192. {
  3193. MACArray[MacPPDefaultInfo.Length + 24] = (byte)'.';
  3194. for (ushort i = 0; i < 8 - MacPPDefaultInfo.Length - 1; i++)
  3195. {
  3196. MACArray[MacPPDefaultInfo.Length + 1 + i + 24] = 0x20;
  3197. }
  3198. }
  3199. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  3200. }
  3201. /// <summary>
  3202. /// 生产模式保存测试页面
  3203. /// </summary>
  3204. /// <param name="sender"></param>
  3205. /// <param name="e"></param>
  3206. private void Button_FacModeSaveResult_Click(object sender, EventArgs e)
  3207. {
  3208. //查询传感器
  3209. richTextBox_SensorParam.Clear();
  3210. textBox_FacModeSensorADC0.Text = "";
  3211. textBox_FacModeSensorADC1.Text = "";
  3212. textBox_FacModeSensorADC2.Text = "";
  3213. textBox_FacModeSensorADC3.Text = "";
  3214. textBox_FacModeSensorADC4.Text = "";
  3215. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) return;
  3216. Delay_ms(100);
  3217. //读取一次电机信息
  3218. var CtrlCode = new byte[2];
  3219. CtrlCode[0] = 0x00;
  3220. CtrlCode[1] = 0xF0;
  3221. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode)) return;
  3222. Delay_ms(100);
  3223. //读取一次整车参数
  3224. textBox_FacModeWheelSize.Text = "";
  3225. textBox_FacModeSpeedLimit.Text = "";
  3226. comboBox_FacModeAssist1.SelectedIndex = -1;
  3227. comboBox_FacModeAssist2.SelectedIndex = -1;
  3228. comboBox_FacModeLightVol.SelectedIndex = -1;
  3229. comboBox_FacModeStartMode.SelectedIndex = -1;
  3230. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) return;
  3231. Delay_ms(100);
  3232. //读取一次助力参数
  3233. var ConfigParam = new byte[4];
  3234. textBox_FacModeStartGain.Text = "";
  3235. textBox_FacModeCircuitK.Text = "";
  3236. textBox_FacModeFltCounter.Text = "";
  3237. textBox_FacModeSpeedLimitTh.Text = "";
  3238. textBox_FacModeSpeedLimitEnd.Text = "";
  3239. textBox_FacModeCadencePer.Text = "";
  3240. ConfigParam[0] = (byte)(1 & 0xFF);
  3241. ConfigParam[1] = (byte)(1 >> 8);
  3242. ConfigParam[2] = (byte)(1 & 0xFF);
  3243. ConfigParam[3] = (byte)(1 >> 8);
  3244. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) return;
  3245. Delay_ms(100);
  3246. //读取一次版本信息
  3247. textBox_Model.Text = "---";
  3248. textBox_SN.Text = "---";
  3249. textBox_HW.Text = "---";
  3250. textBox_FW.Text = "---";
  3251. textBox_OBC_ReadModel.Text = "---";
  3252. textBox_OBC_ReadSN.Text = "---";
  3253. textBox_OBC_ReadHW.Text = "---";
  3254. textBox_OBC_ReadFW.Text = "---";
  3255. textBox_FacModeName.Text = "---";
  3256. textBox_FacModeNum.Text = "---";
  3257. textBox_FacModeHW.Text = "---";
  3258. textBox_FacModeFW.Text = "---";
  3259. Class_Motor_Ver.Mode = "---";
  3260. Class_Motor_Ver.SN = "---";
  3261. Class_Motor_Ver.HW = "---";
  3262. Class_Motor_Ver.FW = "---";
  3263. Class_Motor_Ver.Special = "---";
  3264. if (!mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null)) return;
  3265. Delay_ms(100);
  3266. //提示检查
  3267. timer_1s.Enabled = false;
  3268. if (MessageBox.Show("请检查信息是否完整!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  3269. {
  3270. MessageBox.Show("请检查参数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3271. timer_1s.Enabled = true;
  3272. return;
  3273. }
  3274. timer_1s.Enabled = true;
  3275. Delay_ms(200);
  3276. //保存页面
  3277. Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
  3278. Graphics g = Graphics.FromImage(bit);
  3279. g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片
  3280. SaveFileDialog sf = new SaveFileDialog();
  3281. sf.Title = "页面保存";
  3282. sf.FileName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_页面存储" + ".png";
  3283. sf.Filter = "图片|*.png";
  3284. timer_1s.Enabled = false;
  3285. if (sf.ShowDialog() == DialogResult.OK)
  3286. {
  3287. bit.Save(sf.FileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
  3288. }
  3289. timer_1s.Enabled = true;
  3290. }
  3291. /// <summary>
  3292. /// 工具箱页面保存
  3293. /// </summary>
  3294. /// <param name="sender"></param>
  3295. /// <param name="e"></param>
  3296. private void 页面保存ToolStripMenuItem_Click(object sender, EventArgs e)
  3297. {
  3298. //保存页面
  3299. Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
  3300. Graphics g = Graphics.FromImage(bit);
  3301. g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片
  3302. SaveFileDialog sf = new SaveFileDialog();
  3303. sf.Title = "页面保存";
  3304. sf.FileName = "MotorInfo_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".png";
  3305. sf.Filter = "图片|*.png";
  3306. timer_1s.Enabled = false;
  3307. if (sf.ShowDialog() == DialogResult.OK)
  3308. {
  3309. bit.Save(sf.FileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
  3310. }
  3311. timer_1s.Enabled = true;
  3312. }
  3313. /// <summary>
  3314. /// 生产模式关机
  3315. /// </summary>
  3316. /// <param name="sender"></param>
  3317. /// <param name="e"></param>
  3318. private void Button_FacModePowerOff_Click(object sender, EventArgs e)
  3319. {
  3320. var Code = new byte[5];
  3321. Code[0] = (byte)'O';
  3322. Code[1] = (byte)'F';
  3323. Code[2] = (byte)'F';
  3324. Code[3] = (byte)'.';
  3325. Code[4] = (byte)'.';
  3326. timer_1s.Enabled = false;
  3327. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3328. {
  3329. timer_1s.Enabled = true;
  3330. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  3331. PowerOffAckStatus = false;
  3332. Delay_ms(250);
  3333. int TryCnt = 3;
  3334. while ((TryCnt--) >= 0)
  3335. {
  3336. if (!PowerOffAckStatus)
  3337. {
  3338. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  3339. PowerOffAckStatus = false;
  3340. Delay_ms(250);
  3341. }
  3342. else break;
  3343. }
  3344. if (PowerOffAckStatus)
  3345. {
  3346. timer_1s.Enabled = false;
  3347. MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  3348. timer_1s.Enabled = true;
  3349. }
  3350. else
  3351. {
  3352. timer_1s.Enabled = false;
  3353. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3354. timer_1s.Enabled = true;
  3355. }
  3356. }
  3357. timer_1s.Enabled = true;
  3358. }
  3359. //仪表电源键按下
  3360. private void button_OBC_ButtonPower_Click(object sender, EventArgs e)
  3361. {
  3362. var Code = new byte[2];
  3363. Code[0] = 0;
  3364. Code[1] = 0b00100000;
  3365. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  3366. }
  3367. /// <summary>
  3368. /// 仪表加键按下
  3369. /// </summary>
  3370. /// <param name="sender"></param>
  3371. /// <param name="e"></param>
  3372. private void button_OBC_ButtonAcc_Click(object sender, EventArgs e)
  3373. {
  3374. var Code = new byte[2];
  3375. Code[0] = 0;
  3376. Code[1] = 0b00010000;
  3377. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  3378. }
  3379. /// <summary>
  3380. /// 仪表减键按下
  3381. /// </summary>
  3382. /// <param name="sender"></param>
  3383. /// <param name="e"></param>
  3384. private void button_OBC_ButtonDec_Click(object sender, EventArgs e)
  3385. {
  3386. var Code = new byte[2];
  3387. Code[0] = 0;
  3388. Code[1] = 0b00001000;
  3389. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  3390. }
  3391. /// <summary>
  3392. /// 仪表Walk键按下
  3393. /// </summary>
  3394. /// <param name="sender"></param>
  3395. /// <param name="e"></param>
  3396. private void button_OBC_ButtonWalk_Click(object sender, EventArgs e)
  3397. {
  3398. var Code = new byte[2];
  3399. Code[0] = 0;
  3400. Code[1] = 0b00000100;
  3401. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  3402. }
  3403. /// <summary>
  3404. /// 仪表Light键按下
  3405. /// </summary>
  3406. /// <param name="sender"></param>
  3407. /// <param name="e"></param>
  3408. private void button_OBC_ButtonLight_Click(object sender, EventArgs e)
  3409. {
  3410. var Code = new byte[2];
  3411. Code[0] = 0;
  3412. Code[1] = 0b00000010;
  3413. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  3414. }
  3415. /// <summary>
  3416. /// 仪表Set键按下
  3417. /// </summary>
  3418. /// <param name="sender"></param>
  3419. /// <param name="e"></param>
  3420. private void button_OBC_ButtonSet_Click(object sender, EventArgs e)
  3421. {
  3422. var Code = new byte[2];
  3423. Code[0] = 0;
  3424. Code[1] = 0b00000001;
  3425. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  3426. }
  3427. /// <summary>
  3428. /// 带载类型选择
  3429. /// </summary>
  3430. /// <param name="sender"></param>
  3431. /// <param name="e"></param>
  3432. private void label_Load_Click(object sender, EventArgs e)
  3433. {
  3434. if (label_Load.Text == "带载")
  3435. label_Load.Text = "空载";
  3436. else if (label_Load.Text == "空载")
  3437. label_Load.Text = "带载";
  3438. }
  3439. /// <summary>
  3440. /// 控制模式选择
  3441. /// </summary>
  3442. /// <param name="sender"></param>
  3443. /// <param name="e"></param>
  3444. private void label_MotorSensor_Click(object sender, EventArgs e)
  3445. {
  3446. if (label_MotorSensor.Text == "有感")
  3447. label_MotorSensor.Text = "无感";
  3448. else if (label_MotorSensor.Text == "无感")
  3449. label_MotorSensor.Text = "有感";
  3450. }
  3451. }
  3452. }