ImportForm.cs 148 KB

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