ImportForm.cs 164 KB

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