ImportForm.cs 149 KB

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