Form1.cs 151 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539
  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. for (int i = 0; i < ByteNum; i++)
  811. {
  812. richTextBox_RamFlasgData.AppendText(Convert.ToString(Data[8 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  813. }
  814. }));
  815. }
  816. }
  817. break;
  818. }
  819. }
  820. }
  821. #endregion
  822. #region 解析BMS广播的命令
  823. else if (ID == 0x720)
  824. {
  825. switch (CmdTemp)
  826. {
  827. case 0x1010://BMS运行信息
  828. {
  829. unchecked
  830. {
  831. this.Invoke((EventHandler)(delegate
  832. {
  833. BMS_RunInfo_Refresh = true;
  834. richTextBox_OBC_BMS_RunInfo.Clear();
  835. //电压
  836. uData16 = (ushort)(Data[1] * 256 + Data[0]);
  837. richTextBox_OBC_BMS_RunInfo.AppendText("电压:" + Convert.ToString(uData16) + " mV" + "\r\n");
  838. //电流
  839. uData16 = (ushort)(Data[3] * 256 + Data[2]);
  840. richTextBox_OBC_BMS_RunInfo.AppendText("电流:" + Convert.ToString(uData16) + " mA" + "\r\n");
  841. //剩余容量
  842. uData16 = (ushort)(Data[5] * 256 + Data[4]);
  843. richTextBox_OBC_BMS_RunInfo.AppendText("剩余容量:" + Convert.ToString(uData16) + " mAh" + "\r\n");
  844. //满充容量
  845. uData16 = (ushort)(Data[7] * 256 + Data[6]);
  846. richTextBox_OBC_BMS_RunInfo.AppendText("满充容量:" + Convert.ToString(uData16) + " mV" + "\r\n");
  847. //电芯温度
  848. richTextBox_OBC_BMS_RunInfo.AppendText("电芯温度:" + Convert.ToString((int)(Data[8] - 40) + " ℃" + "\r\n"));
  849. //剩余电量
  850. richTextBox_OBC_BMS_RunInfo.AppendText("剩余电量:" + Convert.ToString(Data[9]) + " %" + "\r\n");
  851. //电池状态
  852. richTextBox_OBC_BMS_RunInfo.AppendText("电池状态:" + Convert.ToString(Data[10], 16).PadLeft(2, '0').ToUpper() + " H" + "\r\n");
  853. //SOH
  854. richTextBox_OBC_BMS_RunInfo.AppendText("电池寿命:" + Convert.ToString(Data[11]) + " %");
  855. }));
  856. }
  857. break;
  858. }
  859. default: break;
  860. }
  861. }
  862. #endregion
  863. #region 解析电机发送OBC的命令
  864. else if (ID == 0x713)
  865. {
  866. switch (CmdTemp)
  867. {
  868. case 0x5408://电机用户参数
  869. {
  870. unchecked
  871. {
  872. this.Invoke((EventHandler)(delegate
  873. {
  874. richTextBox_OBC_ReadUserInfo.Clear();
  875. //默认周长
  876. richTextBox_OBC_ReadUserInfo.AppendText("默认周长:" + Convert.ToString((int)Data[0]) + " cm" + "\r\n");
  877. //启动模式
  878. richTextBox_OBC_ReadUserInfo.AppendText("启动模式:" + ((Data[1] == 0x01) ? "柔和" : (Data[1] == 0x02) ? "正常" : (Data[1] == 0x03) ? "强劲" : "无效") + "\r\n");
  879. comboBox_OBC_StartMode.SelectedIndex = Data[1] - 1;
  880. //限速
  881. richTextBox_OBC_ReadUserInfo.AppendText("限速:" + Convert.ToString(Data[2]) + " km/h" + "\r\n");
  882. //周长微调
  883. numericUpDown_OBC_WheelAdj.Value = (int)(Data[3] > 128 ? (Data[3] - 256) : Data[3]);
  884. richTextBox_OBC_ReadUserInfo.AppendText("周长微调:" + Convert.ToString(numericUpDown_OBC_WheelAdj.Value) + " cm" + "\r\n");
  885. //助力方案
  886. richTextBox_OBC_ReadUserInfo.AppendText("助力方案:" + Convert.ToString(Data[4]) + "\r\n");
  887. comboBox_OBC_AssistFunc.SelectedIndex = Data[4] - 1;
  888. //关机时间
  889. richTextBox_OBC_ReadUserInfo.AppendText("关机时间:" + Convert.ToString(Data[5]) + " min" + "\r\n");
  890. numericUpDown_OBC_OffTime.Value = (int)Data[5];
  891. }));
  892. }
  893. break;
  894. }
  895. case 0x5303://电机应答反馈
  896. {
  897. unchecked
  898. {
  899. this.Invoke((EventHandler)(delegate
  900. {
  901. timer_1s.Enabled = false;
  902. MessageBox.Show("OK", "反馈指令", MessageBoxButtons.OK, MessageBoxIcon.Information);
  903. timer_1s.Enabled = true;
  904. }));
  905. }
  906. break;
  907. }
  908. default: break;
  909. }
  910. }
  911. #endregion
  912. }
  913. #endregion
  914. /// <summary>
  915. /// 端口连接事件
  916. /// </summary>
  917. /// <param name="sender"></param>
  918. /// <param name="e"></param>
  919. private void 连接ToolStripMenuItem_Click(object sender, System.EventArgs e)
  920. {
  921. bool result = false;
  922. if (连接ToolStripMenuItem.Text == "连接")
  923. {
  924. result = mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text);
  925. if (result)
  926. {
  927. toolStripComboBox_ComNum.Enabled = false;
  928. toolStripComboBox_Baudrate.Enabled = false;
  929. 刷新ToolStripMenuItem.Enabled = false;
  930. 连接ToolStripMenuItem.Text = "断开";
  931. 连接ToolStripMenuItem.Checked = true;
  932. label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
  933. }
  934. }
  935. else if (连接ToolStripMenuItem.Text == "断开")
  936. {
  937. checkBox_OBC_StartSetGearSt.Checked = false;
  938. mySerialProcess.SerialClose();
  939. toolStripComboBox_ComNum.Enabled = true;
  940. toolStripComboBox_Baudrate.Enabled = true;
  941. 刷新ToolStripMenuItem.Enabled = true;
  942. 连接ToolStripMenuItem.Text = "连接";
  943. 连接ToolStripMenuItem.Checked = false;
  944. label_COM_Sta.Text = "连接状态:未连接";
  945. }
  946. }
  947. /// <summary>
  948. /// 端口号刷新事件
  949. /// </summary>
  950. /// <param name="sender"></param>
  951. /// <param name="e"></param>
  952. private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
  953. {
  954. toolStripComboBox_ComNum.Items.Clear();
  955. toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
  956. toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
  957. }
  958. /// <summary>
  959. /// 转速调节事件
  960. /// </summary>
  961. /// <param name="sender"></param>
  962. /// <param name="e"></param>
  963. private void numericUpDown_SpeedAdj_ValueChanged(object sender, EventArgs e)
  964. {
  965. //生产模式转速设置值更新
  966. trackBar_FacModeMotorSpeedAdj.Value = (int)numericUpDown_SpeedAdj.Value;
  967. label_FacModeMotorSpeedSet.Text = trackBar_FacModeMotorSpeedAdj.Value.ToString() + "%";
  968. //设置转速百分比
  969. var Data = new byte[1];
  970. Data[0] = (byte)numericUpDown_SpeedAdj.Value;
  971. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  972. }
  973. /// <summary>
  974. /// 存储标志修改事件
  975. /// </summary>
  976. /// <param name="sender"></param>
  977. /// <param name="e"></param>
  978. private void 写入存储ToolStripMenuItem_Click(object sender, EventArgs e)
  979. {
  980. 写入存储ToolStripMenuItem.Checked = !写入存储ToolStripMenuItem.Checked;
  981. }
  982. /// <summary>
  983. /// 1s定时器
  984. /// </summary>
  985. /// <param name="sender"></param>
  986. /// <param name="e"></param>
  987. private void timer_1s_Tick(object sender, EventArgs e)
  988. {
  989. //时间更新
  990. label_SystemTime.Text = "系统时间:" + DateTime.Now.ToString();
  991. //MC_Runinfo超时清除
  992. if (MC_RunInfo_Refresh == false)
  993. {
  994. MC_RunInfo_Refresh_Cnt++;
  995. if (MC_RunInfo_Refresh_Cnt > 10)//5s
  996. {
  997. MC_RunInfo_Clear();
  998. MC_RunInfo_Refresh_Cnt = 0;
  999. }
  1000. }
  1001. else
  1002. {
  1003. MC_RunInfo_Refresh_Cnt = 0;
  1004. }
  1005. MC_RunInfo_Refresh = false;
  1006. //BMS_RunInfo超时清除
  1007. if (BMS_RunInfo_Refresh == false)
  1008. {
  1009. BMS_RunInfo_Refresh_Cnt++;
  1010. if (BMS_RunInfo_Refresh_Cnt > 10)//5s
  1011. {
  1012. richTextBox_OBC_BMS_RunInfo.Clear();
  1013. BMS_RunInfo_Refresh_Cnt = 0;
  1014. }
  1015. }
  1016. else
  1017. {
  1018. BMS_RunInfo_Refresh_Cnt = 0;
  1019. }
  1020. BMS_RunInfo_Refresh = false;
  1021. //故障码超时清除
  1022. if (MC_ErrorCode_Refresh == false)
  1023. {
  1024. MC_ErrorCode_Refresh_Cnt++;
  1025. if (MC_ErrorCode_Refresh_Cnt > 10)//5s
  1026. {
  1027. textBox_ErrorCode.Text = "---";
  1028. MC_ErrorCode_Refresh_Cnt = 0;
  1029. }
  1030. }
  1031. else
  1032. {
  1033. MC_ErrorCode_Refresh_Cnt = 0;
  1034. }
  1035. MC_ErrorCode_Refresh = false;
  1036. //CDL连接超时
  1037. #if false
  1038. if (mySerialProcess.CDL_Online_Flag == false)
  1039. {
  1040. mySerialProcess.CDL_OnlineCheck_Cnt++;
  1041. if (mySerialProcess.CDL_OnlineCheck_Cnt > 3)//3s
  1042. {
  1043. timer_1s.Enabled = false;
  1044. MessageBox.Show("连接失败!", "提示");
  1045. timer_1s.Enabled = true;
  1046. //关闭串口
  1047. mySerialProcess.SerialClose();
  1048. toolStripComboBox_ComNum.Enabled = true;
  1049. toolStripComboBox_Baudrate.Enabled = true;
  1050. 刷新ToolStripMenuItem.Enabled = true;
  1051. 连接ToolStripMenuItem.Text = "连接";
  1052. 连接ToolStripMenuItem.Checked = false;
  1053. label_COM_Sta.Text = "连接状态:未连接";
  1054. }
  1055. }
  1056. #endif
  1057. //OBC定时发送设置档位
  1058. if (checkBox_OBC_StartSetGearSt.Checked == true)
  1059. {
  1060. var CtrlCode = new byte[2];
  1061. if (comboBox_OBC_SetGearST.SelectedIndex == 5)//档位
  1062. CtrlCode[0] = 0x33;
  1063. else if (comboBox_OBC_SetGearST.SelectedIndex == 6)//档位
  1064. CtrlCode[0] = 0x22;
  1065. else
  1066. CtrlCode[0] = (byte)comboBox_OBC_SetGearST.SelectedIndex;
  1067. if (comboBox_OBC_LightSw.SelectedIndex == 0)//车灯
  1068. CtrlCode[1] = 0xF1;
  1069. else
  1070. CtrlCode[1] = 0xF0;
  1071. if (!mySerialProcess.SendCmdWithoutNotice((ushort)0x731, (byte)0x0C, (ushort)0x3002, CtrlCode))
  1072. {
  1073. checkBox_OBC_StartSetGearSt.Checked = false;
  1074. }
  1075. }
  1076. //OBC定时发送查询电池
  1077. if (checkBox_OBC_StartReadBMS.Checked == true)
  1078. {
  1079. if (!mySerialProcess.SendCmd((ushort)0x732, (byte)0x11, (ushort)0x5000, null))
  1080. {
  1081. checkBox_OBC_StartReadBMS.Checked = false;
  1082. }
  1083. }
  1084. }
  1085. /// <summary>
  1086. /// 运行信息清除
  1087. /// </summary>
  1088. private void MC_RunInfo_Clear()
  1089. {
  1090. foreach (Control c in groupBox2.Controls)
  1091. {
  1092. if ((c is TextBox))
  1093. {
  1094. if(c.Name != textBox_ErrorCode.ToString())
  1095. c.Text = "---";
  1096. }
  1097. }
  1098. }
  1099. /// <summary>
  1100. /// 读取马达参数
  1101. /// </summary>
  1102. /// <param name="sender"></param>
  1103. /// <param name="e"></param>
  1104. private void button_Read_MotorParam_Click(object sender, EventArgs e)
  1105. {
  1106. richTextBox_MotorParam.Clear();
  1107. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null);
  1108. }
  1109. /// <summary>
  1110. /// 写入马达参数
  1111. /// </summary>
  1112. /// <param name="sender"></param>
  1113. /// <param name="e"></param>
  1114. private void button_Write_Click(object sender, EventArgs e)
  1115. {
  1116. var ConfigParam = new byte[40];
  1117. for (int i = 0; i < 40; i++)
  1118. ConfigParam[i] = 0;
  1119. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  1120. short wDataTemp = 0;
  1121. string[] strDataTemp = richTextBox_MotorParam.Text.Split(new string[] { ", "},StringSplitOptions.None);
  1122. try
  1123. {
  1124. for (int i = 0; i < strDataTemp.Length; i++)
  1125. {
  1126. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  1127. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  1128. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  1129. }
  1130. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B28, ConfigParam);
  1131. }
  1132. catch (Exception)
  1133. {
  1134. timer_1s.Enabled = false;
  1135. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1136. timer_1s.Enabled = true;
  1137. }
  1138. }
  1139. /// <summary>
  1140. /// 读取整车信息
  1141. /// </summary>
  1142. /// <param name="sender"></param>
  1143. /// <param name="e"></param>
  1144. private void button_ReadBikeParam_Click(object sender, EventArgs e)
  1145. {
  1146. richTextBox_BikeParam.Clear();
  1147. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
  1148. }
  1149. /// <summary>
  1150. /// 写入整车信息
  1151. /// </summary>
  1152. /// <param name="sender"></param>
  1153. /// <param name="e"></param>
  1154. private void button_WriteBikeParam_Click(object sender, EventArgs e)
  1155. {
  1156. var ConfigParam = new byte[28];
  1157. for (int i = 0; i < 28; i++)
  1158. ConfigParam[i] = 0;
  1159. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  1160. short wDataTemp = 0;
  1161. string[] strDataTemp = richTextBox_BikeParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  1162. try
  1163. {
  1164. for (int i = 0; i < strDataTemp.Length; i++)
  1165. {
  1166. wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
  1167. ConfigParam[2 * i + 2] = (byte)wDataTemp;
  1168. ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
  1169. }
  1170. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1C, ConfigParam);
  1171. }
  1172. catch (Exception)
  1173. {
  1174. timer_1s.Enabled = false;
  1175. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1176. timer_1s.Enabled = true;
  1177. }
  1178. }
  1179. /// <summary>
  1180. /// 读取控制器参数
  1181. /// </summary>
  1182. /// <param name="sender"></param>
  1183. /// <param name="e"></param>
  1184. private void button_ReadControlParam_Click(object sender, EventArgs e)
  1185. {
  1186. richTextBox_ControlParam.Clear();
  1187. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null);
  1188. }
  1189. /// <summary>
  1190. /// 写入控制器参数
  1191. /// </summary>
  1192. /// <param name="sender"></param>
  1193. /// <param name="e"></param>
  1194. private void button_WriteControlParam_Click(object sender, EventArgs e)
  1195. {
  1196. var ConfigParam = new byte[34];
  1197. for (int i = 0; i < 34; i++)
  1198. ConfigParam[i] = 0;
  1199. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  1200. ushort uwDataTemp = 0;
  1201. string[] strDataTemp = richTextBox_ControlParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  1202. try
  1203. {
  1204. for (int i = 0; i < strDataTemp.Length; i++)
  1205. {
  1206. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  1207. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  1208. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  1209. }
  1210. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3F22, ConfigParam);
  1211. }
  1212. catch (Exception)
  1213. {
  1214. timer_1s.Enabled = false;
  1215. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1216. timer_1s.Enabled = true;
  1217. }
  1218. }
  1219. /// <summary>
  1220. /// 读取助力参数
  1221. /// </summary>
  1222. /// <param name="sender"></param>
  1223. /// <param name="e"></param>
  1224. private void button_ReadAssistParam_Click(object sender, EventArgs e)
  1225. {
  1226. var ConfigParam = new byte[4];
  1227. int AssistNum = 0;
  1228. try
  1229. {
  1230. AssistNum = Convert.ToInt32(comboBox_AssistTorque.Text);
  1231. ConfigParam[0] = (byte)(AssistNum & 0xFF);
  1232. ConfigParam[1] = (byte)(AssistNum >> 8);
  1233. AssistNum = Convert.ToInt32(comboBox_AssistCadence.Text);
  1234. ConfigParam[2] = (byte)(AssistNum & 0xFF);
  1235. ConfigParam[3] = (byte)(AssistNum >> 8);
  1236. richTextBox_AssistParam.Clear();
  1237. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
  1238. }
  1239. catch (Exception)
  1240. {
  1241. timer_1s.Enabled = false;
  1242. MessageBox.Show("请选择助力参数编号!","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
  1243. timer_1s.Enabled = true;
  1244. }
  1245. }
  1246. /// <summary>
  1247. /// 写入助力参数
  1248. /// </summary>
  1249. /// <param name="sender"></param>
  1250. /// <param name="e"></param>
  1251. private void button_WriteAssistParam_Click(object sender, EventArgs e)
  1252. {
  1253. var ConfigParam = new byte[80];
  1254. for (int i = 0; i < 80; i++)
  1255. ConfigParam[i] = 0;
  1256. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  1257. long lDataTemp = 0;
  1258. string[] strDataTemp = richTextBox_AssistParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  1259. int index_1 = 0, index_2 = 0;
  1260. try
  1261. {
  1262. for (int i = 0; i < strDataTemp.Length; i++)
  1263. {
  1264. if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
  1265. {
  1266. index_1 = i;
  1267. break;
  1268. }
  1269. }
  1270. for (int i = 0; i < strDataTemp.Length; i++)
  1271. {
  1272. if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
  1273. {
  1274. index_2 = i;
  1275. break;
  1276. }
  1277. }
  1278. for (int i = 0; i < strDataTemp.Length; i++)
  1279. {
  1280. lDataTemp = Convert.ToInt32(strDataTemp[i].Split('=')[1]);
  1281. if (i < index_1)
  1282. {
  1283. ConfigParam[2 * i + 4] = (byte)lDataTemp;
  1284. ConfigParam[2 * i + 5] = (byte)(lDataTemp >> 8);
  1285. }
  1286. else if (i <= index_2)
  1287. {
  1288. ConfigParam[4 * i - 4] = (byte)lDataTemp;
  1289. ConfigParam[4 * i - 3] = (byte)(lDataTemp >> 8);
  1290. ConfigParam[4 * i - 2] = (byte)(lDataTemp >> 16);
  1291. ConfigParam[4 * i - 1] = (byte)(lDataTemp >> 24);
  1292. }
  1293. else
  1294. {
  1295. ConfigParam[2 * i + 20] = (byte)lDataTemp;
  1296. ConfigParam[2 * i + 21] = (byte)(lDataTemp >> 8);
  1297. }
  1298. }
  1299. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
  1300. }
  1301. catch (Exception)
  1302. {
  1303. timer_1s.Enabled = false;
  1304. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1305. timer_1s.Enabled = true;
  1306. }
  1307. }
  1308. /// <summary>
  1309. /// 读取调试参数
  1310. /// </summary>
  1311. /// <param name="sender"></param>
  1312. /// <param name="e"></param>
  1313. private void button_ReadDebugParam_Click(object sender, EventArgs e)
  1314. {
  1315. richTextBox_DebugParam.Clear();
  1316. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
  1317. }
  1318. /// <summary>
  1319. /// 写入调试参数
  1320. /// </summary>
  1321. /// <param name="sender"></param>
  1322. /// <param name="e"></param>
  1323. private void button_WriteDebugParam_Click(object sender, EventArgs e)
  1324. {
  1325. var ConfigParam = new byte[60];
  1326. for (int i = 0; i < 60; i++)
  1327. ConfigParam[i] = 0;
  1328. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  1329. ushort uwDataTemp = 0;
  1330. string[] strDataTemp = richTextBox_DebugParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  1331. try
  1332. {
  1333. for (int i = 0; i < strDataTemp.Length; i++)
  1334. {
  1335. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  1336. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  1337. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  1338. }
  1339. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam);
  1340. }
  1341. catch (Exception)
  1342. {
  1343. timer_1s.Enabled = false;
  1344. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1345. timer_1s.Enabled = true;
  1346. }
  1347. }
  1348. /// <summary>
  1349. /// 读取历史
  1350. /// </summary>
  1351. /// <param name="sender"></param>
  1352. /// <param name="e"></param>
  1353. private void button_ReadRecord_Click(object sender, EventArgs e)
  1354. {
  1355. richTextBox_Record.Clear();
  1356. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
  1357. }
  1358. /// <summary>
  1359. /// 读取传感器参数
  1360. /// </summary>
  1361. /// <param name="sender"></param>
  1362. /// <param name="e"></param>
  1363. private void button_ReadSensorParam_Click(object sender, EventArgs e)
  1364. {
  1365. richTextBox_SensorParam.Clear();
  1366. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  1367. }
  1368. /// <summary>
  1369. /// 写入力矩传感器标定值
  1370. /// </summary>
  1371. /// <param name="sender"></param>
  1372. /// <param name="e"></param>
  1373. private void button_Write_Cal_Click(object sender, EventArgs e)
  1374. {
  1375. var ConfigParam = new byte[4];
  1376. for (int i = 0; i < 4; i++)
  1377. ConfigParam[i] = 0;
  1378. ushort uwDataTemp = 0;
  1379. try
  1380. {
  1381. uwDataTemp = Convert.ToUInt16(comboBox_TorqueSet.Text);//负载序号
  1382. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  1383. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  1384. uwDataTemp = (ushort)(decimal.Parse(textBox_Load.Text) * 10); ;//负载值0.1Nm
  1385. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  1386. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  1387. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  1388. }
  1389. catch (Exception)
  1390. {
  1391. timer_1s.Enabled = false;
  1392. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1393. timer_1s.Enabled = true;
  1394. }
  1395. }
  1396. /// <summary>
  1397. /// 写入传感器参数
  1398. /// </summary>
  1399. /// <param name="sender"></param>
  1400. /// <param name="e"></param>
  1401. private void button_WriteSensorParam_Click(object sender, EventArgs e)
  1402. {
  1403. var ConfigParam = new byte[14];
  1404. for (int i = 0; i < 14; i++)
  1405. ConfigParam[i] = 0;
  1406. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  1407. ushort uwDataTemp = 0;
  1408. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  1409. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  1410. int index = 0;
  1411. try
  1412. {
  1413. for (int i = 0; i < strDataTemp.Length; i++)
  1414. {
  1415. if (strDataTemp[i].Split('=')[0] == "踏频传感器一圈脉冲数")
  1416. {
  1417. index = i;
  1418. break;
  1419. }
  1420. }
  1421. for (int i = 0; i < (strDataTemp.Length - index); i++)
  1422. {
  1423. uwDataTemp = Convert.ToUInt16(strDataTemp[i + index].Split('=')[1]);
  1424. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  1425. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  1426. }
  1427. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x420E, ConfigParam);
  1428. }
  1429. catch (Exception)
  1430. {
  1431. timer_1s.Enabled = false;
  1432. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1433. timer_1s.Enabled = true;
  1434. }
  1435. }
  1436. /// <summary>
  1437. /// 写入型号
  1438. /// </summary>
  1439. /// <param name="sender"></param>
  1440. /// <param name="e"></param>
  1441. private void button_WriteModel_Click(object sender, EventArgs e)
  1442. {
  1443. string Mode = textBox_Model.Text;
  1444. var ModeArray = new byte[16];
  1445. for (ushort i = 0; i < Mode.Length; i++)
  1446. {
  1447. ModeArray[i] = (byte)Mode[i];
  1448. }
  1449. if (Mode.Length < 16)
  1450. {
  1451. ModeArray[Mode.Length] = (byte)'.';
  1452. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  1453. {
  1454. ModeArray[Mode.Length + 1 + i] = 0x20;
  1455. }
  1456. }
  1457. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  1458. }
  1459. /// <summary>
  1460. /// 写入SN
  1461. /// </summary>
  1462. /// <param name="sender"></param>
  1463. /// <param name="e"></param>
  1464. private void button_WriteSN_Click(object sender, EventArgs e)
  1465. {
  1466. string SN = textBox_SN.Text;
  1467. var SNArray = new byte[16];
  1468. for (ushort i = 0; i < SN.Length; i++)
  1469. {
  1470. SNArray[i] = (byte)SN[i];
  1471. }
  1472. if (SN.Length < 16)
  1473. {
  1474. SNArray[SN.Length] = (byte)'.';
  1475. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  1476. {
  1477. SNArray[SN.Length + 1 + i] = 0x20;
  1478. }
  1479. }
  1480. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  1481. }
  1482. /// <summary>
  1483. /// 查询版本信息
  1484. /// </summary>
  1485. /// <param name="sender"></param>
  1486. /// <param name="e"></param>
  1487. private void button_ReadVersion_Click(object sender, EventArgs e)
  1488. {
  1489. textBox_Model.Text = "---";
  1490. textBox_SN.Text = "---";
  1491. textBox_HW.Text = "---";
  1492. textBox_FW.Text = "---";
  1493. textBox_SP.Text = "---";
  1494. textBox_OBC_ReadModel.Text = "---";
  1495. textBox_OBC_ReadSN.Text = "---";
  1496. textBox_OBC_ReadHW.Text = "---";
  1497. textBox_OBC_ReadFW.Text = "---";
  1498. textBox_OBC_ReadSP.Text = "---";
  1499. textBox_FacModeName.Text = "---";
  1500. textBox_FacModeNum.Text = "---";
  1501. textBox_FacModeHW.Text = "---";
  1502. textBox_FacModeFW.Text = "---";
  1503. textBox_FacModeSP.Text = "---";
  1504. Class_Motor_Ver.Mode = "---";
  1505. Class_Motor_Ver.SN = "---";
  1506. Class_Motor_Ver.HW = "---";
  1507. Class_Motor_Ver.FW = "---";
  1508. Class_Motor_Ver.Special = "---";
  1509. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  1510. }
  1511. /// <summary>
  1512. /// 查询自定义1
  1513. /// </summary>
  1514. /// <param name="sender"></param>
  1515. /// <param name="e"></param>
  1516. private void button_ReadUser1_Click(object sender, EventArgs e)
  1517. {
  1518. textBox_User1.Text = "---";
  1519. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);
  1520. }
  1521. /// <summary>
  1522. /// 查询自定义2
  1523. /// </summary>
  1524. /// <param name="sender"></param>
  1525. /// <param name="e"></param>
  1526. private void button_ReadUser2_Click(object sender, EventArgs e)
  1527. {
  1528. textBox_User2.Text = "---";
  1529. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);
  1530. }
  1531. /// <summary>
  1532. /// 查询自定义3
  1533. /// </summary>
  1534. /// <param name="sender"></param>
  1535. /// <param name="e"></param>
  1536. private void button_ReadUser3_Click(object sender, EventArgs e)
  1537. {
  1538. textBox_User3.Text = "---";
  1539. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);
  1540. }
  1541. /// <summary>
  1542. /// 写入自定义字符串1
  1543. /// </summary>
  1544. /// <param name="sender"></param>
  1545. /// <param name="e"></param>
  1546. private void button_WriteUser1_Click(object sender, EventArgs e)
  1547. {
  1548. string User = textBox_User1.Text;
  1549. var UserArray = new byte[16];
  1550. for (ushort i = 0; i < User.Length; i++)
  1551. {
  1552. UserArray[i] = (byte)User[i];
  1553. }
  1554. if (User.Length < 16)
  1555. {
  1556. UserArray[User.Length] = (byte)'.';
  1557. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  1558. {
  1559. UserArray[User.Length + 1 + i] = 0x20;
  1560. }
  1561. }
  1562. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1410, UserArray);
  1563. }
  1564. /// <summary>
  1565. /// 写入自定义字符串2
  1566. /// </summary>
  1567. /// <param name="sender"></param>
  1568. /// <param name="e"></param>
  1569. private void button_WriteUser2_Click(object sender, EventArgs e)
  1570. {
  1571. string User = textBox_User2.Text;
  1572. var UserArray = new byte[16];
  1573. for (ushort i = 0; i < User.Length; i++)
  1574. {
  1575. UserArray[i] = (byte)User[i];
  1576. }
  1577. if (User.Length < 16)
  1578. {
  1579. UserArray[User.Length] = (byte)'.';
  1580. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  1581. {
  1582. UserArray[User.Length + 1 + i] = 0x20;
  1583. }
  1584. }
  1585. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1610, UserArray);
  1586. }
  1587. /// <summary>
  1588. /// 写入自定义字符串3
  1589. /// </summary>
  1590. /// <param name="sender"></param>
  1591. /// <param name="e"></param>
  1592. private void button_WriteUser3_Click(object sender, EventArgs e)
  1593. {
  1594. string User = textBox_User3.Text;
  1595. var UserArray = new byte[16];
  1596. for (ushort i = 0; i < User.Length; i++)
  1597. {
  1598. UserArray[i] = (byte)User[i];
  1599. }
  1600. if (User.Length < 16)
  1601. {
  1602. UserArray[User.Length] = (byte)'.';
  1603. for (ushort i = 0; i < 16 - User.Length - 1; i++)
  1604. {
  1605. UserArray[User.Length + 1 + i] = 0x20;
  1606. }
  1607. }
  1608. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1810, UserArray);
  1609. }
  1610. /// <summary>
  1611. /// 查询生产信息
  1612. /// </summary>
  1613. /// <param name="sender"></param>
  1614. /// <param name="e"></param>
  1615. private void button_ReadMAC_Click(object sender, EventArgs e)
  1616. {
  1617. textBox_MAC.Text = "---";
  1618. textBox_MACAdd.Text = "---";
  1619. textBox_MACDate.Text = "---";
  1620. textBox_PP.Text = "---";
  1621. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);
  1622. }
  1623. /// <summary>
  1624. /// 写入生产信息
  1625. /// </summary>
  1626. /// <param name="sender"></param>
  1627. /// <param name="e"></param>
  1628. private void button_WriteMac_Click(object sender, EventArgs e)
  1629. {
  1630. var MACArray = new byte[32];
  1631. //填入生产商
  1632. for (ushort i = 0; i < textBox_MAC.Text.Length; i++)
  1633. {
  1634. MACArray[i] = (byte)textBox_MAC.Text[i];
  1635. }
  1636. if (textBox_MAC.Text.Length < 8)
  1637. {
  1638. MACArray[textBox_MAC.Text.Length] = (byte)'.';
  1639. for (ushort i = 0; i < 8 - textBox_MAC.Text.Length - 1; i++)
  1640. {
  1641. MACArray[textBox_MAC.Text.Length + 1 + i] = 0x20;
  1642. }
  1643. }
  1644. //填入生产地
  1645. for (ushort i = 0; i < textBox_MACAdd.Text.Length; i++)
  1646. {
  1647. MACArray[8 + i] = (byte)textBox_MACAdd.Text[i];
  1648. }
  1649. if (textBox_MACAdd.Text.Length < 8)
  1650. {
  1651. MACArray[textBox_MACAdd.Text.Length + 8] = (byte)'.';
  1652. for (ushort i = 0; i < 8 - textBox_MACAdd.Text.Length - 1; i++)
  1653. {
  1654. MACArray[textBox_MACAdd.Text.Length + 1 + i + 8] = 0x20;
  1655. }
  1656. }
  1657. //填入生产日期
  1658. for (ushort i = 0; i < textBox_MACDate.Text.Length; i++)
  1659. {
  1660. MACArray[16 + i] = (byte)textBox_MACDate.Text[i];
  1661. }
  1662. if (textBox_MACDate.Text.Length < 8)
  1663. {
  1664. MACArray[textBox_MACDate.Text.Length + 16] = (byte)'.';
  1665. for (ushort i = 0; i < 8 - textBox_MACDate.Text.Length - 1; i++)
  1666. {
  1667. MACArray[textBox_MACDate.Text.Length + 1 + i + 16] = 0x20;
  1668. }
  1669. }
  1670. //填入品牌
  1671. for (ushort i = 0; i < textBox_PP.Text.Length; i++)
  1672. {
  1673. MACArray[24 + i] = (byte)textBox_PP.Text[i];
  1674. }
  1675. if (textBox_PP.Text.Length < 8)
  1676. {
  1677. MACArray[textBox_PP.Text.Length + 24] = (byte)'.';
  1678. for (ushort i = 0; i < 8 - textBox_PP.Text.Length - 1; i++)
  1679. {
  1680. MACArray[textBox_PP.Text.Length + 1 + i + 24] = 0x20;
  1681. }
  1682. }
  1683. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  1684. }
  1685. /// <summary>
  1686. /// 查询密钥
  1687. /// </summary>
  1688. /// <param name="sender"></param>
  1689. /// <param name="e"></param>
  1690. private void button_ReadKey_Click(object sender, EventArgs e)
  1691. {
  1692. textBox_Key.Text = "---";
  1693. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);
  1694. }
  1695. /// <summary>
  1696. /// 写入校验密钥
  1697. /// </summary>
  1698. /// <param name="sender"></param>
  1699. /// <param name="e"></param>
  1700. private void button_WriteKey_Click(object sender, EventArgs e)
  1701. {
  1702. string Key = textBox_Key.Text;
  1703. var KeyArray = new byte[8];
  1704. if (Key.Length != 8)
  1705. {
  1706. timer_1s.Enabled = false;
  1707. MessageBox.Show("请检查字符长度是否为8", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1708. timer_1s.Enabled = true;
  1709. return;
  1710. }
  1711. for (ushort i = 0; i < Key.Length; i++)
  1712. {
  1713. KeyArray[i] = (byte)Key[i];
  1714. }
  1715. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1108, KeyArray);
  1716. }
  1717. /// <summary>
  1718. /// 查询在线检测结果
  1719. /// </summary>
  1720. /// <param name="sender"></param>
  1721. /// <param name="e"></param>
  1722. private void button_ReadOnLine_Click(object sender, EventArgs e)
  1723. {
  1724. textBox_Online.Text = "---";
  1725. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2100, null);
  1726. }
  1727. /// <summary>
  1728. /// 系统清除
  1729. /// </summary>
  1730. /// <param name="sender"></param>
  1731. /// <param name="e"></param>
  1732. private void button_SystemClear_Click(object sender, EventArgs e)
  1733. {
  1734. var Code = new byte[5];
  1735. Code[0] = (byte)'C';
  1736. Code[1] = (byte)'L';
  1737. Code[2] = (byte)'E';
  1738. Code[3] = (byte)'A';
  1739. Code[4] = (byte)'R';
  1740. timer_1s.Enabled = false;
  1741. if (MessageBox.Show("系统清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1742. {
  1743. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1744. {
  1745. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1746. {
  1747. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  1748. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  1749. }
  1750. }
  1751. }
  1752. timer_1s.Enabled = true;
  1753. }
  1754. /// <summary>
  1755. /// 参数还原
  1756. /// </summary>
  1757. /// <param name="sender"></param>
  1758. /// <param name="e"></param>
  1759. private void button_Recovery_Click(object sender, EventArgs e)
  1760. {
  1761. var Code = new byte[8];
  1762. Code[0] = (byte)'R';
  1763. Code[1] = (byte)'E';
  1764. Code[2] = (byte)'C';
  1765. Code[3] = (byte)'O';
  1766. Code[4] = (byte)'V';
  1767. Code[5] = (byte)'E';
  1768. Code[6] = (byte)'R';
  1769. Code[7] = (byte)'Y';
  1770. timer_1s.Enabled = false;
  1771. if (MessageBox.Show("参数还原后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1772. {
  1773. if (MessageBox.Show("请再次确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1774. {
  1775. if (MessageBox.Show("请最后确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1776. {
  1777. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2708, Code);
  1778. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  1779. }
  1780. }
  1781. }
  1782. timer_1s.Enabled = true;
  1783. }
  1784. /// <summary>
  1785. /// 系统复位
  1786. /// </summary>
  1787. /// <param name="sender"></param>
  1788. /// <param name="e"></param>
  1789. private void button_Reset_Click(object sender, EventArgs e)
  1790. {
  1791. var Code = new byte[5];
  1792. Code[0] = (byte)'O';
  1793. Code[1] = (byte)'F';
  1794. Code[2] = (byte)'F';
  1795. Code[3] = (byte)'.';
  1796. Code[4] = (byte)'.';
  1797. timer_1s.Enabled = false;
  1798. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1799. {
  1800. timer_1s.Enabled = true;
  1801. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  1802. PowerOffAckStatus = false;
  1803. Delay_ms(250);
  1804. int TryCnt = 3;
  1805. while ((TryCnt--) >= 0)
  1806. {
  1807. if (!PowerOffAckStatus)
  1808. {
  1809. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  1810. PowerOffAckStatus = false;
  1811. Delay_ms(250);
  1812. }
  1813. else break;
  1814. }
  1815. if (PowerOffAckStatus)
  1816. {
  1817. timer_1s.Enabled = false;
  1818. MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  1819. timer_1s.Enabled = true;
  1820. }
  1821. else
  1822. {
  1823. timer_1s.Enabled = false;
  1824. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1825. timer_1s.Enabled = true;
  1826. }
  1827. }
  1828. timer_1s.Enabled = true;
  1829. }
  1830. /// <summary>
  1831. /// 记录清除
  1832. /// </summary>
  1833. /// <param name="sender"></param>
  1834. /// <param name="e"></param>
  1835. private void button_ClearLog_Click(object sender, EventArgs e)
  1836. {
  1837. var Code = new byte[9];
  1838. Code[0] = (byte)'L';
  1839. Code[1] = (byte)'O';
  1840. Code[2] = (byte)'G';
  1841. Code[3] = (byte)' ';
  1842. Code[4] = (byte)'C';
  1843. Code[5] = (byte)'L';
  1844. Code[6] = (byte)'E';
  1845. Code[7] = (byte)'A';
  1846. Code[8] = (byte)'R';
  1847. timer_1s.Enabled = false;
  1848. if (MessageBox.Show("历史记录信息清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1849. {
  1850. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1851. {
  1852. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1853. {
  1854. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3909, Code);
  1855. MessageBox.Show("系统已关机,请重启!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  1856. }
  1857. }
  1858. }
  1859. timer_1s.Enabled = true;
  1860. }
  1861. /// <summary>
  1862. /// 打开系统计算器
  1863. /// </summary>
  1864. /// <param name="sender"></param>
  1865. /// <param name="e"></param>
  1866. private void 计算器ToolStripMenuItem_Click(object sender, EventArgs e)
  1867. {
  1868. System.Diagnostics.Process.Start("calc.exe");
  1869. }
  1870. /// <summary>
  1871. ///故障转换和显示
  1872. /// </summary>
  1873. List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
  1874. "马达缺相","NTC故障","BMS校验失败","","OBC校验失败","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","","","","","","","","","","","","",
  1875. "",""};
  1876. private string ErrorInfoDisplay(UInt32 Code)
  1877. {
  1878. string Result = "";
  1879. if (Code == 0)
  1880. {
  1881. Result = "无故障";
  1882. }
  1883. else
  1884. {
  1885. for (int i = 0; i < 32; i++)
  1886. {
  1887. if ((Code & 0x01) == 0x01)
  1888. {
  1889. Result += ErrorInfo[i] + " ";
  1890. }
  1891. Code >>= 1;
  1892. }
  1893. }
  1894. return Result;
  1895. }
  1896. /// <summary>
  1897. /// 鼠标滑过故障码显示具体内容
  1898. /// </summary>
  1899. /// <param name="sender"></param>
  1900. /// <param name="e"></param>
  1901. private void textBox_ErrorCode_MouseHover(object sender, EventArgs e)
  1902. {
  1903. // 创建the ToolTip
  1904. ToolTip toolTip1 = new ToolTip();
  1905. // 设置显示样式
  1906. toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
  1907. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  1908. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  1909. toolTip1.ShowAlways = true;//是否显示提示框
  1910. // 设置伴随的对象.
  1911. string ErrorCode = this.textBox_ErrorCode.Text;
  1912. UInt32 Code = ErrorCode.Contains("H") ? Convert.ToUInt32(ErrorCode.Split('H')[0], 16) : 0;
  1913. toolTip1.SetToolTip(this.textBox_ErrorCode, ErrorInfoDisplay(Code));//设置故障内容显示
  1914. }
  1915. /// <summary>
  1916. /// 数据记录
  1917. /// </summary>
  1918. private void DataAutoSave()
  1919. {
  1920. if (记录数据ToolStripMenuItem.Checked == true)
  1921. {
  1922. if (SaveFilename == string.Empty)
  1923. {
  1924. return;
  1925. }
  1926. string SaveData = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace(" ", "_") + " ";
  1927. foreach (Control c in groupBox3.Controls)
  1928. {
  1929. if (c is TextBox)
  1930. {
  1931. SaveData += c.Text + " , ";
  1932. }
  1933. }
  1934. SaveData += "\r\n";
  1935. System.IO.File.AppendAllText(SaveFilename, SaveData);//sb.ToString());
  1936. }
  1937. }
  1938. /// <summary>
  1939. /// 打开或关闭数据记录
  1940. /// </summary>
  1941. /// <param name="sender"></param>
  1942. /// <param name="e"></param>
  1943. private void 记录数据ToolStripMenuItem_Click(object sender, EventArgs e)
  1944. {
  1945. if (记录数据ToolStripMenuItem.Checked == false)
  1946. {
  1947. if (mySerialProcess.mySerial.IsOpen == true)
  1948. {
  1949. SaveFilename = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_运行信息" + ".txt";
  1950. timer_1s.Enabled = false;
  1951. MessageBox.Show("开始记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  1952. timer_1s.Enabled = true;
  1953. 记录数据ToolStripMenuItem.Checked = true;
  1954. }
  1955. else
  1956. {
  1957. timer_1s.Enabled = false;
  1958. MessageBox.Show("请连接电机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  1959. timer_1s.Enabled = true;
  1960. }
  1961. }
  1962. else
  1963. {
  1964. 记录数据ToolStripMenuItem.Checked = false;
  1965. timer_1s.Enabled = false;
  1966. MessageBox.Show("停止记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  1967. timer_1s.Enabled = true;
  1968. }
  1969. }
  1970. /// <summary>
  1971. /// 仪表启动控制档位开关事件
  1972. /// </summary>
  1973. /// <param name="sender"></param>
  1974. /// <param name="e"></param>
  1975. private void checkBox_OBC_StartSetGearSt_CheckedChanged(object sender, EventArgs e)
  1976. {
  1977. if (checkBox_OBC_StartSetGearSt.Checked == true)
  1978. {
  1979. //检查串口是否打开
  1980. if (!mySerialProcess.mySerial.IsOpen)
  1981. {
  1982. timer_1s.Enabled = false;
  1983. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  1984. timer_1s.Enabled = true;
  1985. checkBox_OBC_StartSetGearSt.Checked = false;
  1986. return;
  1987. }
  1988. //检查是否选择档位和打开车灯
  1989. if ((comboBox_OBC_SetGearST.SelectedIndex == -1) || (comboBox_OBC_LightSw.SelectedIndex == -1))
  1990. {
  1991. timer_1s.Enabled = false;
  1992. MessageBox.Show("请检查档位设置和大灯开关!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  1993. timer_1s.Enabled = true;
  1994. checkBox_OBC_StartSetGearSt.Checked = false;
  1995. return;
  1996. }
  1997. }
  1998. }
  1999. /// <summary>
  2000. /// OBC查询电机用户参数
  2001. /// </summary>
  2002. /// <param name="sender"></param>
  2003. /// <param name="e"></param>
  2004. private void button_OBC_ReadUserInfo_Click(object sender, EventArgs e)
  2005. {
  2006. richTextBox_OBC_ReadUserInfo.Clear();
  2007. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3300, null);
  2008. }
  2009. /// <summary>
  2010. /// OBC设置电机用户参数
  2011. /// </summary>
  2012. /// <param name="sender"></param>
  2013. /// <param name="e"></param>
  2014. private void button_OBC_WriteUserInfo_Click(object sender, EventArgs e)
  2015. {
  2016. var UserInfoCode = new byte[8];
  2017. for (int i = 0; i < UserInfoCode.Length; i++)
  2018. UserInfoCode[i] = 0;
  2019. if (comboBox_OBC_StartMode.SelectedIndex == -1)//检查数据有效性
  2020. {
  2021. timer_1s.Enabled = false;
  2022. MessageBox.Show("请选择启动模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2023. timer_1s.Enabled = true;
  2024. return;
  2025. }
  2026. if (comboBox_OBC_AssistFunc.SelectedIndex == -1)//检查数据有效性
  2027. {
  2028. timer_1s.Enabled = false;
  2029. MessageBox.Show("请选择助力方案!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2030. timer_1s.Enabled = true;
  2031. return;
  2032. }
  2033. UserInfoCode[0] = (byte)(int)numericUpDown_OBC_WheelAdj.Value;
  2034. UserInfoCode[1] = (byte)(comboBox_OBC_StartMode.SelectedIndex + 1);
  2035. UserInfoCode[2] = (byte)(comboBox_OBC_AssistFunc.SelectedIndex + 1);
  2036. UserInfoCode[3] = (byte)(uint)numericUpDown_OBC_OffTime.Value;
  2037. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3408, UserInfoCode);
  2038. }
  2039. /// <summary>
  2040. /// OBC查询电机版本信息
  2041. /// </summary>
  2042. /// <param name="sender"></param>
  2043. /// <param name="e"></param>
  2044. private void button_OBC_ReadVerInfo_Click(object sender, EventArgs e)
  2045. {
  2046. textBox_Model.Text = "---";
  2047. textBox_SN.Text = "---";
  2048. textBox_HW.Text = "---";
  2049. textBox_FW.Text = "---";
  2050. textBox_SP.Text = "---";
  2051. textBox_OBC_ReadModel.Text = "---";
  2052. textBox_OBC_ReadSN.Text = "---";
  2053. textBox_OBC_ReadHW.Text = "---";
  2054. textBox_OBC_ReadFW.Text = "---";
  2055. textBox_OBC_ReadSP.Text = "---";
  2056. textBox_FacModeName.Text = "---";
  2057. textBox_FacModeNum.Text = "---";
  2058. textBox_FacModeHW.Text = "---";
  2059. textBox_FacModeFW.Text = "---";
  2060. textBox_FacModeSP.Text = "---";
  2061. Class_Motor_Ver.Mode = "---";
  2062. Class_Motor_Ver.SN = "---";
  2063. Class_Motor_Ver.HW = "---";
  2064. Class_Motor_Ver.FW = "---";
  2065. Class_Motor_Ver.Special = "---";
  2066. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  2067. }
  2068. /// <summary>
  2069. /// OBC读取骑行历史
  2070. /// </summary>
  2071. /// <param name="sender"></param>
  2072. /// <param name="e"></param>
  2073. private void button_OBC_ReadRideInfo_Click(object sender, EventArgs e)
  2074. {
  2075. textBox_OBC_TRIP_KM.Text = "";
  2076. textBox_OBC_TRIP_TIME.Text = "";
  2077. textBox_OBC_ODO_KM.Text = "";
  2078. textBox_OBC_ODO_TIME.Text = "";
  2079. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3500, null);
  2080. }
  2081. /// <summary>
  2082. /// OBC清除TRIP里程
  2083. /// </summary>
  2084. /// <param name="sender"></param>
  2085. /// <param name="e"></param>
  2086. private void button_OBC_ClearTrip_Click(object sender, EventArgs e)
  2087. {
  2088. var Code = new byte[5];
  2089. Code[0] = (byte)'C';
  2090. Code[1] = (byte)'L';
  2091. Code[2] = (byte)'E';
  2092. Code[3] = (byte)'A';
  2093. Code[4] = (byte)'R';
  2094. timer_1s.Enabled = false;
  2095. if (MessageBox.Show("TRIP清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2096. mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3605, Code);
  2097. timer_1s.Enabled = true;
  2098. }
  2099. private void checkBox_OBC_StartReadBMS_CheckedChanged(object sender, EventArgs e)
  2100. {
  2101. if (checkBox_OBC_StartReadBMS.Checked == true)
  2102. {
  2103. //检查串口是否打开
  2104. if (!mySerialProcess.mySerial.IsOpen)
  2105. {
  2106. timer_1s.Enabled = false;
  2107. MessageBox.Show("串口未连接!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2108. timer_1s.Enabled = true;
  2109. checkBox_OBC_StartReadBMS.Checked = false;
  2110. return;
  2111. }
  2112. }
  2113. }
  2114. /// <summary>
  2115. /// 写入力矩传感器参数
  2116. /// </summary>
  2117. /// <param name="sender"></param>
  2118. /// <param name="e"></param>
  2119. private void button_WriteTqSensorParam_Click(object sender, EventArgs e)
  2120. {
  2121. var ConfigParam = new byte[46];
  2122. for (int i = 0; i < 14; i++)
  2123. ConfigParam[i] = 0;
  2124. ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
  2125. ushort uwDataTemp = 0;
  2126. //力矩传感器参数只写入前面14项与力矩传感器相关的参数
  2127. string[] strDataTemp = richTextBox_SensorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
  2128. int index = 0;
  2129. try
  2130. {
  2131. for (int i = 0; i < strDataTemp.Length; i++)
  2132. {
  2133. if (strDataTemp[i].Split('=')[0] == "第四阶段转矩点采集值")
  2134. {
  2135. index = i;
  2136. break;
  2137. }
  2138. }
  2139. for (int i = 0; i < (index + 1); i++)
  2140. {
  2141. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2142. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2143. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2144. }
  2145. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x472E, ConfigParam);
  2146. }
  2147. catch (Exception)
  2148. {
  2149. timer_1s.Enabled = false;
  2150. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2151. timer_1s.Enabled = true;
  2152. }
  2153. }
  2154. /// <summary>
  2155. /// 查询存储标志
  2156. /// </summary>
  2157. /// <param name="sender"></param>
  2158. /// <param name="e"></param>
  2159. private void button_ReadSaveFlag_Click(object sender, EventArgs e)
  2160. {
  2161. radioButton_EE_SaveYes.Checked = false;
  2162. radioButton_EE_SaveNo.Checked = false;
  2163. radioButton_SIP_SaveYes.Checked = false;
  2164. radioButton_SIP_SaveNo.Checked = false;
  2165. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null);
  2166. }
  2167. /// <summary>
  2168. /// 写入存储标志
  2169. /// </summary>
  2170. /// <param name="sender"></param>
  2171. /// <param name="e"></param>
  2172. private void button_WriteSaveFlag_Click(object sender, EventArgs e)
  2173. {
  2174. var SaveFlag = new byte[6];
  2175. for (int i = 0; i < 6; i++)
  2176. SaveFlag[i] = 0;
  2177. if ((radioButton_EE_SaveYes.Checked == false) && (radioButton_EE_SaveNo.Checked == false))
  2178. {
  2179. timer_1s.Enabled = false;
  2180. MessageBox.Show("请选择EEPROM存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2181. timer_1s.Enabled = true;
  2182. return;
  2183. }
  2184. if ((radioButton_SIP_SaveYes.Checked == false) && (radioButton_SIP_SaveNo.Checked == false))
  2185. {
  2186. timer_1s.Enabled = false;
  2187. MessageBox.Show("请选择SIP校验存储标志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2188. timer_1s.Enabled = true;
  2189. return;
  2190. }
  2191. SaveFlag[0] = (byte)((checkBox_SaveYes.Checked) ? 0x01 : 0x00);
  2192. SaveFlag[2] = (byte)(radioButton_EE_SaveYes.Checked ? 0x01 : 0x00);
  2193. SaveFlag[3] = 0;
  2194. SaveFlag[4] = (byte)(radioButton_SIP_SaveYes.Checked ? 0x01 : 0x00);
  2195. SaveFlag[5] = 0;
  2196. timer_1s.Enabled = false;
  2197. if (MessageBox.Show("确认修改存储标志?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2198. {
  2199. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4906, SaveFlag);
  2200. }
  2201. timer_1s.Enabled = true;
  2202. }
  2203. /// <summary>
  2204. /// 读取指定地址数据
  2205. /// </summary>
  2206. /// <param name="sender"></param>
  2207. /// <param name="e"></param>
  2208. private void button_ReadRamFlash_Click(object sender, EventArgs e)
  2209. {
  2210. var Address = new byte[4];
  2211. UInt32 Address_Begin;
  2212. UInt32 Addres_End;
  2213. richTextBox_RamFlasgData.Clear();
  2214. if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
  2215. {
  2216. timer_1s.Enabled = false;
  2217. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2218. timer_1s.Enabled = true;
  2219. return;
  2220. }
  2221. else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
  2222. {
  2223. timer_1s.Enabled = false;
  2224. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2225. timer_1s.Enabled = true;
  2226. return;
  2227. }
  2228. else
  2229. {
  2230. Address = mySerialProcess.HexStringToBytes(textBox_Address_Begin.Text, false);
  2231. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2232. Address = mySerialProcess.HexStringToBytes(textBox_Address_End.Text, false);
  2233. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2234. if (Addres_End < Address_Begin)
  2235. {
  2236. timer_1s.Enabled = false;
  2237. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2238. timer_1s.Enabled = true;
  2239. return;
  2240. }
  2241. else
  2242. {
  2243. var SendByte = new byte[8];
  2244. SendByte[0] = (byte)(Address_Begin >> 24);
  2245. SendByte[1] = (byte)(Address_Begin >> 16);
  2246. SendByte[2] = (byte)(Address_Begin >> 8);
  2247. SendByte[3] = (byte)(Address_Begin);
  2248. SendByte[4] = (byte)(Addres_End >> 24);
  2249. SendByte[5] = (byte)(Addres_End >> 16);
  2250. SendByte[6] = (byte)(Addres_End >> 8);
  2251. SendByte[7] = (byte)(Addres_End);
  2252. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  2253. }
  2254. }
  2255. }
  2256. /// <summary>
  2257. /// 工作模式选择
  2258. /// </summary>
  2259. /// <param name="sender"></param>
  2260. /// <param name="e"></param>
  2261. private void comboBox_WorkMode_SelectedIndexChanged(object sender, EventArgs e)
  2262. {
  2263. var RunMode = new byte[1];
  2264. if (comboBox_WorkMode.Text == "配置模式")
  2265. RunMode[0] = 0x01;
  2266. else
  2267. RunMode[0] = 0x00;
  2268. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  2269. }
  2270. /// <summary>
  2271. /// 助力档位选择
  2272. /// </summary>
  2273. /// <param name="sender"></param>
  2274. /// <param name="e"></param>
  2275. private void comboBox_GearSt_SelectedIndexChanged(object sender, EventArgs e)
  2276. {
  2277. var CtrlCode = new byte[2];
  2278. if (comboBox_GearSt.SelectedIndex == 5)//档位
  2279. CtrlCode[0] = 0x33;
  2280. else if (comboBox_GearSt.SelectedIndex == 6)//档位
  2281. CtrlCode[0] = 0x22;
  2282. else
  2283. CtrlCode[0] = (byte)comboBox_GearSt.SelectedIndex;
  2284. if (comboBox_LightSwitch.SelectedIndex == 0)//车灯
  2285. CtrlCode[1] = 0xF1;
  2286. else
  2287. CtrlCode[1] = 0xF0;
  2288. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  2289. comboBox_OBC_SetGearST.SelectedIndex = comboBox_GearSt.SelectedIndex;
  2290. comboBox_OBC_LightSw.SelectedIndex = comboBox_LightSwitch.SelectedIndex;
  2291. }
  2292. /// <summary>
  2293. /// 仪表档位选择
  2294. /// </summary>
  2295. /// <param name="sender"></param>
  2296. /// <param name="e"></param>
  2297. private void comboBox_OBC_SetGearST_SelectedIndexChanged(object sender, EventArgs e)
  2298. {
  2299. comboBox_GearSt.SelectedIndex = comboBox_OBC_SetGearST.SelectedIndex;
  2300. comboBox_LightSwitch.SelectedIndex = comboBox_OBC_LightSw.SelectedIndex;
  2301. }
  2302. /// <summary>
  2303. /// 生产模式初始化
  2304. /// </summary>
  2305. /// <param name="sender"></param>
  2306. /// <param name="e"></param>
  2307. private void button_FacModeInit_Click(object sender, EventArgs e)
  2308. {
  2309. var Code = new byte[5];
  2310. Code[0] = (byte)'C';
  2311. Code[1] = (byte)'L';
  2312. Code[2] = (byte)'E';
  2313. Code[3] = (byte)'A';
  2314. Code[4] = (byte)'R';
  2315. timer_1s.Enabled = false;
  2316. if (MessageBox.Show("电机即将初始化!", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2317. {
  2318. if (MessageBox.Show("请再次确认", "确认?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2319. {
  2320. timer_1s.Enabled = true;
  2321. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  2322. PowerOffAckStatus = false;
  2323. Delay_ms(250);
  2324. int TryCnt = 3;
  2325. while ((TryCnt--) >= 0)
  2326. {
  2327. if (!PowerOffAckStatus)
  2328. {
  2329. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code)) return;
  2330. PowerOffAckStatus = false;
  2331. Delay_ms(250);
  2332. }
  2333. else break;
  2334. }
  2335. if (PowerOffAckStatus)
  2336. {
  2337. timer_1s.Enabled = false;
  2338. MessageBox.Show("系统已关机,请保持无负载重新开机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  2339. timer_1s.Enabled = true;
  2340. }
  2341. else
  2342. {
  2343. timer_1s.Enabled = false;
  2344. MessageBox.Show("初始化失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2345. timer_1s.Enabled = true;
  2346. }
  2347. timer_1s.Enabled = true;
  2348. }
  2349. }
  2350. timer_1s.Enabled = true;
  2351. //清除历史测试记录
  2352. textBox_FacModeSensorADC0.Text = "";
  2353. textBox_FacModeSensorADC1.Text = "";
  2354. textBox_FacModeSensorADC2.Text = "";
  2355. textBox_FacModeSensorADC3.Text = "";
  2356. textBox_FacModeSensorADC4.Text = "";
  2357. checkBox_FacModeCheckBikeSpeed.Checked = false;
  2358. checkBox_FacModeCheckCadence.Checked = false;
  2359. checkBox_FacModeCheckNTC.Checked = false;
  2360. checkBox_FacModeCheckVol.Checked = false;
  2361. LightSwitchStatus = false;
  2362. MotorRunStatus = false;
  2363. trackBar_FacModeMotorSpeedAdj.Value = 5;
  2364. textBox_FacModeWheelSize.Text = "";
  2365. textBox_FacModeSpeedLimit.Text = "";
  2366. comboBox_FacModeAssist1.SelectedIndex = -1;
  2367. comboBox_FacModeAssist2.SelectedIndex = -1;
  2368. comboBox_FacModeLightVol.SelectedIndex = -1;
  2369. comboBox_FacModeStartMode.SelectedIndex = -1;
  2370. textBox_FacModeStartGain.Text = "";
  2371. textBox_FacModeCircuitK.Text = "";
  2372. textBox_FacModeFltCounter.Text = "";
  2373. textBox_FacModeSpeedLimitTh.Text = "";
  2374. textBox_FacModeSpeedLimitEnd.Text = "";
  2375. textBox_FacModeCadencePer.Text = "";
  2376. textBox_FacModeName.Text = "";
  2377. textBox_FacModeNum.Text = "";
  2378. textBox_FacModeHW.Text = "";
  2379. textBox_FacModeFW.Text = "";
  2380. }
  2381. /// <summary>
  2382. /// 生产模式读取传感器参数
  2383. /// </summary>
  2384. /// <param name="sender"></param>
  2385. /// <param name="e"></param>
  2386. private void button_FacModeSensorRead_Click(object sender, EventArgs e)
  2387. {
  2388. richTextBox_SensorParam.Clear();
  2389. textBox_FacModeSensorADC0.Text = "";
  2390. textBox_FacModeSensorADC1.Text = "";
  2391. textBox_FacModeSensorADC2.Text = "";
  2392. textBox_FacModeSensorADC3.Text = "";
  2393. textBox_FacModeSensorADC4.Text = "";
  2394. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  2395. }
  2396. /// <summary>
  2397. /// 生产模式传感器标定1
  2398. /// </summary>
  2399. /// <param name="sender"></param>
  2400. /// <param name="e"></param>
  2401. private void buttonFacModeSet1_Click(object sender, EventArgs e)
  2402. {
  2403. var ConfigParam = new byte[4];
  2404. for (int i = 0; i < 4; i++)
  2405. ConfigParam[i] = 0;
  2406. ushort uwDataTemp = 0;
  2407. try
  2408. {
  2409. uwDataTemp = 1;//负载序号
  2410. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  2411. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  2412. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal1.Text) * 10); ;//负载值0.1Nm
  2413. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  2414. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  2415. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  2416. Delay_ms(200);
  2417. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  2418. }
  2419. catch (Exception)
  2420. {
  2421. timer_1s.Enabled = false;
  2422. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2423. timer_1s.Enabled = true;
  2424. }
  2425. }
  2426. /// <summary>
  2427. /// 生产模式传感器标定2
  2428. /// </summary>
  2429. /// <param name="sender"></param>
  2430. /// <param name="e"></param>
  2431. private void buttonFacModeSet2_Click(object sender, EventArgs e)
  2432. {
  2433. var ConfigParam = new byte[4];
  2434. for (int i = 0; i < 4; i++)
  2435. ConfigParam[i] = 0;
  2436. ushort uwDataTemp = 0;
  2437. try
  2438. {
  2439. uwDataTemp = 2;//负载序号
  2440. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  2441. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  2442. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal2.Text) * 10); ;//负载值0.1Nm
  2443. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  2444. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  2445. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  2446. Delay_ms(200);
  2447. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  2448. }
  2449. catch (Exception)
  2450. {
  2451. timer_1s.Enabled = false;
  2452. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2453. timer_1s.Enabled = true;
  2454. }
  2455. }
  2456. /// <summary>
  2457. /// 生产模式传感器标定3
  2458. /// </summary>
  2459. /// <param name="sender"></param>
  2460. /// <param name="e"></param>
  2461. private void buttonFacModeSet3_Click(object sender, EventArgs e)
  2462. {
  2463. var ConfigParam = new byte[4];
  2464. for (int i = 0; i < 4; i++)
  2465. ConfigParam[i] = 0;
  2466. ushort uwDataTemp = 0;
  2467. try
  2468. {
  2469. uwDataTemp = 3;//负载序号
  2470. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  2471. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  2472. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal3.Text) * 10); ;//负载值0.1Nm
  2473. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  2474. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  2475. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  2476. Delay_ms(200);
  2477. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  2478. }
  2479. catch (Exception)
  2480. {
  2481. timer_1s.Enabled = false;
  2482. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2483. timer_1s.Enabled = true;
  2484. }
  2485. }
  2486. /// <summary>
  2487. /// 生产模式传感器标定3
  2488. /// </summary>
  2489. /// <param name="sender"></param>
  2490. /// <param name="e"></param>
  2491. private void buttonFacModeSet4_Click(object sender, EventArgs e)
  2492. {
  2493. var ConfigParam = new byte[4];
  2494. for (int i = 0; i < 4; i++)
  2495. ConfigParam[i] = 0;
  2496. ushort uwDataTemp = 0;
  2497. try
  2498. {
  2499. uwDataTemp = 4;//负载序号
  2500. ConfigParam[0] = (byte)(uwDataTemp & 0xFF);
  2501. ConfigParam[1] = (byte)(uwDataTemp >> 8);
  2502. uwDataTemp = (ushort)(decimal.Parse(textBox_FacModeSensorCal4.Text) * 10); ;//负载值0.1Nm
  2503. ConfigParam[2] = (byte)(uwDataTemp & 0xFF);
  2504. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  2505. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4104, ConfigParam);
  2506. Delay_ms(200);
  2507. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null);
  2508. }
  2509. catch (Exception)
  2510. {
  2511. timer_1s.Enabled = false;
  2512. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2513. timer_1s.Enabled = true;
  2514. }
  2515. }
  2516. /// <summary>
  2517. /// 生产模式采集按钮
  2518. /// </summary>
  2519. /// <param name="sender"></param>
  2520. /// <param name="e"></param>
  2521. private void button_FacModeWorkMode_Click(object sender, EventArgs e)
  2522. {
  2523. var RunMode = new byte[1];
  2524. if (button_FacModeWorkMode.Text == "开始")
  2525. {
  2526. RunMode[0] = 0x01;
  2527. if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode))
  2528. {
  2529. button_FacModeWorkMode.Text = "停止";
  2530. button_FacModeWorkMode.BackColor = Color.Yellow;
  2531. }
  2532. }
  2533. else if (button_FacModeWorkMode.Text == "停止")
  2534. {
  2535. RunMode[0] = 0x00;
  2536. if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode))
  2537. {
  2538. button_FacModeWorkMode.Text = "开始";
  2539. button_FacModeWorkMode.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
  2540. }
  2541. }
  2542. }
  2543. /// <summary>
  2544. /// 生产模式开关灯
  2545. /// </summary>
  2546. /// <param name="sender"></param>
  2547. /// <param name="e"></param>
  2548. bool LightSwitchStatus = false;
  2549. private void button_FacModeLightSW_Click(object sender, EventArgs e)
  2550. {
  2551. var CtrlCode = new byte[2];
  2552. CtrlCode[0] = 0x00;
  2553. if (LightSwitchStatus)
  2554. {
  2555. CtrlCode[1] = 0xF0;
  2556. button_FacModeLightSW.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128)))));
  2557. }
  2558. else
  2559. {
  2560. CtrlCode[1] = 0xF1;
  2561. button_FacModeLightSW.BackColor = Color.Yellow;
  2562. }
  2563. if(mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode))
  2564. {
  2565. LightSwitchStatus = !LightSwitchStatus;
  2566. comboBox_LightSwitch.SelectedIndex = LightSwitchStatus ? 0 : 1;
  2567. comboBox_OBC_LightSw.SelectedIndex = LightSwitchStatus ? 0 : 1;
  2568. }
  2569. }
  2570. /// <summary>
  2571. /// 生产模式电机控制
  2572. /// </summary>
  2573. /// <param name="sender"></param>
  2574. /// <param name="e"></param>
  2575. bool MotorRunStatus = false;
  2576. private void button_FacModeMotorRun_Click(object sender, EventArgs e)
  2577. {
  2578. 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";
  2579. string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  2580. var ConfigParam = new byte[60];
  2581. for (int i = 0; i < 60; i++)
  2582. ConfigParam[i] = 0;
  2583. ConfigParam[0] = 0x00;
  2584. ushort uwDataTemp = 0;
  2585. if (!MotorRunStatus) //停止状态
  2586. {
  2587. //设置电机系列
  2588. if (radioButton_FacModeDriverCity.Checked == true)
  2589. {
  2590. strDataTemp[0] = "整体运行模式=3";
  2591. strDataTemp[3] = "旋转方向=1";
  2592. strDataTemp[18] = "惯量=300";
  2593. }
  2594. else if (radioButton_FacModeDriverMtb.Checked == true)
  2595. {
  2596. strDataTemp[0] = "整体运行模式=3";
  2597. strDataTemp[3] = "旋转方向=0";
  2598. strDataTemp[18] = "惯量=500";
  2599. }
  2600. else
  2601. {
  2602. timer_1s.Enabled = false;
  2603. MessageBox.Show("请选择电机类型!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2604. timer_1s.Enabled = true;
  2605. return;
  2606. }
  2607. //设置带载类型
  2608. if (空载ToolStripMenuItem.Checked == true)
  2609. {
  2610. strDataTemp[10] = "转速环控制器带宽=3";
  2611. }
  2612. else if (带载ToolStripMenuItem.Checked == true)
  2613. {
  2614. strDataTemp[10] = "转速环控制器带宽=15";
  2615. }
  2616. else
  2617. {
  2618. timer_1s.Enabled = false;
  2619. MessageBox.Show("请选择带载类型!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2620. timer_1s.Enabled = true;
  2621. return;
  2622. }
  2623. //选择位置模式
  2624. if (有感ToolStripMenuItem.Checked == true)
  2625. {
  2626. strDataTemp[1] = "位置获取模式=1";
  2627. }
  2628. else if (无感ToolStripMenuItem.Checked == true)
  2629. {
  2630. strDataTemp[1] = "位置获取模式=0";
  2631. }
  2632. else
  2633. {
  2634. timer_1s.Enabled = false;
  2635. MessageBox.Show("请选择位置模式!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2636. timer_1s.Enabled = true;
  2637. return;
  2638. }
  2639. //发送数据
  2640. try
  2641. {
  2642. for (int i = 0; i < strDataTemp.Length; i++)
  2643. {
  2644. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2645. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2646. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2647. }
  2648. if(!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  2649. return;
  2650. }
  2651. catch (Exception)
  2652. {
  2653. timer_1s.Enabled = false;
  2654. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2655. timer_1s.Enabled = true;
  2656. }
  2657. //设置转速百分比100%
  2658. trackBar_FacModeMotorSpeedAdj.Value = 100;
  2659. MotorRunStatus = !MotorRunStatus;
  2660. button_FacModeMotorRun.BackColor = Color.Yellow;
  2661. //电机进入配置模式
  2662. var RunMode = new byte[1];
  2663. RunMode[0] = 0x01;
  2664. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  2665. button_FacModeWorkMode.Text = "停止";
  2666. button_FacModeWorkMode.BackColor = Color.Yellow;
  2667. }
  2668. else //运转状态
  2669. {
  2670. //设置电机调试参数
  2671. if (radioButton_FacModeDriverCity.Checked == true)
  2672. {
  2673. strDataTemp[0] = "整体运行模式=4";
  2674. strDataTemp[1] = "位置获取模式=1";
  2675. strDataTemp[3] = "旋转方向=1";
  2676. strDataTemp[10] = "转速环控制器带宽=15";
  2677. strDataTemp[18] = "惯量=300";
  2678. }
  2679. else if (radioButton_FacModeDriverMtb.Checked == true)
  2680. {
  2681. strDataTemp[0] = "整体运行模式=5";
  2682. strDataTemp[1] = "位置获取模式=1";
  2683. strDataTemp[3] = "旋转方向=0";
  2684. strDataTemp[10] = "转速环控制器带宽=15";
  2685. strDataTemp[18] = "惯量=500";
  2686. }
  2687. else
  2688. {
  2689. timer_1s.Enabled = false;
  2690. MessageBox.Show("请选择电机类型!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2691. timer_1s.Enabled = true;
  2692. return;
  2693. }
  2694. try
  2695. {
  2696. for (int i = 0; i < strDataTemp.Length; i++)
  2697. {
  2698. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2699. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2700. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2701. }
  2702. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
  2703. return;
  2704. }
  2705. catch (Exception)
  2706. {
  2707. timer_1s.Enabled = false;
  2708. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2709. timer_1s.Enabled = true;
  2710. }
  2711. //设置转速百分比2%
  2712. trackBar_FacModeMotorSpeedAdj.Value = 2;
  2713. MotorRunStatus = !MotorRunStatus;
  2714. button_FacModeMotorRun.BackColor = Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
  2715. //电机退出配置模式
  2716. var RunMode = new byte[1];
  2717. RunMode[0] = 0x00;
  2718. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  2719. button_FacModeWorkMode.Text = "开始";
  2720. button_FacModeWorkMode.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
  2721. }
  2722. }
  2723. /// <summary>
  2724. /// 生产模式转速调节
  2725. /// </summary>
  2726. /// <param name="sender"></param>
  2727. /// <param name="e"></param>
  2728. private void trackBar_FacModeMotorSpeedAdj_ValueChanged(object sender, EventArgs e)
  2729. {
  2730. //转速百分比更新
  2731. label_FacModeMotorSpeedSet.Text = trackBar_FacModeMotorSpeedAdj.Value.ToString() + "%";
  2732. numericUpDown_SpeedAdj.Value = trackBar_FacModeMotorSpeedAdj.Value;
  2733. }
  2734. /// <summary>
  2735. /// 生产模式读取整车参数
  2736. /// </summary>
  2737. /// <param name="sender"></param>
  2738. /// <param name="e"></param>
  2739. private void button_FacModeBikeParaRead_Click(object sender, EventArgs e)
  2740. {
  2741. textBox_FacModeWheelSize.Text = "";
  2742. textBox_FacModeSpeedLimit.Text = "";
  2743. comboBox_FacModeAssist1.SelectedIndex = -1;
  2744. comboBox_FacModeAssist2.SelectedIndex = -1;
  2745. comboBox_FacModeLightVol.SelectedIndex = -1;
  2746. comboBox_FacModeStartMode.SelectedIndex = -1;
  2747. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null);
  2748. }
  2749. /// <summary>
  2750. /// 生产模式写入整车参数
  2751. /// </summary>
  2752. /// <param name="sender"></param>
  2753. /// <param name="e"></param>
  2754. private void button_FacModeBikeParaSet_Click(object sender, EventArgs e)
  2755. {
  2756. string BikeDefaultInfo = "轮胎周长=219, 电控传动比=35, 助力最大限速=25, 推行模式限速=6, 前牙盘T数=38, 后牙盘T数=11, 助力方案1=341, 助力方案2=682, 前后灯电压=6, 轮胎周长微调=0, 启动模式=2, 自动关机时间=15";
  2757. var ConfigParam = new byte[28];
  2758. for (int i = 0; i < 28; i++)
  2759. ConfigParam[i] = 0;
  2760. ConfigParam[0] = (byte)(0x01);
  2761. ushort uwDataTemp = 0;
  2762. string[] strDataTemp = BikeDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  2763. try
  2764. {
  2765. for (int i = 0; i < strDataTemp.Length; i++)
  2766. {
  2767. uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
  2768. ConfigParam[2 * i + 2] = (byte)uwDataTemp;
  2769. ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
  2770. }
  2771. //周长
  2772. uwDataTemp = Convert.ToUInt16(textBox_FacModeWheelSize.Text);
  2773. ConfigParam[2] = (byte)uwDataTemp;
  2774. ConfigParam[3] = (byte)(uwDataTemp >> 8);
  2775. //限速
  2776. uwDataTemp = Convert.ToUInt16(textBox_FacModeSpeedLimit.Text);
  2777. ConfigParam[6] = (byte)uwDataTemp;
  2778. ConfigParam[7] = (byte)(uwDataTemp >> 8);
  2779. //助力方案1
  2780. if (comboBox_FacModeAssist1.SelectedIndex == 0) uwDataTemp = 0;
  2781. else if (comboBox_FacModeAssist1.SelectedIndex == 1) uwDataTemp = 341;
  2782. else if (comboBox_FacModeAssist1.SelectedIndex == 2) uwDataTemp = 682;
  2783. else
  2784. {
  2785. timer_1s.Enabled = false;
  2786. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2787. timer_1s.Enabled = true;
  2788. return;
  2789. }
  2790. ConfigParam[14] = (byte)uwDataTemp;
  2791. ConfigParam[15] = (byte)(uwDataTemp >> 8);
  2792. //助力方案2
  2793. if(comboBox_FacModeAssist2.SelectedIndex == 0) uwDataTemp = 0;
  2794. else if (comboBox_FacModeAssist2.SelectedIndex == 1) uwDataTemp = 341;
  2795. else if (comboBox_FacModeAssist2.SelectedIndex == 2) uwDataTemp = 682;
  2796. else
  2797. {
  2798. timer_1s.Enabled = false;
  2799. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2800. timer_1s.Enabled = true;
  2801. return;
  2802. }
  2803. ConfigParam[16] = (byte)uwDataTemp;
  2804. ConfigParam[17] = (byte)(uwDataTemp >> 8);
  2805. //灯压
  2806. if(comboBox_FacModeLightVol.SelectedIndex == 0) uwDataTemp = 6;
  2807. else if (comboBox_FacModeLightVol.SelectedIndex == 1) uwDataTemp = 12;
  2808. else
  2809. {
  2810. timer_1s.Enabled = false;
  2811. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2812. timer_1s.Enabled = true;
  2813. return;
  2814. }
  2815. ConfigParam[18] = (byte)uwDataTemp;
  2816. ConfigParam[19] = (byte)(uwDataTemp >> 8);
  2817. //启动模式
  2818. if (comboBox_FacModeStartMode.SelectedIndex == 0) uwDataTemp = 1;
  2819. else if (comboBox_FacModeStartMode.SelectedIndex == 2) uwDataTemp = 3;
  2820. else uwDataTemp = 2;
  2821. ConfigParam[22] = (byte)uwDataTemp;
  2822. ConfigParam[23] = (byte)(uwDataTemp >> 8);
  2823. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3D1C, ConfigParam);
  2824. }
  2825. catch (Exception)
  2826. {
  2827. timer_1s.Enabled = false;
  2828. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2829. timer_1s.Enabled = true;
  2830. }
  2831. }
  2832. /// <summary>
  2833. /// 生产模式读取助力参数
  2834. /// </summary>
  2835. /// <param name="sender"></param>
  2836. /// <param name="e"></param>
  2837. private void button_FacModeAssistParaRead_Click(object sender, EventArgs e)
  2838. {
  2839. var ConfigParam = new byte[4];
  2840. textBox_FacModeStartGain.Text = "";
  2841. textBox_FacModeCircuitK.Text = "";
  2842. textBox_FacModeFltCounter.Text = "";
  2843. textBox_FacModeSpeedLimitTh.Text ="";
  2844. textBox_FacModeSpeedLimitEnd.Text = "";
  2845. textBox_FacModeCadencePer.Text = "";
  2846. ConfigParam[0] = (byte)(1 & 0xFF);
  2847. ConfigParam[1] = (byte)(1 >> 8);
  2848. ConfigParam[2] = (byte)(1 & 0xFF);
  2849. ConfigParam[3] = (byte)(1 >> 8);
  2850. mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam);
  2851. }
  2852. /// <summary>
  2853. /// 生产模式写入助力参数
  2854. /// </summary>
  2855. /// <param name="sender"></param>
  2856. /// <param name="e"></param>
  2857. private void button_FacModeAssistParaSet_Click(object sender, EventArgs e)
  2858. {
  2859. 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";
  2860. var ConfigParam = new byte[80];
  2861. for (int i = 0; i < 80; i++)
  2862. ConfigParam[i] = 0;
  2863. ConfigParam[0] = (byte)(0x01);
  2864. ushort uwDataTemp = 0;
  2865. ulong ulDataTemp = 0;
  2866. int index_1 = 0, index_2 = 0;
  2867. string[] strDataTemp = AssistDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
  2868. try
  2869. {
  2870. //因数据类型不同,预处理
  2871. for (int i = 0; i < strDataTemp.Length; i++)
  2872. {
  2873. if (strDataTemp[i].Split('=')[0] == "转矩曲线.a")
  2874. {
  2875. index_1 = i;
  2876. break;
  2877. }
  2878. }
  2879. for (int i = 0; i < strDataTemp.Length; i++)
  2880. {
  2881. if (strDataTemp[i].Split('=')[0] == "踏频曲线.d")
  2882. {
  2883. index_2 = i;
  2884. break;
  2885. }
  2886. }
  2887. for (int i = 0; i < strDataTemp.Length; i++)
  2888. {
  2889. ulDataTemp = Convert.ToUInt32(strDataTemp[i].Split('=')[1]);
  2890. if (i < index_1)
  2891. {
  2892. ConfigParam[2 * i + 4] = (byte)ulDataTemp;
  2893. ConfigParam[2 * i + 5] = (byte)(ulDataTemp >> 8);
  2894. }
  2895. else if (i <= index_2)
  2896. {
  2897. ConfigParam[4 * i - 4] = (byte)ulDataTemp;
  2898. ConfigParam[4 * i - 3] = (byte)(ulDataTemp >> 8);
  2899. ConfigParam[4 * i - 2] = (byte)(ulDataTemp >> 16);
  2900. ConfigParam[4 * i - 1] = (byte)(ulDataTemp >> 24);
  2901. }
  2902. else
  2903. {
  2904. ConfigParam[2 * i + 20] = (byte)ulDataTemp;
  2905. ConfigParam[2 * i + 21] = (byte)(ulDataTemp >> 8);
  2906. }
  2907. }
  2908. //零速增益
  2909. uwDataTemp = Convert.ToUInt16(textBox_FacModeStartGain.Text);
  2910. ConfigParam[4] = (byte)uwDataTemp;
  2911. ConfigParam[5] = (byte)(uwDataTemp >> 8);
  2912. //电流阶梯
  2913. uwDataTemp = Convert.ToUInt16(textBox_FacModeCircuitK.Text);
  2914. ConfigParam[48] = (byte)uwDataTemp;
  2915. ConfigParam[49] = (byte)(uwDataTemp >> 8);
  2916. //滤波脉冲
  2917. uwDataTemp = Convert.ToUInt16(textBox_FacModeFltCounter.Text);
  2918. ConfigParam[52] = (byte)uwDataTemp;
  2919. ConfigParam[53] = (byte)(uwDataTemp >> 8);
  2920. //限速启动
  2921. uwDataTemp = Convert.ToUInt16(textBox_FacModeSpeedLimitTh.Text);
  2922. ConfigParam[58] = (byte)uwDataTemp;
  2923. ConfigParam[59] = (byte)(uwDataTemp >> 8);
  2924. //限速停止
  2925. uwDataTemp = Convert.ToUInt16(textBox_FacModeSpeedLimitEnd.Text);
  2926. ConfigParam[60] = (byte)uwDataTemp;
  2927. ConfigParam[61] = (byte)(uwDataTemp >> 8);
  2928. //踏频占比
  2929. uwDataTemp = Convert.ToUInt16(textBox_FacModeCadencePer.Text);
  2930. ConfigParam[62] = (byte)uwDataTemp;
  2931. ConfigParam[63] = (byte)(uwDataTemp >> 8);
  2932. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
  2933. }
  2934. catch (Exception)
  2935. {
  2936. timer_1s.Enabled = false;
  2937. MessageBox.Show("数据格式不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  2938. timer_1s.Enabled = true;
  2939. }
  2940. }
  2941. /// <summary>
  2942. /// 生产模式写入型号
  2943. /// </summary>
  2944. /// <param name="sender"></param>
  2945. /// <param name="e"></param>
  2946. private void button_FacModeSetName_Click(object sender, EventArgs e)
  2947. {
  2948. string Mode = textBox_FacModeName.Text;
  2949. var ModeArray = new byte[16];
  2950. for (ushort i = 0; i < Mode.Length; i++)
  2951. {
  2952. ModeArray[i] = (byte)Mode[i];
  2953. }
  2954. if (Mode.Length < 16)
  2955. {
  2956. ModeArray[Mode.Length] = (byte)'.';
  2957. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  2958. {
  2959. ModeArray[Mode.Length + 1 + i] = 0x20;
  2960. }
  2961. }
  2962. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  2963. }
  2964. /// <summary>
  2965. /// 生产模式写入SN
  2966. /// </summary>
  2967. /// <param name="sender"></param>
  2968. /// <param name="e"></param>
  2969. private void Button_FacModeSetNum_Click(object sender, EventArgs e)
  2970. {
  2971. string SN = textBox_FacModeNum.Text;
  2972. var SNArray = new byte[16];
  2973. for (ushort i = 0; i < SN.Length; i++)
  2974. {
  2975. SNArray[i] = (byte)SN[i];
  2976. }
  2977. if (SN.Length < 16)
  2978. {
  2979. SNArray[SN.Length] = (byte)'.';
  2980. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  2981. {
  2982. SNArray[SN.Length + 1 + i] = 0x20;
  2983. }
  2984. }
  2985. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  2986. }
  2987. /// <summary>
  2988. /// 生产模式读取版本信息
  2989. /// </summary>
  2990. /// <param name="sender"></param>
  2991. /// <param name="e"></param>
  2992. private void Button_FacModeReadVer_Click_1(object sender, EventArgs e)
  2993. {
  2994. textBox_Model.Text = "---";
  2995. textBox_SN.Text = "---";
  2996. textBox_HW.Text = "---";
  2997. textBox_FW.Text = "---";
  2998. textBox_SP.Text = "---";
  2999. textBox_OBC_ReadModel.Text = "---";
  3000. textBox_OBC_ReadSN.Text = "---";
  3001. textBox_OBC_ReadHW.Text = "---";
  3002. textBox_OBC_ReadFW.Text = "---";
  3003. textBox_OBC_ReadSP.Text = "---";
  3004. textBox_FacModeName.Text = "---";
  3005. textBox_FacModeNum.Text = "---";
  3006. textBox_FacModeHW.Text = "---";
  3007. textBox_FacModeFW.Text = "---";
  3008. textBox_FacModeSP.Text = "---";
  3009. Class_Motor_Ver.Mode = "---";
  3010. Class_Motor_Ver.SN = "---";
  3011. Class_Motor_Ver.HW = "---";
  3012. Class_Motor_Ver.FW = "---";
  3013. Class_Motor_Ver.Special = "---";
  3014. mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null);
  3015. }
  3016. /// <summary>
  3017. /// 生产模式写入生产信息
  3018. /// </summary>
  3019. /// <param name="sender"></param>
  3020. /// <param name="e"></param>
  3021. private void Button_FacModeSetMacDate_Click(object sender, EventArgs e)
  3022. {
  3023. var MACArray = new byte[32];
  3024. string MacDefaultInfo = "TTIUM";
  3025. string MacAddDefaultInfo = "WUHAN";
  3026. string MacDateDefaultInfo = DateTime.Now.ToString("yyyyMMdd");
  3027. string MacPPDefaultInfo = "MM_MC1";
  3028. //填入生产商
  3029. for (ushort i = 0; i < MacDefaultInfo.Length; i++)
  3030. {
  3031. MACArray[i] = (byte)MacDefaultInfo[i];
  3032. }
  3033. if (MacDefaultInfo.Length < 8)
  3034. {
  3035. MACArray[MacDefaultInfo.Length] = (byte)'.';
  3036. for (ushort i = 0; i < 8 - MacDefaultInfo.Length - 1; i++)
  3037. {
  3038. MACArray[MacDefaultInfo.Length + 1 + i] = 0x20;
  3039. }
  3040. }
  3041. //填入生产地
  3042. for (ushort i = 0; i < MacAddDefaultInfo.Length; i++)
  3043. {
  3044. MACArray[8 + i] = (byte)MacAddDefaultInfo[i];
  3045. }
  3046. if (MacAddDefaultInfo.Length < 8)
  3047. {
  3048. MACArray[MacAddDefaultInfo.Length + 8] = (byte)'.';
  3049. for (ushort i = 0; i < 8 - MacAddDefaultInfo.Length - 1; i++)
  3050. {
  3051. MACArray[MacAddDefaultInfo.Length + 1 + i + 8] = 0x20;
  3052. }
  3053. }
  3054. //填入生产日期
  3055. for (ushort i = 0; i < MacDateDefaultInfo.Length; i++)
  3056. {
  3057. MACArray[16 + i] = (byte)MacDateDefaultInfo[i];
  3058. }
  3059. if (MacDateDefaultInfo.Length < 8)
  3060. {
  3061. MACArray[MacDateDefaultInfo.Length + 16] = (byte)'.';
  3062. for (ushort i = 0; i < 8 - MacDateDefaultInfo.Length - 1; i++)
  3063. {
  3064. MACArray[MacDateDefaultInfo.Length + 1 + i + 16] = 0x20;
  3065. }
  3066. }
  3067. //填入产品标识
  3068. for (ushort i = 0; i < MacPPDefaultInfo.Length; i++)
  3069. {
  3070. MACArray[24 + i] = (byte)MacPPDefaultInfo[i];
  3071. }
  3072. if (MacPPDefaultInfo.Length < 8)
  3073. {
  3074. MACArray[MacPPDefaultInfo.Length + 24] = (byte)'.';
  3075. for (ushort i = 0; i < 8 - MacPPDefaultInfo.Length - 1; i++)
  3076. {
  3077. MACArray[MacPPDefaultInfo.Length + 1 + i + 24] = 0x20;
  3078. }
  3079. }
  3080. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
  3081. }
  3082. /// <summary>
  3083. /// 生产模式保存测试页面
  3084. /// </summary>
  3085. /// <param name="sender"></param>
  3086. /// <param name="e"></param>
  3087. private void Button_FacModeSaveResult_Click(object sender, EventArgs e)
  3088. {
  3089. //查询传感器
  3090. richTextBox_SensorParam.Clear();
  3091. textBox_FacModeSensorADC0.Text = "";
  3092. textBox_FacModeSensorADC1.Text = "";
  3093. textBox_FacModeSensorADC2.Text = "";
  3094. textBox_FacModeSensorADC3.Text = "";
  3095. textBox_FacModeSensorADC4.Text = "";
  3096. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) return;
  3097. Delay_ms(100);
  3098. //读取一次电机信息
  3099. var CtrlCode = new byte[2];
  3100. CtrlCode[0] = 0x00;
  3101. CtrlCode[1] = 0xF0;
  3102. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode)) return;
  3103. Delay_ms(100);
  3104. //读取一次整车参数
  3105. textBox_FacModeWheelSize.Text = "";
  3106. textBox_FacModeSpeedLimit.Text = "";
  3107. comboBox_FacModeAssist1.SelectedIndex = -1;
  3108. comboBox_FacModeAssist2.SelectedIndex = -1;
  3109. comboBox_FacModeLightVol.SelectedIndex = -1;
  3110. comboBox_FacModeStartMode.SelectedIndex = -1;
  3111. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) return;
  3112. Delay_ms(100);
  3113. //读取一次助力参数
  3114. var ConfigParam = new byte[4];
  3115. textBox_FacModeStartGain.Text = "";
  3116. textBox_FacModeCircuitK.Text = "";
  3117. textBox_FacModeFltCounter.Text = "";
  3118. textBox_FacModeSpeedLimitTh.Text = "";
  3119. textBox_FacModeSpeedLimitEnd.Text = "";
  3120. textBox_FacModeCadencePer.Text = "";
  3121. ConfigParam[0] = (byte)(1 & 0xFF);
  3122. ConfigParam[1] = (byte)(1 >> 8);
  3123. ConfigParam[2] = (byte)(1 & 0xFF);
  3124. ConfigParam[3] = (byte)(1 >> 8);
  3125. if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) return;
  3126. Delay_ms(100);
  3127. //读取一次版本信息
  3128. textBox_Model.Text = "---";
  3129. textBox_SN.Text = "---";
  3130. textBox_HW.Text = "---";
  3131. textBox_FW.Text = "---";
  3132. textBox_OBC_ReadModel.Text = "---";
  3133. textBox_OBC_ReadSN.Text = "---";
  3134. textBox_OBC_ReadHW.Text = "---";
  3135. textBox_OBC_ReadFW.Text = "---";
  3136. textBox_FacModeName.Text = "---";
  3137. textBox_FacModeNum.Text = "---";
  3138. textBox_FacModeHW.Text = "---";
  3139. textBox_FacModeFW.Text = "---";
  3140. Class_Motor_Ver.Mode = "---";
  3141. Class_Motor_Ver.SN = "---";
  3142. Class_Motor_Ver.HW = "---";
  3143. Class_Motor_Ver.FW = "---";
  3144. Class_Motor_Ver.Special = "---";
  3145. if (!mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null)) return;
  3146. Delay_ms(100);
  3147. //提示检查
  3148. timer_1s.Enabled = false;
  3149. if (MessageBox.Show("请检查信息是否完整!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  3150. {
  3151. MessageBox.Show("请检查参数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3152. timer_1s.Enabled = true;
  3153. return;
  3154. }
  3155. timer_1s.Enabled = true;
  3156. Delay_ms(200);
  3157. //保存页面
  3158. Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
  3159. Graphics g = Graphics.FromImage(bit);
  3160. g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片
  3161. SaveFileDialog sf = new SaveFileDialog();
  3162. sf.Title = "页面保存";
  3163. sf.FileName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_页面存储" + ".png";
  3164. sf.Filter = "图片|*.png";
  3165. timer_1s.Enabled = false;
  3166. if (sf.ShowDialog() == DialogResult.OK)
  3167. {
  3168. bit.Save(sf.FileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
  3169. }
  3170. timer_1s.Enabled = true;
  3171. }
  3172. /// <summary>
  3173. /// 工具箱页面保存
  3174. /// </summary>
  3175. /// <param name="sender"></param>
  3176. /// <param name="e"></param>
  3177. private void 页面保存ToolStripMenuItem_Click(object sender, EventArgs e)
  3178. {
  3179. //保存页面
  3180. Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
  3181. Graphics g = Graphics.FromImage(bit);
  3182. g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片
  3183. SaveFileDialog sf = new SaveFileDialog();
  3184. sf.Title = "页面保存";
  3185. sf.FileName = "MotorInfo_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + ".png";
  3186. sf.Filter = "图片|*.png";
  3187. timer_1s.Enabled = false;
  3188. if (sf.ShowDialog() == DialogResult.OK)
  3189. {
  3190. bit.Save(sf.FileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
  3191. }
  3192. timer_1s.Enabled = true;
  3193. }
  3194. /// <summary>
  3195. /// 生产模式关机
  3196. /// </summary>
  3197. /// <param name="sender"></param>
  3198. /// <param name="e"></param>
  3199. private void Button_FacModePowerOff_Click(object sender, EventArgs e)
  3200. {
  3201. var Code = new byte[5];
  3202. Code[0] = (byte)'O';
  3203. Code[1] = (byte)'F';
  3204. Code[2] = (byte)'F';
  3205. Code[3] = (byte)'.';
  3206. Code[4] = (byte)'.';
  3207. timer_1s.Enabled = false;
  3208. if (MessageBox.Show("系统将关机", "确认关机?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3209. {
  3210. timer_1s.Enabled = true;
  3211. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  3212. PowerOffAckStatus = false;
  3213. Delay_ms(250);
  3214. int TryCnt = 3;
  3215. while ((TryCnt--) >= 0)
  3216. {
  3217. if (!PowerOffAckStatus)
  3218. {
  3219. mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  3220. PowerOffAckStatus = false;
  3221. Delay_ms(250);
  3222. }
  3223. else break;
  3224. }
  3225. if (PowerOffAckStatus)
  3226. {
  3227. timer_1s.Enabled = false;
  3228. MessageBox.Show("已关机!", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  3229. timer_1s.Enabled = true;
  3230. }
  3231. else
  3232. {
  3233. timer_1s.Enabled = false;
  3234. MessageBox.Show("关机失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  3235. timer_1s.Enabled = true;
  3236. }
  3237. }
  3238. timer_1s.Enabled = true;
  3239. }
  3240. //仪表电源键按下
  3241. private void button_OBC_ButtonPower_Click(object sender, EventArgs e)
  3242. {
  3243. var Code = new byte[2];
  3244. Code[0] = 0;
  3245. Code[1] = 0b00100000;
  3246. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  3247. }
  3248. /// <summary>
  3249. /// 仪表加键按下
  3250. /// </summary>
  3251. /// <param name="sender"></param>
  3252. /// <param name="e"></param>
  3253. private void button_OBC_ButtonAcc_Click(object sender, EventArgs e)
  3254. {
  3255. var Code = new byte[2];
  3256. Code[0] = 0;
  3257. Code[1] = 0b00010000;
  3258. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  3259. }
  3260. /// <summary>
  3261. /// 仪表减键按下
  3262. /// </summary>
  3263. /// <param name="sender"></param>
  3264. /// <param name="e"></param>
  3265. private void button_OBC_ButtonDec_Click(object sender, EventArgs e)
  3266. {
  3267. var Code = new byte[2];
  3268. Code[0] = 0;
  3269. Code[1] = 0b00001000;
  3270. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  3271. }
  3272. /// <summary>
  3273. /// 仪表Walk键按下
  3274. /// </summary>
  3275. /// <param name="sender"></param>
  3276. /// <param name="e"></param>
  3277. private void button_OBC_ButtonWalk_Click(object sender, EventArgs e)
  3278. {
  3279. var Code = new byte[2];
  3280. Code[0] = 0;
  3281. Code[1] = 0b00000100;
  3282. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  3283. }
  3284. /// <summary>
  3285. /// 仪表Light键按下
  3286. /// </summary>
  3287. /// <param name="sender"></param>
  3288. /// <param name="e"></param>
  3289. private void button_OBC_ButtonLight_Click(object sender, EventArgs e)
  3290. {
  3291. var Code = new byte[2];
  3292. Code[0] = 0;
  3293. Code[1] = 0b00000010;
  3294. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  3295. }
  3296. /// <summary>
  3297. /// 仪表Set键按下
  3298. /// </summary>
  3299. /// <param name="sender"></param>
  3300. /// <param name="e"></param>
  3301. private void button_OBC_ButtonSet_Click(object sender, EventArgs e)
  3302. {
  3303. var Code = new byte[2];
  3304. Code[0] = 0;
  3305. Code[1] = 0b00000001;
  3306. mySerialProcess.SendCmd((ushort)0x731, (byte)0x0C, (ushort)0x3A02, Code);
  3307. }
  3308. /// <summary>
  3309. /// 带载类型选择空载
  3310. /// </summary>
  3311. /// <param name="sender"></param>
  3312. /// <param name="e"></param>
  3313. private void 空载ToolStripMenuItem_Click(object sender, EventArgs e)
  3314. {
  3315. 空载ToolStripMenuItem.Checked = true;
  3316. 带载ToolStripMenuItem.Checked = false;
  3317. }
  3318. /// <summary>
  3319. /// 带载类型选择带载
  3320. /// </summary>
  3321. /// <param name="sender"></param>
  3322. /// <param name="e"></param>
  3323. private void 带载ToolStripMenuItem_Click(object sender, EventArgs e)
  3324. {
  3325. 空载ToolStripMenuItem.Checked = false;
  3326. 带载ToolStripMenuItem.Checked = true;
  3327. }
  3328. /// <summary>
  3329. /// 位置模式选择无感
  3330. /// </summary>
  3331. /// <param name="sender"></param>
  3332. /// <param name="e"></param>
  3333. private void 无感ToolStripMenuItem_Click(object sender, EventArgs e)
  3334. {
  3335. 无感ToolStripMenuItem.Checked = true;
  3336. 有感ToolStripMenuItem.Checked = false;
  3337. }
  3338. /// <summary>
  3339. /// 位置模式选择有感
  3340. /// </summary>
  3341. /// <param name="sender"></param>
  3342. /// <param name="e"></param>
  3343. private void 有感ToolStripMenuItem_Click(object sender, EventArgs e)
  3344. {
  3345. 有感ToolStripMenuItem.Checked = true;
  3346. 无感ToolStripMenuItem.Checked = false;
  3347. }
  3348. }
  3349. }