ImportForm.cs 149 KB

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