ImportForm.cs 160 KB

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