Form1.cs 189 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.IO.Ports;
  9. using System.Threading;
  10. using System.Runtime.InteropServices;
  11. using System.Runtime.CompilerServices;
  12. using System.Collections;
  13. using System.IO;
  14. namespace MOTINOVA_MC_Test
  15. {
  16. public partial class Form1 : Form
  17. {
  18. #region------------------------本地变量-----------------------------
  19. #region 串口相关
  20. private List<byte> buffer = new List<byte>(4096);
  21. private byte[] binary_data_1 = new byte[1024];
  22. private bool Listening = false;// 侦听串口是否是接收数据标志位
  23. public static string m_strDataBits = "8";
  24. public static string m_strStopBits = "1";
  25. public static string m_strCheckBits = "None";
  26. public static bool g_blnIsOpen = false;
  27. #endregion
  28. #region FTP实例
  29. public static ftp myFtp = new ftp();
  30. public static string ServerIP = "";
  31. public static string ServerPort = "";
  32. public static string ServerUser = "";
  33. public static string ServerPasswd = "";
  34. public static string ServerPath = "";
  35. #endregion
  36. #region 离线使用标识
  37. bool Offline = true;
  38. #endregion
  39. #region 本地配置存储数据路径
  40. public static string LocalPath = "";
  41. string ConfigFileName = "";
  42. #endregion
  43. #region MC运行信息超时计数
  44. bool MC_RunInfo_Refresh = false;
  45. ushort MC_RunInfo_Refresh_Cnt = 0;
  46. #endregion
  47. #region MC故障码超时计数
  48. bool MC_ErrorCode_Refresh = false;
  49. ushort MC_ErrorCode_Refresh_Cnt = 0;
  50. #endregion
  51. #region 力矩传感器平均值采集
  52. byte[] TorqueArray = new byte[25];
  53. byte[] Sensor1Array = new byte[25];
  54. byte[] Sensor2Array = new byte[25];
  55. byte[] Sensor3Array = new byte[25];
  56. ushort TorqueArray_Index = 0;
  57. #endregion
  58. #region 自动发送助力档位计时
  59. ushort AutoSendTimeCnt;
  60. #endregion
  61. #region 骑行信息超时计数
  62. bool MC_RideInfo_Refresh = false;
  63. ushort MC_RideInfo_Refresh_Cnt = 0;
  64. #endregion
  65. #region 姿态信息超时计数
  66. bool MC_AttitudeAngle_Refresh = false;
  67. ushort MC_AttitudeAngle_Refresh_Cnt = 0;
  68. #endregion
  69. #region 自动发送查询姿态信息计时
  70. ushort AutoSendReadAttitudeAngleTimeCnt;
  71. #endregion
  72. #region 自动发送查询骑行信息计时
  73. ushort AutoSendReadRideInfoTimeCnt;
  74. #endregion
  75. #region 自动存储数据
  76. string AutoSaveFileName = "";
  77. #endregion
  78. #region 故障日志存储相关
  79. bool ErrorLogSaveFlag = false;
  80. string ErrorLogSaveFileName = "";
  81. #endregion
  82. #region CDL在线检测延时
  83. ushort CDL_OnlineCheck_Cnt = 0;
  84. bool CDL_Online_Flag = true;
  85. #endregion
  86. #region 截图悬浮窗
  87. topFormCapture myCapture;
  88. #endregion
  89. #region 解锁写保护标志
  90. bool WriteProtectUnlock = false;
  91. #endregion
  92. Form2 LoginForm = new Form2();
  93. #endregion
  94. public Form1()
  95. {
  96. InitializeComponent();
  97. //显示截图悬浮窗
  98. myCapture = new topFormCapture();
  99. myCapture.Show();
  100. //检查配置文件
  101. LocalPath = Directory.GetCurrentDirectory();
  102. if (Directory.Exists(LocalPath + "\\" + "MotorRunTest") == false)
  103. Directory.CreateDirectory(LocalPath + "\\" + "MotorRunTest");
  104. ConfigFileName = Directory.GetCurrentDirectory() + "\\" + "Config.ttcfg";
  105. if (File.Exists(ConfigFileName)) //存在配置文件,导入配置信息
  106. {
  107. //打开文件
  108. StreamReader objReader = new StreamReader(ConfigFileName);
  109. string sLine = "";
  110. ArrayList array_CfgInfo = new ArrayList();
  111. array_CfgInfo.Clear();
  112. while (sLine != null)
  113. {
  114. sLine = objReader.ReadLine();
  115. array_CfgInfo.Add(sLine);
  116. }
  117. objReader.Close();
  118. //解析配置文件
  119. try
  120. {
  121. ServerIP = array_CfgInfo[1].ToString().Split(':')[1];
  122. ServerPort = array_CfgInfo[2].ToString().Split(':')[1];
  123. ServerUser = array_CfgInfo[3].ToString().Split(':')[1];
  124. ServerPasswd = array_CfgInfo[4].ToString().Split(':')[1];
  125. ServerPath = array_CfgInfo[5].ToString().Split(':')[1];
  126. Offline = (array_CfgInfo[6].ToString().Split(':')[1] == "TRUE") ? true : false;
  127. }
  128. catch (System.Exception)
  129. {
  130. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  131. }
  132. }
  133. else //不存在配置文件,生成文件写入默认值
  134. {
  135. string CfgFileInfo = "";
  136. ServerIP = "10.176.42.30";
  137. ServerPort = "21";
  138. ServerUser = "factory_test";
  139. ServerPasswd = "ttium";
  140. ServerPath = "MotorRunTest";
  141. CfgFileInfo += "[ServerSet]" + "\r\n";
  142. CfgFileInfo += "IPAddress:" + ServerIP + "\r\n";
  143. CfgFileInfo += "Port:" + ServerPort + "\r\n";
  144. CfgFileInfo += "User:" + ServerUser + "\r\n";
  145. CfgFileInfo += "Password:" + ServerPasswd + "\r\n";
  146. CfgFileInfo += "PathName:" + ServerPath + "\r\n";
  147. CfgFileInfo += "Offline:" + "FALSE" + "\r\n";
  148. System.IO.File.WriteAllText(ConfigFileName, CfgFileInfo);
  149. }
  150. //配置网络FTP服务器
  151. myFtp.FtpOption(ServerIP, ServerPort, ServerUser, ServerPasswd);
  152. //创建线程,定时检测网络连接状态
  153. Thread th = new Thread(NetworkCheck);
  154. th.IsBackground = true;
  155. th.Start();
  156. }
  157. /// <summary>
  158. /// 检查网络状态线程
  159. /// </summary>
  160. private void NetworkCheck()
  161. {
  162. //初始化第一次连接FTP服务器
  163. bool Result = myFtp.CheckFtp();
  164. this.Invoke((EventHandler)(delegate
  165. {
  166. if (Result == true)//服务器连接成功
  167. {
  168. MessageBox.Show("服务器连接成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  169. myFtp.IsNetConnected = true;
  170. myCapture.label_ServerStatus.BackColor = Color.Green;
  171. }
  172. else//服务器连接失败
  173. {
  174. MessageBox.Show("服务器连接失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  175. myFtp.IsNetConnected = false;
  176. myCapture.label_ServerStatus.BackColor = Color.Red;
  177. if (Offline != true)
  178. this.Dispose();
  179. }
  180. }));
  181. //创建定时器,定时30s检查网络
  182. System.Timers.Timer timer_CheckNet = new System.Timers.Timer();
  183. timer_CheckNet.Enabled = true;
  184. timer_CheckNet.Interval = 30000;
  185. timer_CheckNet.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_CheckNet_Tick);
  186. timer_CheckNet.Start();
  187. while (true)
  188. {
  189. Thread.Sleep(1);
  190. }
  191. }
  192. /// <summary>
  193. /// 线程中定时任务,检查网络状态
  194. /// </summary>
  195. /// <param name="sender"></param>
  196. /// <param name="e"></param>
  197. private void timer_CheckNet_Tick(object sender, EventArgs e)
  198. {
  199. //连接FTP服务器
  200. bool Result = myFtp.CheckFtp();
  201. this.Invoke((EventHandler)(delegate
  202. {
  203. if (Result == true)//服务器连接成功
  204. {
  205. myFtp.IsNetConnected = true;
  206. myCapture.label_ServerStatus.BackColor = Color.Green;
  207. }
  208. else//服务器连接失败
  209. {
  210. myFtp.IsNetConnected = false;
  211. myCapture.label_ServerStatus.BackColor = Color.Red;
  212. }
  213. }));
  214. }
  215. #region 打开或关闭串口
  216. private void button_ComOpen_Click(object sender, EventArgs e)
  217. {
  218. byte[] Data = new byte[1];
  219. try
  220. {
  221. if (!serialPort1.IsOpen)
  222. {
  223. serialPort1.PortName = comboBox_ComIndex.Text;
  224. serialPort1.BaudRate = int.Parse(comboBox_Baudrate.Text);
  225. serialPort1.Parity = (Parity)Enum.Parse(typeof(Parity), m_strCheckBits);
  226. serialPort1.DataBits = Int32.Parse(m_strDataBits);
  227. serialPort1.StopBits = (StopBits)Enum.Parse(typeof(StopBits), (m_strStopBits == "1.5") ? "3" : m_strStopBits);
  228. serialPort1.Open();
  229. comboBox_ComIndex.Enabled = false;
  230. comboBox_Baudrate.Enabled = false;
  231. button_ComOpen.Text = "断开(&C)";
  232. g_blnIsOpen = true;
  233. timer1.Enabled = true;
  234. button_RefreshPort.Enabled = false;
  235. //发送指令检测CDL是否在线
  236. SendCmd((ushort)0x7FF, (byte)0x11, (ushort)0x1100, null);
  237. CDL_OnlineCheck_Cnt = 0;
  238. CDL_Online_Flag = false;
  239. //开机
  240. Data[0] = 0xF1;
  241. SendCmd(0x7FF, 0x16, 0x2201, Data);
  242. }
  243. else
  244. {
  245. //关机
  246. Data[0] = 0xF0;
  247. SendCmd(0x7FF, 0x16, 0x2201, Data);
  248. while (Listening) Application.DoEvents();
  249. //打开时点击,则关闭串口
  250. serialPort1.Close();
  251. comboBox_ComIndex.Enabled = true;
  252. comboBox_Baudrate.Enabled = true;
  253. button_ComOpen.Text = "连接(&C)";
  254. g_blnIsOpen = false;
  255. timer1.Enabled = false;
  256. button_RefreshPort.Enabled = true;
  257. CDL_Online_Flag = true;
  258. }
  259. }
  260. catch (System.Exception ex)
  261. {
  262. MessageBox.Show(ex.Message);
  263. return;
  264. }
  265. }
  266. #endregion
  267. private void Form1_Load(object sender, EventArgs e)
  268. {
  269. string[] ports = SerialPort.GetPortNames();
  270. Array.Sort(ports);
  271. comboBox_ComIndex.Items.AddRange(ports);
  272. comboBox_ComIndex.SelectedIndex = comboBox_ComIndex.Items.Count > 0 ? 0 : -1;
  273. comboBox_Baudrate.SelectedIndex = comboBox_Baudrate.Items.IndexOf("115200");
  274. MC_Config_Clear();
  275. Motor_Config_Clear();
  276. MC_RunInfo_Clear();
  277. MC_ErrorCode_Clear();
  278. MC_Config_Ext_Clear();
  279. MC_AttitudeAngle_Clear();
  280. MC_RideInfo_Clear();
  281. MC_RunLog_Clear();
  282. label_BiuldTime.Text = System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString();
  283. }
  284. #region CRC校验
  285. static UInt32[] crc32_table = new UInt32[256]
  286. {
  287. 0x00000000, 0x04C11DB7, 0x09823B6E, 0x0D4326D9, 0x130476DC, 0x17C56B6B,
  288. 0x1A864DB2, 0x1E475005, 0x2608EDB8, 0x22C9F00F, 0x2F8AD6D6, 0x2B4BCB61,
  289. 0x350C9B64, 0x31CD86D3, 0x3C8EA00A, 0x384FBDBD, 0x4C11DB70, 0x48D0C6C7,
  290. 0x4593E01E, 0x4152FDA9, 0x5F15ADAC, 0x5BD4B01B, 0x569796C2, 0x52568B75,
  291. 0x6A1936C8, 0x6ED82B7F, 0x639B0DA6, 0x675A1011, 0x791D4014, 0x7DDC5DA3,
  292. 0x709F7B7A, 0x745E66CD, 0x9823B6E0, 0x9CE2AB57, 0x91A18D8E, 0x95609039,
  293. 0x8B27C03C, 0x8FE6DD8B, 0x82A5FB52, 0x8664E6E5, 0xBE2B5B58, 0xBAEA46EF,
  294. 0xB7A96036, 0xB3687D81, 0xAD2F2D84, 0xA9EE3033, 0xA4AD16EA, 0xA06C0B5D,
  295. 0xD4326D90, 0xD0F37027, 0xDDB056FE, 0xD9714B49, 0xC7361B4C, 0xC3F706FB,
  296. 0xCEB42022, 0xCA753D95, 0xF23A8028, 0xF6FB9D9F, 0xFBB8BB46, 0xFF79A6F1,
  297. 0xE13EF6F4, 0xE5FFEB43, 0xE8BCCD9A, 0xEC7DD02D, 0x34867077, 0x30476DC0,
  298. 0x3D044B19, 0x39C556AE, 0x278206AB, 0x23431B1C, 0x2E003DC5, 0x2AC12072,
  299. 0x128E9DCF, 0x164F8078, 0x1B0CA6A1, 0x1FCDBB16, 0x018AEB13, 0x054BF6A4,
  300. 0x0808D07D, 0x0CC9CDCA, 0x7897AB07, 0x7C56B6B0, 0x71159069, 0x75D48DDE,
  301. 0x6B93DDDB, 0x6F52C06C, 0x6211E6B5, 0x66D0FB02, 0x5E9F46BF, 0x5A5E5B08,
  302. 0x571D7DD1, 0x53DC6066, 0x4D9B3063, 0x495A2DD4, 0x44190B0D, 0x40D816BA,
  303. 0xACA5C697, 0xA864DB20, 0xA527FDF9, 0xA1E6E04E, 0xBFA1B04B, 0xBB60ADFC,
  304. 0xB6238B25, 0xB2E29692, 0x8AAD2B2F, 0x8E6C3698, 0x832F1041, 0x87EE0DF6,
  305. 0x99A95DF3, 0x9D684044, 0x902B669D, 0x94EA7B2A, 0xE0B41DE7, 0xE4750050,
  306. 0xE9362689, 0xEDF73B3E, 0xF3B06B3B, 0xF771768C, 0xFA325055, 0xFEF34DE2,
  307. 0xC6BCF05F, 0xC27DEDE8, 0xCF3ECB31, 0xCBFFD686, 0xD5B88683, 0xD1799B34,
  308. 0xDC3ABDED, 0xD8FBA05A, 0x690CE0EE, 0x6DCDFD59, 0x608EDB80, 0x644FC637,
  309. 0x7A089632, 0x7EC98B85, 0x738AAD5C, 0x774BB0EB, 0x4F040D56, 0x4BC510E1,
  310. 0x46863638, 0x42472B8F, 0x5C007B8A, 0x58C1663D, 0x558240E4, 0x51435D53,
  311. 0x251D3B9E, 0x21DC2629, 0x2C9F00F0, 0x285E1D47, 0x36194D42, 0x32D850F5,
  312. 0x3F9B762C, 0x3B5A6B9B, 0x0315D626, 0x07D4CB91, 0x0A97ED48, 0x0E56F0FF,
  313. 0x1011A0FA, 0x14D0BD4D, 0x19939B94, 0x1D528623, 0xF12F560E, 0xF5EE4BB9,
  314. 0xF8AD6D60, 0xFC6C70D7, 0xE22B20D2, 0xE6EA3D65, 0xEBA91BBC, 0xEF68060B,
  315. 0xD727BBB6, 0xD3E6A601, 0xDEA580D8, 0xDA649D6F, 0xC423CD6A, 0xC0E2D0DD,
  316. 0xCDA1F604, 0xC960EBB3, 0xBD3E8D7E, 0xB9FF90C9, 0xB4BCB610, 0xB07DABA7,
  317. 0xAE3AFBA2, 0xAAFBE615, 0xA7B8C0CC, 0xA379DD7B, 0x9B3660C6, 0x9FF77D71,
  318. 0x92B45BA8, 0x9675461F, 0x8832161A, 0x8CF30BAD, 0x81B02D74, 0x857130C3,
  319. 0x5D8A9099, 0x594B8D2E, 0x5408ABF7, 0x50C9B640, 0x4E8EE645, 0x4A4FFBF2,
  320. 0x470CDD2B, 0x43CDC09C, 0x7B827D21, 0x7F436096, 0x7200464F, 0x76C15BF8,
  321. 0x68860BFD, 0x6C47164A, 0x61043093, 0x65C52D24, 0x119B4BE9, 0x155A565E,
  322. 0x18197087, 0x1CD86D30, 0x029F3D35, 0x065E2082, 0x0B1D065B, 0x0FDC1BEC,
  323. 0x3793A651, 0x3352BBE6, 0x3E119D3F, 0x3AD08088, 0x2497D08D, 0x2056CD3A,
  324. 0x2D15EBE3, 0x29D4F654, 0xC5A92679, 0xC1683BCE, 0xCC2B1D17, 0xC8EA00A0,
  325. 0xD6AD50A5, 0xD26C4D12, 0xDF2F6BCB, 0xDBEE767C, 0xE3A1CBC1, 0xE760D676,
  326. 0xEA23F0AF, 0xEEE2ED18, 0xF0A5BD1D, 0xF464A0AA, 0xF9278673, 0xFDE69BC4,
  327. 0x89B8FD09, 0x8D79E0BE, 0x803AC667, 0x84FBDBD0, 0x9ABC8BD5, 0x9E7D9662,
  328. 0x933EB0BB, 0x97FFAD0C, 0xAFB010B1, 0xAB710D06, 0xA6322BDF, 0xA2F33668,
  329. 0xBCB4666D, 0xB8757BDA, 0xB5365D03, 0xB1F740B4
  330. };
  331. static UInt32 crc32_cal(byte[] pData, UInt16 Length)
  332. {
  333. UInt32 nReg;
  334. UInt32 nTemp = 0;
  335. UInt16 i, n;
  336. nReg = 0xFFFFFFFF;
  337. for (n = 0; n < Length; n++)
  338. {
  339. nReg ^= (UInt32)pData[n];
  340. for (i = 0; i < 4; i++)
  341. {
  342. nTemp = crc32_table[((nReg >> 24) & 0xFF)];
  343. nReg <<= 8;
  344. nReg ^= nTemp;
  345. }
  346. }
  347. return nReg;
  348. }
  349. #endregion
  350. #region 平均值计算
  351. private ushort GetAvg(byte[] pData, UInt16 Length)
  352. {
  353. UInt32 Sum = 0;
  354. for(ushort i=0; i<Length; i++)
  355. {
  356. Sum += pData[i];
  357. }
  358. return (ushort)(Sum/Length);
  359. }
  360. #endregion
  361. #region 标准差计算
  362. private ushort GetStDev(byte[] pData, UInt16 Length)
  363. {
  364. double Result = 0;
  365. //计算平均值
  366. UInt32 Avg = GetAvg(pData, Length);
  367. //计算各个数值与平均值的差值平方和
  368. UInt32 Sum = 0;
  369. for (ushort i = 0; i < Length; i++)
  370. {
  371. Sum += (pData[i] - Avg) * (pData[i] - Avg);
  372. }
  373. //计算标准差
  374. Result = Math.Sqrt((double)Sum / Length);
  375. return (ushort)(Result);
  376. }
  377. #endregion
  378. #region 发送指令函数
  379. private bool SendCmd(ushort ID, byte Mode, ushort Cmd, byte[] Data)
  380. {
  381. if (!serialPort1.IsOpen)
  382. {
  383. MessageBox.Show("串口未连接");
  384. return false;
  385. }
  386. ushort DataLength = (ushort)(Cmd & 0xFF);
  387. var SendCmdTmp = new byte[DataLength + 13];
  388. //帧头
  389. SendCmdTmp[0] = 0x55;
  390. SendCmdTmp[1] = 0xAA;
  391. //ID
  392. SendCmdTmp[2] = (byte)(ID >> 8);
  393. SendCmdTmp[3] = (byte)(ID & 0xFF);
  394. //MODE
  395. SendCmdTmp[4] = Mode;
  396. //长度
  397. SendCmdTmp[5] = (byte)((Cmd & 0xFF) + 2);
  398. //命令字
  399. SendCmdTmp[6] = (byte)(Cmd >> 8);
  400. SendCmdTmp[7] = (byte)(Cmd & 0xFF);
  401. //数据段
  402. for (UInt16 i = 0; i < (Cmd & 0xFF); i++)
  403. {
  404. SendCmdTmp[8 + i] = Data[i];
  405. }
  406. //校验
  407. UInt32 CRC_Result = crc32_cal(SendCmdTmp, (ushort)(DataLength + 8));
  408. SendCmdTmp[DataLength + 8] = Convert.ToByte(CRC_Result >> 24);
  409. SendCmdTmp[DataLength + 9] = Convert.ToByte((CRC_Result >> 16) % 256);
  410. SendCmdTmp[DataLength + 10] = Convert.ToByte((CRC_Result >> 8) % 256);
  411. SendCmdTmp[DataLength + 11] = Convert.ToByte(CRC_Result % 256);
  412. //帧尾
  413. SendCmdTmp[DataLength + 12] = 0xF0;
  414. //发送数据
  415. serialPort1.Write(SendCmdTmp, 0, SendCmdTmp.Length);
  416. return true;
  417. }
  418. #endregion
  419. #region 力矩传感器查询和写入相关
  420. //发送力矩传感器校正系数
  421. private void button_WriteK_Click(object sender, EventArgs e)
  422. {
  423. if (radioButton_SingleSensor.Checked)
  424. {
  425. var K = new byte[1];
  426. ushort DataTemp;
  427. DataTemp = (ushort)(decimal.Parse(textBox_Sensor1_K.Text) * 100);
  428. K[0] = Convert.ToByte(DataTemp);
  429. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2A01, K);
  430. }
  431. else if (radioButton_ThreeSensor.Checked)
  432. {
  433. var K = new byte[2];
  434. ushort DataTemp;
  435. if ((checkBox_Sensor1.Checked == false) && (checkBox_Sensor2.Checked == false) && (checkBox_Sensor3.Checked == false))
  436. {
  437. timer1.Enabled = false;
  438. MessageBox.Show("请选择传感器", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  439. timer1.Enabled = true;
  440. return;
  441. }
  442. else
  443. {
  444. if (MessageBox.Show("确认写入", "确认写入?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  445. {
  446. if (checkBox_Sensor1.Checked == true)
  447. {
  448. if (textBox_Sensor1_K.Text != string.Empty)
  449. {
  450. K[0] = 1;
  451. DataTemp = (ushort)(decimal.Parse(textBox_Sensor1_K.Text) * 100);
  452. K[1] = Convert.ToByte(DataTemp);
  453. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3402, K);
  454. Thread.Sleep(20);
  455. }
  456. }
  457. if (checkBox_Sensor2.Checked == true)
  458. {
  459. if (textBox_Sensor2_K.Text != string.Empty)
  460. {
  461. K[0] = 2;
  462. DataTemp = (ushort)(decimal.Parse(textBox_Sensor2_K.Text) * 100);
  463. K[1] = Convert.ToByte(DataTemp);
  464. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3402, K);
  465. Thread.Sleep(20);
  466. }
  467. }
  468. if (checkBox_Sensor3.Checked == true)
  469. {
  470. if (textBox_Sensor3_K.Text != string.Empty)
  471. {
  472. K[0] = 3;
  473. DataTemp = (ushort)(decimal.Parse(textBox_Sensor3_K.Text) * 100);
  474. K[1] = Convert.ToByte(DataTemp);
  475. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3402, K);
  476. Thread.Sleep(20);
  477. }
  478. }
  479. }
  480. }
  481. }
  482. }
  483. //查询传感器零点
  484. private void button_ReadZero_Click(object sender, EventArgs e)
  485. {
  486. if (radioButton_SingleSensor.Checked)
  487. {
  488. textBox_Sensor1_Zero.Text = "---";
  489. textBox_Sensor1_K.Text = "---";
  490. textBox_Torque_Start.Text = "---";
  491. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2000, null); //单力矩零点值
  492. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2900, null); //单力矩校正系数和启动值
  493. }
  494. else if (radioButton_ThreeSensor.Checked)
  495. {
  496. var K = new byte[1];
  497. textBox_Sensor1_Zero.Text = "---";
  498. textBox_Sensor2_Zero.Text = "---";
  499. textBox_Sensor3_Zero.Text = "---";
  500. textBox_Sensor1_K.Text = "---";
  501. textBox_Sensor2_K.Text = "---";
  502. textBox_Sensor3_K.Text = "---";
  503. //轮询零点
  504. for (ushort i = 1; i <= 3; i++)
  505. {
  506. K[0] = (byte)i;
  507. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3201, K);
  508. }
  509. //轮询校正系数
  510. for (ushort i = 1; i <= 3; i++)
  511. {
  512. K[0] = (byte)i;
  513. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3301, K);
  514. }
  515. }
  516. }
  517. //计算校正系数
  518. private void label119_DoubleClick(object sender, EventArgs e)
  519. {
  520. float K;
  521. string DataTemp;
  522. if (radioButton_SingleSensor.Checked)
  523. {
  524. if (checkBox_Sensor1.Checked == false)
  525. {
  526. timer1.Enabled = false;
  527. MessageBox.Show("请选择传感器", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  528. timer1.Enabled = true;
  529. return;
  530. }
  531. else
  532. {
  533. if ((textBox_Sensor1_Avg.Text != "---") && (textBox_Sensor1_Avg.Text != string.Empty))
  534. {
  535. DataTemp = textBox_Sensor1_Avg.Text;
  536. DataTemp = System.Text.RegularExpressions.Regex.Replace(DataTemp, @"[^0-9]+", "");
  537. K = float.Parse(DataTemp) / 75f;
  538. textBox_Sensor1_K.Text = K.ToString("#0.00");
  539. }
  540. else
  541. {
  542. textBox_Sensor1_K.Text = "";
  543. }
  544. }
  545. }
  546. else if (radioButton_ThreeSensor.Checked)
  547. {
  548. if ((checkBox_Sensor1.Checked == false) && (checkBox_Sensor2.Checked == false) && (checkBox_Sensor3.Checked == false))
  549. {
  550. timer1.Enabled = false;
  551. MessageBox.Show("请选择传感器", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  552. timer1.Enabled = true;
  553. return;
  554. }
  555. else
  556. {
  557. if (checkBox_Sensor1.Checked == true)
  558. {
  559. if ((textBox_Sensor1_Avg.Text != "---") && (textBox_Sensor1_Avg.Text != string.Empty))
  560. {
  561. DataTemp = textBox_Sensor1_Avg.Text;
  562. DataTemp = System.Text.RegularExpressions.Regex.Replace(DataTemp, @"[^0-9]+", "");
  563. K = float.Parse(DataTemp) / 75f;
  564. textBox_Sensor1_K.Text = K.ToString("#0.00");
  565. }
  566. else
  567. {
  568. textBox_Sensor1_K.Text = "";
  569. }
  570. }
  571. if (checkBox_Sensor2.Checked == true)
  572. {
  573. if ((textBox_Sensor2_Avg.Text != "---") && (textBox_Sensor2_Avg.Text != string.Empty))
  574. {
  575. DataTemp = textBox_Sensor2_Avg.Text;
  576. DataTemp = System.Text.RegularExpressions.Regex.Replace(DataTemp, @"[^0-9]+", "");
  577. K = float.Parse(DataTemp) / 75f;
  578. textBox_Sensor2_K.Text = K.ToString("#0.00");
  579. }
  580. else
  581. {
  582. textBox_Sensor2_K.Text = "";
  583. }
  584. }
  585. if (checkBox_Sensor3.Checked == true)
  586. {
  587. if ((textBox_Sensor3_Avg.Text != "---") && (textBox_Sensor3_Avg.Text != string.Empty))
  588. {
  589. DataTemp = textBox_Sensor3_Avg.Text;
  590. DataTemp = System.Text.RegularExpressions.Regex.Replace(DataTemp, @"[^0-9]+", "");
  591. K = float.Parse(DataTemp) / 75f;
  592. textBox_Sensor3_K.Text = K.ToString("#0.00");
  593. }
  594. else
  595. {
  596. textBox_Sensor3_K.Text = "";
  597. }
  598. }
  599. }
  600. }
  601. }
  602. //发送力矩传感器启动值
  603. private void button_Write_Torque_Start_Click(object sender, EventArgs e)
  604. {
  605. ushort StarData = Convert.ToUInt16(textBox_Torque_Start.Text);
  606. var StarData_Array = new byte[2];
  607. StarData_Array[0] = (byte)(StarData & 0xFF);
  608. StarData_Array[1] = (byte)(StarData >> 8);
  609. if (MessageBox.Show("确认写入", "确认写入?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  610. {
  611. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2B02, StarData_Array);
  612. }
  613. }
  614. //查询力矩传感器启动值
  615. private void button_ReadStartData_Click(object sender, EventArgs e)
  616. {
  617. if (radioButton_SingleSensor.Checked)
  618. {
  619. textBox_Sensor1_Zero.Text = "---";
  620. textBox_Sensor1_K.Text = "---";
  621. textBox_Torque_Start.Text = "---";
  622. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2900, null);
  623. }
  624. else if (radioButton_ThreeSensor.Checked)
  625. {
  626. textBox_Torque_Start.Text = "---";
  627. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3500, null);
  628. }
  629. }
  630. //根据采集值计算启动值
  631. private void label9_DoubleClick(object sender, EventArgs e)
  632. {
  633. ushort StartData;
  634. string DataTemp;
  635. if ((textBox_TorqueData.Text == "---") || (textBox_TorqueData.Text == string.Empty))
  636. {
  637. return;
  638. }
  639. DataTemp = textBox_TorqueData.Text;
  640. DataTemp = System.Text.RegularExpressions.Regex.Replace(DataTemp, @"[^0-9]+", "");
  641. StartData = (ushort)(Convert.ToUInt16(DataTemp) * 28);
  642. textBox_Torque_Start.Text = StartData.ToString();
  643. }
  644. #endregion
  645. #region 工作模式设置
  646. //进入运行模式
  647. private void radioButton_WorkMode_Run_Click(object sender, EventArgs e)
  648. {
  649. var RunMode = new byte[1];
  650. RunMode[0] = 0x00;
  651. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  652. checkBox_ReadTorqueData.Checked = false;
  653. }
  654. //进入配置模式
  655. private void radioButton_WorkMode_Confg_Click(object sender, EventArgs e)
  656. {
  657. var RunMode = new byte[1];
  658. RunMode[0] = 0x01;
  659. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  660. checkBox_AutoSend.Checked = false;
  661. }
  662. #endregion
  663. #region 助力档位设置
  664. //设置OFF档位
  665. private void radioButton_Gear_OFF_Click(object sender, EventArgs e)
  666. {
  667. var CtrlCode = new byte[2];
  668. CtrlCode[0] = 0x00;
  669. if (radioButton_Light_OFF.Checked == true)
  670. {
  671. CtrlCode[1] = 0xF0;
  672. }
  673. else if (radioButton_Light_ON.Checked == true)
  674. {
  675. CtrlCode[1] = 0xF1;
  676. }
  677. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  678. }
  679. //设置ECO档位
  680. private void radioButton_Gear_ECO_Click(object sender, EventArgs e)
  681. {
  682. var CtrlCode = new byte[2];
  683. CtrlCode[0] = 0x01;
  684. if (radioButton_Light_OFF.Checked == true)
  685. {
  686. CtrlCode[1] = 0xF0;
  687. }
  688. else if (radioButton_Light_ON.Checked == true)
  689. {
  690. CtrlCode[1] = 0xF1;
  691. }
  692. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  693. }
  694. //设置NORM档位
  695. private void radioButton_Gear_NORM_Click(object sender, EventArgs e)
  696. {
  697. var CtrlCode = new byte[2];
  698. CtrlCode[0] = 0x02;
  699. if (radioButton_Light_OFF.Checked == true)
  700. {
  701. CtrlCode[1] = 0xF0;
  702. }
  703. else if (radioButton_Light_ON.Checked == true)
  704. {
  705. CtrlCode[1] = 0xF1;
  706. }
  707. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  708. }
  709. //设置SPORT档位
  710. private void radioButton_Gear_SPORT_Click(object sender, EventArgs e)
  711. {
  712. var CtrlCode = new byte[2];
  713. CtrlCode[0] = 0x03;
  714. if (radioButton_Light_OFF.Checked == true)
  715. {
  716. CtrlCode[1] = 0xF0;
  717. }
  718. else if (radioButton_Light_ON.Checked == true)
  719. {
  720. CtrlCode[1] = 0xF1;
  721. }
  722. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  723. }
  724. //设置TURBO档位
  725. private void radioButton_Gear_TURBO_Click(object sender, EventArgs e)
  726. {
  727. var CtrlCode = new byte[2];
  728. CtrlCode[0] = 0x04;
  729. if (radioButton_Light_OFF.Checked == true)
  730. {
  731. CtrlCode[1] = 0xF0;
  732. }
  733. else if (radioButton_Light_ON.Checked == true)
  734. {
  735. CtrlCode[1] = 0xF1;
  736. }
  737. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  738. }
  739. //设置SMART档位
  740. private void radioButton_Gear_SMART_Click(object sender, EventArgs e)
  741. {
  742. var CtrlCode = new byte[2];
  743. CtrlCode[0] = 0x33;
  744. if (radioButton_Light_OFF.Checked == true)
  745. {
  746. CtrlCode[1] = 0xF0;
  747. }
  748. else if (radioButton_Light_ON.Checked == true)
  749. {
  750. CtrlCode[1] = 0xF1;
  751. }
  752. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  753. }
  754. //设置WALK档位
  755. private void radioButton_Gear_WALK_Click(object sender, EventArgs e)
  756. {
  757. var CtrlCode = new byte[2];
  758. CtrlCode[0] = 0x22;
  759. if (radioButton_Light_OFF.Checked == true)
  760. {
  761. CtrlCode[1] = 0xF0;
  762. }
  763. else if (radioButton_Light_ON.Checked == true)
  764. {
  765. CtrlCode[1] = 0xF1;
  766. }
  767. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  768. }
  769. #endregion
  770. #region 大灯开关
  771. //大灯关
  772. private void radioButton_Light_OFF_Click(object sender, EventArgs e)
  773. {
  774. var CtrlCode = new byte[2];
  775. if (radioButton_Gear_OFF.Checked == true)
  776. {
  777. CtrlCode[0] = 0x00;
  778. }
  779. else if (radioButton_Gear_ECO.Checked == true)
  780. {
  781. CtrlCode[0] = 0x01;
  782. }
  783. else if (radioButton_Gear_NORM.Checked == true)
  784. {
  785. CtrlCode[0] = 0x02;
  786. }
  787. else if (radioButton_Gear_SPORT.Checked == true)
  788. {
  789. CtrlCode[0] = 0x03;
  790. }
  791. else if (radioButton_Gear_TURBO.Checked == true)
  792. {
  793. CtrlCode[0] = 0x04;
  794. }
  795. else if (radioButton_Gear_SMART.Checked == true)
  796. {
  797. CtrlCode[0] = 0x33;
  798. }
  799. else if (radioButton_Gear_WALK.Checked == true)
  800. {
  801. CtrlCode[0] = 0x22;
  802. }
  803. CtrlCode[1] = 0xF0;
  804. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  805. }
  806. //大灯开
  807. private void radioButton_Light_ON_Click(object sender, EventArgs e)
  808. {
  809. var CtrlCode = new byte[2];
  810. if (radioButton_Gear_OFF.Checked == true)
  811. {
  812. CtrlCode[0] = 0x00;
  813. }
  814. else if (radioButton_Gear_ECO.Checked == true)
  815. {
  816. CtrlCode[0] = 0x01;
  817. }
  818. else if (radioButton_Gear_NORM.Checked == true)
  819. {
  820. CtrlCode[0] = 0x02;
  821. }
  822. else if (radioButton_Gear_SPORT.Checked == true)
  823. {
  824. CtrlCode[0] = 0x03;
  825. }
  826. else if (radioButton_Gear_TURBO.Checked == true)
  827. {
  828. CtrlCode[0] = 0x04;
  829. }
  830. else if (radioButton_Gear_SMART.Checked == true)
  831. {
  832. CtrlCode[0] = 0x33;
  833. }
  834. else if (radioButton_Gear_WALK.Checked == true)
  835. {
  836. CtrlCode[0] = 0x22;
  837. }
  838. CtrlCode[1] = 0xF1;
  839. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
  840. }
  841. #endregion
  842. //数据清除指令
  843. private void button_ClearData_Click(object sender, EventArgs e)
  844. {
  845. var Code = new byte[5];
  846. Code[0] = (byte)'C';
  847. Code[1] = (byte)'L';
  848. Code[2] = (byte)'E';
  849. Code[3] = (byte)'A';
  850. Code[4] = (byte)'R';
  851. timer1.Enabled = false;
  852. if (MessageBox.Show("系统清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  853. {
  854. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  855. {
  856. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  857. {
  858. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
  859. }
  860. }
  861. }
  862. timer1.Enabled = true;
  863. }
  864. //查询版本信息
  865. private void button_Read_VerInfo_Click(object sender, EventArgs e)
  866. {
  867. textBox_Mode.Text = "---";
  868. textBox_SN.Text = "---";
  869. textBox_HW.Text = "---";
  870. textBox_FW.Text = "---";
  871. textBox_Firmware_Special.Text = "---";
  872. textBox_BuildTime.Text = "---";
  873. Class_Motor_Ver.Mode = "---";
  874. Class_Motor_Ver.SN = "---";
  875. Class_Motor_Ver.HW = "---";
  876. Class_Motor_Ver.FW = "---";
  877. Class_Motor_Ver.Special = "---";
  878. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  879. textBox_TE_FW.Text = "---";
  880. SendCmd((ushort)0x651, (byte)0x11, (ushort)0x1200, null);
  881. }
  882. //串口数据接收
  883. private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
  884. {
  885. try
  886. {
  887. Listening = true;
  888. int n = serialPort1.BytesToRead;
  889. byte[] buf = new byte[n];//将一次串口事件中接收到的数据暂存于buf中(注:对于超过8个字节的数据,C#的
  890. //串口接收事件将按每次处理8个字节的方式多次处理
  891. serialPort1.Read(buf, 0, n);//将接收到的数据读入buf
  892. this.Invoke((EventHandler)delegate
  893. {
  894. });
  895. buffer.AddRange(buf);//将读取的数据放入buffer中
  896. }
  897. catch (Exception ex)
  898. {
  899. MessageBox.Show(ex.Message);
  900. return;
  901. }
  902. finally
  903. {
  904. Listening = false;
  905. }
  906. }
  907. //time1定时任务
  908. private void timer1_Tick(object sender, EventArgs e)
  909. {
  910. //MC_RunInfo超时清除
  911. if (MC_RunInfo_Refresh == false)
  912. {
  913. MC_RunInfo_Refresh_Cnt++;
  914. if (MC_RunInfo_Refresh_Cnt > 50)
  915. {
  916. //运行信息清除
  917. MC_RunInfo_Clear();
  918. //传感器数值清除
  919. textBox_TorqueData.Text = "---";
  920. textBox_Torque_Stdev.Text = "---";
  921. textBox_Sensor1_Avg.Text = "---";
  922. textBox_Sensor1_Std.Text = "---";
  923. textBox_Sensor2_Avg.Text = "---";
  924. textBox_Sensor2_Std.Text = "---";
  925. textBox_Sensor3_Avg.Text = "---";
  926. textBox_Sensor3_Std.Text = "---";
  927. MC_RunInfo_Refresh_Cnt = 0;
  928. TorqueArray_Index = 0;
  929. }
  930. }
  931. else
  932. {
  933. MC_RunInfo_Refresh_Cnt = 0;
  934. }
  935. MC_RunInfo_Refresh = false;
  936. //MC故障信息超时清除
  937. if (MC_ErrorCode_Refresh == false)
  938. {
  939. MC_ErrorCode_Refresh_Cnt++;
  940. if (MC_ErrorCode_Refresh_Cnt > 50)
  941. {
  942. MC_ErrorCode_Clear();
  943. MC_ErrorCode_Refresh_Cnt = 0;
  944. }
  945. }
  946. else
  947. {
  948. MC_ErrorCode_Refresh_Cnt = 0;
  949. }
  950. MC_ErrorCode_Refresh = false;
  951. //MC骑行信息超时清除
  952. if (MC_RideInfo_Refresh == false)
  953. {
  954. MC_RideInfo_Refresh_Cnt++;
  955. if (MC_RideInfo_Refresh_Cnt > 50)
  956. {
  957. MC_RideInfo_Clear();
  958. MC_RideInfo_Refresh_Cnt = 0;
  959. }
  960. }
  961. else
  962. {
  963. MC_RideInfo_Refresh_Cnt = 0;
  964. }
  965. MC_RideInfo_Refresh = false;
  966. //MC姿态信息超时清除
  967. if (MC_AttitudeAngle_Refresh == false)
  968. {
  969. MC_AttitudeAngle_Refresh_Cnt++;
  970. if (MC_AttitudeAngle_Refresh_Cnt > 50)
  971. {
  972. MC_AttitudeAngle_Clear();
  973. MC_AttitudeAngle_Refresh_Cnt = 0;
  974. }
  975. }
  976. else
  977. {
  978. MC_AttitudeAngle_Refresh_Cnt = 0;
  979. }
  980. MC_AttitudeAngle_Refresh = false;
  981. //定时发送助力档位
  982. if (checkBox_AutoSend.Checked == true)
  983. {
  984. var CtrlCode = new byte[2];
  985. AutoSendTimeCnt++;
  986. if (AutoSendTimeCnt >= 10)
  987. {
  988. AutoSendTimeCnt = 0;
  989. //助力档位
  990. if (radioButton_Gear_OFF.Checked == true)
  991. {
  992. CtrlCode[0] = 0x00;
  993. }
  994. else if (radioButton_Gear_ECO.Checked == true)
  995. {
  996. CtrlCode[0] = 0x01;
  997. }
  998. else if (radioButton_Gear_NORM.Checked == true)
  999. {
  1000. CtrlCode[0] = 0x02;
  1001. }
  1002. else if (radioButton_Gear_SPORT.Checked == true)
  1003. {
  1004. CtrlCode[0] = 0x03;
  1005. }
  1006. else if (radioButton_Gear_TURBO.Checked == true)
  1007. {
  1008. CtrlCode[0] = 0x04;
  1009. }
  1010. else if (radioButton_Gear_SMART.Checked == true)
  1011. {
  1012. CtrlCode[0] = 0x33;
  1013. }
  1014. else if (radioButton_Gear_WALK.Checked == true)
  1015. {
  1016. CtrlCode[0] = 0x22;
  1017. }
  1018. //大灯状态
  1019. if (radioButton_Light_OFF.Checked == true)
  1020. {
  1021. CtrlCode[1] = 0xF0;
  1022. }
  1023. else if (radioButton_Light_ON.Checked == true)
  1024. {
  1025. CtrlCode[1] = 0xF1;
  1026. }
  1027. if (serialPort1.IsOpen)
  1028. {
  1029. if (!SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode))
  1030. checkBox_AutoSend.Checked = false;
  1031. }
  1032. }
  1033. }
  1034. else
  1035. {
  1036. AutoSendTimeCnt = 0;
  1037. }
  1038. //定时查询姿态信息
  1039. if (checkBox_ReadAttitudeAngleAutoSend.Checked == true)
  1040. {
  1041. AutoSendReadAttitudeAngleTimeCnt++;
  1042. if (AutoSendReadAttitudeAngleTimeCnt >= 20)
  1043. {
  1044. AutoSendReadAttitudeAngleTimeCnt = 0;
  1045. if (serialPort1.IsOpen)
  1046. {
  1047. if (!SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2F00, null))
  1048. checkBox_ReadAttitudeAngleAutoSend.Checked = false;
  1049. }
  1050. }
  1051. }
  1052. else
  1053. {
  1054. AutoSendReadAttitudeAngleTimeCnt = 0;
  1055. }
  1056. //定时查询骑行信息
  1057. if ( checkBox_ReadRideInfo.Checked == true)
  1058. {
  1059. AutoSendReadRideInfoTimeCnt++;
  1060. if (AutoSendReadRideInfoTimeCnt >= 20)
  1061. {
  1062. AutoSendReadRideInfoTimeCnt = 0;
  1063. if (serialPort1.IsOpen)
  1064. {
  1065. if (!SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2E00, null))
  1066. checkBox_ReadRideInfo.Checked = false;
  1067. }
  1068. }
  1069. }
  1070. else
  1071. {
  1072. AutoSendReadRideInfoTimeCnt = 0;
  1073. }
  1074. //CDL在线检测超时判断
  1075. if (CDL_Online_Flag == false)
  1076. {
  1077. CDL_OnlineCheck_Cnt++;
  1078. if (CDL_OnlineCheck_Cnt > 10)
  1079. {
  1080. timer1.Enabled = false;
  1081. MessageBox.Show("连接失败!", "提示");
  1082. timer1.Enabled = true;
  1083. //关闭串口
  1084. serialPort1.Close();
  1085. comboBox_ComIndex.Enabled = true;
  1086. comboBox_Baudrate.Enabled = true;
  1087. button_ComOpen.Text = "连接(&C)";
  1088. g_blnIsOpen = false;
  1089. timer1.Enabled = false;
  1090. button_RefreshPort.Enabled = true;
  1091. }
  1092. }
  1093. //...
  1094. //串口解析
  1095. byte DataNum = 0; //记录每条命令数据段的长度
  1096. while (buffer.Count >= 13)//当buffer中的数据的个数大于等于4个时,即每一帧的数据长度所在位(第4位)出现时
  1097. {
  1098. if (buffer[0] == 0x55 && buffer[1] == 0xAA)//判断帧头
  1099. {
  1100. ushort PackageID;
  1101. PackageID = (ushort)(buffer[2] * 256 + buffer[3]);
  1102. if ((PackageID == 0x0710) || (PackageID == 0x0715) || (PackageID == 0x0610) || (PackageID == 0x0615) || (PackageID == 0x07FF))
  1103. {
  1104. int CmdLen = buffer[5];
  1105. if (buffer.Count < CmdLen + 11) break;//如果接收到的数据没有达到一帧数据的指定长度, 则执行下次循环
  1106. buffer.RemoveRange(0, 6);//数据达到要求长度后删去帧头,ID,模式,和命令长度
  1107. while (CmdLen > 0) //读取命令段
  1108. {
  1109. DataNum = (byte)(buffer[1]);//命令字的第二个字节的表示数据位的长度
  1110. if (DataNum <= (CmdLen - 2))
  1111. {
  1112. for (int i = 0; i < DataNum + 2; i++)
  1113. {
  1114. binary_data_1[i] = buffer[i];
  1115. }
  1116. DataCmdProcess(PackageID);//对于不同的命令段,做不同的处理
  1117. buffer.RemoveRange(0, DataNum + 2);//移除处理过的命令段与数据段
  1118. CmdLen -= (DataNum + 2);
  1119. if (CmdLen < 2)
  1120. {
  1121. buffer.RemoveRange(0, CmdLen + 2);
  1122. return;
  1123. }
  1124. }
  1125. else
  1126. {
  1127. buffer.RemoveRange(0, CmdLen + 11);
  1128. }
  1129. }
  1130. }
  1131. else
  1132. {
  1133. buffer.RemoveAt(0);//ID不对
  1134. }
  1135. }
  1136. else
  1137. {
  1138. buffer.RemoveAt(0);//帧头不对,删除帧头高字节
  1139. }
  1140. }
  1141. }
  1142. //故障转换和显示
  1143. List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
  1144. "马达缺相","NTC故障","","","","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","电路故障","TE故障","TE电路故障","","","","","","","","","",
  1145. "",""};
  1146. private string ErrorInfoDisplay(UInt32 Code)
  1147. {
  1148. string Result = "";
  1149. if (Code == 0)
  1150. {
  1151. Result = "无故障";
  1152. }
  1153. else
  1154. {
  1155. for (int i = 0; i < 32; i++)
  1156. {
  1157. if ((Code & 0x01) == 0x01)
  1158. {
  1159. Result += ErrorInfo[i] + " ";
  1160. }
  1161. Code >>= 1;
  1162. }
  1163. }
  1164. return Result;
  1165. }
  1166. #region 命令段处理函数
  1167. private void DataCmdProcess(ushort ID)
  1168. {
  1169. ushort CmdTemp = (ushort)(binary_data_1[0] * 256 + binary_data_1[1]);
  1170. ushort DataTemp;
  1171. short DataTemp_int16;
  1172. textBox_RevCnt.Text = Convert.ToString(Convert.ToInt32(textBox_RevCnt.Text) + 1);
  1173. #region 解析发送给CDL的指令
  1174. if (ID == 0x7FF)
  1175. {
  1176. switch (CmdTemp)
  1177. {
  1178. case 0x1100://TE APP版本信息
  1179. {
  1180. unchecked
  1181. {
  1182. this.Invoke((EventHandler)(delegate
  1183. {
  1184. //CDL连接成功
  1185. CDL_Online_Flag = true;
  1186. timer1.Enabled = false;
  1187. MessageBox.Show("连接成功!", "提示");
  1188. timer1.Enabled = true;
  1189. //显示其它界面
  1190. foreach (Control c in this.Controls)
  1191. {
  1192. if (c is GroupBox)
  1193. {
  1194. if (c != groupBox1)
  1195. {
  1196. c.Visible = true;
  1197. }
  1198. }
  1199. if (c is TabControl)
  1200. c.Visible = true;
  1201. }
  1202. button_ReadAll.Visible = true;
  1203. label1_Welcom.Visible = false;
  1204. }));
  1205. }
  1206. break;
  1207. }
  1208. default: break;
  1209. }
  1210. }
  1211. #endregion
  1212. #region 解析主控的命令
  1213. else if ((ID == 0x715) || (ID == 0x710))
  1214. {
  1215. switch (CmdTemp)
  1216. {
  1217. case 0xA318://力矩传感器零点值,单力矩
  1218. {
  1219. unchecked
  1220. {
  1221. this.Invoke((EventHandler)(delegate
  1222. {
  1223. DataTemp = (ushort)(binary_data_1[25] * 256 + binary_data_1[24]);
  1224. textBox_Sensor1_Zero.Text = Convert.ToString(DataTemp);
  1225. }));
  1226. }
  1227. break;
  1228. }
  1229. case 0xAE1A://力矩传感器零点值,针对3力矩传感器使用
  1230. {
  1231. unchecked
  1232. {
  1233. this.Invoke((EventHandler)(delegate
  1234. {
  1235. if (binary_data_1[2] == 1)
  1236. {
  1237. DataTemp = (ushort)(binary_data_1[26] * 256 + binary_data_1[25]);
  1238. textBox_Sensor1_Zero.Text = Convert.ToString(DataTemp);
  1239. }
  1240. else if (binary_data_1[2] == 2)
  1241. {
  1242. DataTemp = (ushort)(binary_data_1[26] * 256 + binary_data_1[25]);
  1243. textBox_Sensor2_Zero.Text = Convert.ToString(DataTemp);
  1244. }
  1245. else if (binary_data_1[2] == 3)
  1246. {
  1247. DataTemp = (ushort)(binary_data_1[26] * 256 + binary_data_1[25]);
  1248. textBox_Sensor3_Zero.Text = Convert.ToString(DataTemp);
  1249. }
  1250. }));
  1251. }
  1252. break;
  1253. }
  1254. case 0xAA04://力矩传感器值校正参数和启动值,单力矩
  1255. {
  1256. unchecked
  1257. {
  1258. this.Invoke((EventHandler)(delegate
  1259. {
  1260. //启动值
  1261. DataTemp = (ushort)(binary_data_1[3] * 256 + binary_data_1[2]);
  1262. textBox_Torque_Start.Text = Convert.ToString(DataTemp);
  1263. //标定系数
  1264. DataTemp = (ushort)(binary_data_1[4]);
  1265. float K = (float)DataTemp / 100f;
  1266. textBox_Sensor1_K.Text = K.ToString("#0.00");
  1267. }));
  1268. }
  1269. break;
  1270. }
  1271. case 0xAF02://力矩传感器值校正参数,针对3力矩传感器使用
  1272. {
  1273. unchecked
  1274. {
  1275. this.Invoke((EventHandler)(delegate
  1276. {
  1277. if (binary_data_1[2] == 1)
  1278. {
  1279. DataTemp = (ushort)(binary_data_1[3]);
  1280. float K = (float)DataTemp / 100f;
  1281. textBox_Sensor1_K.Text = K.ToString("#0.00");
  1282. }
  1283. else if (binary_data_1[2] == 2)
  1284. {
  1285. DataTemp = (ushort)(binary_data_1[3]);
  1286. float K = (float)DataTemp / 100f;
  1287. textBox_Sensor2_K.Text = K.ToString("#0.00");
  1288. }
  1289. else if (binary_data_1[2] == 3)
  1290. {
  1291. DataTemp = (ushort)(binary_data_1[3]);
  1292. float K = (float)DataTemp / 100f;
  1293. textBox_Sensor3_K.Text = K.ToString("#0.00");
  1294. }
  1295. }));
  1296. }
  1297. break;
  1298. }
  1299. case 0xB002://力矩传感器值启动值
  1300. {
  1301. unchecked
  1302. {
  1303. this.Invoke((EventHandler)(delegate
  1304. {
  1305. DataTemp = (ushort)(binary_data_1[3] * 256 + binary_data_1[2]);
  1306. textBox_Torque_Start.Text = Convert.ToString(DataTemp);
  1307. }));
  1308. }
  1309. break;
  1310. }
  1311. case 0x1240://电机版本信息
  1312. {
  1313. unchecked
  1314. {
  1315. this.Invoke((EventHandler)(delegate
  1316. {
  1317. //电机型号
  1318. textBox_Mode.Text = "";
  1319. for (ushort i = 0; i < 16; i++)
  1320. {
  1321. if (binary_data_1[2 + i] == 0x2E)
  1322. {
  1323. break;
  1324. }
  1325. textBox_Mode.Text += ((char)binary_data_1[2 + i]).ToString();
  1326. }
  1327. Class_Motor_Ver.Mode = textBox_Mode.Text;
  1328. //电机SN
  1329. textBox_SN.Text = "";
  1330. for (ushort i = 0; i < 16; i++)
  1331. {
  1332. if (binary_data_1[18 + i] == 0x2E)
  1333. {
  1334. break;
  1335. }
  1336. textBox_SN.Text += ((char)binary_data_1[18 + i]).ToString();
  1337. }
  1338. Class_Motor_Ver.SN = textBox_SN.Text;
  1339. //电机HW
  1340. textBox_HW.Text = "";
  1341. for (ushort i = 0; i < 10; i++)//前10位是PCB版号,以'.'结束
  1342. {
  1343. if (binary_data_1[34 + i] == 0x2E)
  1344. {
  1345. break;
  1346. }
  1347. if (binary_data_1[34 + i] == 'r')
  1348. {
  1349. binary_data_1[34 + i] = (byte)'.';
  1350. }
  1351. textBox_HW.Text += ((char)binary_data_1[34 + i]).ToString();
  1352. }
  1353. switch (binary_data_1[34 + 10])//第10位代表MCU品牌
  1354. {
  1355. case (byte)'1':
  1356. textBox_HW.Text += " " + "ST" + " "; break;
  1357. case (byte)'2':
  1358. textBox_HW.Text += " " + "APM" + " "; break;
  1359. case (byte)'3':
  1360. textBox_HW.Text += " " + "HK" + " "; break;
  1361. case (byte)'4':
  1362. textBox_HW.Text += " " + "GD" + " "; break;
  1363. default:
  1364. textBox_HW.Text += " " + "NULL" + " "; break;
  1365. }
  1366. for (ushort i = 0; i < 4; i++)//后4位是MCU的ID校验码,用于识别板子的ID
  1367. {
  1368. textBox_HW.Text += Convert.ToString(binary_data_1[46 + i], 16).PadLeft(2, '0').ToUpper();//MCU ID 的CRC32值
  1369. }
  1370. Class_Motor_Ver.HW = textBox_HW.Text;
  1371. //电机FW
  1372. textBox_FW.Text = "";
  1373. for (ushort i = 0; i < 16; i++)
  1374. {
  1375. if (binary_data_1[50 + i] == 0x2E)
  1376. {
  1377. break;
  1378. }
  1379. if (binary_data_1[50 + i] == 'r')
  1380. {
  1381. binary_data_1[50 + i] = (byte)'.';
  1382. }
  1383. textBox_FW.Text += ((char)binary_data_1[50 + i]).ToString();
  1384. }
  1385. Class_Motor_Ver.FW = textBox_FW.Text;
  1386. }));
  1387. }
  1388. break;
  1389. }
  1390. case 0x1720://电机程序特性信息
  1391. {
  1392. unchecked
  1393. {
  1394. this.Invoke((EventHandler)(delegate
  1395. {
  1396. //程序特性
  1397. textBox_Firmware_Special.Text = "";
  1398. for (ushort i = 0; i < 32; i++)
  1399. {
  1400. if (binary_data_1[2 + i] == 0x2E)
  1401. {
  1402. break;
  1403. }
  1404. textBox_Firmware_Special.Text += ((char)binary_data_1[2 + i]).ToString();
  1405. }
  1406. //编译时间
  1407. textBox_BuildTime.Text = "";
  1408. do
  1409. {
  1410. ushort[] DateTime = new ushort[6];
  1411. DateTime[0] = (ushort)(binary_data_1[2 + 26] + 2000);
  1412. DateTime[1] = (ushort)(binary_data_1[2 + 27]);
  1413. DateTime[2] = (ushort)(binary_data_1[2 + 28]);
  1414. DateTime[3] = (ushort)(binary_data_1[2 + 29]);
  1415. DateTime[4] = (ushort)(binary_data_1[2 + 30]);
  1416. DateTime[5] = (ushort)(binary_data_1[2 + 31]);
  1417. //年
  1418. textBox_BuildTime.Text += Convert.ToString(DateTime[0]).PadLeft(4, '0');
  1419. //月
  1420. textBox_BuildTime.Text += Convert.ToString(DateTime[1]).PadLeft(2, '0');
  1421. //日
  1422. textBox_BuildTime.Text += Convert.ToString(DateTime[2]).PadLeft(2, '0');
  1423. textBox_BuildTime.Text += " ";
  1424. //时
  1425. textBox_BuildTime.Text += Convert.ToString(DateTime[3]).PadLeft(2, '0');
  1426. textBox_BuildTime.Text += ":";
  1427. //分
  1428. textBox_BuildTime.Text += Convert.ToString(DateTime[4]).PadLeft(2, '0');
  1429. textBox_BuildTime.Text += ":";
  1430. //秒
  1431. textBox_BuildTime.Text += Convert.ToString(DateTime[5]).PadLeft(2, '0');
  1432. } while (false);
  1433. }));
  1434. }
  1435. break;
  1436. }
  1437. case 0x1020://电机运行信息
  1438. {
  1439. unchecked
  1440. {
  1441. this.Invoke((EventHandler)(delegate
  1442. {
  1443. MC_RunInfo_Refresh = true;
  1444. //车速
  1445. DataTemp = (ushort)(binary_data_1[3] * 256 + binary_data_1[2]);
  1446. textBox_RunInfo_BikeSpeed.Text = ((float)DataTemp / 10f).ToString("0.0") + " km/h";
  1447. //输出转速
  1448. DataTemp = (ushort)(binary_data_1[5] * 256 + binary_data_1[4]);
  1449. textBox_RunInfo_OutSpeed.Text = Convert.ToString(DataTemp) + " rpm";
  1450. Class_MotorSpeed.String = textBox_RunInfo_OutSpeed.Text;
  1451. Class_MotorSpeed.Data = DataTemp;
  1452. //电功率
  1453. DataTemp = (ushort)(binary_data_1[7] * 256 + binary_data_1[6]);
  1454. textBox_RunInfo_Power.Text = Convert.ToString(DataTemp) + " W";
  1455. //母线电压
  1456. DataTemp = (ushort)(binary_data_1[9] * 256 + binary_data_1[8]);
  1457. textBox_RunInfo_Voltage.Text = Convert.ToString(DataTemp) + " mV";
  1458. //母线电流
  1459. DataTemp = (ushort)(binary_data_1[11] * 256 + binary_data_1[10]);
  1460. textBox_RunInfo_Current.Text = Convert.ToString(DataTemp) + " mA";
  1461. Class_CurrentData.String = textBox_RunInfo_Current.Text;
  1462. Class_CurrentData.Data = DataTemp;
  1463. //踏频
  1464. DataTemp = (ushort)(binary_data_1[12]);
  1465. textBox_RunInfo_Cadence.Text = Convert.ToString(DataTemp) + " rpm";
  1466. //踩踏力矩
  1467. DataTemp = (ushort)(binary_data_1[13]);
  1468. textBox_RunInfo_Torque.Text = Convert.ToString(DataTemp) + " N.m";
  1469. Class_TorqueData.String = textBox_RunInfo_Torque.Text;
  1470. Class_TorqueData.Data = DataTemp;
  1471. //踩踏方向
  1472. DataTemp = (ushort)(binary_data_1[14]);
  1473. if (DataTemp == 0)
  1474. {
  1475. textBox_RunInfo_Dir.Text = "正向";
  1476. }
  1477. else if (DataTemp == 1)
  1478. {
  1479. textBox_RunInfo_Dir.Text = "反向";
  1480. }
  1481. else if (DataTemp == 2)
  1482. {
  1483. textBox_RunInfo_Dir.Text = "停止";
  1484. }
  1485. //助力档位
  1486. DataTemp = (ushort)(binary_data_1[15]);
  1487. if (DataTemp == 0x00)
  1488. {
  1489. textBox_RunInfo_Gear.Text = "OFF";
  1490. radioButton_Gear_OFF.Checked = true;
  1491. }
  1492. else if (DataTemp == 0x01)
  1493. {
  1494. textBox_RunInfo_Gear.Text = "ECO";
  1495. radioButton_Gear_ECO.Checked = true;
  1496. }
  1497. else if (DataTemp == 0x02)
  1498. {
  1499. textBox_RunInfo_Gear.Text = "NORM";
  1500. radioButton_Gear_NORM.Checked = true;
  1501. }
  1502. else if (DataTemp == 0x03)
  1503. {
  1504. textBox_RunInfo_Gear.Text = "SPORT";
  1505. radioButton_Gear_SPORT.Checked = true;
  1506. }
  1507. else if (DataTemp == 0x04)
  1508. {
  1509. textBox_RunInfo_Gear.Text = "TURBO";
  1510. radioButton_Gear_TURBO.Checked = true;
  1511. }
  1512. else if (DataTemp == 0x33)
  1513. {
  1514. textBox_RunInfo_Gear.Text = "SMART";
  1515. radioButton_Gear_SMART.Checked = true;
  1516. }
  1517. else if (DataTemp == 0x22)
  1518. {
  1519. textBox_RunInfo_Gear.Text = "WALK";
  1520. radioButton_Gear_WALK.Checked = true;
  1521. }
  1522. //大灯状态
  1523. DataTemp = (ushort)(binary_data_1[16]);
  1524. if (DataTemp == 0xF0)
  1525. {
  1526. textBox_RunInfo_Light.Text = "OFF";
  1527. radioButton_Light_OFF.Checked = true;
  1528. }
  1529. else if (DataTemp == 0xF1)
  1530. {
  1531. textBox_RunInfo_Light.Text = "ON";
  1532. radioButton_Light_ON.Checked = true;
  1533. }
  1534. //剩余电量
  1535. DataTemp = (ushort)(binary_data_1[17]);
  1536. if (DataTemp == 0xFF)
  1537. {
  1538. textBox_RunInfo_SOC.Text = "---";
  1539. }
  1540. else
  1541. {
  1542. textBox_RunInfo_SOC.Text = Convert.ToString(DataTemp) + " %";
  1543. }
  1544. //剩余续航里程
  1545. DataTemp = (ushort)(binary_data_1[19] * 256 + binary_data_1[18]);
  1546. if ((DataTemp == 0xEEEE) || (DataTemp == 0xFFFF))
  1547. {
  1548. textBox_RunInfo_Range.Text = "---";
  1549. }
  1550. else
  1551. {
  1552. textBox_RunInfo_Range.Text = Convert.ToString(DataTemp) + " km";
  1553. }
  1554. //ODO里程
  1555. DataTemp = (ushort)(binary_data_1[21] * 256 + binary_data_1[20]);
  1556. textBox_RunInfo_ODO_Km.Text = Convert.ToString(DataTemp) + " km";
  1557. //平均功耗
  1558. DataTemp = (ushort)(binary_data_1[22]);
  1559. textBox_RunInfo_PowerAvg.Text = Convert.ToString(DataTemp * 10) + " mAh/km";
  1560. //PCB温度
  1561. DataTemp = (ushort)(binary_data_1[23]);
  1562. textBox_RunInfo_T_PCB.Text = Convert.ToString((int)(DataTemp - 40));
  1563. //绕组温度
  1564. DataTemp = (ushort)(binary_data_1[24]);
  1565. textBox_RunInfo_T_Roil.Text = Convert.ToString((int)(DataTemp - 40));
  1566. //MCU温度
  1567. DataTemp = (ushort)(binary_data_1[25]);
  1568. textBox_RunInfo_T_MCU.Text = Convert.ToString((int)(DataTemp - 40));
  1569. //单次里程
  1570. DataTemp = (ushort)(binary_data_1[27] * 256 + binary_data_1[26]);
  1571. textBox_RunInfo_Distance.Text = ((float)DataTemp / 10f).ToString("0.0") + " km";
  1572. //单次时间
  1573. DataTemp = (ushort)(binary_data_1[29] * 256 + binary_data_1[28]);
  1574. textBox_RunInfo_Time.Text = Convert.ToString(DataTemp) + " s";
  1575. //传感器1
  1576. DataTemp = (ushort)(binary_data_1[30]);
  1577. textBox_Sensor1.Text = Convert.ToString(DataTemp) + " N.m";
  1578. Class_Sensor1Data.String = textBox_Sensor1.Text;
  1579. Class_Sensor1Data.Data = DataTemp;
  1580. //传感器2
  1581. DataTemp = (ushort)(binary_data_1[31]);
  1582. textBox_Sensor2.Text = Convert.ToString(DataTemp) + " N.m";
  1583. Class_Sensor2Data.String = textBox_Sensor2.Text;
  1584. Class_Sensor2Data.Data = DataTemp;
  1585. //传感器3
  1586. DataTemp = (ushort)(binary_data_1[32]);
  1587. textBox_Sensor3.Text = Convert.ToString(DataTemp) + " N.m";
  1588. Class_Sensor3Data.String = textBox_Sensor3.Text;
  1589. Class_Sensor3Data.Data = DataTemp;
  1590. //变速器状态
  1591. DataTemp = (ushort)(binary_data_1[33]);
  1592. textBox_GearBox.Text = Convert.ToString(DataTemp, 16).PadLeft(2, '0').ToUpper();
  1593. //计算传感器均值和标准差
  1594. TorqueArray[TorqueArray_Index] = binary_data_1[13];
  1595. Sensor1Array[TorqueArray_Index] = binary_data_1[30];
  1596. Sensor2Array[TorqueArray_Index] = binary_data_1[31];
  1597. Sensor3Array[TorqueArray_Index] = binary_data_1[32];
  1598. TorqueArray_Index++;
  1599. if (TorqueArray_Index >= 25)
  1600. {
  1601. textBox_TorqueData.Text = Convert.ToString(GetAvg(TorqueArray, 25)) + " N.m";
  1602. textBox_Torque_Stdev.Text = Convert.ToString(GetStDev(TorqueArray, 25));
  1603. textBox_Sensor1_Avg.Text = Convert.ToString(GetAvg(Sensor1Array, 25)) + " N.m";
  1604. textBox_Sensor1_Std.Text = Convert.ToString(GetStDev(Sensor1Array, 25));
  1605. textBox_Sensor2_Avg.Text = Convert.ToString(GetAvg(Sensor2Array, 25)) + " N.m";
  1606. textBox_Sensor2_Std.Text = Convert.ToString(GetStDev(Sensor2Array, 25));
  1607. textBox_Sensor3_Avg.Text = Convert.ToString(GetAvg(Sensor3Array, 25)) + " N.m";
  1608. textBox_Sensor3_Std.Text = Convert.ToString(GetStDev(Sensor3Array, 25));
  1609. TorqueArray_Index = 0;
  1610. }
  1611. //数据自动保存
  1612. DateAutoSave();
  1613. }));
  1614. }
  1615. break;
  1616. }
  1617. case 0xA020://用户参数
  1618. {
  1619. unchecked
  1620. {
  1621. this.Invoke((EventHandler)(delegate
  1622. {
  1623. //指拨模式
  1624. DataTemp = (ushort)(binary_data_1[2]);
  1625. textBox_Config_GasMode.Text = Convert.ToString(DataTemp, 16).PadLeft(2, '0').ToUpper();
  1626. //启动模式
  1627. DataTemp = (ushort)(binary_data_1[3]);
  1628. if (DataTemp == 0x01)
  1629. comboBox_StartMode.Text = "柔和";
  1630. else if (DataTemp == 0x02)
  1631. comboBox_StartMode.Text = "正常";
  1632. else if (DataTemp == 0x03)
  1633. comboBox_StartMode.Text = "强劲";
  1634. //停机时间
  1635. DataTemp = (ushort)(binary_data_1[5] * 256 + binary_data_1[4]);
  1636. textBox_Config_StopTime.Text = Convert.ToString(DataTemp);
  1637. //限速值
  1638. DataTemp = (ushort)(binary_data_1[6]);
  1639. textBox_Config_MaxSpeed.Text = Convert.ToString(DataTemp);
  1640. //下降速度
  1641. DataTemp = (ushort)(binary_data_1[7]);
  1642. if (DataTemp == 0x01)
  1643. comboBox_DownDec.Text = "超慢";
  1644. else if (DataTemp == 0x02)
  1645. comboBox_DownDec.Text = "慢";
  1646. else if (DataTemp == 0x03)
  1647. comboBox_DownDec.Text = "正常";
  1648. else if (DataTemp == 0x02)
  1649. comboBox_DownDec.Text = "快";
  1650. else if (DataTemp == 0x03)
  1651. comboBox_DownDec.Text = "超快";
  1652. //前飞
  1653. DataTemp = (ushort)(binary_data_1[8]);
  1654. textBox_Config_Teeth_F.Text = Convert.ToString(DataTemp);
  1655. //后飞
  1656. DataTemp = (ushort)(binary_data_1[9]);
  1657. textBox_Config_Teeth_B.Text = Convert.ToString(DataTemp);
  1658. //限流
  1659. DataTemp = (ushort)(binary_data_1[10]);
  1660. textBox_Config_MaxCurrent.Text = Convert.ToString(DataTemp);
  1661. //温度预警
  1662. DataTemp = (ushort)(binary_data_1[11]);
  1663. textBox_Config_T_Alarm.Text = Convert.ToString((Int16)(DataTemp - 40));
  1664. //温度保护
  1665. DataTemp = (ushort)(binary_data_1[12]);
  1666. textBox_Config_T_Protect.Text = Convert.ToString((Int16)(DataTemp - 40));
  1667. //无PBU标志
  1668. DataTemp = (ushort)(binary_data_1[13]);
  1669. if (DataTemp == 0x55)
  1670. {
  1671. comboBox_NoWatch.Text = "有";
  1672. }
  1673. else if (DataTemp == 0xAA)
  1674. {
  1675. comboBox_NoWatch.Text = "无";
  1676. }
  1677. //轮胎周长
  1678. DataTemp = (ushort)(binary_data_1[14]);
  1679. textBox_Config_WheelSize.Text = Convert.ToString(DataTemp);
  1680. //电机系列号
  1681. DataTemp = (ushort)(binary_data_1[15]);
  1682. comboBox_SerNum.Text = Convert.ToString(DataTemp);
  1683. //ECO助力增益
  1684. DataTemp = (ushort)(binary_data_1[16]);
  1685. textBox_Config_ECO_K.Text = Convert.ToString(DataTemp);
  1686. //ECO加速
  1687. DataTemp = (ushort)(binary_data_1[17]);
  1688. textBox_Config_ECO_Acc.Text = Convert.ToString(DataTemp);
  1689. //NORM助力增益
  1690. DataTemp = (ushort)(binary_data_1[18]);
  1691. textBox_Config_NORM_K.Text = Convert.ToString(DataTemp);
  1692. //NORM加速
  1693. DataTemp = (ushort)(binary_data_1[19]);
  1694. textBox_Config_NORM_Acc.Text = Convert.ToString(DataTemp);
  1695. //SPORT助力增益
  1696. DataTemp = (ushort)(binary_data_1[20]);
  1697. textBox_Config_SPORT_K.Text = Convert.ToString(DataTemp);
  1698. //SPORT加速
  1699. DataTemp = (ushort)(binary_data_1[21]);
  1700. textBox_Config_SPORT_Acc.Text = Convert.ToString(DataTemp);
  1701. //TURBO助力增益
  1702. DataTemp = (ushort)(binary_data_1[22]);
  1703. textBox_Config_TURBO_K.Text = Convert.ToString(DataTemp);
  1704. //TURBO加速
  1705. DataTemp = (ushort)(binary_data_1[23]);
  1706. textBox_Config_TURBO_Acc.Text = Convert.ToString(DataTemp);
  1707. //SMART助力增益
  1708. DataTemp = (ushort)(binary_data_1[24]);
  1709. textBox_Config_SMART_K.Text = Convert.ToString(DataTemp);
  1710. //SMART加速
  1711. DataTemp = (ushort)(binary_data_1[25]);
  1712. textBox_Config_SMART_Acc.Text = Convert.ToString(DataTemp);
  1713. //速度传感器信号个数
  1714. DataTemp = (ushort)(binary_data_1[26]);
  1715. textBox_Config_SpeedNum.Text = Convert.ToString(DataTemp);
  1716. //踏频启动信号个数
  1717. DataTemp = (ushort)(binary_data_1[27]);
  1718. textBox_Config_CadenceNum.Text = Convert.ToString(DataTemp);
  1719. //无速度传感器
  1720. DataTemp = (ushort)(binary_data_1[28]);
  1721. if (DataTemp == 0x55)
  1722. {
  1723. comboBox_SpeedSing.Text = "传感器";
  1724. }
  1725. else if (DataTemp == 0xAA)
  1726. {
  1727. comboBox_SpeedSing.Text = "踏频";
  1728. }
  1729. else if (DataTemp == 0xEE)
  1730. {
  1731. comboBox_SpeedSing.Text = "通信";
  1732. }
  1733. //周长微调
  1734. DataTemp_int16 = (short)binary_data_1[29];
  1735. textBox_Config_WheelAdj.Text = Convert.ToString((DataTemp_int16 >= 128) ? (DataTemp_int16 - 256) : DataTemp_int16);
  1736. //低压保护阈值
  1737. DataTemp = (ushort)(binary_data_1[31] * 256 + binary_data_1[30]);
  1738. textBox_Config_UV_Protect.Text = Convert.ToString(DataTemp);
  1739. //推行限速值
  1740. DataTemp = (ushort)(binary_data_1[32]);
  1741. textBox_Config_WalkSpeedLimit.Text = ((float)DataTemp / 10f).ToString("#0.0");
  1742. //推行马达转速
  1743. DataTemp = (ushort)(binary_data_1[33]);
  1744. textBox_Config_WalkMotorSpeed.Text = Convert.ToString(DataTemp);
  1745. }));
  1746. }
  1747. break;
  1748. }
  1749. case 0xA110://马达参数
  1750. {
  1751. unchecked
  1752. {
  1753. this.Invoke((EventHandler)(delegate
  1754. {
  1755. //额定功率
  1756. DataTemp = (ushort)(binary_data_1[3] * 256 + binary_data_1[2]);
  1757. textBox_Motor_Power.Text = Convert.ToString(DataTemp);
  1758. //额定转速
  1759. DataTemp = (ushort)(binary_data_1[5] * 256 + binary_data_1[4]);
  1760. textBox_Motor_Speed.Text = Convert.ToString(DataTemp);
  1761. //定子电阻
  1762. DataTemp = (ushort)(binary_data_1[7] * 256 + binary_data_1[6]);
  1763. textBox_Motor_R.Text = Convert.ToString(DataTemp);
  1764. //Lq
  1765. DataTemp = (ushort)(binary_data_1[9] * 256 + binary_data_1[8]);
  1766. textBox_Motor_Lq.Text = Convert.ToString(DataTemp);
  1767. //Ld
  1768. DataTemp = (ushort)(binary_data_1[11] * 256 + binary_data_1[10]);
  1769. textBox_Motor_Ld.Text = Convert.ToString(DataTemp);
  1770. //反电动势
  1771. DataTemp = (ushort)(binary_data_1[13] * 256 + binary_data_1[12]);
  1772. textBox_Motor_E.Text = Convert.ToString(DataTemp);
  1773. //额定电压
  1774. DataTemp = (ushort)(binary_data_1[14]);
  1775. textBox_Motor_Voltage.Text = Convert.ToString(DataTemp);
  1776. //极对数
  1777. DataTemp = (ushort)(binary_data_1[15]);
  1778. textBox_Motor_Pole.Text = Convert.ToString(DataTemp);
  1779. }));
  1780. }
  1781. break;
  1782. }
  1783. case 0xA230://历史信息1
  1784. {
  1785. unchecked
  1786. {
  1787. this.Invoke((EventHandler)(delegate
  1788. {
  1789. UInt32 DataTemp_Uint32;
  1790. ushort DataTemp_Uint16;
  1791. short DataTemp_Int16;
  1792. //开机次数
  1793. DataTemp_Uint32 = (UInt32)((binary_data_1[5] << 24) + (binary_data_1[4] << 16) + (binary_data_1[3] << 8) + binary_data_1[2]);
  1794. textBox_Runlog1_PowerCount.Text = Convert.ToString(DataTemp_Uint32);
  1795. //使用时间
  1796. DataTemp_Uint32 = (UInt32)((binary_data_1[9] << 24) + (binary_data_1[8] << 16) + (binary_data_1[7] << 8) + binary_data_1[6]);
  1797. textBox_Runlog1_RunTime.Text = Convert.ToString(DataTemp_Uint32);
  1798. //过流保护
  1799. DataTemp_Uint16 = (ushort)(binary_data_1[11] * 256 + binary_data_1[10]);
  1800. textBox_Runlog1_OC.Text = Convert.ToString(DataTemp_Uint16);
  1801. //低压保护
  1802. DataTemp_Uint16 = (ushort)(binary_data_1[13] * 256 + binary_data_1[12]);
  1803. textBox_Runlog1_UV.Text = Convert.ToString(DataTemp_Uint16);
  1804. //过压保护
  1805. DataTemp_Uint16 = (ushort)(binary_data_1[15] * 256 + binary_data_1[14]);
  1806. textBox_Runlog1_OV.Text = Convert.ToString(DataTemp_Uint16);
  1807. //堵转保护
  1808. DataTemp_Uint16 = (ushort)(binary_data_1[17] * 256 + binary_data_1[16]);
  1809. textBox_Runlog1_Lock.Text = Convert.ToString(DataTemp_Uint16);
  1810. //过热保护
  1811. DataTemp_Uint16 = (ushort)(binary_data_1[19] * 256 + binary_data_1[18]);
  1812. textBox_Runlog1_OT.Text = Convert.ToString(DataTemp_Uint16);
  1813. //速度传感器故障
  1814. DataTemp_Uint16 = (ushort)(binary_data_1[21] * 256 + binary_data_1[20]);
  1815. textBox_Runlog1_SPSFault.Text = Convert.ToString(DataTemp_Uint16);
  1816. //力矩传感器
  1817. DataTemp_Uint16 = (ushort)(binary_data_1[23] * 256 + binary_data_1[22]);
  1818. textBox_Runlog1_TQSFault.Text = Convert.ToString(DataTemp_Uint16);
  1819. //霍尔故障
  1820. DataTemp_Uint16 = (ushort)(binary_data_1[25] * 256 + binary_data_1[24]);
  1821. textBox_Runlog1_HallFault.Text = Convert.ToString(DataTemp_Uint16);
  1822. //马达缺相
  1823. DataTemp_Uint16 = (ushort)(binary_data_1[27] * 256 + binary_data_1[26]);
  1824. textBox_Runlog1_Phase.Text = Convert.ToString(DataTemp_Uint16);
  1825. //NTC故障
  1826. DataTemp_Uint16 = (ushort)(binary_data_1[29] * 256 + binary_data_1[28]);
  1827. textBox_Runlog1_NTCFault.Text = Convert.ToString(DataTemp_Uint16);
  1828. //BMS校验失败
  1829. DataTemp_Uint16 = (ushort)(binary_data_1[31] * 256 + binary_data_1[30]);
  1830. textBox_Runlog1_BMSFault.Text = Convert.ToString(DataTemp_Uint16);
  1831. //HMI校验失败
  1832. DataTemp_Uint16 = (ushort)(binary_data_1[33] * 256 + binary_data_1[32]);
  1833. textBox_Runlog1_HMIFault.Text = Convert.ToString(DataTemp_Uint16);
  1834. //PBU校验失败
  1835. DataTemp_Uint16 = (ushort)(binary_data_1[35] * 256 + binary_data_1[34]);
  1836. textBox_Runlog1_PBUFault.Text = Convert.ToString(DataTemp_Uint16);
  1837. //PCB最高温
  1838. DataTemp_Int16 = (short)(ushort)binary_data_1[36];
  1839. textBox_Runlog1_PCB_MAX.Text = Convert.ToString(DataTemp_Int16 - 40);
  1840. //PCB最低温
  1841. DataTemp_Int16 = (short)(ushort)binary_data_1[37];
  1842. textBox_Runlog1_PCB_MIN.Text = Convert.ToString(DataTemp_Int16 - 40);
  1843. //ODO里程
  1844. DataTemp_Uint32 = (UInt32)((binary_data_1[41] << 24) + (binary_data_1[40] << 16) + (binary_data_1[39] << 8) + binary_data_1[38]);
  1845. textBox_ODO_Km.Text = ((float)DataTemp_Uint32 / 10f).ToString("0.0");
  1846. //绕组最高温
  1847. DataTemp_Int16 = (short)(ushort)binary_data_1[42];
  1848. textBox_Runlog1_Coil_MAX.Text = Convert.ToString(DataTemp_Int16 - 40);
  1849. //绕组最低温
  1850. DataTemp_Int16 = (short)(ushort)binary_data_1[43];
  1851. textBox_Runlog1_Coil_MIN.Text = Convert.ToString(DataTemp_Int16 - 40);
  1852. //MCU最高温
  1853. DataTemp_Int16 = (short)(ushort)binary_data_1[44];
  1854. textBox_Runlog1_MCU_MAX.Text = Convert.ToString(DataTemp_Int16 - 40);
  1855. //MCU最低温
  1856. DataTemp_Int16 = (short)(ushort)binary_data_1[45];
  1857. textBox_Runlog1_MCU_MIN.Text = Convert.ToString(DataTemp_Int16 - 40);
  1858. //ODO时间
  1859. DataTemp_Uint32 = (UInt32)((binary_data_1[49] << 24) + (binary_data_1[48] << 16) + (binary_data_1[47] << 8) + binary_data_1[46]);
  1860. textBox_ODO_Time.Text = Convert.ToString(DataTemp_Uint32);
  1861. }));
  1862. }
  1863. break;
  1864. }
  1865. case 0xAB09://存储器数据
  1866. case 0xAB0A:
  1867. case 0xAB0B:
  1868. case 0xAB0C:
  1869. {
  1870. unchecked
  1871. {
  1872. this.Invoke((EventHandler)(delegate
  1873. {
  1874. long ByteNum = 0;
  1875. ByteNum = ((binary_data_1[6] << 24) + (binary_data_1[7] << 16) + (binary_data_1[8] << 8) + binary_data_1[9]) - ((binary_data_1[2] << 24) + (binary_data_1[3] << 16) + (binary_data_1[4] << 8) + binary_data_1[5]) + 1;
  1876. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  1877. {
  1878. for (int i = 0; i < ByteNum; i++)
  1879. {
  1880. richTextBox_DebugInfo.AppendText(Convert.ToString(binary_data_1[10 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  1881. }
  1882. }
  1883. else //根据设置自动转换10进制显示
  1884. {
  1885. if (radioButton_DebugDec.Checked == true) //10进制显示
  1886. {
  1887. switch (ByteNum)
  1888. {
  1889. case 1:
  1890. {
  1891. richTextBox_DebugInfo.AppendText(Convert.ToString(binary_data_1[10]) + ", ");
  1892. break;
  1893. }
  1894. case 2:
  1895. {
  1896. richTextBox_DebugInfo.AppendText(Convert.ToString(binary_data_1[10] + (binary_data_1[11] << 8)) + ", ");
  1897. break;
  1898. }
  1899. case 3:
  1900. {
  1901. richTextBox_DebugInfo.AppendText(Convert.ToString(binary_data_1[10] + (binary_data_1[11] << 8) + (binary_data_1[12] << 16)) + ", ");
  1902. break;
  1903. }
  1904. case 4:
  1905. {
  1906. richTextBox_DebugInfo.AppendText(Convert.ToString(binary_data_1[10] + (binary_data_1[11] << 8) + (binary_data_1[12] << 16) + (binary_data_1[13] << 24)) + ", ");
  1907. break;
  1908. }
  1909. default:
  1910. {
  1911. richTextBox_DebugInfo.AppendText("无效数据" + ", ");
  1912. break;
  1913. }
  1914. }
  1915. }
  1916. else if (radioButton_DebugHex.Checked == true)//16进制显示
  1917. {
  1918. switch (ByteNum)
  1919. {
  1920. case 1:
  1921. {
  1922. richTextBox_DebugInfo.AppendText("0x" + Convert.ToString(binary_data_1[10], 16).PadLeft(2, '0').ToUpper() + ", ");
  1923. break;
  1924. }
  1925. case 2:
  1926. {
  1927. richTextBox_DebugInfo.AppendText("0x" + Convert.ToString(binary_data_1[10] + (binary_data_1[11] << 8), 16).PadLeft(4, '0').ToUpper() + ", ");
  1928. break;
  1929. }
  1930. case 3:
  1931. {
  1932. richTextBox_DebugInfo.AppendText("0x" + Convert.ToString(binary_data_1[10] + (binary_data_1[11] << 8) + (binary_data_1[12] << 16), 16).PadLeft(6, '0').ToUpper() + ", ");
  1933. break;
  1934. }
  1935. case 4:
  1936. {
  1937. richTextBox_DebugInfo.AppendText("0x" + Convert.ToString(binary_data_1[10] + (binary_data_1[11] << 8) + (binary_data_1[12] << 16) + (binary_data_1[13] << 24), 16).PadLeft(8, '0').ToUpper() + ", ");
  1938. break;
  1939. }
  1940. default:
  1941. {
  1942. richTextBox_DebugInfo.AppendText("无效数据" + ", ");
  1943. break;
  1944. }
  1945. }
  1946. }
  1947. }
  1948. }));
  1949. }
  1950. break;
  1951. }
  1952. case 0xAB88://故障日志
  1953. {
  1954. unchecked
  1955. {
  1956. this.Invoke((EventHandler)(delegate
  1957. {
  1958. //电机存储的故障日志,一包128字节包含2条故障日志
  1959. var ErrorLogSaveInfo1 = new MC_ErrorLogSaveInfo_Struct_t();
  1960. var ErrorLogSaveInfo2 = new MC_ErrorLogSaveInfo_Struct_t();
  1961. ErrorLogSaveInfo1 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(binary_data_1, 10);
  1962. ErrorLogSaveInfo2 = MyConverter.ByteToStructure<MC_ErrorLogSaveInfo_Struct_t>(binary_data_1, 74);
  1963. //数据存储
  1964. ErrorLogDateSave(ErrorLogSaveInfo1, ErrorLogSaveInfo2);
  1965. }));
  1966. }
  1967. break;
  1968. }
  1969. case 0xAC10://运行历史2
  1970. {
  1971. unchecked
  1972. {
  1973. this.Invoke((EventHandler)(delegate
  1974. {
  1975. ushort DataTemp_Uint16;
  1976. //MCU故障
  1977. DataTemp_Uint16 = (ushort)(binary_data_1[3] * 256 + binary_data_1[2]);
  1978. textBox_Runlog2_MCUFault.Text = Convert.ToString(DataTemp_Uint16);
  1979. //踏频传感器故障
  1980. DataTemp_Uint16 = (ushort)(binary_data_1[5] * 256 + binary_data_1[4]);
  1981. textBox_Runlog2_CDSFault.Text = Convert.ToString(DataTemp_Uint16);
  1982. //指拨故障
  1983. DataTemp_Uint16 = (ushort)(binary_data_1[7] * 256 + binary_data_1[6]);
  1984. textBox_Runlog2_GasFault.Text = Convert.ToString(DataTemp_Uint16);
  1985. //MOS短路
  1986. DataTemp_Uint16 = (ushort)(binary_data_1[9] * 256 + binary_data_1[8]);
  1987. textBox_Runlog2_MOS_SC.Text = Convert.ToString(DataTemp_Uint16);
  1988. //电压异常
  1989. DataTemp_Uint16 = (ushort)(binary_data_1[11] * 256 + binary_data_1[10]);
  1990. textBox_Runlog2_VolFault.Text = Convert.ToString(DataTemp_Uint16);
  1991. //电路异常
  1992. DataTemp_Uint16 = (ushort)(binary_data_1[13] * 256 + binary_data_1[12]);
  1993. textBox_Runlog2_CircuitFault.Text = Convert.ToString(DataTemp_Uint16);
  1994. //TE MCU异常
  1995. DataTemp_Uint16 = (ushort)(binary_data_1[15] * 256 + binary_data_1[14]);
  1996. textBox_Runlog2_TE_MCUFault.Text = Convert.ToString(DataTemp_Uint16);
  1997. //TE电路故障
  1998. DataTemp_Uint16 = (ushort)(binary_data_1[17] * 256 + binary_data_1[16]);
  1999. textBox_Runlog2_TE_CircuitFault.Text = Convert.ToString(DataTemp_Uint16);
  2000. }));
  2001. }
  2002. break;
  2003. }
  2004. case 0x1104://故障码
  2005. {
  2006. unchecked
  2007. {
  2008. this.Invoke((EventHandler)(delegate
  2009. {
  2010. MC_ErrorCode_Refresh = true;
  2011. textBox_RunInfo_ErrorCode.Text =
  2012. Convert.ToString(binary_data_1[5], 16).PadLeft(2, '0').ToUpper() +
  2013. Convert.ToString(binary_data_1[4], 16).PadLeft(2, '0').ToUpper() +
  2014. Convert.ToString(binary_data_1[3], 16).PadLeft(2, '0').ToUpper() +
  2015. Convert.ToString(binary_data_1[2], 16).PadLeft(2, '0').ToUpper() +
  2016. "H";
  2017. }));
  2018. }
  2019. break;
  2020. }
  2021. case 0xA903://反馈指令
  2022. {
  2023. unchecked
  2024. {
  2025. this.Invoke((EventHandler)(delegate
  2026. {
  2027. timer1.Enabled = false;
  2028. MessageBox.Show("OK", "反馈指令", MessageBoxButtons.OK, MessageBoxIcon.Information);
  2029. timer1.Enabled = true;
  2030. }));
  2031. }
  2032. break;
  2033. }
  2034. case 0xAD20://用户参数2
  2035. {
  2036. unchecked
  2037. {
  2038. this.Invoke((EventHandler)(delegate
  2039. {
  2040. short DataTemp_Int16;
  2041. sbyte DataTemp_byte;
  2042. //俯仰角零偏
  2043. DataTemp_Int16 = (short)(binary_data_1[3] * 256 + binary_data_1[2]);
  2044. textBox_Config_Angle_Pitch.Text = ((float)DataTemp_Int16 / 10f).ToString("0.0");
  2045. //横滚角零偏
  2046. DataTemp_Int16 = (short)(binary_data_1[5] * 256 + binary_data_1[4]);
  2047. textBox_Config_Angle_Roll.Text = ((float)DataTemp_Int16 / 10f).ToString("0.0");
  2048. //支持姿态传感器
  2049. DataTemp = (ushort)(binary_data_1[6]);
  2050. if (DataTemp == 0x55)
  2051. {
  2052. comboBox_AttiSensor.Text = "不支持";
  2053. }
  2054. else if (DataTemp == 0xAA)
  2055. {
  2056. comboBox_AttiSensor.Text = "支持";
  2057. }
  2058. //前灯模式
  2059. DataTemp = (ushort)(binary_data_1[7] & 0xF0);
  2060. if (DataTemp == 0x10)
  2061. {
  2062. comboBox_FrontLightMode.Text = "模式1";
  2063. }
  2064. else if (DataTemp == 0x20)
  2065. {
  2066. comboBox_FrontLightMode.Text = "模式2";
  2067. }
  2068. else
  2069. {
  2070. comboBox_FrontLightMode.Text = "0";
  2071. }
  2072. //尾灯模式
  2073. DataTemp = (ushort)(binary_data_1[7] & 0x0F);
  2074. if (DataTemp == 0x01)
  2075. {
  2076. comboBox_TailLightMode.Text = "模式1";
  2077. }
  2078. else if (DataTemp == 0x02)
  2079. {
  2080. comboBox_TailLightMode.Text = "模式2";
  2081. }
  2082. else if (DataTemp == 0x03)
  2083. {
  2084. comboBox_TailLightMode.Text = "模式3";
  2085. }
  2086. else if (DataTemp == 0x04)
  2087. {
  2088. comboBox_TailLightMode.Text = "模式4";
  2089. }
  2090. else if (DataTemp == 0x05)
  2091. {
  2092. comboBox_TailLightMode.Text = "模式5";
  2093. }
  2094. else if (DataTemp == 0x06)
  2095. {
  2096. comboBox_TailLightMode.Text = "模式6";
  2097. }
  2098. else
  2099. {
  2100. comboBox_TailLightMode.Text = "0";
  2101. }
  2102. //前灯电压
  2103. DataTemp = (ushort)(binary_data_1[8]);
  2104. if (DataTemp == 0x06)
  2105. {
  2106. comboBox_FrontLigthVol.Text = "6V";
  2107. }
  2108. else if (DataTemp == 0x0C)
  2109. {
  2110. comboBox_FrontLigthVol.Text = "12V";
  2111. }
  2112. else if (DataTemp == 0xFF)
  2113. {
  2114. comboBox_FrontLigthVol.Text = "随电池";
  2115. }
  2116. else if (DataTemp == 0x00)
  2117. {
  2118. comboBox_FrontLigthVol.Text = "硬件";
  2119. }
  2120. else
  2121. {
  2122. comboBox_FrontLigthVol.Text = "无效";
  2123. }
  2124. //尾灯电压
  2125. DataTemp = (ushort)(binary_data_1[9]);
  2126. if (DataTemp == 0x06)
  2127. {
  2128. comboBox_TailLightVol.Text = "6V";
  2129. }
  2130. else if (DataTemp == 0x0C)
  2131. {
  2132. comboBox_TailLightVol.Text = "12V";
  2133. }
  2134. else if (DataTemp == 0xFF)
  2135. {
  2136. comboBox_TailLightVol.Text = "随电池";
  2137. }
  2138. else if (DataTemp == 0x00)
  2139. {
  2140. comboBox_TailLightVol.Text = "硬件";
  2141. }
  2142. else
  2143. {
  2144. comboBox_TailLightVol.Text = "无效";
  2145. }
  2146. //超速报警阈值
  2147. DataTemp = (ushort)(binary_data_1[11] * 256 + binary_data_1[10]);
  2148. textBox_Config_SpeedAlarm.Text = ((float)DataTemp / 10f).ToString("#0.0");
  2149. //尾灯脉宽
  2150. DataTemp = (ushort)(binary_data_1[13] * 256 + binary_data_1[12]);
  2151. textBox_Config_Pulse.Text = Convert.ToString(DataTemp);
  2152. //尾灯周期
  2153. DataTemp = (ushort)(binary_data_1[15] * 256 + binary_data_1[14]);
  2154. textBox_Config_Period.Text = Convert.ToString(DataTemp);
  2155. //起始限速
  2156. DataTemp_byte = (sbyte)(binary_data_1[16]);
  2157. textBox_Config_SpeedlimitStart.Text = ((float)(DataTemp_byte) / 10f).ToString("#0.0");
  2158. //结束限速
  2159. DataTemp_byte = (sbyte)(binary_data_1[17]);
  2160. textBox_Config_SpeedlimitStop.Text = ((float)DataTemp_byte / 10f).ToString("#0.0");
  2161. //限速微调
  2162. DataTemp_int16 = (short)binary_data_1[18];
  2163. textBox_Config_SpeedlimitAdj.Text = Convert.ToString((DataTemp_int16 >= 128) ? (DataTemp_int16 - 256) : DataTemp_int16);
  2164. }));
  2165. }
  2166. break;
  2167. }
  2168. case 0x1510:
  2169. {
  2170. unchecked
  2171. {
  2172. this.Invoke((EventHandler)(delegate
  2173. {
  2174. long DataTemp32;
  2175. MC_RideInfo_Refresh = true;
  2176. //ODO里程
  2177. DataTemp32 = (long)((binary_data_1[5] << 24) + (binary_data_1[4] << 16) + (binary_data_1[3] << 8) + binary_data_1[2]);
  2178. textBox_RideInfo_ODO_Km.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  2179. //ODO时间
  2180. DataTemp32 = (long)((binary_data_1[9] << 24) + (binary_data_1[8] << 16) + (binary_data_1[7] << 8) + binary_data_1[6]);
  2181. if (DataTemp32 >= 60 * 1000)
  2182. textBox_RideInfo_ODO_Time.Text = Convert.ToString(DataTemp32 / 60) + " h";
  2183. else
  2184. textBox_RideInfo_ODO_Time.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  2185. //TRIP里程
  2186. DataTemp32 = (long)((binary_data_1[13] << 24) + (binary_data_1[12] << 16) + (binary_data_1[11] << 8) + binary_data_1[10]);
  2187. textBox_RideInfo_Trip_Km.Text = ((float)DataTemp32 / 10f).ToString("0.0") + " km";
  2188. //TRIP时间
  2189. DataTemp32 = (long)((binary_data_1[17] << 24) + (binary_data_1[16] << 16) + (binary_data_1[15] << 8) + binary_data_1[14]);
  2190. if (DataTemp32 >= 60 * 1000)
  2191. textBox_RideInfo_Trip_Time.Text = Convert.ToString(DataTemp32 / 60) + " h";
  2192. else
  2193. textBox_RideInfo_Trip_Time.Text = Convert.ToString(DataTemp32 / 60) + " h " + Convert.ToString(DataTemp32 % 60) + " m";
  2194. }));
  2195. }
  2196. break;
  2197. }
  2198. case 0x1608://姿态信息
  2199. {
  2200. unchecked
  2201. {
  2202. this.Invoke((EventHandler)(delegate
  2203. {
  2204. short DataTemp_Int16;
  2205. MC_AttitudeAngle_Refresh = true;
  2206. //俯仰角度绝对
  2207. DataTemp_Int16 = (short)(binary_data_1[3] * 256 + binary_data_1[2]);
  2208. textBox_Attitude_PitchAngle_Abs.Text = ((float)DataTemp_Int16 / 10f).ToString("0.0");
  2209. //横滚角度绝对
  2210. DataTemp_Int16 = (short)(binary_data_1[5] * 256 + binary_data_1[4]);
  2211. textBox_Attitude_RollAngle_Abs.Text = ((float)DataTemp_Int16 / 10f).ToString("0.0");
  2212. //俯仰角度相对
  2213. DataTemp_Int16 = (short)(binary_data_1[7] * 256 + binary_data_1[6]);
  2214. textBox_Attitude_PitchAngle_Rel.Text = ((float)DataTemp_Int16 / 10f).ToString("0.0");
  2215. //横滚角度相对
  2216. DataTemp_Int16 = (short)(binary_data_1[9] * 256 + binary_data_1[8]);
  2217. textBox_Attitude_RollAngle_Rel.Text = ((float)DataTemp_Int16 / 10f).ToString("0.0");
  2218. }));
  2219. }
  2220. break;
  2221. }
  2222. default: break;
  2223. }
  2224. //存储器导出数据显示
  2225. if ((CmdTemp & 0xFF00) == 0xAB00)
  2226. {
  2227. unchecked
  2228. {
  2229. this.Invoke((EventHandler)(delegate
  2230. {
  2231. long ByteNum = 0;
  2232. ByteNum = ((binary_data_1[6] << 24) + (binary_data_1[7] << 16) + (binary_data_1[8] << 8) + binary_data_1[9]) - ((binary_data_1[2] << 24) + (binary_data_1[3] << 16) + (binary_data_1[4] << 8) + binary_data_1[5]) + 1;
  2233. if (ByteNum > 4) //数据长度超过4Bytes,按照16进制显示字节流
  2234. {
  2235. for (int i = 0; i < ByteNum; i++)
  2236. {
  2237. richTextBox_DebugInfo.AppendText(Convert.ToString(binary_data_1[10 + i], 16).PadLeft(2, '0').ToUpper() + " ");
  2238. }
  2239. }
  2240. }));
  2241. }
  2242. }
  2243. }
  2244. #endregion
  2245. #region 解析MC TE的命令
  2246. else if ((ID == 0x615) || (ID == 0x610))
  2247. {
  2248. switch (CmdTemp)
  2249. {
  2250. case 0x1240://TE APP版本信息
  2251. {
  2252. unchecked
  2253. {
  2254. this.Invoke((EventHandler)(delegate
  2255. {
  2256. //电机FW
  2257. textBox_TE_FW.Text = "";
  2258. for (ushort i = 0; i < 16; i++)
  2259. {
  2260. if (binary_data_1[50 + i] == 0x2E)
  2261. {
  2262. break;
  2263. }
  2264. if (binary_data_1[50 + i] == 'r')
  2265. {
  2266. binary_data_1[50 + i] = (byte)'.';
  2267. }
  2268. textBox_TE_FW.Text += ((char)binary_data_1[50 + i]).ToString();
  2269. }
  2270. }));
  2271. }
  2272. break;
  2273. }
  2274. default: break;
  2275. }
  2276. #endregion
  2277. }
  2278. }
  2279. #endregion
  2280. //用户参数显示清除
  2281. private void MC_Config_Clear()
  2282. {
  2283. foreach (Control c in groupBox10.Controls)
  2284. {
  2285. if ((c is TextBox) || (c is ComboBox))
  2286. {
  2287. c.Text = "---";
  2288. }
  2289. }
  2290. }
  2291. //用户参数2清除
  2292. private void MC_Config_Ext_Clear()
  2293. {
  2294. foreach (Control c in groupBox4.Controls)
  2295. {
  2296. if ((c is TextBox) || (c is ComboBox))
  2297. {
  2298. c.Text = "---";
  2299. }
  2300. }
  2301. }
  2302. //马达参数显示清除
  2303. private void Motor_Config_Clear()
  2304. {
  2305. foreach (Control c in groupBox11.Controls)
  2306. {
  2307. if (c is TextBox)
  2308. {
  2309. c.Text = "---";
  2310. }
  2311. }
  2312. }
  2313. //电机运行信息清除
  2314. private void MC_RunInfo_Clear()
  2315. {
  2316. foreach (Control c in tabPage1.Controls)
  2317. {
  2318. if (c is TextBox)
  2319. {
  2320. c.Text = "---";
  2321. }
  2322. }
  2323. }
  2324. //姿态传感器信息清除
  2325. private void MC_AttitudeAngle_Clear()
  2326. {
  2327. foreach (Control c in groupBox13.Controls)
  2328. {
  2329. if (c is TextBox)
  2330. {
  2331. c.Text = "---";
  2332. }
  2333. }
  2334. }
  2335. //骑行信息清除
  2336. private void MC_RideInfo_Clear()
  2337. {
  2338. foreach (Control c in groupBox12.Controls)
  2339. {
  2340. if (c is TextBox)
  2341. {
  2342. c.Text = "---";
  2343. }
  2344. }
  2345. }
  2346. //历史信息清除
  2347. private void MC_RunLog_Clear()
  2348. {
  2349. foreach (Control c in groupBox14.Controls)
  2350. {
  2351. if (c is TextBox)
  2352. {
  2353. c.Text = "---";
  2354. }
  2355. }
  2356. }
  2357. //电机故障码显示清除
  2358. private void MC_ErrorCode_Clear()
  2359. {
  2360. //故障码
  2361. textBox_RunInfo_ErrorCode.Text = "---";
  2362. }
  2363. //接收计数清零
  2364. private void label58_Click(object sender, EventArgs e)
  2365. {
  2366. textBox_RevCnt.Text = "0";
  2367. }
  2368. //读取用户参数
  2369. private void button_Read_Config_Click(object sender, EventArgs e)
  2370. {
  2371. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1A00, null);
  2372. MC_Config_Clear();
  2373. }
  2374. //写入用户参数
  2375. private void button_Write_Config_Click(object sender, EventArgs e)
  2376. {
  2377. var ConfigParam = new byte[32];
  2378. for (int i = 0; i < 32; i++)
  2379. ConfigParam[i] = 0;
  2380. ushort DataTemp;
  2381. //指拨参数
  2382. ConfigParam[0] = byte.Parse(textBox_Config_GasMode.Text, System.Globalization.NumberStyles.HexNumber);
  2383. //启动模式
  2384. if (comboBox_StartMode.Text == "柔和")
  2385. ConfigParam[1] = 0x01;
  2386. else if (comboBox_StartMode.Text == "强劲")
  2387. ConfigParam[1] = 0x03;
  2388. else
  2389. ConfigParam[1] = 0x02;
  2390. //停机时间
  2391. DataTemp = Convert.ToUInt16(textBox_Config_StopTime.Text);
  2392. ConfigParam[2] = (byte)(DataTemp & 0xFF);
  2393. ConfigParam[3] = (byte)(DataTemp >> 8);
  2394. //限速
  2395. ConfigParam[4] = Convert.ToByte(textBox_Config_MaxSpeed.Text);
  2396. //下降速度
  2397. if (comboBox_DownDec.Text == "超慢")
  2398. ConfigParam[5] = 0x01;
  2399. else if (comboBox_DownDec.Text == "慢")
  2400. ConfigParam[5] = 0x02;
  2401. else if (comboBox_DownDec.Text == "快")
  2402. ConfigParam[5] = 0x04;
  2403. else if (comboBox_DownDec.Text == "超快")
  2404. ConfigParam[5] = 0x05;
  2405. else
  2406. ConfigParam[5] = 0x03;
  2407. //前飞
  2408. ConfigParam[6] = Convert.ToByte(textBox_Config_Teeth_F.Text);
  2409. //后飞
  2410. ConfigParam[7] = Convert.ToByte(textBox_Config_Teeth_B.Text);
  2411. //限流
  2412. ConfigParam[8] = Convert.ToByte(textBox_Config_MaxCurrent.Text);
  2413. //温度预警
  2414. ConfigParam[9] = (byte)(Convert.ToByte(textBox_Config_T_Alarm.Text) + 40);
  2415. //温度保护
  2416. ConfigParam[10] = (byte)(Convert.ToByte(textBox_Config_T_Protect.Text) + 40);
  2417. //无PBU
  2418. if (comboBox_NoWatch.Text == "无")
  2419. ConfigParam[11] = 0xAA;
  2420. else
  2421. ConfigParam[11] = 0x55;
  2422. //轮胎周长
  2423. ConfigParam[12] = Convert.ToByte(textBox_Config_WheelSize.Text);
  2424. //电机系列号
  2425. ConfigParam[13] = Convert.ToByte(comboBox_SerNum.Text);
  2426. //ECO助力增益
  2427. ConfigParam[14] = Convert.ToByte(textBox_Config_ECO_K.Text);
  2428. //ECO加速
  2429. ConfigParam[15] = Convert.ToByte(textBox_Config_ECO_Acc.Text);
  2430. //NORM助力增益
  2431. ConfigParam[16] = Convert.ToByte(textBox_Config_NORM_K.Text);
  2432. //NORM加速
  2433. ConfigParam[17] = Convert.ToByte(textBox_Config_NORM_Acc.Text);
  2434. //SPORT助力增益
  2435. ConfigParam[18] = Convert.ToByte(textBox_Config_SPORT_K.Text);
  2436. //SPORT加速
  2437. ConfigParam[19] = Convert.ToByte(textBox_Config_SPORT_Acc.Text);
  2438. //TURBO助力增益
  2439. ConfigParam[20] = Convert.ToByte(textBox_Config_TURBO_K.Text);
  2440. //TURBO加速
  2441. ConfigParam[21] = Convert.ToByte(textBox_Config_TURBO_Acc.Text);
  2442. //SMART助力增益
  2443. ConfigParam[22] = Convert.ToByte(textBox_Config_SMART_K.Text);
  2444. //SMART加速
  2445. ConfigParam[23] = Convert.ToByte(textBox_Config_SMART_Acc.Text);
  2446. //速度传感器信号个数
  2447. ConfigParam[24] = Convert.ToByte(textBox_Config_SpeedNum.Text);
  2448. //踏频启动信号个数
  2449. ConfigParam[25] = Convert.ToByte(textBox_Config_CadenceNum.Text);
  2450. //速度传感器
  2451. if (comboBox_SpeedSing.Text == "踏频")
  2452. ConfigParam[26] = 0xAA;
  2453. else if (comboBox_SpeedSing.Text == "通信")
  2454. ConfigParam[26] = 0xEE;
  2455. else
  2456. ConfigParam[26] = 0x55;
  2457. //周长微调
  2458. ConfigParam[27] = (byte)Convert.ToInt16(textBox_Config_WheelAdj.Text);
  2459. //低压保护阈值
  2460. DataTemp = Convert.ToUInt16(textBox_Config_UV_Protect.Text);
  2461. ConfigParam[28] = (byte)(DataTemp & 0xFF);
  2462. ConfigParam[29] = (byte)(DataTemp >> 8);
  2463. //推行限速
  2464. DataTemp = (ushort)(decimal.Parse(textBox_Config_WalkSpeedLimit.Text) * 10);
  2465. ConfigParam[30] = (byte)Convert.ToByte(DataTemp);
  2466. //推行马达转速
  2467. ConfigParam[31] = (byte)Convert.ToByte(textBox_Config_WalkMotorSpeed.Text);
  2468. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1B20, ConfigParam);
  2469. }
  2470. //读取马达参数
  2471. private void button_Read_MortoConfig_Click(object sender, EventArgs e)
  2472. {
  2473. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1C00, null);
  2474. Motor_Config_Clear();
  2475. }
  2476. //写入马达参数
  2477. private void button_Write_MotorConfig_Click(object sender, EventArgs e)
  2478. {
  2479. var ConfigParam = new byte[16];
  2480. for (int i = 0; i < 16; i++)
  2481. ConfigParam[i] = 0;
  2482. ushort DataTemp;
  2483. //额定功率
  2484. DataTemp = Convert.ToUInt16(textBox_Motor_Power.Text);
  2485. ConfigParam[0] = (byte)(DataTemp & 0xFF);
  2486. ConfigParam[1] = (byte)(DataTemp >> 8);
  2487. //额定转速
  2488. DataTemp = Convert.ToUInt16(textBox_Motor_Speed.Text);
  2489. ConfigParam[2] = (byte)(DataTemp & 0xFF);
  2490. ConfigParam[3] = (byte)(DataTemp >> 8);
  2491. //定子电阻
  2492. DataTemp = Convert.ToUInt16(textBox_Motor_R.Text);
  2493. ConfigParam[4] = (byte)(DataTemp & 0xFF);
  2494. ConfigParam[5] = (byte)(DataTemp >> 8);
  2495. //Lq
  2496. DataTemp = Convert.ToUInt16(textBox_Motor_Lq.Text);
  2497. ConfigParam[6] = (byte)(DataTemp & 0xFF);
  2498. ConfigParam[7] = (byte)(DataTemp >> 8);
  2499. //Ld
  2500. DataTemp = Convert.ToUInt16(textBox_Motor_Ld.Text);
  2501. ConfigParam[8] = (byte)(DataTemp & 0xFF);
  2502. ConfigParam[9] = (byte)(DataTemp >> 8);
  2503. //反电动势
  2504. DataTemp = Convert.ToUInt16(textBox_Motor_E.Text);
  2505. ConfigParam[10] = (byte)(DataTemp & 0xFF);
  2506. ConfigParam[11] = (byte)(DataTemp >> 8);
  2507. //额定电压
  2508. ConfigParam[12] = Convert.ToByte(textBox_Motor_Voltage.Text);
  2509. //极对数
  2510. ConfigParam[13] = Convert.ToByte(textBox_Motor_Pole.Text);
  2511. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1D10, ConfigParam);
  2512. }
  2513. //写入电机型号
  2514. private void button_Write_Mode_Click(object sender, EventArgs e)
  2515. {
  2516. string Mode = textBox_Mode.Text;
  2517. var ModeArray = new byte[16];
  2518. for (ushort i = 0; i < Mode.Length; i++)
  2519. {
  2520. ModeArray[i] = (byte)Mode[i];
  2521. }
  2522. if (Mode.Length < 16)
  2523. {
  2524. ModeArray[Mode.Length] = (byte)'.';
  2525. for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
  2526. {
  2527. ModeArray[Mode.Length + 1 + i] = 0x20;
  2528. }
  2529. }
  2530. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
  2531. }
  2532. //写入电机SN
  2533. private void button_Write_SN_Click(object sender, EventArgs e)
  2534. {
  2535. string SN = textBox_SN.Text;
  2536. var SNArray = new byte[16];
  2537. for (ushort i = 0; i < SN.Length; i++)
  2538. {
  2539. SNArray[i] = (byte)SN[i];
  2540. }
  2541. if (SN.Length < 16)
  2542. {
  2543. SNArray[SN.Length] = (byte)'.';
  2544. for (ushort i = 0; i < 16 - SN.Length - 1; i++)
  2545. {
  2546. SNArray[SN.Length + 1 + i] = 0x20;
  2547. }
  2548. }
  2549. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
  2550. }
  2551. //系统复位
  2552. private void button_Reset_Click(object sender, EventArgs e)
  2553. {
  2554. var Code = new byte[5];
  2555. Code[0] = (byte)'R';
  2556. Code[1] = (byte)'E';
  2557. Code[2] = (byte)'S';
  2558. Code[3] = (byte)'E';
  2559. Code[4] = (byte)'T';
  2560. timer1.Enabled = false;
  2561. if (MessageBox.Show("系统将重启", "确认重启?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  2562. {
  2563. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
  2564. }
  2565. timer1.Enabled = true;
  2566. }
  2567. private void button_RefreshPort_Click(object sender, EventArgs e)
  2568. {
  2569. string[] ports = SerialPort.GetPortNames();
  2570. Array.Sort(ports);
  2571. comboBox_ComIndex.Items.Clear();
  2572. comboBox_ComIndex.Items.AddRange(ports);
  2573. comboBox_ComIndex.SelectedIndex = comboBox_ComIndex.Items.Count > 0 ? 0 : -1;
  2574. }
  2575. private void checkBox_AutoSend_CheckedChanged(object sender, EventArgs e)
  2576. {
  2577. if (checkBox_AutoSend.Checked == false)
  2578. {
  2579. radioButton_Gear_ECO.Enabled = true;
  2580. radioButton_Gear_NORM.Enabled = true;
  2581. radioButton_Gear_SPORT.Enabled = true;
  2582. radioButton_Gear_TURBO.Enabled = true;
  2583. radioButton_Gear_WALK.Enabled = true;
  2584. radioButton_Gear_SMART.Enabled = true;
  2585. radioButton_Gear_OFF.Enabled = true;
  2586. }
  2587. else
  2588. {
  2589. radioButton_Gear_ECO.Enabled = false;
  2590. radioButton_Gear_NORM.Enabled = false;
  2591. radioButton_Gear_SPORT.Enabled = false;
  2592. radioButton_Gear_TURBO.Enabled = false;
  2593. radioButton_Gear_WALK.Enabled = false;
  2594. radioButton_Gear_SMART.Enabled = false;
  2595. radioButton_Gear_OFF.Enabled = false;
  2596. }
  2597. }
  2598. private void button_Read_Config_Ext_Click(object sender, EventArgs e)
  2599. {
  2600. MC_Config_Ext_Clear();
  2601. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3000, null);
  2602. }
  2603. private void button_Write_Config_Ext_Click(object sender, EventArgs e)
  2604. {
  2605. var ConfigParam = new byte[32];
  2606. for (int i = 0; i < 32; i++)
  2607. ConfigParam[i] = 0;
  2608. short DataTemp_Int16;
  2609. ushort DataTemp;
  2610. //俯仰角零偏
  2611. DataTemp_Int16 = (short)(decimal.Parse(textBox_Config_Angle_Pitch.Text) * 10);
  2612. ConfigParam[0] = (byte)(DataTemp_Int16 & 0xFF);
  2613. ConfigParam[1] = (byte)(DataTemp_Int16 >> 8);
  2614. //横滚角零偏
  2615. DataTemp_Int16 = (short)(decimal.Parse(textBox_Config_Angle_Roll.Text) * 10);
  2616. ConfigParam[2] = (byte)(DataTemp_Int16 & 0xFF);
  2617. ConfigParam[3] = (byte)(DataTemp_Int16 >> 8);
  2618. //支持姿态传感器
  2619. if (comboBox_AttiSensor.Text == "支持")
  2620. ConfigParam[4] = 0xAA;
  2621. else
  2622. ConfigParam[4] = 0x55;
  2623. //前灯模式
  2624. if (comboBox_FrontLightMode.Text == "模式1")
  2625. {
  2626. ConfigParam[5] = 0x10;
  2627. }
  2628. else if (comboBox_FrontLightMode.Text == "模式2")
  2629. {
  2630. ConfigParam[5] = 0x20;
  2631. }
  2632. else
  2633. {
  2634. ConfigParam[5] = 0x20;
  2635. }
  2636. //尾灯模式
  2637. if (comboBox_TailLightMode.Text == "模式1")
  2638. {
  2639. ConfigParam[5] |= 0x01;
  2640. }
  2641. else if (comboBox_TailLightMode.Text == "模式2")
  2642. {
  2643. ConfigParam[5] |= 0x02;
  2644. }
  2645. else if (comboBox_TailLightMode.Text == "模式3")
  2646. {
  2647. ConfigParam[5] |= 0x03;
  2648. }
  2649. else if (comboBox_TailLightMode.Text == "模式4")
  2650. {
  2651. ConfigParam[5] |= 0x04;
  2652. }
  2653. else if (comboBox_TailLightMode.Text == "模式5")
  2654. {
  2655. ConfigParam[5] |= 0x05;
  2656. }
  2657. else if (comboBox_TailLightMode.Text == "模式6")
  2658. {
  2659. ConfigParam[5] |= 0x06;
  2660. }
  2661. else
  2662. ConfigParam[5] |= 0x02;
  2663. //前灯电压
  2664. if (comboBox_FrontLigthVol.Text == "6V")
  2665. ConfigParam[6] = 0x06;
  2666. else if (comboBox_FrontLigthVol.Text == "12V")
  2667. ConfigParam[6] = 0x0C;
  2668. else if (comboBox_FrontLigthVol.Text == "随电池")
  2669. ConfigParam[6] = 0xFF;
  2670. else
  2671. ConfigParam[6] = 0x00;
  2672. //尾灯电压
  2673. if (comboBox_TailLightVol.Text == "6V")
  2674. ConfigParam[7] = 0x06;
  2675. else if (comboBox_TailLightVol.Text == "12V")
  2676. ConfigParam[7] = 0x0C;
  2677. else if (comboBox_TailLightVol.Text == "随电池")
  2678. ConfigParam[7] = 0xFF;
  2679. else
  2680. ConfigParam[7] = 0x00;
  2681. //超速报警阈值
  2682. DataTemp = (ushort)(decimal.Parse(textBox_Config_SpeedAlarm.Text) * 10);
  2683. ConfigParam[8] = (byte)(DataTemp & 0xFF);
  2684. ConfigParam[9] = (byte)(DataTemp >> 8);
  2685. //尾灯脉宽
  2686. DataTemp = Convert.ToUInt16(textBox_Config_Pulse.Text);
  2687. ConfigParam[10] = (byte)(DataTemp & 0xFF);
  2688. ConfigParam[11] = (byte)(DataTemp >> 8);
  2689. //尾灯周期
  2690. DataTemp = Convert.ToUInt16(textBox_Config_Period.Text);
  2691. ConfigParam[12] = (byte)(DataTemp & 0xFF);
  2692. ConfigParam[13] = (byte)(DataTemp >> 8);
  2693. //起始限速
  2694. DataTemp_Int16 = (short)(decimal.Parse(textBox_Config_SpeedlimitStart.Text) * 10);
  2695. ConfigParam[14] = (byte)(DataTemp_Int16 & 0xFF);
  2696. //结束限速
  2697. DataTemp_Int16 = (short)(decimal.Parse(textBox_Config_SpeedlimitStop.Text) * 10);
  2698. ConfigParam[15] = (byte)(DataTemp_Int16 & 0xFF);
  2699. //限速微调
  2700. ConfigParam[16] = (byte)Convert.ToInt16(textBox_Config_SpeedlimitAdj.Text);
  2701. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3120, ConfigParam);
  2702. }
  2703. private void button_Read_AttitudeAngle_Click(object sender, EventArgs e)
  2704. {
  2705. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2F00, null);
  2706. MC_AttitudeAngle_Clear();
  2707. }
  2708. private void button_Read_RidedInfo_Click(object sender, EventArgs e)
  2709. {
  2710. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2E00, null);
  2711. MC_RideInfo_Clear();
  2712. }
  2713. private void button_ReadRunLog_Click(object sender, EventArgs e)
  2714. {
  2715. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
  2716. MC_RunLog_Clear();
  2717. }
  2718. private void timer2_Tick(object sender, EventArgs e)
  2719. {
  2720. //定时显示系统时钟
  2721. label_DateTime.Text = DateTime.Now.ToString();
  2722. //定时读取存储器
  2723. if (checkBox_DebugAuto.Checked == true)
  2724. {
  2725. var Address = new byte[4];
  2726. UInt32 Address_Begin;
  2727. UInt32 Addres_End;
  2728. if (!serialPort1.IsOpen)
  2729. {
  2730. checkBox_DebugAuto.Checked = false;
  2731. return;
  2732. }
  2733. if (checkBox_DebugReset.Checked == true)
  2734. richTextBox_DebugInfo.Clear();
  2735. do
  2736. {
  2737. if ((textBox_DebugAddrBegin.Text == string.Empty) || (textBox_DebugAddrEnd.Text == string.Empty))
  2738. {
  2739. checkBox_DebugAuto.Checked = false;
  2740. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2741. continue;
  2742. }
  2743. else if ((textBox_DebugAddrBegin.Text.Length != 8) || (textBox_DebugAddrEnd.Text.Length != 8))
  2744. {
  2745. checkBox_DebugAuto.Checked = false;
  2746. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2747. continue;
  2748. }
  2749. else
  2750. {
  2751. Address = HexStringToBytes(textBox_DebugAddrBegin.Text, false);
  2752. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2753. Address = HexStringToBytes(textBox_DebugAddrEnd.Text, false);
  2754. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  2755. if (Addres_End < Address_Begin)
  2756. {
  2757. checkBox_DebugAuto.Checked = false;
  2758. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2759. continue;
  2760. }
  2761. else
  2762. {
  2763. var SendByte = new byte[8];
  2764. SendByte[0] = (byte)(Address_Begin >> 24);
  2765. SendByte[1] = (byte)(Address_Begin >> 16);
  2766. SendByte[2] = (byte)(Address_Begin >> 8);
  2767. SendByte[3] = (byte)(Address_Begin);
  2768. SendByte[4] = (byte)(Addres_End >> 24);
  2769. SendByte[5] = (byte)(Addres_End >> 16);
  2770. SendByte[6] = (byte)(Addres_End >> 8);
  2771. SendByte[7] = (byte)(Addres_End);
  2772. if (!SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte))
  2773. checkBox_DebugAuto.Checked = false;
  2774. }
  2775. }
  2776. } while (false);
  2777. }
  2778. }
  2779. private void checkBox_ReadTorqueData_CheckedChanged(object sender, EventArgs e)
  2780. {
  2781. if (checkBox_ReadTorqueData.Checked == true)
  2782. {
  2783. #if true
  2784. foreach (Control c in tabPage1.Controls)
  2785. {
  2786. if (c is TextBox)
  2787. {
  2788. if ((c != textBox_RunInfo_Range) && (c != textBox_RunInfo_ErrorCode))
  2789. {
  2790. if ((c.Text == string.Empty) || (c.Text == "---"))
  2791. {
  2792. timer1.Enabled = false;
  2793. MessageBox.Show("请确认进入配置模式!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2794. timer1.Enabled = true;
  2795. checkBox_Savedata.Checked = false;
  2796. checkBox_ReadTorqueData.Checked = false;
  2797. return;
  2798. }
  2799. else
  2800. {
  2801. LoginForm.Show();
  2802. }
  2803. }
  2804. }
  2805. }
  2806. #else
  2807. if (radioButton_WorkMode_Confg.Checked == false)
  2808. {
  2809. timer1.Enabled = false;
  2810. MessageBox.Show("请确认进入配置模式", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2811. timer1.Enabled = true;
  2812. checkBox_ReadTorqueData.Checked = false;
  2813. }
  2814. else
  2815. {
  2816. LoginForm.Show();
  2817. }
  2818. #endif
  2819. }
  2820. else
  2821. {
  2822. LoginForm.Hide();
  2823. }
  2824. }
  2825. private void checkBox_Savedata_CheckedChanged(object sender, EventArgs e)
  2826. {
  2827. if (checkBox_Savedata.Checked == true)
  2828. {
  2829. //判断是否显示运行信息
  2830. foreach (Control c in tabPage1.Controls)
  2831. {
  2832. if (c is TextBox)
  2833. {
  2834. if ((c != textBox_RunInfo_Range) && (c != textBox_RunInfo_ErrorCode))
  2835. {
  2836. if ((c.Text == string.Empty) || (c.Text == "---"))
  2837. {
  2838. timer1.Enabled = false;
  2839. MessageBox.Show("请设置电机进入配置模式!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2840. timer1.Enabled = true;
  2841. checkBox_Savedata.Checked = false;
  2842. return;
  2843. }
  2844. }
  2845. }
  2846. }
  2847. //判断是否查询版本信息
  2848. foreach (Control c in groupBox9.Controls)
  2849. {
  2850. if (c is TextBox)
  2851. {
  2852. if ((c.Text == string.Empty) || (c.Text == "---"))
  2853. {
  2854. if ((c == textBox_Mode) || (c == textBox_SN))
  2855. {
  2856. timer1.Enabled = false;
  2857. MessageBox.Show("请查询版本信息!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2858. timer1.Enabled = true;
  2859. checkBox_Savedata.Checked = false;
  2860. return;
  2861. }
  2862. }
  2863. }
  2864. }
  2865. AutoSaveFileName = textBox_Mode.Text + "_" + textBox_SN.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_实时数据" + ".txt"; ;
  2866. timer1.Enabled = false;
  2867. MessageBox.Show("开始记录数据!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2868. timer1.Enabled = true;
  2869. }
  2870. else
  2871. {
  2872. AutoSaveFileName = "";
  2873. timer1.Enabled = false;
  2874. MessageBox.Show("停止记录数据!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2875. timer1.Enabled = true;
  2876. }
  2877. }
  2878. private void DateAutoSave()
  2879. {
  2880. if (checkBox_Savedata.Checked == true)
  2881. {
  2882. if (AutoSaveFileName == string.Empty)
  2883. {
  2884. return;
  2885. }
  2886. string SaveData = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace(" ", "_")+" ";
  2887. foreach (Control c in tabPage1.Controls)
  2888. {
  2889. if (c is TextBox)
  2890. {
  2891. SaveData += c.Text + " , ";
  2892. }
  2893. }
  2894. SaveData += "\r\n";
  2895. System.IO.File.AppendAllText(AutoSaveFileName, SaveData);//sb.ToString());
  2896. }
  2897. }
  2898. private void button_DataExport_Click(object sender, EventArgs e)
  2899. {
  2900. //增加控件查空处理,存在没有数据时提示
  2901. //判断是否查询力矩传感器
  2902. foreach (Control c in groupBox2.Controls)
  2903. {
  2904. if (c is TextBox)
  2905. {
  2906. if ((c != textBox_TorqueData) && (c != textBox_Torque_Stdev))
  2907. {
  2908. if ((c.Text == string.Empty) || (c.Text == "---"))
  2909. {
  2910. timer1.Enabled = false;
  2911. MessageBox.Show("请查询力矩传感器!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2912. timer1.Enabled = true;
  2913. return;
  2914. }
  2915. }
  2916. }
  2917. }
  2918. //判断是否显示运行信息
  2919. foreach (Control c in tabPage1.Controls)
  2920. {
  2921. if (c is TextBox)
  2922. {
  2923. if ((c != textBox_RunInfo_Range) && (c != textBox_RunInfo_ErrorCode))
  2924. {
  2925. if ((c.Text == string.Empty) || (c.Text == "---"))
  2926. {
  2927. timer1.Enabled = false;
  2928. MessageBox.Show("请设置电机进入配置模式!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2929. timer1.Enabled = true;
  2930. return;
  2931. }
  2932. }
  2933. }
  2934. }
  2935. //判断是否查询用户参数1
  2936. foreach (Control c in groupBox10.Controls)
  2937. {
  2938. if (c is TextBox)
  2939. {
  2940. if (c.Text == string.Empty)
  2941. {
  2942. timer1.Enabled = false;
  2943. MessageBox.Show("请查询用户参数1!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2944. timer1.Enabled = true;
  2945. return;
  2946. }
  2947. }
  2948. }
  2949. //判断是否查询用户参数2
  2950. foreach (Control c in groupBox4.Controls)
  2951. {
  2952. if (c is TextBox)
  2953. {
  2954. if (c.Text == string.Empty)
  2955. {
  2956. timer1.Enabled = false;
  2957. MessageBox.Show("请查询用户参数2!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2958. timer1.Enabled = true;
  2959. return;
  2960. }
  2961. }
  2962. }
  2963. #if false
  2964. //判断是否显示骑行信息
  2965. foreach (Control c in groupBox12.Controls)
  2966. {
  2967. if (c is TextBox)
  2968. {
  2969. if ((c.Text == string.Empty) || (c.Text == "---"))
  2970. {
  2971. timer1.Enabled = false;
  2972. MessageBox.Show("请自动查询骑行信息!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2973. timer1.Enabled = true;
  2974. return;
  2975. }
  2976. }
  2977. }
  2978. #endif
  2979. #if false
  2980. //判断是否查询姿态信息
  2981. foreach (Control c in groupBox13.Controls)
  2982. {
  2983. if (c is TextBox)
  2984. {
  2985. if ((c.Text == string.Empty) || (c.Text == "---"))
  2986. {
  2987. timer1.Enabled = false;
  2988. MessageBox.Show("请自动查询姿态信息!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2989. timer1.Enabled = true;
  2990. return;
  2991. }
  2992. }
  2993. }
  2994. #endif
  2995. //判断是否查询马达参数信息
  2996. foreach (Control c in groupBox11.Controls)
  2997. {
  2998. if (c is TextBox)
  2999. {
  3000. if ((c.Text == string.Empty) || (c.Text == "---"))
  3001. {
  3002. timer1.Enabled = false;
  3003. MessageBox.Show("请查询马达参数!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3004. timer1.Enabled = true ;
  3005. return;
  3006. }
  3007. }
  3008. }
  3009. //判断是否查询版本信息
  3010. foreach (Control c in groupBox9.Controls)
  3011. {
  3012. if (c is TextBox)
  3013. {
  3014. if ((c.Text == string.Empty) || (c.Text == "---"))
  3015. {
  3016. if (c == textBox_TE_FW)//忽略TE版本和软件标识
  3017. {
  3018. continue;
  3019. }
  3020. else
  3021. {
  3022. timer1.Enabled = false;
  3023. MessageBox.Show("请查询版本信息!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3024. timer1.Enabled = true;
  3025. return;
  3026. }
  3027. }
  3028. }
  3029. }
  3030. //判断是否查询历史信息
  3031. foreach (Control c in groupBox14.Controls)
  3032. {
  3033. if (c is TextBox)
  3034. {
  3035. if ((c.Text == string.Empty) || (c.Text == "---"))
  3036. {
  3037. timer1.Enabled = false;
  3038. MessageBox.Show("请查询历史信息!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3039. timer1.Enabled = true;
  3040. return;
  3041. }
  3042. }
  3043. }
  3044. //...
  3045. Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
  3046. Graphics g = Graphics.FromImage(bit);
  3047. g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片
  3048. SaveFileDialog sf = new SaveFileDialog();
  3049. sf.Title = "数据保存";
  3050. sf.FileName = textBox_Mode.Text + "_" + textBox_SN.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_页面存储" + ".png";
  3051. sf.Filter = "图片|*.png";
  3052. if (sf.ShowDialog() == DialogResult.OK)
  3053. {
  3054. bit.Save(sf.FileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
  3055. }
  3056. }
  3057. private void Form1_FormClosed(object sender, FormClosedEventArgs e)
  3058. {
  3059. }
  3060. private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  3061. {
  3062. timer1.Enabled = false;
  3063. DialogResult result = MessageBox.Show("确定关闭吗!", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
  3064. if (result == DialogResult.OK)
  3065. {
  3066. if (serialPort1.IsOpen == true)
  3067. {
  3068. //发送指令退出配置模式
  3069. var RunMode = new byte[1];
  3070. RunMode[0] = 0x00;
  3071. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, RunMode);
  3072. serialPort1.Close();
  3073. myCapture.Dispose();
  3074. }
  3075. e.Cancel = false; //点击OK
  3076. }
  3077. else
  3078. {
  3079. e.Cancel = true;
  3080. timer1.Enabled = true;
  3081. }
  3082. }
  3083. private void trackBar_MotorSpeedSet_Scroll(object sender, EventArgs e)
  3084. {
  3085. var Data = new byte[1];
  3086. label_MotorSpeedSet.Text = Convert.ToString(trackBar_MotorSpeedSet.Value) + "%";
  3087. Data[0] = (byte)trackBar_MotorSpeedSet.Value;
  3088. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2C01, Data);
  3089. }
  3090. private void button_Recovery_Click(object sender, EventArgs e)
  3091. {
  3092. var Code = new byte[8];
  3093. Code[0] = (byte)'R';
  3094. Code[1] = (byte)'E';
  3095. Code[2] = (byte)'C';
  3096. Code[3] = (byte)'O';
  3097. Code[4] = (byte)'V';
  3098. Code[5] = (byte)'E';
  3099. Code[6] = (byte)'R';
  3100. Code[7] = (byte)'Y';
  3101. timer1.Enabled = false;
  3102. if (MessageBox.Show("参数还原后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3103. {
  3104. if (MessageBox.Show("请再次确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3105. {
  3106. if (MessageBox.Show("请最后确认", "确认还原?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3107. {
  3108. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2708, Code);
  3109. }
  3110. }
  3111. }
  3112. timer1.Enabled = true;
  3113. }
  3114. #region 字符串转换为字节流
  3115. public static byte[] HexStringToBytes(string hexStr, bool Flag_Space)
  3116. {
  3117. if (string.IsNullOrEmpty(hexStr))
  3118. {
  3119. return new byte[0];
  3120. }
  3121. if (hexStr.StartsWith("0x"))
  3122. {
  3123. hexStr = hexStr.Remove(0, 2);
  3124. }
  3125. var count = hexStr.Length;
  3126. var byteCount = 0;
  3127. if (Flag_Space == true)//相邻字节含空格
  3128. {
  3129. if ((count % 3) == 0)//最后字节含空格
  3130. {
  3131. byteCount = count / 3;
  3132. }
  3133. else if ((count % 3) == 2)//最后字节不含空格
  3134. {
  3135. byteCount = (count + 1) / 3;
  3136. }
  3137. else//数据无效
  3138. {
  3139. MessageBox.Show("相邻字节请插入空格!", "提示");
  3140. }
  3141. var result = new byte[byteCount];
  3142. for (int ii = 0; ii < byteCount; ++ii)
  3143. {
  3144. var tempBytes = Byte.Parse(hexStr.Substring(3 * ii, 2), System.Globalization.NumberStyles.HexNumber);
  3145. result[ii] = tempBytes;
  3146. }
  3147. return result;
  3148. }
  3149. else if (Flag_Space == false)//相邻字节不含空格
  3150. {
  3151. if (count % 2 == 1)
  3152. {
  3153. MessageBox.Show("请删除相邻字节之间空格!", "提示");
  3154. }
  3155. byteCount = count / 2;
  3156. var result = new byte[byteCount];
  3157. for (int ii = 0; ii < byteCount; ++ii)
  3158. {
  3159. var tempBytes = Byte.Parse(hexStr.Substring(2 * ii, 2), System.Globalization.NumberStyles.HexNumber);
  3160. result[ii] = tempBytes;
  3161. }
  3162. return result;
  3163. }
  3164. else
  3165. {
  3166. return new byte[0];
  3167. }
  3168. }
  3169. #endregion
  3170. #region 故障日志结构体定义
  3171. //故障日志记录信息 60 bytes,1K空间可以保存最近16条故障记录
  3172. [StructLayout(LayoutKind.Sequential)]
  3173. public struct MC_ErrorLogSaveInfo_Struct_t
  3174. {
  3175. public UInt16 Error_Index; //故障列表索引 2 bytes, 地址偏移 0
  3176. public UInt16 NotesInfo1; //备注信息1,地址偏移 2
  3177. public UInt16 NotesInfo2; //备注信息2,地址偏移 4
  3178. public UInt16 NotesInfo3; //备注信息3,地址偏移 6
  3179. public UInt32 ErrorCode; //故障码 4 bytes, 地址偏移 8
  3180. public UInt32 RunTime; //运行时间 4bytes, 地址偏移 12
  3181. //电机运行信息,占用空间32bytes
  3182. [StructLayout(LayoutKind.Sequential)]
  3183. public struct MC_RunInfo_Struct_t
  3184. {
  3185. public ushort BikeSpeed; //车速 0.1km/h,地址偏移0
  3186. public ushort MotorSpeed; //输出转速 1rpm,地址偏移2
  3187. public ushort Power; //电功率 1W,地址偏移4
  3188. public ushort BusVoltage; //母线电压 1mV,地址偏移6
  3189. public ushort BusCurrent; //母线电流 1mA,地址偏移8
  3190. public byte Cadence; //踏频 1rpm,地址偏移10
  3191. public byte Torque; //踩踏力矩 1Nm,地址偏移11
  3192. public byte CadenceDir; //踩踏方向 0-正,1-反,2-停止,地址偏移12
  3193. public byte GearSt; //助力档位,地址偏移13
  3194. public byte LightSwitch; //灯开关 0xF0-关,0xF1-开,地址偏移14
  3195. public byte SOC; //剩余电量 1%,地址偏移15
  3196. public ushort RemainDistance; //续航里程 1km,地址偏移16
  3197. public ushort ODO_Km; //总里程 1km,地址偏移18
  3198. public byte PowerPerKm; //平均功耗 0.01Ah/km ,地址偏移20
  3199. public byte T_PCB; //PCB温度 +40℃,地址偏移21
  3200. public byte T_Coil; //绕组温度 +40℃,地址偏移22
  3201. public byte T_MCU; //MCU温度 +40℃,地址偏移23
  3202. public ushort Ride_Km; //开机后骑行里程 0.1km, 地址偏移24
  3203. public ushort Ride_Time; //开机后骑行时间 1s,地址偏移26
  3204. public UInt32 RS; //预留 4bytes
  3205. };
  3206. [MarshalAs(UnmanagedType.Struct)]
  3207. public MC_RunInfo_Struct_t RunInfo; //运行信息 32bytes, 地址偏移 16
  3208. //姿态传感器数值
  3209. [StructLayout(LayoutKind.Sequential)]
  3210. public struct MC_AttitudeAngle_Struct_t
  3211. {
  3212. public Int16 Angle_Pitch_Absolute; //俯仰角绝对角度
  3213. public Int16 Angle_Roll_Absolute; //横滚角绝对角度
  3214. public Int16 Angle_Pitch_Relative; //俯仰角相对角度
  3215. public Int16 Angle_Roll_Relative; //横滚角相对角度
  3216. };
  3217. [MarshalAs(UnmanagedType.Struct)]
  3218. public MC_AttitudeAngle_Struct_t AttitudeAngle; //车辆姿态角度 8bytes, 地址偏移 48
  3219. //电机控制参数
  3220. [StructLayout(LayoutKind.Sequential)]
  3221. public struct MC_CalParam_Struct_t
  3222. {
  3223. public byte AssistRunMode; //助力模式
  3224. public Int16 Ref_Torque; //力矩模式输入FOC值
  3225. public Int16 Ref_Speed; //速度模式输入FOC值
  3226. public byte Foc_Flag; //FCO运算标志
  3227. };
  3228. [MarshalAs(UnmanagedType.Struct)]
  3229. public MC_CalParam_Struct_t MC_CalParam; //马达控制参数 8bytes , 地址偏移 56
  3230. };
  3231. #endregion
  3232. public static class MyConverter
  3233. {
  3234. /// <summary>
  3235. /// 由结构体转换为byte数组
  3236. /// </summary>
  3237. public static byte[] StructureToByte<T>(T structure)
  3238. {
  3239. int size = Marshal.SizeOf(typeof(T));
  3240. byte[] buffer = new byte[size];
  3241. IntPtr bufferIntPtr = Marshal.AllocHGlobal(size);
  3242. try
  3243. {
  3244. Marshal.StructureToPtr(structure, bufferIntPtr, true);
  3245. Marshal.Copy(bufferIntPtr, buffer, 0, size);
  3246. }
  3247. finally
  3248. {
  3249. Marshal.FreeHGlobal(bufferIntPtr);
  3250. }
  3251. return buffer;
  3252. }
  3253. /// <summary>
  3254. /// 由byte数组转换为结构体
  3255. /// </summary>
  3256. public static T ByteToStructure<T>(byte[] dataBuffer, ushort StarIndex)
  3257. {
  3258. object structure = null;
  3259. int size = Marshal.SizeOf(typeof(T));
  3260. IntPtr allocIntPtr = Marshal.AllocHGlobal(size);
  3261. try
  3262. {
  3263. Marshal.Copy(dataBuffer, StarIndex, allocIntPtr, size);
  3264. structure = Marshal.PtrToStructure(allocIntPtr, typeof(T));
  3265. }
  3266. finally
  3267. {
  3268. Marshal.FreeHGlobal(allocIntPtr);
  3269. }
  3270. return (T)structure;
  3271. }
  3272. }
  3273. private void button_ReadErrorLog_Click(object sender, EventArgs e)
  3274. {
  3275. var Address = new byte[4];
  3276. UInt32 Address_Begin;
  3277. UInt32 Addres_End;
  3278. string textBox_Address_Begin = "0801F000";
  3279. string textBox_Address_End = "0801F3FF";
  3280. if (!serialPort1.IsOpen)
  3281. {
  3282. timer1.Enabled = false;
  3283. MessageBox.Show("串口未连接");
  3284. timer1.Enabled = true;
  3285. return;
  3286. }
  3287. if ((textBox_Address_Begin == string.Empty) || (textBox_Address_End == string.Empty))
  3288. {
  3289. timer1.Enabled = false;
  3290. MessageBox.Show("请输入地址!", "提示");
  3291. timer1.Enabled = true;
  3292. return;
  3293. }
  3294. else
  3295. {
  3296. Address = HexStringToBytes(textBox_Address_Begin, false);
  3297. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3298. Address = HexStringToBytes(textBox_Address_End, false);
  3299. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3300. if (Addres_End <= Address_Begin)
  3301. {
  3302. timer1.Enabled = false;
  3303. MessageBox.Show("结束地址应大于起始地址!", "提示");
  3304. timer1.Enabled = true;
  3305. return;
  3306. }
  3307. else if (((Addres_End - Address_Begin + 1) % 128) != 0) //
  3308. {
  3309. timer1.Enabled = false;
  3310. MessageBox.Show("(结束地址 - 起始地址 + 1)应为128整数倍!", "提示");
  3311. timer1.Enabled = true;
  3312. return;
  3313. }
  3314. else
  3315. {
  3316. button_ReadErrorLog.Text = "读取中";
  3317. button_ReadErrorLog.Enabled = false;
  3318. //设置保存路经
  3319. SaveFileDialog saveFileDialog1 = new SaveFileDialog();
  3320. saveFileDialog1.Title = "设置保存路经";
  3321. saveFileDialog1.RestoreDirectory = true;
  3322. saveFileDialog1.Filter = "文本文件(*.txt)|*.txt";
  3323. if (((textBox_Mode.Text == string.Empty) || (textBox_Mode.Text == "---")) && ((textBox_SN.Text == string.Empty) || (textBox_SN.Text == "---")))
  3324. {
  3325. timer1.Enabled = false;
  3326. MessageBox.Show("未查询电机版本信息!", "提示");
  3327. timer1.Enabled = true;
  3328. saveFileDialog1.FileName = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_故障日志"; ;
  3329. }
  3330. else
  3331. {
  3332. saveFileDialog1.FileName = textBox_Mode.Text + "_" + textBox_SN.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_故障日志";
  3333. }
  3334. if (saveFileDialog1.ShowDialog() == DialogResult.OK)
  3335. {
  3336. ErrorLogSaveFileName = saveFileDialog1.FileName.ToString();
  3337. }
  3338. else
  3339. {
  3340. button_ReadErrorLog.Enabled = true;
  3341. button_ReadErrorLog.Text = "读取";
  3342. return;
  3343. }
  3344. string SaveInfo = "读取时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  3345. SaveInfo += "电机型号:" + textBox_Mode.Text + "\r\n";
  3346. SaveInfo += "序列号:" + textBox_SN.Text + "\r\n";
  3347. SaveInfo += "硬件版本:" + textBox_HW.Text + "\r\n";
  3348. SaveInfo += "软件版本:" + textBox_FW.Text + "\r\n";
  3349. SaveInfo += "TE软件版本:" + textBox_TE_FW.Text + "\r\n\r\n";
  3350. System.IO.File.WriteAllText(ErrorLogSaveFileName, SaveInfo + "无日志记录");
  3351. ErrorLogSaveFlag = false;
  3352. UInt32 ReadCount = 0;
  3353. ReadCount = (Addres_End - Address_Begin + 1) / 128;
  3354. for (ushort i = 0; i < ReadCount; i++)
  3355. {
  3356. var SendByte = new byte[8];
  3357. UInt32 Address_Temp_Begin;
  3358. UInt32 Address_Temp_End;
  3359. Address_Temp_Begin = Address_Begin + 128 * (UInt32)i;
  3360. SendByte[0] = (byte)(Address_Temp_Begin >> 24);
  3361. SendByte[1] = (byte)(Address_Temp_Begin >> 16);
  3362. SendByte[2] = (byte)(Address_Temp_Begin >> 8);
  3363. SendByte[3] = (byte)(Address_Temp_Begin);
  3364. Address_Temp_End = Address_Temp_Begin + 127;
  3365. SendByte[4] = (byte)(Address_Temp_End >> 24);
  3366. SendByte[5] = (byte)(Address_Temp_End >> 16);
  3367. SendByte[6] = (byte)(Address_Temp_End >> 8);
  3368. SendByte[7] = (byte)(Address_Temp_End);
  3369. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  3370. Thread.Sleep(200);
  3371. }
  3372. timer1.Enabled = false;
  3373. MessageBox.Show("读取完成,请查看日志!", "提示");
  3374. timer1.Enabled = true;
  3375. button_ReadErrorLog.Enabled = true;
  3376. button_ReadErrorLog.Text = "读取";
  3377. }
  3378. }
  3379. }
  3380. private void ErrorLogDateSave(MC_ErrorLogSaveInfo_Struct_t Log1, MC_ErrorLogSaveInfo_Struct_t Log2)
  3381. {
  3382. if (ErrorLogSaveFileName.Substring(ErrorLogSaveFileName.Length - 4, 4) != ".txt")
  3383. {
  3384. timer1.Enabled = false;
  3385. MessageBox.Show("日志存储失败!", "提示");
  3386. timer1.Enabled = true;
  3387. return;
  3388. }
  3389. string SaveData = "";
  3390. //Log1
  3391. if (Log1.Error_Index != 0xFFFF)
  3392. {
  3393. if (ErrorLogSaveFlag == false)
  3394. {
  3395. ErrorLogSaveFlag = true;
  3396. string SaveInfo = "读取时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  3397. SaveInfo += "电机型号:" + textBox_Mode.Text + "\r\n";
  3398. SaveInfo += "序列号:" + textBox_SN.Text + "\r\n";
  3399. SaveInfo += "硬件版本:" + textBox_HW.Text + "\r\n";
  3400. SaveInfo += "软件版本:" + textBox_FW.Text + "\r\n";
  3401. SaveInfo += "TE软件版本:" + textBox_TE_FW.Text + "\r\n\r\n";
  3402. System.IO.File.WriteAllText(ErrorLogSaveFileName, SaveInfo);
  3403. }
  3404. SaveData += "故障序号:" + Convert.ToString(Log1.Error_Index) + ", ";
  3405. SaveData += "备注1:" + Convert.ToString(Log1.NotesInfo1) + ", ";
  3406. SaveData += "备注2:" + Convert.ToString(Log1.NotesInfo2) + ", ";
  3407. SaveData += "备注3:" + Convert.ToString(Log1.NotesInfo3) + ", ";
  3408. SaveData += "故障码:" + "0x" + Convert.ToString(Log1.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  3409. SaveData += "运行时间:" + Convert.ToString(Log1.RunTime) + "min" + ", ";
  3410. SaveData += "车速:" + ((float)Log1.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  3411. SaveData += "电机转速:" + Convert.ToString(Log1.RunInfo.MotorSpeed) + "rpm" + ", ";
  3412. SaveData += "功率:" + Convert.ToString(Log1.RunInfo.Power * 2) + "w" + ", ";
  3413. SaveData += "电压:" + Convert.ToString(Log1.RunInfo.BusVoltage) + "mV" + ", ";
  3414. SaveData += "电流:" + Convert.ToString(Log1.RunInfo.BusCurrent) + "mA" + ", ";
  3415. SaveData += "踏频:" + Convert.ToString(Log1.RunInfo.Cadence) + "rpm" + ", ";
  3416. SaveData += "力矩:" + Convert.ToString(Log1.RunInfo.Torque) + "N.m" + ", ";
  3417. SaveData += "方向:" + ((Log1.RunInfo.CadenceDir == 0) ? "正" : ((Log1.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  3418. SaveData += "档位:" + "0x" + Convert.ToString(Log1.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  3419. SaveData += "灯开关:" + ((Log1.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  3420. SaveData += "电量:" + Convert.ToString(Log1.RunInfo.SOC) + "%" + ", ";
  3421. if ((Log1.RunInfo.RemainDistance == 0xEEEE) || (Log1.RunInfo.RemainDistance == 0xFFFF))
  3422. {
  3423. SaveData += "续航:" + "---km" + ", ";
  3424. }
  3425. else
  3426. {
  3427. SaveData += "续航:" + Convert.ToString(Log1.RunInfo.RemainDistance) + "km" + ", ";
  3428. }
  3429. SaveData += "总里程:" + Convert.ToString(Log1.RunInfo.ODO_Km) + "km" + ", ";
  3430. SaveData += "功耗:" + Convert.ToString(Log1.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  3431. SaveData += "PCB温度:" + Convert.ToString((int)(Log1.RunInfo.T_PCB - 40)) + "DegreeC" + ", ";
  3432. SaveData += "绕组温度:" + Convert.ToString((int)(Log1.RunInfo.T_Coil - 40)) + "DegreeC" + ", ";
  3433. SaveData += "MCU温度:" + Convert.ToString((int)(Log1.RunInfo.T_MCU - 40)) + "DegreeC" + ", ";
  3434. SaveData += "单次里程:" + Convert.ToString((float)Log1.RunInfo.Ride_Km / 10f) + "km" + ", ";
  3435. SaveData += "单次时间:" + Convert.ToString(Log1.RunInfo.Ride_Time) + "s" + ", ";
  3436. SaveData += "俯仰绝对角度:" + ((float)Log1.AttitudeAngle.Angle_Pitch_Absolute / 10f).ToString("0.0") + "Degree" + ", ";
  3437. SaveData += "横滚绝对角度:" + ((float)Log1.AttitudeAngle.Angle_Roll_Absolute / 10f).ToString("0.0") + "Degree" + ", ";
  3438. SaveData += "俯仰相对角度:" + ((float)Log1.AttitudeAngle.Angle_Pitch_Relative / 10f).ToString("0.0") + "Degree" + ", ";
  3439. SaveData += "横滚相对角度:" + ((float)Log1.AttitudeAngle.Angle_Roll_Relative / 10f).ToString("0.0") + "Degree" + ", ";
  3440. SaveData += "运行模式:" + Convert.ToString(Log1.MC_CalParam.AssistRunMode) + ", ";
  3441. SaveData += "力矩环给定:" + Convert.ToString(Log1.MC_CalParam.Ref_Torque) + ", ";
  3442. SaveData += "速度环给定:" + Convert.ToString(Log1.MC_CalParam.Ref_Speed) + ", ";
  3443. SaveData += "FOC_Flag:" + Convert.ToString(Log1.MC_CalParam.Foc_Flag) + ", ";
  3444. SaveData += "\r\n\r\n";
  3445. System.IO.File.AppendAllText(ErrorLogSaveFileName, SaveData);
  3446. SaveData = "";
  3447. }
  3448. //Log2
  3449. if (Log2.Error_Index != 0xFFFF)
  3450. {
  3451. if (ErrorLogSaveFlag == false)
  3452. {
  3453. ErrorLogSaveFlag = true;
  3454. string SaveInfo = "读取时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n\r\n";
  3455. SaveInfo += "电机型号:" + textBox_Mode.Text + "\r\n";
  3456. SaveInfo += "序列号:" + textBox_SN.Text + "\r\n";
  3457. SaveInfo += "硬件版本:" + textBox_HW.Text + "\r\n";
  3458. SaveInfo += "软件版本:" + textBox_FW.Text + "\r\n";
  3459. SaveInfo += "TE软件版本:" + textBox_TE_FW.Text + "\r\n\r\n";
  3460. System.IO.File.WriteAllText(ErrorLogSaveFileName, SaveInfo);
  3461. }
  3462. SaveData += "故障序号:" + Convert.ToString(Log2.Error_Index) + ", ";
  3463. SaveData += "备注1:" + Convert.ToString(Log2.NotesInfo1) + ", ";
  3464. SaveData += "备注2:" + Convert.ToString(Log2.NotesInfo2) + ", ";
  3465. SaveData += "备注3:" + Convert.ToString(Log2.NotesInfo3) + ", ";
  3466. SaveData += "故障码:" + "0x" + Convert.ToString(Log2.ErrorCode, 16).PadLeft(8, '0').ToUpper() + ", ";
  3467. SaveData += "运行时间:" + Convert.ToString(Log2.RunTime) + "min" + ", ";
  3468. SaveData += "车速:" + ((float)Log2.RunInfo.BikeSpeed / 10f).ToString("0.0") + "km/h" + ", ";
  3469. SaveData += "电机转速:" + Convert.ToString(Log2.RunInfo.MotorSpeed) + "rpm" + ", ";
  3470. SaveData += "功率:" + Convert.ToString(Log2.RunInfo.Power * 2) + "w" + ", ";
  3471. SaveData += "电压:" + Convert.ToString(Log2.RunInfo.BusVoltage) + "mV" + ", ";
  3472. SaveData += "电流:" + Convert.ToString(Log2.RunInfo.BusCurrent) + "mA" + ", ";
  3473. SaveData += "踏频:" + Convert.ToString(Log2.RunInfo.Cadence) + "rpm" + ", ";
  3474. SaveData += "力矩:" + Convert.ToString(Log2.RunInfo.Torque) + "N.m" + ", ";
  3475. SaveData += "方向:" + ((Log2.RunInfo.CadenceDir == 0) ? "正" : ((Log2.RunInfo.CadenceDir == 1) ? "反" : "停止")) + ", ";
  3476. SaveData += "档位:" + "0x" + Convert.ToString(Log2.RunInfo.GearSt, 16).PadLeft(2, '0').ToUpper() + ", ";
  3477. SaveData += "灯开关:" + ((Log2.RunInfo.LightSwitch == 0xF1) ? "开" : "关") + ", ";
  3478. SaveData += "电量:" + Convert.ToString(Log2.RunInfo.SOC) + "%" + ", ";
  3479. if ((Log1.RunInfo.RemainDistance == 0xEEEE) || (Log1.RunInfo.RemainDistance == 0xFFFF))
  3480. {
  3481. SaveData += "续航:" + "---km" + ", ";
  3482. }
  3483. else
  3484. {
  3485. SaveData += "续航:" + Convert.ToString(Log1.RunInfo.RemainDistance) + "km" + ", ";
  3486. }
  3487. SaveData += "总里程:" + Convert.ToString(Log2.RunInfo.ODO_Km) + "km" + ", ";
  3488. SaveData += "功耗:" + Convert.ToString(Log2.RunInfo.PowerPerKm * 10) + "mAh/km" + ", ";
  3489. SaveData += "PCB温度:" + Convert.ToString((int)(Log2.RunInfo.T_PCB - 40)) + "DegreeC" + ", ";
  3490. SaveData += "绕组温度:" + Convert.ToString((int)(Log2.RunInfo.T_Coil - 40)) + "DegreeC" + ", ";
  3491. SaveData += "MCU温度:" + Convert.ToString((int)(Log2.RunInfo.T_MCU - 40)) + "DegreeC" + ", ";
  3492. SaveData += "单次里程:" + Convert.ToString((float)Log2.RunInfo.Ride_Km / 10f) + "km" + ", ";
  3493. SaveData += "单次时间:" + Convert.ToString(Log2.RunInfo.Ride_Time) + "s" + ", ";
  3494. SaveData += "俯仰绝对角度:" + ((float)Log2.AttitudeAngle.Angle_Pitch_Absolute / 10f).ToString("0.0") + "Degree" + ", ";
  3495. SaveData += "横滚绝对角度:" + ((float)Log2.AttitudeAngle.Angle_Roll_Absolute / 10f).ToString("0.0") + "Degree" + ", ";
  3496. SaveData += "俯仰相对角度:" + ((float)Log2.AttitudeAngle.Angle_Pitch_Relative / 10f).ToString("0.0") + "Degree" + ", ";
  3497. SaveData += "横滚相对角度:" + ((float)Log2.AttitudeAngle.Angle_Roll_Relative / 10f).ToString("0.0") + "Degree" + ", ";
  3498. SaveData += "运行模式:" + Convert.ToString(Log2.MC_CalParam.AssistRunMode) + ", ";
  3499. SaveData += "力矩环给定:" + Convert.ToString(Log2.MC_CalParam.Ref_Torque) + ", ";
  3500. SaveData += "速度环给定:" + Convert.ToString(Log2.MC_CalParam.Ref_Speed) + ", ";
  3501. SaveData += "FOC_Flag:" + Convert.ToString(Log2.MC_CalParam.Foc_Flag) + ", ";
  3502. SaveData += "\r\n\r\n";
  3503. System.IO.File.AppendAllText(ErrorLogSaveFileName, SaveData);
  3504. SaveData = "";
  3505. }
  3506. }
  3507. private void button_ClearData_MouseHover(object sender, EventArgs e)
  3508. {
  3509. // 创建the ToolTip
  3510. ToolTip toolTip1 = new ToolTip();
  3511. // 设置显示样式
  3512. toolTip1.AutoPopDelay = 5000;//提示信息的可见时间
  3513. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  3514. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  3515. toolTip1.ShowAlways = true;//是否显示提示框
  3516. // 设置伴随的对象.
  3517. toolTip1.SetToolTip(this.button_ClearData, "清除电机内部所有数据,包括配置参数、历史记录等。");//设置提示按钮和提示内容
  3518. }
  3519. private void button_Recovery_MouseHover(object sender, EventArgs e)
  3520. {
  3521. // 创建the ToolTip
  3522. ToolTip toolTip1 = new ToolTip();
  3523. // 设置显示样式
  3524. toolTip1.AutoPopDelay = 5000;//提示信息的可见时间
  3525. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  3526. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  3527. toolTip1.ShowAlways = true;//是否显示提示框
  3528. // 设置伴随的对象.
  3529. toolTip1.SetToolTip(this.button_Recovery, "还原配置参数为初始值。");//设置提示按钮和提示内容
  3530. }
  3531. private void button_DataExport_MouseHover(object sender, EventArgs e)
  3532. {
  3533. // 创建the ToolTip
  3534. ToolTip toolTip1 = new ToolTip();
  3535. // 设置显示样式
  3536. toolTip1.AutoPopDelay = 5000;//提示信息的可见时间
  3537. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  3538. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  3539. toolTip1.ShowAlways = true;//是否显示提示框
  3540. // 设置伴随的对象.
  3541. toolTip1.SetToolTip(this.button_DataExport, "存储窗体页面,请先查询相关信息后操作。");//设置提示按钮和提示内容
  3542. }
  3543. private void label9_MouseHover(object sender, EventArgs e)
  3544. {
  3545. // 创建the ToolTip
  3546. ToolTip toolTip1 = new ToolTip();
  3547. // 设置显示样式
  3548. toolTip1.AutoPopDelay = 5000;//提示信息的可见时间
  3549. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  3550. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  3551. toolTip1.ShowAlways = true;//是否显示提示框
  3552. // 设置伴随的对象.
  3553. toolTip1.SetToolTip(this.label9, "双击自动计算启动值。");//设置提示按钮和提示内容
  3554. }
  3555. private void button_ReadErrorLog_MouseHover(object sender, EventArgs e)
  3556. {
  3557. // 创建the ToolTip
  3558. ToolTip toolTip1 = new ToolTip();
  3559. // 设置显示样式
  3560. toolTip1.AutoPopDelay = 5000;//提示信息的可见时间
  3561. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  3562. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  3563. toolTip1.ShowAlways = true;//是否显示提示框
  3564. // 设置伴随的对象.
  3565. toolTip1.SetToolTip(this.button_ReadErrorLog, "导出电机内部存储的故障日志,读取完后自动保存。");//设置提示按钮和提示内容
  3566. }
  3567. private void label119_MouseHover(object sender, EventArgs e)
  3568. {
  3569. // 创建the ToolTip
  3570. ToolTip toolTip1 = new ToolTip();
  3571. // 设置显示样式
  3572. toolTip1.AutoPopDelay = 5000;//提示信息的可见时间
  3573. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  3574. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  3575. toolTip1.ShowAlways = true;//是否显示提示框
  3576. // 设置伴随的对象.
  3577. toolTip1.SetToolTip(this.label119, "双击自动计算校正系数。");//设置提示按钮和提示内容
  3578. }
  3579. private void button_LogClear_Click(object sender, EventArgs e)
  3580. {
  3581. var Code = new byte[9];
  3582. Code[0] = (byte)'L';
  3583. Code[1] = (byte)'O';
  3584. Code[2] = (byte)'G';
  3585. Code[3] = (byte)' ';
  3586. Code[4] = (byte)'C';
  3587. Code[5] = (byte)'L';
  3588. Code[6] = (byte)'E';
  3589. Code[7] = (byte)'A';
  3590. Code[8] = (byte)'R';
  3591. timer1.Enabled = false;
  3592. if (MessageBox.Show("历史记录信息清除后将无法恢复", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3593. {
  3594. if (MessageBox.Show("请再次确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3595. {
  3596. if (MessageBox.Show("请最后确认", "确认清除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  3597. {
  3598. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3909, Code);
  3599. }
  3600. }
  3601. }
  3602. timer1.Enabled = true;
  3603. }
  3604. private void textBox_RunInfo_ErrorCode_MouseHover(object sender, EventArgs e)
  3605. {
  3606. // 创建the ToolTip
  3607. ToolTip toolTip1 = new ToolTip();
  3608. // 设置显示样式
  3609. toolTip1.AutoPopDelay = 30000;//提示信息的可见时间
  3610. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  3611. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  3612. toolTip1.ShowAlways = true;//是否显示提示框
  3613. // 设置伴随的对象.
  3614. string ErrorCode = this.textBox_RunInfo_ErrorCode.Text;
  3615. UInt32 Code = ErrorCode.Contains("H") ? Convert.ToUInt32(ErrorCode.Split('H')[0], 16) : 0;
  3616. toolTip1.SetToolTip(this.textBox_RunInfo_ErrorCode, ErrorInfoDisplay(Code));//设置故障内容显示
  3617. }
  3618. private void button_LogClear_MouseHover(object sender, EventArgs e)
  3619. {
  3620. // 创建the ToolTip
  3621. ToolTip toolTip1 = new ToolTip();
  3622. // 设置显示样式
  3623. toolTip1.AutoPopDelay = 5000;//提示信息的可见时间
  3624. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  3625. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  3626. toolTip1.ShowAlways = true;//是否显示提示框
  3627. // 设置伴随的对象.
  3628. toolTip1.SetToolTip(this.button_LogClear, "清除电机历史记录信息");//设置提示按钮和提示内容
  3629. }
  3630. private void button_ReadAll_Click(object sender, EventArgs e)
  3631. {
  3632. if (!serialPort1.IsOpen)
  3633. {
  3634. MessageBox.Show("串口未连接");
  3635. return;
  3636. }
  3637. //查询力矩传感器
  3638. var K = new byte[1];
  3639. textBox_Sensor1_Zero.Text = "---";
  3640. textBox_Sensor2_Zero.Text = "---";
  3641. textBox_Sensor3_Zero.Text = "---";
  3642. textBox_Sensor1_K.Text = "---";
  3643. textBox_Sensor2_K.Text = "---";
  3644. textBox_Sensor3_K.Text = "---";
  3645. //轮询零点
  3646. for (ushort i = 1; i <= 3; i++)
  3647. {
  3648. K[0] = (byte)i;
  3649. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3201, K);
  3650. }
  3651. //轮询校正系数
  3652. for (ushort i = 1; i <= 3; i++)
  3653. {
  3654. K[0] = (byte)i;
  3655. SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3301, K);
  3656. }
  3657. textBox_Torque_Start.Text = "---";
  3658. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3500, null);
  3659. //查询单力矩零点和校正系数
  3660. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2000, null); //单力矩零点值
  3661. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2900, null); //单力矩校正系数和启动值
  3662. //查询用户参数1
  3663. MC_Config_Clear();
  3664. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1A00, null);
  3665. //查询用户参数2
  3666. MC_Config_Ext_Clear();
  3667. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3000, null);
  3668. //查询姿态传感器参数
  3669. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2F00, null);
  3670. MC_AttitudeAngle_Clear();
  3671. //查询马达参数
  3672. Motor_Config_Clear();
  3673. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1C00, null);
  3674. //查询版本信息
  3675. textBox_Mode.Text = "---";
  3676. textBox_SN.Text = "---";
  3677. textBox_HW.Text = "---";
  3678. textBox_FW.Text = "---";
  3679. textBox_Firmware_Special.Text = "---";
  3680. Class_Motor_Ver.Mode = "---";
  3681. Class_Motor_Ver.SN = "---";
  3682. Class_Motor_Ver.HW = "---";
  3683. Class_Motor_Ver.FW = "---";
  3684. Class_Motor_Ver.Special = "---";
  3685. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
  3686. textBox_TE_FW.Text = "---";
  3687. SendCmd((ushort)0x651, (byte)0x11, (ushort)0x1200, null);
  3688. //查询历史信息
  3689. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
  3690. MC_RunLog_Clear();
  3691. //查询骑行历史
  3692. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2E00, null);
  3693. MC_RideInfo_Clear();
  3694. }
  3695. //双击时允许解锁写保护
  3696. private void label127_DoubleClick(object sender, EventArgs e)
  3697. {
  3698. WriteProtectUnlock = true;
  3699. }
  3700. //双击解锁写保护
  3701. private void label1_Welcom_DoubleClick(object sender, EventArgs e)
  3702. {
  3703. if (WriteProtectUnlock == false)
  3704. return;
  3705. button_ClearData.Enabled = true;
  3706. button_Recovery.Enabled = true;
  3707. button_Write_Config.Enabled = true;
  3708. button_Write_Config_Ext.Enabled = true;
  3709. button_Write_MotorConfig.Enabled = true;
  3710. button_Write_Mode.Enabled = true;
  3711. button_Write_SN.Enabled = true;
  3712. }
  3713. //读取指定地址的数据
  3714. private void button_DebugRead_Click(object sender, EventArgs e)
  3715. {
  3716. var Address = new byte[4];
  3717. UInt32 Address_Begin;
  3718. UInt32 Addres_End;
  3719. if (checkBox_DebugReset.Checked == true)
  3720. richTextBox_DebugInfo.Clear();
  3721. if ((textBox_DebugAddrBegin.Text == string.Empty) || (textBox_DebugAddrEnd.Text == string.Empty))
  3722. {
  3723. MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3724. return;
  3725. }
  3726. else if ((textBox_DebugAddrBegin.Text.Length != 8) || (textBox_DebugAddrEnd.Text.Length != 8))
  3727. {
  3728. MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3729. return;
  3730. }
  3731. else
  3732. {
  3733. Address = HexStringToBytes(textBox_DebugAddrBegin.Text, false);
  3734. Address_Begin = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3735. Address = HexStringToBytes(textBox_DebugAddrEnd.Text, false);
  3736. Addres_End = ((UInt32)Address[0] << 24) + ((UInt32)Address[1] << 16) + ((UInt32)Address[2] << 8) + ((UInt32)Address[3]);
  3737. if (Addres_End < Address_Begin)
  3738. {
  3739. MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  3740. return;
  3741. }
  3742. else
  3743. {
  3744. var SendByte = new byte[8];
  3745. SendByte[0] = (byte)(Address_Begin >> 24);
  3746. SendByte[1] = (byte)(Address_Begin >> 16);
  3747. SendByte[2] = (byte)(Address_Begin >> 8);
  3748. SendByte[3] = (byte)(Address_Begin);
  3749. SendByte[4] = (byte)(Addres_End >> 24);
  3750. SendByte[5] = (byte)(Addres_End >> 16);
  3751. SendByte[6] = (byte)(Addres_End >> 8);
  3752. SendByte[7] = (byte)(Addres_End);
  3753. SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
  3754. }
  3755. }
  3756. }
  3757. //选择单力矩
  3758. private void radioButton_SingleSensor_CheckedChanged(object sender, EventArgs e)
  3759. {
  3760. checkBox_Sensor1.Checked = true;
  3761. label5.Visible = false;
  3762. textBox_Sensor2_Avg.Visible = false;
  3763. textBox_Sensor2_Std.Visible = false;
  3764. textBox_Sensor2_Zero.Visible = false;
  3765. textBox_Sensor2_K.Visible = false;
  3766. checkBox_Sensor2.Visible = false;
  3767. checkBox_Sensor2.Checked = false;
  3768. label115.Visible = false;
  3769. textBox_Sensor3_Avg.Visible = false;
  3770. textBox_Sensor3_Std.Visible = false;
  3771. textBox_Sensor3_Zero.Visible = false;
  3772. textBox_Sensor3_K.Visible = false;
  3773. checkBox_Sensor3.Visible = false;
  3774. checkBox_Sensor3.Checked = false;
  3775. this.BackColor = System.Drawing.Color.FromArgb((int)0, (int)192, (int)192);
  3776. }
  3777. //选择三力矩
  3778. private void radioButton_ThreeSensor_CheckedChanged(object sender, EventArgs e)
  3779. {
  3780. checkBox_Sensor1.Checked = true;
  3781. label5.Visible = true;
  3782. textBox_Sensor2_Avg.Visible = true;
  3783. textBox_Sensor2_Std.Visible = true;
  3784. textBox_Sensor2_Zero.Visible = true;
  3785. textBox_Sensor2_K.Visible = true;
  3786. checkBox_Sensor2.Visible = true;
  3787. checkBox_Sensor2.Checked = true;
  3788. label115.Visible = true;
  3789. textBox_Sensor3_Avg.Visible = true;
  3790. textBox_Sensor3_Std.Visible = true;
  3791. textBox_Sensor3_Zero.Visible = true;
  3792. textBox_Sensor3_K.Visible = true;
  3793. checkBox_Sensor3.Visible = true;
  3794. checkBox_Sensor3.Checked = true;
  3795. this.BackColor = System.Drawing.Color.FromArgb((int)46, (int)193, (int)144);
  3796. }
  3797. }
  3798. }