ImportForm.cs 135 KB

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