123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Text;
- using System.Windows.Forms;
- using System.IO.Ports;
- using System.Collections;
- using System.Threading;
- using System.Text.RegularExpressions;
- namespace MOTINOVA_Motor_Factory_Set
- {
- public partial class ImportForm : Form
- {
- #region 文件路径
- string LogSaveFileName = "";
- public string LogSavePath = "";
- public string LocalCfgFilePath = "";
- #endregion
- #region 测试参数配置
- //以下值在根据电机测试的配置文件中更改
- ushort MotorRadeSpeed = 1200; //空载转速
- ushort RateVoltage = 36000; //额定电压
- bool GasModeTest = true; //转把模式检测开关
- bool SpeedSensorTest = true; //速度传感器检测开关
- //以下值在软件测试文件params.cfg文件中修改
- ushort No_load_Current = 1000; //空载电流
- ushort SpeedSensorThData = 60; //车速传感器判断阈值
- ushort RateCadence = 120; //踏频
- ushort GasModeSpeed = 1200; //指拨模式测试转速
- ushort TorSensorZeroMin = 100; //力矩零点下限
- ushort TorSensorZeroMax = 2000;//力矩零点上限
- #endregion
- #region 配置文件信息
- ArrayList array_CfgInfo = new ArrayList();
- #endregion
- #region 端口设置界面
- public static PortSettings portsettings_form = new PortSettings();
- #endregion
- #region 串口缓存
- public static List<byte> buffer = new List<byte>(4096);
- private byte[] binary_data_1 = new byte[1024];
- #endregion
- #region MC运行信息超时计数
- bool MC_RunInfo_Refresh = false;
- ushort MC_RunInfo_Refresh_Cnt = 0;
- #endregion
- #region MC故障码超时计数
- bool MC_ErrorCode_Refresh = false;
- ushort MC_ErrorCode_Refresh_Cnt = 0;
- #endregion
- #region 执行步骤
- public enum TestStep_Enum
- {
- Step_Init = 0,
- Step_SysClear = 1, //系统清除
- Step_Write = 2, //参数写入
- Step_Light = 3, //灯电压测试
- Step_Walk = 4, //推行测试
- Step_GasMode = 5, //转把测试
- Step_CheckVer = 6, //版本查询和确认
- Step_Save = 7 //数据读取和存储
- }
- TestStep_Enum TestStep;
- #endregion
- #region 反馈指令判断计时
- bool Ack_Flag = true;
- ushort Ack_Cnt = 0;
- #endregion
- #region 单步测试标志
- public enum StepTestResult_Enum
- {
- StepTestResult_Ready = 0,
- StepTestResult_Testing = 1,
- StepTestResult_OK = 2,
- StepTestResult_Fail = 3
- }
- StepTestResult_Enum StepTestFlag = StepTestResult_Enum.StepTestResult_Ready;
- #endregion
- #region 推行/转把测试计时
- ushort WalkProcess_Cnt = 0;
- ushort OK_cnt = 0;
- #endregion
- int TorqueSensorZero = -1, TorqueSensorZero1 = -1, TorqueSensorZero2 = -1, TorqueSensorZero3 = -1;
- public ImportForm()
- {
- InitializeComponent();
- System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
- //加载用户路径
- LogSavePath = StartForm.UserPath;
- LocalCfgFilePath = StartForm.UserPath;
- }
- #region 获取配置文件日期
- private void GetDateList(bool DisAll)
- {
- string[] DateList = { "" };
- if (checkBox_LocalFile.Checked == true)//从本地更新日期列表
- {
- DateList = System.IO.Directory.GetDirectories(LocalCfgFilePath);
- }
- else//从服务器更新日期列表
- {
- DateList = StartForm.myFtp.GetDirectoryList(StartForm.myServerCfg.RootPath + "/cfg");
- }
- comboBox_cfgFileDate.Items.Clear();
- //日期列表加载
- if (DisAll == true)
- {
- comboBox_cfgFileDate.Items.Add("显示近期");
- comboBox_cfgFileDate.Items.Add("---");
- foreach (var file in DateList)
- comboBox_cfgFileDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
- }
- else
- {
- if (DateList.Length > 10)
- {
- comboBox_cfgFileDate.Items.Add("显示全部");
- comboBox_cfgFileDate.Items.Add("---");
- }
- for (int i = (DateList.Length > 10) ? (DateList.Length - 10) : 0; i < DateList.Length; i++)//显示最近10个日期
- comboBox_cfgFileDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
- }
- }
- #endregion
- #region 获取配置文件列表
- private void GetFileListFrom(string date)
- {
- string[] FileList = { "" };
- if (checkBox_LocalFile.Checked == true)//从本地更新文件列表
- {
- FileList = System.IO.Directory.GetFiles(LocalCfgFilePath + date);
- }
- else//从服务器更新文件列表
- {
- FileList = StartForm.myFtp.GetFileNameList(StartForm.myServerCfg.RootPath + "/cfg/" + date);
- }
- comboBox_File.Items.Clear();
- foreach (var file in FileList)
- {
- if (file.Contains(".ttcfg"))
- {
- comboBox_File.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
- }
- }
- }
- #endregion
- #region 选择文件日期后更新文件列表
- private void comboBox_cfgFileDate_SelectionChangeCommitted(object sender, EventArgs e)
- {
- if (comboBox_cfgFileDate.SelectedItem.ToString() == "显示全部")
- {
- GetDateList(true);
- }
- else if (comboBox_cfgFileDate.SelectedItem.ToString() == "显示近期")
- {
- GetDateList(false);
- }
- else
- {
- comboBox_File.Text = "";
- GetFileListFrom(comboBox_cfgFileDate.SelectedItem.ToString());
- }
- }
- #endregion
- #region 选择文件后加载文件
- private void comboBox_File_SelectionChangeCommitted(object sender, EventArgs e)
- {
- //清空原来数据
- array_CfgInfo.Clear();
- string SelectFile = "";
- if (checkBox_LocalFile.Checked == false)//非本地模式从服务器下载文件
- {
- SelectFile = comboBox_cfgFileDate.SelectedItem.ToString() + "\\" + comboBox_File.SelectedItem.ToString();
- if (File.Exists(LocalCfgFilePath + SelectFile))//本地存在选定文件,先删除本地
- {
- File.Delete(LocalCfgFilePath + SelectFile);
- }
- SelectFile = comboBox_cfgFileDate.SelectedItem.ToString() + "/" + comboBox_File.SelectedItem.ToString();
- StartForm.myFtp.DownloadFile(StartForm.myServerCfg.RootPath + "/cfg/" + SelectFile, LocalCfgFilePath + comboBox_cfgFileDate.SelectedItem.ToString());
- }
- SelectFile = comboBox_cfgFileDate.SelectedItem.ToString() + "\\" + comboBox_File.SelectedItem.ToString();
- //打开选中文件
- StreamReader objReader = new StreamReader(LocalCfgFilePath + SelectFile);
- string sLine = "";
- while (sLine != null)
- {
- sLine = objReader.ReadLine();
- array_CfgInfo.Add(sLine);
- }
- objReader.Close();
- //解析显示配置文件
- richTextBox_CfgFile.Text = "";
- try
- {
- foreach (string sOutput in array_CfgInfo)
- {
- richTextBox_CfgFile.AppendText(sOutput + "\r\n");
- }
- }
- catch (System.Exception)
- {
- return;
- }
- //更新推行模式测试判断标准
- MotorRadeSpeed = Convert.ToUInt16(array_CfgInfo[58].ToString().Split(',')[1]);
- RateVoltage = (ushort)(Convert.ToByte(array_CfgInfo[63].ToString().Split(',')[1]) * 1000);
- //更新指拨和速度传感器测试标志
- byte temp = Convert.ToByte(array_CfgInfo[25].ToString().Split(',')[1]);
- GasModeTest = temp == 0x55 ? false : true;
- temp = Convert.ToByte(array_CfgInfo[26].ToString().Split(',')[1]);
- SpeedSensorTest = temp == 0x55 || (temp == 0xAA ? false : temp == 0xEE ? false : false);
- //更新空载电流和车速传感器判断阈值
- if (array_CfgInfo.Count > 56)//旧版本无改配置项,采用默认值
- {
- No_load_Current = Convert.ToUInt16(array_CfgInfo[75].ToString().Split(',')[1]);
- SpeedSensorThData = Convert.ToUInt16(array_CfgInfo[76].ToString().Split(',')[1]);
- RateCadence = Convert.ToUInt16(array_CfgInfo[77].ToString().Split(',')[1]);
- GasModeSpeed = Convert.ToUInt16(array_CfgInfo[78].ToString().Split(',')[1]);
- TorSensorZeroMin = Convert.ToUInt16(array_CfgInfo[79].ToString().Split(',')[1]);
- TorSensorZeroMax = Convert.ToUInt16(array_CfgInfo[80].ToString().Split(',')[1]);
- }
- }
- #endregion
- #region 修改获取文件方式,本地或服务器
- private void checkBox_LocalFile_CheckedChanged(object sender, EventArgs e)
- {
- comboBox_cfgFileDate.Text = "";
- comboBox_File.Text = "";
- richTextBox_CfgFile.Text = "";
- GetDateList(false);
- }
- #endregion
- private void ImportForm_Load(object sender, EventArgs e)
- {
- timer1.Enabled = true;
- timer2.Enabled = true;
- //显示测试员信息
- label_TestUser.Text = "测试员:" + StartForm.EnterForm1.comboBox_User.Text;
- #if false
- //针对越南测试,默认不执行系统清除
- if (StartForm.EnterForm1.comboBox_User.Text == "越南Vietnam")
- {
- 系统清除执行ToolStripMenuItem.Checked = false;
- 系统清除不执行ToolStripMenuItem.Checked = true;
- label_TestFunsUpdate();
- 系统清除执行ToolStripMenuItem.Enabled = false;
- 系统清除不执行ToolStripMenuItem.Enabled = false;
- }
- #endif
- //显示版本信息
- label_Ver.Text = StartForm.Version + " " + StartForm.BuildTime;
- //装载配置文件
- GetDateList(false);
- //装载序列号文件
- string cfg_file = System.IO.Directory.GetCurrentDirectory() + "\\TestSerialNum";
- StreamReader objReader = new StreamReader(cfg_file);
- string sLine = "";
- ArrayList arrText = new ArrayList();//创建一个动态数组
- while (sLine != null)
- {
- sLine = objReader.ReadLine();
- arrText.Add(sLine);
- }
- objReader.Close();
- label_SerialNum.Text = arrText[1].ToString();//流水号
- label_OK_Count.Text = arrText[3].ToString();//合格计数
- }
- private void toolStripMenuIte_PortSet_Click(object sender, EventArgs e)
- {
- portsettings_form.Show();
- }
- #region CRC32校验
- static UInt32[] crc32_table = new UInt32[256]
- {
- 0x00000000, 0x04C11DB7, 0x09823B6E, 0x0D4326D9, 0x130476DC, 0x17C56B6B,
- 0x1A864DB2, 0x1E475005, 0x2608EDB8, 0x22C9F00F, 0x2F8AD6D6, 0x2B4BCB61,
- 0x350C9B64, 0x31CD86D3, 0x3C8EA00A, 0x384FBDBD, 0x4C11DB70, 0x48D0C6C7,
- 0x4593E01E, 0x4152FDA9, 0x5F15ADAC, 0x5BD4B01B, 0x569796C2, 0x52568B75,
- 0x6A1936C8, 0x6ED82B7F, 0x639B0DA6, 0x675A1011, 0x791D4014, 0x7DDC5DA3,
- 0x709F7B7A, 0x745E66CD, 0x9823B6E0, 0x9CE2AB57, 0x91A18D8E, 0x95609039,
- 0x8B27C03C, 0x8FE6DD8B, 0x82A5FB52, 0x8664E6E5, 0xBE2B5B58, 0xBAEA46EF,
- 0xB7A96036, 0xB3687D81, 0xAD2F2D84, 0xA9EE3033, 0xA4AD16EA, 0xA06C0B5D,
- 0xD4326D90, 0xD0F37027, 0xDDB056FE, 0xD9714B49, 0xC7361B4C, 0xC3F706FB,
- 0xCEB42022, 0xCA753D95, 0xF23A8028, 0xF6FB9D9F, 0xFBB8BB46, 0xFF79A6F1,
- 0xE13EF6F4, 0xE5FFEB43, 0xE8BCCD9A, 0xEC7DD02D, 0x34867077, 0x30476DC0,
- 0x3D044B19, 0x39C556AE, 0x278206AB, 0x23431B1C, 0x2E003DC5, 0x2AC12072,
- 0x128E9DCF, 0x164F8078, 0x1B0CA6A1, 0x1FCDBB16, 0x018AEB13, 0x054BF6A4,
- 0x0808D07D, 0x0CC9CDCA, 0x7897AB07, 0x7C56B6B0, 0x71159069, 0x75D48DDE,
- 0x6B93DDDB, 0x6F52C06C, 0x6211E6B5, 0x66D0FB02, 0x5E9F46BF, 0x5A5E5B08,
- 0x571D7DD1, 0x53DC6066, 0x4D9B3063, 0x495A2DD4, 0x44190B0D, 0x40D816BA,
- 0xACA5C697, 0xA864DB20, 0xA527FDF9, 0xA1E6E04E, 0xBFA1B04B, 0xBB60ADFC,
- 0xB6238B25, 0xB2E29692, 0x8AAD2B2F, 0x8E6C3698, 0x832F1041, 0x87EE0DF6,
- 0x99A95DF3, 0x9D684044, 0x902B669D, 0x94EA7B2A, 0xE0B41DE7, 0xE4750050,
- 0xE9362689, 0xEDF73B3E, 0xF3B06B3B, 0xF771768C, 0xFA325055, 0xFEF34DE2,
- 0xC6BCF05F, 0xC27DEDE8, 0xCF3ECB31, 0xCBFFD686, 0xD5B88683, 0xD1799B34,
- 0xDC3ABDED, 0xD8FBA05A, 0x690CE0EE, 0x6DCDFD59, 0x608EDB80, 0x644FC637,
- 0x7A089632, 0x7EC98B85, 0x738AAD5C, 0x774BB0EB, 0x4F040D56, 0x4BC510E1,
- 0x46863638, 0x42472B8F, 0x5C007B8A, 0x58C1663D, 0x558240E4, 0x51435D53,
- 0x251D3B9E, 0x21DC2629, 0x2C9F00F0, 0x285E1D47, 0x36194D42, 0x32D850F5,
- 0x3F9B762C, 0x3B5A6B9B, 0x0315D626, 0x07D4CB91, 0x0A97ED48, 0x0E56F0FF,
- 0x1011A0FA, 0x14D0BD4D, 0x19939B94, 0x1D528623, 0xF12F560E, 0xF5EE4BB9,
- 0xF8AD6D60, 0xFC6C70D7, 0xE22B20D2, 0xE6EA3D65, 0xEBA91BBC, 0xEF68060B,
- 0xD727BBB6, 0xD3E6A601, 0xDEA580D8, 0xDA649D6F, 0xC423CD6A, 0xC0E2D0DD,
- 0xCDA1F604, 0xC960EBB3, 0xBD3E8D7E, 0xB9FF90C9, 0xB4BCB610, 0xB07DABA7,
- 0xAE3AFBA2, 0xAAFBE615, 0xA7B8C0CC, 0xA379DD7B, 0x9B3660C6, 0x9FF77D71,
- 0x92B45BA8, 0x9675461F, 0x8832161A, 0x8CF30BAD, 0x81B02D74, 0x857130C3,
- 0x5D8A9099, 0x594B8D2E, 0x5408ABF7, 0x50C9B640, 0x4E8EE645, 0x4A4FFBF2,
- 0x470CDD2B, 0x43CDC09C, 0x7B827D21, 0x7F436096, 0x7200464F, 0x76C15BF8,
- 0x68860BFD, 0x6C47164A, 0x61043093, 0x65C52D24, 0x119B4BE9, 0x155A565E,
- 0x18197087, 0x1CD86D30, 0x029F3D35, 0x065E2082, 0x0B1D065B, 0x0FDC1BEC,
- 0x3793A651, 0x3352BBE6, 0x3E119D3F, 0x3AD08088, 0x2497D08D, 0x2056CD3A,
- 0x2D15EBE3, 0x29D4F654, 0xC5A92679, 0xC1683BCE, 0xCC2B1D17, 0xC8EA00A0,
- 0xD6AD50A5, 0xD26C4D12, 0xDF2F6BCB, 0xDBEE767C, 0xE3A1CBC1, 0xE760D676,
- 0xEA23F0AF, 0xEEE2ED18, 0xF0A5BD1D, 0xF464A0AA, 0xF9278673, 0xFDE69BC4,
- 0x89B8FD09, 0x8D79E0BE, 0x803AC667, 0x84FBDBD0, 0x9ABC8BD5, 0x9E7D9662,
- 0x933EB0BB, 0x97FFAD0C, 0xAFB010B1, 0xAB710D06, 0xA6322BDF, 0xA2F33668,
- 0xBCB4666D, 0xB8757BDA, 0xB5365D03, 0xB1F740B4
- };
- static UInt32 crc32_cal(byte[] pData, UInt16 Length)
- {
- UInt32 nReg;
- UInt32 nTemp = 0;
- UInt16 i, n;
- nReg = 0xFFFFFFFF;
- for (n = 0; n < Length; n++)
- {
- nReg ^= (UInt32)pData[n];
- for (i = 0; i < 4; i++)
- {
- nTemp = crc32_table[((nReg >> 24) & 0xFF)];
- nReg <<= 8;
- nReg ^= nTemp;
- }
- }
- return nReg;
- }
- #endregion
- #region 命令发送
- private void SendCmd(ushort ID, byte Mode, ushort Cmd, byte[] Data)
- {
- if (!portsettings_form.serialPort1.IsOpen)
- {
- MessageBox.Show("串口未连接");
- return;
- }
- ushort DataLength = (ushort)(Cmd & 0xFF);
- var SendCmdTmp = new byte[DataLength + 13];
- //帧头
- SendCmdTmp[0] = 0x55;
- SendCmdTmp[1] = 0xAA;
- //ID
- SendCmdTmp[2] = (byte)(ID >> 8);
- SendCmdTmp[3] = (byte)(ID & 0xFF);
- //MODE
- SendCmdTmp[4] = Mode;
- //长度
- SendCmdTmp[5] = (byte)((Cmd & 0xFF) + 2);
- //命令字
- SendCmdTmp[6] = (byte)(Cmd >> 8);
- SendCmdTmp[7] = (byte)(Cmd & 0xFF);
- //数据段
- for (UInt16 i = 0; i < (Cmd & 0xFF); i++)
- {
- SendCmdTmp[8 + i] = Data[i];
- }
- //校验
- UInt32 CRC_Result = crc32_cal(SendCmdTmp, (ushort)(DataLength + 8));
- SendCmdTmp[DataLength + 8] = Convert.ToByte(CRC_Result >> 24);
- SendCmdTmp[DataLength + 9] = Convert.ToByte((CRC_Result >> 16) % 256);
- SendCmdTmp[DataLength + 10] = Convert.ToByte((CRC_Result >> 8) % 256);
- SendCmdTmp[DataLength + 11] = Convert.ToByte(CRC_Result % 256);
- //帧尾
- SendCmdTmp[DataLength + 12] = 0xF0;
- //发送数据
- portsettings_form.serialPort1.Write(SendCmdTmp, 0, SendCmdTmp.Length);
- }
- #endregion
- #region 串口数据解析
- private void Serial_DataReceived_Process()
- {
- //串口解析
- byte DataNum = 0; //记录每条命令数据段的长度
- while (buffer.Count >= 13)//当buffer中的数据的个数大于等于4个时,即每一帧的数据长度所在位(第4位)出现时
- {
- if (buffer[0] == 0x55 && buffer[1] == 0xAA)//判断帧头
- {
- ushort PackageID;
- PackageID = (ushort)(buffer[2] * 256 + buffer[3]);
- if ((PackageID == 0x0710) || (PackageID == 0x0715) ||
- (PackageID == 0x0610) || (PackageID == 0x0615) ||
- (PackageID == 0x07FF) ||
- (PackageID == 0x0725) || (PackageID == 0x0720))
- {
- int CmdLen = buffer[5];
- if (buffer.Count < CmdLen + 11) break;//如果接收到的数据没有达到一帧数据的指定长度, 则执行下次循环
- buffer.RemoveRange(0, 6);//数据达到要求长度后删去帧头,ID,模式,和命令长度
- DataNum = (byte)(buffer[1]);//命令字的第二个字节的表示数据位的长度
- if (DataNum == (CmdLen - 2))
- {
- for (int i = 0; i < DataNum + 2; i++)
- {
- binary_data_1[i] = buffer[i];
- }
- if (TestStep == TestStep_Enum.Step_Save)
- {
- //数据存储
- var RecData = new byte[CmdLen];
- Array.Copy(binary_data_1, RecData, CmdLen);
- if ((PackageID == 0x0710) || (PackageID == 0x0715) ||
- (PackageID == 0x0610) || (PackageID == 0x0615) ||
- (PackageID == 0x07FF))
- {
- DataSave(RecData);
- }
- }
- DataCmdProcess(PackageID);//对于不同的命令段,做不同的处理
- }
- buffer.RemoveRange(0, CmdLen + 5);//解析完成
- }
- else
- {
- buffer.RemoveAt(0);//ID不对
- }
- }
- else
- {
- buffer.RemoveAt(0);//帧头不对,删除帧头高字节
- }
- }
- }
- #endregion
- #region 数据存储
- private void DataSave(byte[] Data)
- {
- string SaveData = "";
- //数据存储
- for (int i = 0; i < Data.Length; i++)
- {
- SaveData += Convert.ToString(Data[i], 16).PadLeft(2, '0').ToUpper() + " ";
- }
- SaveData += "\r\n";
- System.IO.File.AppendAllText(LogSaveFileName, SaveData);
- }
- #endregion
- //故障转换和显示
- List<string> ErrorInfo = new List<string>{ "过流保护", "低压保护", "过压保护", "堵转保护","过热保护","速度传感器故障","力矩传感器故障","霍尔故障",
- "马达缺相","NTC故障","","","","MCU故障","踏频传感器故障","指拨故障","MOS短路","电压异常","电路故障","TE故障","TE电路故障","","","","","","","","","",
- "",""};
- private void ErrorInfoDisplay(UInt32 Code)
- {
- label_ErrorInfo.Text = "";
- if (Code == 0)
- {
- label_ErrorInfo.Text = "无故障";
- label_ErrorInfo.ForeColor = Color.Green;
- }
- else
- {
- label_ErrorInfo.ForeColor = Color.Red;
- for (int i = 0; i < 32; i++)
- {
- if ((Code & 0x01) == 0x01)
- {
- label_ErrorInfo.Text += ErrorInfo[i] + " ";
- }
- Code >>= 1;
- }
- }
- }
- #region 数据解析处理
- private void DataCmdProcess(ushort ID)
- {
- ushort CmdTemp = (ushort)(binary_data_1[0] * 256 + binary_data_1[1]);
- ushort DataTemp;
- #region 主控信息
- if ((ID == 0x715) || (ID == 0x710))
- {
- switch (CmdTemp)
- {
- case 0xC109://Boot 版本
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- if (label_Boot_Version.Text != "OK")
- {
- richTextBox_TestRecord.AppendText("Bootloader版本:");
- string boot_Version = "";
- for (ushort i = 0; i < 9; i++)
- {
- boot_Version += ((char)binary_data_1[2 + i]).ToString();
- }
- richTextBox_TestRecord.AppendText(boot_Version + " ");
- richTextBox_TestRecord.AppendText(boot_Version.Contains("V1") ? "125K" : "250K");
- richTextBox_TestRecord.AppendText("\r\n");
- }
- label_Boot_Version.BackColor = Color.Green;
- label_Boot_Version.Text = "OK";
- }));
- }
- break;
- }
- case 0x1020://电机运行信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- MC_RunInfo_Refresh = true;
- //车速
- DataTemp = (ushort)(binary_data_1[3] * 256 + binary_data_1[2]);
- textBox_BikeSpeed.Text = ((float)DataTemp / 10f).ToString("0.0");
- //输出转速
- DataTemp = (ushort)(binary_data_1[5] * 256 + binary_data_1[4]);
- textBox_MotorSpeed.Text = Convert.ToString(DataTemp);
- //母线电压
- DataTemp = (ushort)(binary_data_1[9] * 256 + binary_data_1[8]);
- textBox_Vol.Text = Convert.ToString(DataTemp);
- //母线电流
- DataTemp = (ushort)(binary_data_1[11] * 256 + binary_data_1[10]);
- textBox_Cur.Text = Convert.ToString(DataTemp);
- //踏频
- DataTemp = (ushort)(binary_data_1[12]);
- textBox_Cadence.Text = Convert.ToString(DataTemp);
- //踩踏力矩
- DataTemp = (ushort)(binary_data_1[13]);
- textBox_Torque.Text = Convert.ToString(DataTemp);
- //踩踏方向
- DataTemp = (ushort)(binary_data_1[14]);
- if (DataTemp == 0)
- {
- textBox_Dir.Text = "正向";
- }
- else if (DataTemp == 1)
- {
- textBox_Dir.Text = "反向";
- }
- else if (DataTemp == 2)
- {
- textBox_Dir.Text = "停止";
- }
- //PCB温度
- DataTemp = (ushort)(binary_data_1[23]);
- textBox_PCB.Text = Convert.ToString((int)(DataTemp - 40));
- //绕组温度
- DataTemp = (ushort)(binary_data_1[24]);
- textBox_Coil.Text = Convert.ToString((int)(DataTemp - 40));
- //MCU温度
- DataTemp = (ushort)(binary_data_1[25]);
- textBox_MOS.Text = Convert.ToString((int)(DataTemp - 40));
- Ack_Flag = true;
- StepTestFlag = StepTestResult_Enum.StepTestResult_OK;
- }));
- }
- break;
- }
- case 0x1104://故障码
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- MC_ErrorCode_Refresh = true;
- label_error_code.Text =
- Convert.ToString(binary_data_1[5], 16).PadLeft(2, '0').ToUpper() +
- Convert.ToString(binary_data_1[4], 16).PadLeft(2, '0').ToUpper() +
- Convert.ToString(binary_data_1[3], 16).PadLeft(2, '0').ToUpper() +
- Convert.ToString(binary_data_1[2], 16).PadLeft(2, '0').ToUpper() +
- "H";
- label_error_code.BackColor = Color.Red;
- UInt32 ErrorCode = (UInt32)((binary_data_1[5] << 24) + (binary_data_1[4] << 16) + (binary_data_1[3] << 8) + binary_data_1[2]);
- ErrorInfoDisplay(ErrorCode);
- }));
- }
- break;
- }
- case 0x1240://电机版本信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- richTextBox_Ver.Text += "";
- //电机型号
- richTextBox_Ver.Text += "型号:";
- for (ushort i = 0; i < 16; i++)
- {
- if (binary_data_1[2 + i] == 0x2E)
- {
- break;
- }
- richTextBox_Ver.Text += ((char)binary_data_1[2 + i]).ToString();
- }
- richTextBox_Ver.Text += "\r\n";
- //电机SN
- richTextBox_Ver.Text += "序列号:";
- for (ushort i = 0; i < 16; i++)
- {
- if (binary_data_1[18 + i] == 0x2E)
- {
- break;
- }
- richTextBox_Ver.Text += ((char)binary_data_1[18 + i]).ToString();
- }
- richTextBox_Ver.Text += "\r\n";
- //电机HW
- richTextBox_Ver.Text += "硬件版本:";
- for (ushort i = 0; i < 10; i++)//前10位是PCB版号,以'.'结束
- {
- if (binary_data_1[34 + i] == 0x2E)
- {
- break;
- }
- if (binary_data_1[34 + i] == 'r')
- {
- binary_data_1[34 + i] = (byte)'.';
- }
- richTextBox_Ver.Text += ((char)binary_data_1[34 + i]).ToString();
- }
- switch (binary_data_1[34 + 10])//第10位代表MCU品牌
- {
- case (byte)'1':
- richTextBox_Ver.Text += " " + "ST" + " "; break;
- case (byte)'2':
- richTextBox_Ver.Text += " " + "APM" + " "; break;
- case (byte)'3':
- richTextBox_Ver.Text += " " + "HK" + " "; break;
- case (byte)'4':
- richTextBox_Ver.Text += " " + "GD" + " "; break;
- default:
- richTextBox_Ver.Text += " " + "NULL" + " "; break;
- }
- for (ushort i = 0; i < 4; i++)//后4位是MCU的ID校验码,用于识别板子的ID
- {
- richTextBox_Ver.Text += Convert.ToString(binary_data_1[46 + i], 16).PadLeft(2, '0').ToUpper();//MCU ID 的CRC32值
- }
- richTextBox_Ver.Text += "\r\n";
- //电机FW
- richTextBox_Ver.Text += "软件版本:";
- for (ushort i = 0; i < 16; i++)
- {
- if (binary_data_1[50 + i] == 0x2E)
- {
- break;
- }
- if (binary_data_1[50 + i] == 'r')
- {
- binary_data_1[50 + i] = (byte)'.';
- }
- richTextBox_Ver.Text += ((char)binary_data_1[50 + i]).ToString();
- }
- richTextBox_Ver.Text += "\r\n";
- }));
- }
- break;
- }
- case 0x1720://电机程序特性信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- //程序特性
- for (ushort i = 0; i < 32; i++)
- {
- if (binary_data_1[2 + i] == 0x2E)
- {
- break;
- }
- if (binary_data_1[2 + i] == 'r')
- {
- binary_data_1[2 + i] = (byte)'.';
- }
- richTextBox_Ver.Text += ((char)binary_data_1[2 + i]).ToString();
- }
- richTextBox_Ver.Text += "\r\n";
- }));
- }
- break;
- }
- case 0xA318://单传感器零点值
- {
- unchecked
- {
- TorqueSensorZero = (ushort)((binary_data_1[3] << 8) + binary_data_1[2]);
- }
- break;
- }
- case 0xA903://反馈指令
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- Ack_Flag = true;
- StepTestFlag = StepTestResult_Enum.StepTestResult_OK;
- }));
- }
- break;
- }
- case 0xAE1A://三传感器零点
- {
- unchecked
- {
- if (binary_data_1[2] == 1)
- TorqueSensorZero1 = (ushort)((binary_data_1[4] << 8) + binary_data_1[3]);
- else if (binary_data_1[2] == 2)
- TorqueSensorZero2 = (ushort)((binary_data_1[4] << 8) + binary_data_1[3]);
- else if (binary_data_1[2] == 3)
- TorqueSensorZero3 = (ushort)((binary_data_1[4] << 8) + binary_data_1[3]);
- }
- break;
- }
- default: break;
- }
- }
- #endregion
- #region TE
- else if ((ID == 0x615) || (ID == 0x610))
- {
- switch (CmdTemp)
- {
- case 0x1240://TE APP版本信息
- {
- unchecked
- {
- this.Invoke((EventHandler)(delegate
- {
- //TE 软件版本
- richTextBox_Ver.Text += "TE软件版本:";
- for (ushort i = 0; i < 16; i++)
- {
- if (binary_data_1[50 + i] == 0x2E)
- {
- break;
- }
- if (binary_data_1[50 + i] == 'r')
- {
- binary_data_1[50 + i] = (byte)'.';
- }
- richTextBox_Ver.Text += ((char)binary_data_1[50 + i]).ToString();
- }
- }));
- }
- break;
- }
- default: break;
- }
- }
- #endregion
- #region //电池信息
- else if ((ID == 0x725) || (ID == 0x720))
- {
- label_BMS_COM.BackColor = Color.Green;
- label_BMS_COM.Text = "OK";
- }
- #endregion
- }
- #endregion
- //20ms定时器
- private void timer1_Tick(object sender, EventArgs e)
- {
- //串口数据解析
- Serial_DataReceived_Process();
- }
- #region 非独占性延时函数
- public static void Delay_ms(int milliSecond)
- {
- int start = Environment.TickCount;
- while (Math.Abs(Environment.TickCount - start) < milliSecond)//毫秒
- {
- Application.DoEvents();
- }
- }
- #endregion
- //电机运行信息清除
- private void MC_RunInfo_Clear()
- {
- foreach (Control c in groupBox9.Controls)
- {
- if (c is TextBox)
- {
- c.Text = "---";
- }
- }
- }
- private void ImportForm_FormClosing(object sender, FormClosingEventArgs e)
- {
- portsettings_form.serialPort1.Close();
- portsettings_form.comboBox_ComIndex.Enabled = true;
- portsettings_form.button_Enter.Text = "确认";
- portsettings_form.g_blnIsOpen = false;
- #if false
- //针对越南和工程账户,直接退出,不执行删除本地配置
- if ((StartForm.EnterForm1.comboBox_User.Text == "越南Vietnam")|| (StartForm.EnterForm1.comboBox_User.Text == "工程Engineer"))
- {
- return;
- }
- //关闭前,删除本地所有配置文件
- string path = StartForm.UserPath + "\\cfg\\";
- try
- {
- DirectoryInfo dir = new DirectoryInfo(path);
- FileSystemInfo[] fileinfo = dir.GetFileSystemInfos(); //返回目录中所有文件和子目录
- foreach (FileSystemInfo i in fileinfo)
- {
- if (i is DirectoryInfo) //判断是否文件夹
- {
- DirectoryInfo subdir = new DirectoryInfo(i.FullName);
- subdir.Delete(true); //删除子目录和文件
- }
- else
- {
- File.Delete(i.FullName); //删除指定文件
- }
- }
- //MessageBox.Show("文件清理成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- catch (Exception)
- {
- MessageBox.Show("文件清理失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- #endif
- }
- //开关灯
- private void LightProcess()
- {
- var CtrlCode = new byte[2];
- CtrlCode[0] = 0x00;
- if (button_LightCtl.Text == "开灯")
- {
- button_LightCtl.Text = "关灯";
- CtrlCode[1] = 0xF1;
- button_LightCtl.BackColor = Color.Yellow;
- button_LightCtl.ForeColor = Color.Black;
- }
- else
- {
- button_LightCtl.Text = "开灯";
- CtrlCode[1] = 0xF0;
- button_LightCtl.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
- button_LightCtl.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(113)))), ((int)(((byte)(185)))));
- }
- SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode);
- }
- //开关灯按钮
- private void button_LightCtl_Click(object sender, EventArgs e)
- {
- LightProcess();
- }
- //电机启动/停止控制
- private void Walk_Process(byte GearSt)
- {
- var Code = new byte[2];
- if (button_Walk.Text == "启动")
- {
- button_Walk.Text = "停止";
- //发送指令使电机进入配置模式
- Code[0] = 0x01;
- SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
- Thread.Sleep(200);
- //发送指令进入设定档位
- Code[0] = GearSt;
- if (button_LightCtl.Text == "关灯")
- Code[1] = 0xF1;
- else
- Code[1] = 0xF0;
- button_Walk.BackColor = Color.Yellow;
- button_Walk.ForeColor = Color.Black;
- SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
- }
- else
- {
- button_Walk.Text = "启动";
- //发送指令关闭档位模式
- Code[0] = 0x00;
- if (button_LightCtl.Text == "关灯")
- Code[1] = 0xF1;
- else
- Code[1] = 0xF0;
- SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
- Thread.Sleep(200);
- //发送指令使电机退出配置模式
- Code[0] = 0x00;
- button_Walk.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
- button_Walk.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(113)))), ((int)(((byte)(185)))));
- SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
- }
- }
- //电机启动/停止按钮
- private void button_Walk_Click(object sender, EventArgs e)
- {
- Walk_Process(0x22);
- }
- //查询版本信息
- private void button_Check_Ver_Click(object sender, EventArgs e)
- {
- richTextBox_Ver.Text = "";
- SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
- Delay_ms(200);
- SendCmd((ushort)0x651, (byte)0x11, (ushort)0x1200, null);
- }
- //按钮初始化
- private void label_Init()
- {
- radioButton_Light_OK.Checked = false;//灯电压确认按钮
- radioButton_Light_OK.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
- radioButton_Light_OK.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(113)))), ((int)(((byte)(185)))));
- radioButton_Light_NG.Checked = false;
- radioButton_Light_NG.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
- radioButton_Light_NG.ForeColor= System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(113)))), ((int)(((byte)(185)))));
- label_error_code.BackColor = Color.Green;//故障码
- label_error_code.Text = "OK";
- label_Sta_Clear.BackColor = Color.Red;//系统清除
- label_Sta_Clear.Text = "NG";
- label_Sta_Write.BackColor = Color.Red;//参数写入
- label_Sta_Write.Text = "NG";
- label_sta_light.BackColor = Color.Red;//灯电压
- label_sta_light.Text = "NG";
- label_sensor_vol.BackColor = Color.Red;//电压检测
- label_sensor_vol.Text = "NG";
- label_sensor_cur.BackColor = Color.Red;//电流检测
- label_sensor_cur.Text = "NG";
- label_sensor_speed.BackColor = Color.Red;//车速检测
- label_sensor_speed.Text = "NG";
- label_sensor_cadence.BackColor = Color.Red;//踏频检测
- label_sensor_cadence.Text = "NG";
- label_sensor_motor.BackColor = Color.Red;//电机转速检测
- label_sensor_motor.Text = "NG";
- label_sensor_PCB_temp.BackColor = Color.Red;//PCB温度检测
- label_sensor_PCB_temp.Text = "NG";
- label_sensor_coil_temp.BackColor = Color.Red;//绕组温度检测
- label_sensor_coil_temp.Text = "NG";
- label_sensor_MCU_temp.BackColor = Color.Red;//MCU温度检测
- label_sensor_MCU_temp.Text = "NG";
- label_Sensor_Break1.BackColor = Color.Red;//断电刹把
- label_Sensor_Break1.Text = "NG";
- label_Sensor_Break2.BackColor = Color.Red;//断电刹把
- label_Sensor_Break2.Text = "NG";
- label_sensor_tor.BackColor = Color.Red;//力矩零点
- label_sensor_tor.Text = "NG";
- label_Sensor_Gas.BackColor = Color.Red;//转把
- label_Sensor_Gas.Text = "NG";
- label_FW_Version.BackColor = Color.Red;//版本信息
- label_FW_Version.Text = "NG";
- label_Boot_Version.BackColor = Color.Red;//Boot 版本
- label_Boot_Version.Text = "NG";
- label_BMS_COM.BackColor = Color.Red;//BMS通信
- label_BMS_COM.Text = "NG";
- label_Result.BackColor = Color.Red;//测试结果
- label_Result.Text = "不合格";
- richTextBox_Ver.Text = "";//版本信息
- richTextBox_TestRecord.Text = "";//测试过程记录
- }
- //测试失败存储测试界面
- private void ErrorSaveLog()
- {
- //页面存储
- Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
- Graphics g = Graphics.FromImage(bit);
- g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片
- LogSaveFileName = LogSavePath + "\\errorlog\\" + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\";
- if (System.IO.Directory.Exists(LogSaveFileName) == false)
- System.IO.Directory.CreateDirectory(LogSaveFileName);
- LogSaveFileName += textBox_PDinfo.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_测试记录" + ".png";
- bit.Save(LogSaveFileName);
- //测试页面上传服务器
- if (StartForm.myFtp.IsNetConnected == true)
- {
- string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
- if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/walkTest/errorlog/", DateNow) == false)
- {
- StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/walkTest/errorlog/" + DateNow);
- }
- bool result = StartForm.myFtp.UploadFile(LogSaveFileName, StartForm.myServerCfg.RootPath + "/walkTest/errorlog/" + DateNow);
- if (result == true)
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试异常页面上传服务器成功" + "\r\n";
- }
- }
- //执行一次测试任务
- private void Thread_Task()
- {
- //开始测试
- richTextBox_TestRecord.Text += "电机信息:" + textBox_PDinfo.Text + "\r\n";
- richTextBox_TestRecord.Text += "配置文件:" + comboBox_File.Text + "\r\n";
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始测试" + "\r\n";
- //公有变量
- var Code = new byte[32];//发送的指令数据
- ushort DataTemp;
- short DataTemp_Int16;
- string ResultPathName = "";
- //开机
- Code[0] = 0xF1;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = true;
- 关ToolStripMenuItem.Checked = false;
- Delay_ms(500);
- //检查是否有故障
- if (label_error_code.Text != "OK")
- {
- label_Step.Text = "电机存在故障!";
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- #region Step1:发送指令,系统清除
- if (系统清除执行ToolStripMenuItem.Checked == true)
- {
- TestStep = TestStep_Enum.Step_SysClear;
- label_Step.Text = "系统清除,请等待!";
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送系统清除指令" + "\r\n";
- Array.Clear(Code, 0, 32);
- Code[0] = (byte)'C';
- Code[1] = (byte)'L';
- Code[2] = (byte)'E';
- Code[3] = (byte)'A';
- Code[4] = (byte)'R';
- SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
- Ack_Flag = false;
- Ack_Cnt = 0;
- StepTestFlag = StepTestResult_Enum.StepTestResult_Testing;
- while (StepTestFlag == StepTestResult_Enum.StepTestResult_Testing) ;//等待测试结束
- if (StepTestFlag == StepTestResult_Enum.StepTestResult_OK)//成功
- {
- richTextBox_TestRecord.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
- label_Sta_Clear.BackColor = Color.Green;
- label_Sta_Clear.Text = "OK";
- }
- else//失败
- {
- label_Step.Text = "系统清除失败,测试结束!";
- richTextBox_TestRecord.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除失败,测试结束" + "\r\n");
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- //系统清除完成后会重启,等待3s
- Delay_ms(2000);
- }
- else if (系统清除不执行ToolStripMenuItem.Checked == true)
- {
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "不执行系统清除" + "\r\n";
- label_Sta_Clear.BackColor = Color.Yellow;
- label_Sta_Clear.Text = "N/A";
- //发送复位指令,等待电机复位
- label_Step.Text = "系统复位,请等待!";
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送系统复位指令" + "\r\n";
- Array.Clear(Code, 0, 32);
- Code[0] = (byte)'R';
- Code[1] = (byte)'E';
- Code[2] = (byte)'S';
- Code[3] = (byte)'E';
- Code[4] = (byte)'T';
- SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2505, Code);
- Ack_Flag = false;
- Ack_Cnt = 0;
- StepTestFlag = StepTestResult_Enum.StepTestResult_Testing;
- while (StepTestFlag == StepTestResult_Enum.StepTestResult_Testing) ;//等待测试结束
- if (StepTestFlag == StepTestResult_Enum.StepTestResult_OK)//成功
- {
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统复位成功" + "\r\n";
- }
- else//失败
- {
- label_Step.Text = "系统复位失败,测试结束!";
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统复位失败,测试结束" + "\r\n";
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- //系统复位后会重启,等待1s
- Delay_ms(1000);
- }
- #endregion
- //初始化助力档位为OFF,避免配置无仪表时默认为SMART,导致参数不保存
- do
- {
- Code[0] = 0x00;
- Code[1] = 0xF0;
- SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, Code);
- Ack_Flag = false;
- Ack_Cnt = 0;
- StepTestFlag = StepTestResult_Enum.StepTestResult_Testing;
- while (StepTestFlag == StepTestResult_Enum.StepTestResult_Testing) ;//等待测试结束
- if (StepTestFlag == StepTestResult_Enum.StepTestResult_OK)//成功
- {
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "助力档位设置为OFF成功" + "\r\n";
- }
- else//失败
- {
- label_Step.Text = "通信失败!";
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "助力档位设置OFF失败,测试结束" + "\r\n";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- } while (false);
- //读力矩传感器零点
- do
- {
- //发送读取指令
- TorqueSensorZero = -1;
- TorqueSensorZero1 = -1;
- TorqueSensorZero2 = -1;
- TorqueSensorZero3 = -1;
- SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2000, null);//单传感器零点
- Delay_ms(200);
- Code[0] = 1;
- SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3201, Code);//传感器1零点
- Delay_ms(200);
- Code[0] = 2;
- SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3201, Code);//传感器2零点
- Delay_ms(200);
- Code[0] = 3;
- SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3201, Code);//传感器3零点
- Delay_ms(200);
- //比较
- if (TorqueSensorZero != -1)
- {
- if ((TorqueSensorZero >= TorSensorZeroMin) && (TorqueSensorZero <= TorSensorZeroMax))
- {
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器零点正常" + "," + TorqueSensorZero.ToString() + "\r\n";
- label_sensor_tor.BackColor = Color.Green;
- label_sensor_tor.Text = "OK";
- }
- else
- {
- label_Step.Text = "力矩传感器零点超范围";
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器零点超范围" + "," + TorqueSensorZero.ToString() + "\r\n";
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- }
- else if ((TorqueSensorZero1 != -1) && (TorqueSensorZero2 != -1) && (TorqueSensorZero3 != -1))
- {
- if (TorqueSensorZero1 != -1)
- {
- if ((TorqueSensorZero1 >= TorSensorZeroMin) && (TorqueSensorZero1 <= TorSensorZeroMax))
- {
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器1零点正常" + "," + TorqueSensorZero1.ToString() + "\r\n";
- label_sensor_tor.BackColor = Color.Green;
- label_sensor_tor.Text = "OK";
- }
- else
- {
- label_Step.Text = "力矩传感器1零点超范围";
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器1零点超范围" + "," + TorqueSensorZero1.ToString() + "\r\n";
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- }
- if (TorqueSensorZero2 != -1)
- {
- if ((TorqueSensorZero2 >= TorSensorZeroMin) && (TorqueSensorZero2 <= TorSensorZeroMax))
- {
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器2零点正常" + "," + TorqueSensorZero2.ToString() + "\r\n";
- label_sensor_tor.BackColor = Color.Green;
- label_sensor_tor.Text = "OK";
- }
- else
- {
- label_Step.Text = "力矩传感器2零点超范围";
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器零点2超范围" + "," + TorqueSensorZero2.ToString() + "\r\n";
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- }
- if (TorqueSensorZero3 != -1)
- {
- if ((TorqueSensorZero3 >= TorSensorZeroMin) && (TorqueSensorZero3 <= TorSensorZeroMax))
- {
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器3零点正常" + "," + TorqueSensorZero3.ToString() + "\r\n";
- label_sensor_tor.BackColor = Color.Green;
- label_sensor_tor.Text = "OK";
- }
- else
- {
- label_Step.Text = "力矩传感器3零点超范围";
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器3零点超范围" + "," + TorqueSensorZero3.ToString() + "\r\n";
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- }
- }
- else
- {
- label_Step.Text = "力矩传感器零点读取失败";
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "力矩传感器零点读取失败" + "\r\n";
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
-
- } while (false);
- #region Step2:发送指令,依次写入参数
- TestStep = TestStep_Enum.Step_Write;
- label_Step.Text = "参数写入中,请等待!";
- #region Step2.1:写入电机型号和序列号
- string Mode = textBox_PDinfo.Text.Contains("%#") ? textBox_PDinfo.Text.Substring(0, textBox_PDinfo.Text.LastIndexOf('%'))
- : textBox_PDinfo.Text.Substring(0, textBox_PDinfo.Text.LastIndexOf(' ')).Trim();
- string SN = textBox_PDinfo.Text.Contains("%#") ? textBox_PDinfo.Text.Remove(0, textBox_PDinfo.Text.LastIndexOf('#') + 1)
- : textBox_PDinfo.Text.Remove(0, textBox_PDinfo.Text.LastIndexOf(' ') + 1);
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入电机型号" + "\r\n";
- Array.Clear(Code, 0, 32);
- for (ushort i = 0; i < ((Mode.Length > 16) ? 16 : Mode.Length); i++)
- {
- Code[i] = (byte)Mode[i];
- }
- if (Mode.Length < 16)
- {
- Code[Mode.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
- {
- Code[Mode.Length + 1 + i] = 0x20;
- }
- }
- SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, Code);
- Ack_Flag = false;
- Ack_Cnt = 0;
- StepTestFlag = StepTestResult_Enum.StepTestResult_Testing;
- while (StepTestFlag == StepTestResult_Enum.StepTestResult_Testing) ;//等待测试结束
- if (StepTestFlag == StepTestResult_Enum.StepTestResult_OK)//成功
- {
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机型号写入成功" + "\r\n";
- }
- else//失败
- {
- label_Step.Text = "参数写入失败,测试结束!";
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机型号写入失败,测试结束" + "\r\n";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- Delay_ms(200);
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入电机序列号" + "\r\n";
- Array.Clear(Code, 0, 32);
- for (ushort i = 0; i < ((SN.Length > 16) ? 16 : SN.Length); i++)
- {
- Code[i] = (byte)SN[i];
- }
- if (SN.Length < 16)
- {
- Code[SN.Length] = (byte)'.';
- for (ushort i = 0; i < 16 - SN.Length - 1; i++)
- {
- Code[SN.Length + 1 + i] = 0x20;
- }
- }
- SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, Code);
- Ack_Flag = false;
- Ack_Cnt = 0;
- StepTestFlag = StepTestResult_Enum.StepTestResult_Testing;
- while (StepTestFlag == StepTestResult_Enum.StepTestResult_Testing) ;//等待测试结束
- if (StepTestFlag == StepTestResult_Enum.StepTestResult_OK)//成功
- {
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机序列号写入成功" + "\r\n";
- }
- else//失败
- {
- label_Step.Text = "参数写入失败,测试结束!";
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机序列号写入失败,测试结束" + "\r\n";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- #endregion
- #region Step2.2:写入用户参数1
- Delay_ms(200);
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入用户参数1" + "\r\n";
- Array.Clear(Code, 0, 32);
- //指拨模式
- Code[0] = Convert.ToByte(array_CfgInfo[25].ToString().Split(',')[1]);
- //启动模式
- Code[1] = Convert.ToByte(array_CfgInfo[1].ToString().Split(',')[1]);
- //停机时间
- DataTemp = Convert.ToUInt16(array_CfgInfo[2].ToString().Split(',')[1]);
- Code[2] = (byte)(DataTemp & 0xFF);
- Code[3] = (byte)(DataTemp >> 8);
- //限速
- Code[4] = Convert.ToByte(array_CfgInfo[3].ToString().Split(',')[1]);
- //下降速度
- Code[5] = Convert.ToByte(array_CfgInfo[4].ToString().Split(',')[1]);
- //前飞
- Code[6] = Convert.ToByte(array_CfgInfo[5].ToString().Split(',')[1]);
- //后飞
- Code[7] = Convert.ToByte(array_CfgInfo[6].ToString().Split(',')[1]);
- //限流
- Code[8] = Convert.ToByte(array_CfgInfo[7].ToString().Split(',')[1]);
- //温度预警
- Code[9] = (byte)(Convert.ToByte(array_CfgInfo[8].ToString().Split(',')[1]) + 40);
- //温度保护
- Code[10] = (byte)(Convert.ToByte(array_CfgInfo[9].ToString().Split(',')[1]) + 40);
- //无PBU
- Code[11] = Convert.ToByte(array_CfgInfo[10].ToString().Split(',')[1]);
- //轮胎周长
- Code[12] = Convert.ToByte(array_CfgInfo[11].ToString().Split(',')[1]);
- //电机系列号
- Code[13] = Convert.ToByte(array_CfgInfo[12].ToString().Split(',')[1]);
- //ECO助力增益
- Code[14] = Convert.ToByte(array_CfgInfo[13].ToString().Split(',')[1]);
- //ECO加速
- Code[15] = Convert.ToByte(array_CfgInfo[14].ToString().Split(',')[1]);
- //NORM助力增益
- Code[16] = Convert.ToByte(array_CfgInfo[15].ToString().Split(',')[1]);
- //NORM加速
- Code[17] = Convert.ToByte(array_CfgInfo[16].ToString().Split(',')[1]);
- //SPORT助力增益
- Code[18] = Convert.ToByte(array_CfgInfo[17].ToString().Split(',')[1]);
- //SPORT加速
- Code[19] = Convert.ToByte(array_CfgInfo[18].ToString().Split(',')[1]);
- //TURBO助力增益
- Code[20] = Convert.ToByte(array_CfgInfo[19].ToString().Split(',')[1]);
- //TURBO加速
- Code[21] = Convert.ToByte(array_CfgInfo[20].ToString().Split(',')[1]);
- //SMART助力增益
- Code[22] = Convert.ToByte(array_CfgInfo[21].ToString().Split(',')[1]);
- //SMART加速
- Code[23] = Convert.ToByte(array_CfgInfo[22].ToString().Split(',')[1]);
- //速度传感器信号个数
- Code[24] = Convert.ToByte(array_CfgInfo[23].ToString().Split(',')[1]);
- //踏频启动信号个数
- Code[25] = Convert.ToByte(array_CfgInfo[24].ToString().Split(',')[1]);
- //速度传感器
- Code[26] = Convert.ToByte(array_CfgInfo[26].ToString().Split(',')[1]);
- //周长微调
- Code[27] = (byte)Convert.ToInt16(array_CfgInfo[27].ToString().Split(',')[1]);
- //低压保护阈值
- DataTemp = Convert.ToUInt16(array_CfgInfo[28].ToString().Split(',')[1]);
- Code[28] = (byte)(DataTemp & 0xFF);
- Code[29] = (byte)(DataTemp >> 8);
- //推行限速
- DataTemp = Convert.ToByte(array_CfgInfo[29].ToString().Split(',')[1]);
- Code[30] = (byte)Convert.ToByte(DataTemp);
- //推行马达转速
- Code[31] = (byte)Convert.ToByte(array_CfgInfo[30].ToString().Split(',')[1]);
- SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1B20, Code);
- Ack_Flag = false;
- Ack_Cnt = 0;
- StepTestFlag = StepTestResult_Enum.StepTestResult_Testing;
- while (StepTestFlag == StepTestResult_Enum.StepTestResult_Testing) ;//等待测试结束
- if (StepTestFlag == StepTestResult_Enum.StepTestResult_OK)//成功
- {
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "用户参数1写入成功" + "\r\n";
- }
- else//失败
- {
- label_Step.Text = "参数写入失败,测试结束!";
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "用户参数1写入失败,测试结束" + "\r\n";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- #endregion
- #region Step2.3:写入用户参数2
- Delay_ms(200);
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入用户参数2" + "\r\n";
- Array.Clear(Code, 0, 32);
- //俯仰角零偏
- DataTemp = Convert.ToUInt16(array_CfgInfo[34].ToString().Split(',')[1]);
- Code[0] = (byte)(DataTemp & 0xFF);
- Code[1] = (byte)(DataTemp >> 8);
- //横滚角零偏
- DataTemp = Convert.ToUInt16(array_CfgInfo[35].ToString().Split(',')[1]);
- Code[2] = (byte)(DataTemp & 0xFF);
- Code[3] = (byte)(DataTemp >> 8);
- //支持姿态传感器
- Code[4] = Convert.ToByte(array_CfgInfo[33].ToString().Split(',')[1]);
- //尾灯模式
- Code[5] = Convert.ToByte(array_CfgInfo[36].ToString().Split(',')[1]);
- //前灯电压
- Code[6] = Convert.ToByte(array_CfgInfo[37].ToString().Split(',')[1]);
- //后灯电压
- Code[7] = Convert.ToByte(array_CfgInfo[38].ToString().Split(',')[1]);
- //超速报警阈值
- DataTemp = Convert.ToUInt16(array_CfgInfo[39].ToString().Split(',')[1]);
- Code[8] = (byte)(DataTemp & 0xFF);
- Code[9] = (byte)(DataTemp >> 8);
- //尾灯脉宽
- DataTemp = Convert.ToUInt16(array_CfgInfo[40].ToString().Split(',')[1]);
- Code[10] = (byte)(DataTemp & 0xFF);
- Code[11] = (byte)(DataTemp >> 8);
- //尾灯周期
- DataTemp = Convert.ToUInt16(array_CfgInfo[41].ToString().Split(',')[1]);
- Code[12] = (byte)(DataTemp & 0xFF);
- Code[13] = (byte)(DataTemp >> 8);
- //起始限速
- Code[14] = Convert.ToByte(array_CfgInfo[42].ToString().Split(',')[1]);
- //结束限速
- Code[15] = Convert.ToByte(array_CfgInfo[43].ToString().Split(',')[1]);
- //限速微调
- Code[16] = Convert.ToByte(array_CfgInfo[44].ToString().Split(',')[1]);
- //预留
- Code[17] = 0x00;
- //ECO最大电流增益
- Code[18] = Convert.ToByte(array_CfgInfo[45].ToString().Split(',')[1]);
- //ECO最大力矩增益
- Code[19] = Convert.ToByte(array_CfgInfo[46].ToString().Split(',')[1]);
- //NORM最大电流增益
- Code[20] = Convert.ToByte(array_CfgInfo[47].ToString().Split(',')[1]);
- //NORM最大力矩增益
- Code[21] = Convert.ToByte(array_CfgInfo[48].ToString().Split(',')[1]);
- //SPORT最大电流增益
- Code[22] = Convert.ToByte(array_CfgInfo[49].ToString().Split(',')[1]);
- //SPORT最大力矩增益
- Code[23] = Convert.ToByte(array_CfgInfo[50].ToString().Split(',')[1]);
- //TURBO最大电流增益
- Code[24] = Convert.ToByte(array_CfgInfo[51].ToString().Split(',')[1]);
- //TURBO最大力矩增益
- Code[25] = Convert.ToByte(array_CfgInfo[52].ToString().Split(',')[1]);
- //SMART最大电流增益
- Code[26] = Convert.ToByte(array_CfgInfo[53].ToString().Split(',')[1]);
- //SMART最大力矩增益
- Code[27] = Convert.ToByte(array_CfgInfo[54].ToString().Split(',')[1]);
- SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3120, Code);
- Ack_Flag = false;
- Ack_Cnt = 0;
- StepTestFlag = StepTestResult_Enum.StepTestResult_Testing;
- while (StepTestFlag == StepTestResult_Enum.StepTestResult_Testing) ;//等待测试结束
- if (StepTestFlag == StepTestResult_Enum.StepTestResult_OK)//成功
- {
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "用户参数2写入成功" + "\r\n";
- }
- else//失败
- {
- label_Step.Text = "参数写入失败,测试结束!";
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "用户参数2写入失败,测试结束" + "\r\n";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- #endregion
- #region Step2.4:写入马达参数
- Delay_ms(200);
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入马达参数" + "\r\n";
- Array.Clear(Code, 0, 32);
- //额定功率
- DataTemp = Convert.ToUInt16(array_CfgInfo[57].ToString().Split(',')[1]);
- Code[0] = (byte)(DataTemp & 0xFF);
- Code[1] = (byte)(DataTemp >> 8);
- //额定转速
- DataTemp = Convert.ToUInt16(array_CfgInfo[58].ToString().Split(',')[1]);
- Code[2] = (byte)(DataTemp & 0xFF);
- Code[3] = (byte)(DataTemp >> 8);
- //定子电阻
- DataTemp = Convert.ToUInt16(array_CfgInfo[59].ToString().Split(',')[1]);
- Code[4] = (byte)(DataTemp & 0xFF);
- Code[5] = (byte)(DataTemp >> 8);
- //Lq
- DataTemp = Convert.ToUInt16(array_CfgInfo[60].ToString().Split(',')[1]);
- Code[6] = (byte)(DataTemp & 0xFF);
- Code[7] = (byte)(DataTemp >> 8);
- //Ld
- DataTemp = Convert.ToUInt16(array_CfgInfo[61].ToString().Split(',')[1]);
- Code[8] = (byte)(DataTemp & 0xFF);
- Code[9] = (byte)(DataTemp >> 8);
- //反电动势
- DataTemp = Convert.ToUInt16(array_CfgInfo[62].ToString().Split(',')[1]);
- Code[10] = (byte)(DataTemp & 0xFF);
- Code[11] = (byte)(DataTemp >> 8);
- //额定电压
- Code[12] = Convert.ToByte(array_CfgInfo[63].ToString().Split(',')[1]);
- SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1D10, Code);
- Ack_Flag = false;
- Ack_Cnt = 0;
- StepTestFlag = StepTestResult_Enum.StepTestResult_Testing;
- while (StepTestFlag == StepTestResult_Enum.StepTestResult_Testing) ;//等待测试结束
- if (StepTestFlag == StepTestResult_Enum.StepTestResult_OK)//成功
- {
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "马达参数写入成功" + "\r\n";
- }
- else//失败
- {
- label_Step.Text = "参数写入失败,测试结束!";
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "马达参数写入失败,测试结束" + "\r\n";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- #endregion
- #region Step2.5:写入生产信息
- Delay_ms(200);
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入生产信息" + "\r\n";
- Array.Clear(Code, 0, 32);
- string MAC_Info = array_CfgInfo[66].ToString().Split(',')[1];
- for (ushort i = 0; i < ((MAC_Info.Length > 8) ? 8 : MAC_Info.Length); i++) //品牌
- {
- Code[i] = (byte)MAC_Info[i];
- }
- MAC_Info = array_CfgInfo[67].ToString().Split(',')[1];
- for (ushort i = 0; i < ((MAC_Info.Length > 8) ? 8 : MAC_Info.Length); i++) //生产地
- {
- Code[8 + i] = (byte)MAC_Info[i];
- }
- MAC_Info = array_CfgInfo[68].ToString().Split(',')[1];
- for (ushort i = 0; i < ((MAC_Info.Length > 8) ? 8 : MAC_Info.Length); i++) //生产日期
- {
- Code[16 + i] = (byte)MAC_Info[i];
- }
- MAC_Info = "MM_VP1. ";
- for (ushort i = 0; i < ((MAC_Info.Length > 8) ? 8 : MAC_Info.Length); i++) //产品标识
- {
- Code[24 + i] = (byte)MAC_Info[i];
- }
- SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, Code);
- Ack_Flag = false;
- Ack_Cnt = 0;
- StepTestFlag = StepTestResult_Enum.StepTestResult_Testing;
- while (StepTestFlag == StepTestResult_Enum.StepTestResult_Testing) ;//等待测试结束
- if (StepTestFlag == StepTestResult_Enum.StepTestResult_OK)//成功
- {
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "生产信息写入成功" + "\r\n";
- }
- else//失败
- {
- label_Step.Text = "参数写入失败,测试结束!";
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "生产信息写入失败,测试结束" + "\r\n";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- #endregion
- #region Step2.6:写入校验密钥
- Delay_ms(200);
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入校验密钥" + "\r\n";
- Array.Clear(Code, 0, 32);
- if (array_CfgInfo[69].ToString().EndsWith(",") == false)
- {
- string KeyString = array_CfgInfo[69].ToString().Split(',')[1];
- for (ushort i = 0; i < ((KeyString.Length > 8) ? 8 : KeyString.Length); i++)
- {
- Code[i] = (byte)KeyString[i];
- }
- }
- else
- {
- Code.Initialize();
- }
- SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1108, Code);
- Ack_Flag = false;
- Ack_Cnt = 0;
- StepTestFlag = StepTestResult_Enum.StepTestResult_Testing;
- while (StepTestFlag == StepTestResult_Enum.StepTestResult_Testing) ;//等待测试结束
- if (StepTestFlag == StepTestResult_Enum.StepTestResult_OK)//成功
- {
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "校验密钥写入成功" + "\r\n";
- }
- else//失败
- {
- label_Step.Text = "参数写入失败,测试结束!";
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "校验密钥写入失败,测试结束" + "\r\n";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- #endregion
- #region Step2.7:写入自定义信息1、2、3
- //自定义信息1
- Delay_ms(200);
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入自定义信息1" + "\r\n";
- Array.Clear(Code, 0, 32);
- if (array_CfgInfo[70].ToString().EndsWith(",") == false)
- {
- string UserInfo1String = array_CfgInfo[70].ToString().Split(',')[1];
- for (ushort i = 0; i < (UserInfo1String.Length > 16 ? 16 : UserInfo1String.Length); i++)
- {
- Code[i] = (byte)UserInfo1String[i];
- }
- }
- else
- {
- Array.Clear(Code, 0, 16);
- }
- SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1410, Code);
- Ack_Flag = false;
- Ack_Cnt = 0;
- StepTestFlag = StepTestResult_Enum.StepTestResult_Testing;
- while (StepTestFlag == StepTestResult_Enum.StepTestResult_Testing) ;//等待测试结束
- if (StepTestFlag == StepTestResult_Enum.StepTestResult_OK)//成功
- {
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "自定义信息1写入成功" + "\r\n";
- }
- else//失败
- {
- label_Step.Text = "参数写入失败,测试结束!";
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "自定义信息1写入失败,测试结束" + "\r\n";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- //自定义信息2
- Delay_ms(200);
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入自定义信息2" + "\r\n";
- Array.Clear(Code, 0, 32);
- if (array_CfgInfo[71].ToString().EndsWith(",") == false)
- {
- string UserInfo2String = array_CfgInfo[71].ToString().Split(',')[1];
- for (ushort i = 0; i < (UserInfo2String.Length > 16 ? 16 : UserInfo2String.Length); i++)
- {
- Code[i] = (byte)UserInfo2String[i];
- }
- }
- else
- {
- Array.Clear(Code, 0, 16);
- }
- SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1610, Code);
- Ack_Flag = false;
- Ack_Cnt = 0;
- StepTestFlag = StepTestResult_Enum.StepTestResult_Testing;
- while (StepTestFlag == StepTestResult_Enum.StepTestResult_Testing) ;//等待测试结束
- if (StepTestFlag == StepTestResult_Enum.StepTestResult_OK)//成功
- {
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "自定义信息2写入成功" + "\r\n";
- }
- else//失败
- {
- label_Step.Text = "参数写入失败,测试结束!";
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "自定义信息2写入失败,测试结束" + "\r\n";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- //自定义信息3
- Delay_ms(200);
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入自定义信息3" + "\r\n";
- Array.Clear(Code, 0, 32);
- if (array_CfgInfo[72].ToString().EndsWith(",") == false)
- {
- string UserInfo3String = array_CfgInfo[72].ToString().Split(',')[1];
- for (ushort i = 0; i < (UserInfo3String.Length > 16 ? 16 : UserInfo3String.Length); i++)
- {
- Code[i] = (byte)UserInfo3String[i];
- }
- }
- else
- {
- Array.Clear(Code, 0, 16);
- }
- SendCmd((ushort)0x751, (byte)0x16, (ushort)0x1810, Code);
- Ack_Flag = false;
- Ack_Cnt = 0;
- StepTestFlag = StepTestResult_Enum.StepTestResult_Testing;
- while (StepTestFlag == StepTestResult_Enum.StepTestResult_Testing) ;//等待测试结束
- if (StepTestFlag == StepTestResult_Enum.StepTestResult_OK)//成功
- {
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "自定义信息3写入成功" + "\r\n";
- }
- else//失败
- {
- label_Step.Text = "参数写入失败,测试结束!";
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "自定义信息3写入失败,测试结束" + "\r\n";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- #endregion
- //参数写入完成
- label_Sta_Write.BackColor = Color.Green;
- label_Sta_Write.Text = "OK";
- #endregion
- if (推行测试执行ToolStripMenuItem.Checked == true)
- {
- #region Step3:灯电压测试
- TestStep = TestStep_Enum.Step_Light;
- label_Step.Text = "灯电压测试,请确认电压!";
- button_LightCtl.Text = "开灯";
- LightProcess();
- radioButton_Light_OK.Checked = false;
- radioButton_Light_OK.BackColor = Color.Green;
- radioButton_Light_OK.ForeColor = Color.White;
- radioButton_Light_OK.Enabled = true;
- radioButton_Light_NG.Checked = false;
- radioButton_Light_NG.Enabled = true;
- radioButton_Light_NG.BackColor = Color.Red;
- radioButton_Light_NG.ForeColor = Color.White;
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送开灯指令,请确认灯电压是否正确……" + "\r\n";
- while ((radioButton_Light_OK.Checked == false) && (radioButton_Light_NG.Checked == false)) ;
- if (radioButton_Light_OK.Checked == true)
- {
- label_sta_light.BackColor = Color.Green;
- radioButton_Light_NG.BackColor = Color.Gray;
- label_sta_light.Text = "OK";
- radioButton_Light_OK.Enabled = false;
- radioButton_Light_NG.Enabled = false;
- }
- else if (radioButton_Light_NG.Checked == true)
- {
- label_sta_light.BackColor = Color.Red;
- radioButton_Light_OK.BackColor = Color.Gray;
- label_sta_light.Text = "NG";
- label_Step.Text = "灯电压错误,测试结束!";
- button_LightCtl.Text = "关灯";
- LightProcess();
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "灯电压错误,测试结束" + "\r\n";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- radioButton_Light_OK.Enabled = false;
- radioButton_Light_NG.Enabled = false;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "灯电压确认完成" + "\r\n";
- button_LightCtl.Text = "关灯";
- LightProcess();
- #endregion
- #region Step4:推行测试
- TestStep = TestStep_Enum.Step_Walk;
- //判断母线电压
- label_Step.Text = "母线电压检测!";
- button_Walk.Text = "启动";
- Walk_Process(0x00);
- Delay_ms(500);
- try
- {
- DataTemp = Convert.ToUInt16(textBox_Vol.Text);
- }
- catch (System.Exception ex)
- {
- MessageBox.Show(ex.Message);
- label_Step.Text = "母线电压测试异常,测试结束!";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- if ((DataTemp > (RateVoltage - 1000)) && (DataTemp < (RateVoltage + 1000)))
- {
- if (label_sensor_vol.BackColor == Color.Red)
- {
- label_sensor_vol.BackColor = Color.Green;
- label_sensor_vol.Text = "OK";
- }
- }
- else
- {
- label_Step.Text = "母线电压异常,测试结束!";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- //传感器判断
- label_Step.Text = "推行测试,电机开始自动运转!";
- button_Walk.Text = "启动";
- Walk_Process(0x22);
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机进入推行模式,请注意安全!" + "\r\n";
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "传感器自动检测开始" + "\r\n";
- OK_cnt = 0;
- WalkProcess_Cnt = 0;
- while (WalkProcess_Cnt < 20)//开始判断传感器,超时20s
- {
- //车速传感器 1
- if (SpeedSensorTest == false)
- {
- if (label_sensor_speed.BackColor == Color.Red)
- {
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过车速传感器测试" + "\r\n";
- label_sensor_speed.BackColor = Color.Green;
- label_sensor_speed.Text = "OK";
- OK_cnt++;
- }
- }
- else
- {
- try
- {
- DataTemp = (ushort)(Convert.ToDecimal(textBox_BikeSpeed.Text) * 10);
- }
- catch (System.Exception ex)
- {
- MessageBox.Show(ex.Message);
- label_Step.Text = "推行测试异常,测试结束!";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- if ((DataTemp > (SpeedSensorThData - 50)) && (DataTemp < (SpeedSensorThData + 50)))
- {
- if (label_sensor_speed.BackColor == Color.Red)
- {
- label_sensor_speed.BackColor = Color.Green;
- label_sensor_speed.Text = "OK";
- OK_cnt++;
- }
- }
- }
- //马达转速 2
- try
- {
- DataTemp = Convert.ToUInt16(textBox_MotorSpeed.Text);
- }
- catch (System.Exception ex)
- {
- MessageBox.Show(ex.Message);
- label_Step.Text = "推行测试异常,测试结束!";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- if ((DataTemp > (MotorRadeSpeed - 200)) && (DataTemp < (MotorRadeSpeed + 200)))
- {
- if (label_sensor_motor.BackColor == Color.Red)
- {
- label_sensor_motor.BackColor = Color.Green;
- label_sensor_motor.Text = "OK";
- OK_cnt++;
- }
- }
- ////母线电压,推行时母线电压会被抬高,放到静止是检测
- //try
- //{
- // DataTemp = Convert.ToUInt16(textBox_Vol.Text);
- //}
- //catch (System.Exception ex)
- //{
- // MessageBox.Show(ex.Message);
- // label_Step.Text = "推行测试异常,测试结束!";
- // //关机
- // Code[0] = 0xF0;
- // SendCmd(0x7FF, 0x16, 0x2201, Code);
- // 开ToolStripMenuItem.Checked = false;
- // 关ToolStripMenuItem.Checked = true;
- // button_Start.Enabled = true;
- // textBox_PDinfo.Enabled = true;
- // Delay_ms(500);
- // //关闭串口
- // portsettings_form.closePort();
- // //存储测试数据
- // ErrorSaveLog();
- // return;
- //}
- //if ((DataTemp > (RateVoltage - 1000)) && (DataTemp < (RateVoltage + 1000)))
- //{
- // if (label_sensor_vol.BackColor == Color.Red)
- // {
- // label_sensor_vol.BackColor = Color.Green;
- // label_sensor_vol.Text = "OK";
- // OK_cnt++;
- // }
- //}
- //母线电流 3
- try
- {
- DataTemp = Convert.ToUInt16(textBox_Cur.Text);
- }
- catch (System.Exception ex)
- {
- MessageBox.Show(ex.Message);
- label_Step.Text = "推行测试异常,测试结束!";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- if ((DataTemp > No_load_Current - 500) && (DataTemp < No_load_Current + 500))
- {
- if (label_sensor_cur.BackColor == Color.Red)
- {
- label_sensor_cur.BackColor = Color.Green;
- label_sensor_cur.Text = "OK";
- OK_cnt++;
- }
- }
- //踏频 4
- try
- {
- DataTemp = Convert.ToUInt16(textBox_Cadence.Text);
- }
- catch (System.Exception ex)
- {
- MessageBox.Show(ex.Message);
- label_Step.Text = "推行测试异常,测试结束!";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- if ((DataTemp > (RateCadence - 20)) && (DataTemp < (RateCadence + 20)))
- {
- if (label_sensor_cadence.BackColor == Color.Red)
- {
- label_sensor_cadence.BackColor = Color.Green;
- label_sensor_cadence.Text = "OK";
- OK_cnt++;
- }
- }
- //PCB温度 5
- try
- {
- DataTemp_Int16 = Convert.ToInt16(textBox_PCB.Text);
- }
- catch (System.Exception ex)
- {
- MessageBox.Show(ex.Message);
- label_Step.Text = "推行测试异常,测试结束!";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- if ((DataTemp_Int16 > -20) && (DataTemp_Int16 < 60))
- {
- if (label_sensor_PCB_temp.BackColor == Color.Red)
- {
- label_sensor_PCB_temp.BackColor = Color.Green;
- label_sensor_PCB_temp.Text = "OK";
- OK_cnt++;
- }
- }
- //绕组温度 6
- try
- {
- DataTemp_Int16 = Convert.ToInt16(textBox_Coil.Text);
- }
- catch (System.Exception ex)
- {
- MessageBox.Show(ex.Message);
- label_Step.Text = "推行测试异常,测试结束!";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- if ((DataTemp_Int16 > -20) && (DataTemp_Int16 < 60))
- {
- if (label_sensor_coil_temp.BackColor == Color.Red)
- {
- label_sensor_coil_temp.BackColor = Color.Green;
- label_sensor_coil_temp.Text = "OK";
- OK_cnt++;
- }
- }
- //MCU温度 7
- try
- {
- DataTemp_Int16 = Convert.ToInt16(textBox_MOS.Text);
- }
- catch (System.Exception ex)
- {
- MessageBox.Show(ex.Message);
- label_Step.Text = "推行测试异常,测试结束!";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- if ((DataTemp_Int16 > -20) && (DataTemp_Int16 < 60))
- {
- if (label_sensor_MCU_temp.BackColor == Color.Red)
- {
- label_sensor_MCU_temp.BackColor = Color.Green;
- label_sensor_MCU_temp.Text = "OK";
- OK_cnt++;
- }
- }
- //测试完成,退出
- if (OK_cnt == 7)
- {
- break;
- }
- }
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "传感器自动检测结束" + "\r\n";
- //断电开关1
- label_Step.Text = "请在10s内捏下断电刹把 1!";
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "断电刹把 1 检测开始,请捏下断电刹把 1" + "\r\n";
- WalkProcess_Cnt = 0;
- while (WalkProcess_Cnt < 15)//10s内判断电机是否停止
- {
- try
- {
- DataTemp = Convert.ToUInt16(textBox_MotorSpeed.Text);
- }
- catch (System.Exception ex)
- {
- MessageBox.Show(ex.Message);
- label_Step.Text = "推行测试异常,测试结束!";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- if (DataTemp < 100)
- {
- if (label_Sensor_Break1.BackColor == Color.Red)
- {
- label_Sensor_Break1.BackColor = Color.Green;
- label_Sensor_Break1.Text = "OK";
- OK_cnt++;
- }
- break;
- }
- }
- label_Step.Text = "请松开断电刹把 1";
- WalkProcess_Cnt = 0;
- while (WalkProcess_Cnt < 10)//等待电机再次启动,如果超时提示错误
- {
- try
- {
- DataTemp = Convert.ToUInt16(textBox_MotorSpeed.Text);
- }
- catch (System.Exception ex)
- {
- MessageBox.Show(ex.Message);
- label_Step.Text = "推行测试异常,测试结束!";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- if (DataTemp > 300)//电机转速超过300rpm,再次启动测试
- break;
- }
- if (WalkProcess_Cnt >= 10)//表示超时退出,电机未启动
- {
- label_Step.Text = "推行测试异常,测试结束!";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- //断电开关2
- label_Step.Text = "请在10s内捏下断电刹把 2!";
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "断电刹把 2 检测开始,请捏下断电刹把 2" + "\r\n";
- WalkProcess_Cnt = 0;
- while (WalkProcess_Cnt < 15)//10s内判断电机是否停止
- {
- try
- {
- DataTemp = Convert.ToUInt16(textBox_MotorSpeed.Text);
- }
- catch (System.Exception ex)
- {
- MessageBox.Show(ex.Message);
- label_Step.Text = "推行测试异常,测试结束!";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- if (DataTemp < 100)
- {
- if (label_Sensor_Break2.BackColor == Color.Red)
- {
- label_Sensor_Break2.BackColor = Color.Green;
- label_Sensor_Break2.Text = "OK";
- OK_cnt++;
- }
- break;
- }
- }
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "断电刹把检测结束" + "\r\n";
- label_Step.Text = "请松开断电刹把 2!";
- button_Walk.Text = "停止";
- Walk_Process(0x00);
- Delay_ms(1000);
- //判断测试结果
- if (OK_cnt < 9)
- {
- label_Step.Text = "推行测试异常,测试结束!";
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "推行测试失败,测试结束" + "\r\n";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- //判断BMS通信是否正常
- if (BMS检测执行ToolStripMenuItem1.Checked == true)
- {
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检测BMS通信状态" + "\r\n";
- if (label_BMS_COM.Text != "OK")
- {
- label_Step.Text = "BMS通信异常,测试结束!";
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "推行测试失败,测试结束" + "\r\n";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- }
- else if (BMS检测不执行ToolStripMenuItem1.Checked == true)
- {
- label_BMS_COM.BackColor = Color.Yellow;
- label_BMS_COM.Text = "N/A";
- }
- #endregion
- #region Step5:转把模式测试(非必需)
- if (GasModeTest == false)
- {
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过指拨模式测试" + "\r\n";
- label_Sensor_Gas.BackColor = Color.Green;
- label_Sensor_Gas.Text = "OK";
- }
- else
- {
- TestStep = TestStep_Enum.Step_GasMode;
- label_Step.Text = "指拨模式测试,请在10s内转动指拨!";
- button_Walk.Text = "启动";
- Walk_Process(0x04);
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "指拨模式测试开始,请转动指拨" + "\r\n";
- OK_cnt = 0;
- WalkProcess_Cnt = 0;
- while (WalkProcess_Cnt < 10)//10s内判断电机是否启动
- {
- try
- {
- DataTemp = Convert.ToUInt16(textBox_MotorSpeed.Text);
- }
- catch (System.Exception ex)
- {
- MessageBox.Show(ex.Message);
- label_Step.Text = "推行测试异常,测试结束!";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- if ((DataTemp > (GasModeSpeed - 100)) && (DataTemp < (GasModeSpeed + 100)))
- {
- label_Sensor_Gas.BackColor = Color.Green;
- label_Sensor_Gas.Text = "OK";
- OK_cnt++;
- break;
- }
- }
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "指拨模式测试结束" + "\r\n";
- Delay_ms(1000);
- button_Walk.Text = "停止";
- Walk_Process(0x00);
- //判断测试结果
- if (OK_cnt < 1)
- {
- label_Step.Text = "指拨模式测试异常,测试结束!";
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "指拨模式测试失败,测试结束" + "\r\n";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- }
- #endregion
- }
- else
- {
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "不执行推行测试" + "\r\n";
- label_sta_light.BackColor = Color.Yellow;
- label_sta_light.Text = "N/A";
- label_sensor_cadence.BackColor = Color.Yellow;
- label_sensor_cadence.Text = "N/A";
- label_sensor_cur.BackColor = Color.Yellow;
- label_sensor_cur.Text = "N/A";
- label_sensor_vol.BackColor = Color.Yellow;
- label_sensor_vol.Text = "N/A";
- label_sensor_motor.BackColor = Color.Yellow;
- label_sensor_motor.Text = "N/A";
- label_sensor_coil_temp.BackColor = Color.Yellow;
- label_sensor_coil_temp.Text = "N/A";
- label_sensor_MCU_temp.BackColor = Color.Yellow;
- label_sensor_MCU_temp.Text = "N/A";
- label_sensor_PCB_temp.BackColor = Color.Yellow;
- label_sensor_PCB_temp.Text = "N/A";
- label_sensor_speed.BackColor = Color.Yellow;
- label_sensor_speed.Text = "N/A";
- label_Sensor_Gas.BackColor = Color.Yellow;
- label_Sensor_Gas.Text = "N/A";
- label_Sensor_Break1.BackColor = Color.Yellow;
- label_Sensor_Break1.Text = "N/A";
- label_Sensor_Break2.BackColor = Color.Yellow;
- label_Sensor_Break2.Text = "N/A";
- label_BMS_COM.BackColor = Color.Yellow;
- label_BMS_COM.Text = "N/A";
- label_sensor_tor.BackColor = Color.Yellow;
- label_sensor_tor.Text = "N/A";
- }
- #region Step6:版本查询和确认
- TestStep = TestStep_Enum.Step_CheckVer;
- label_Step.Text = "版本查询和确认";
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "发送指令查询版本信息" + "\r\n";
- richTextBox_Ver.Text = "";
- SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);//查询主控版本
- Delay_ms(200);
- SendCmd((ushort)0x651, (byte)0x11, (ushort)0x1200, null);//查询TE版本
- Delay_ms(200);
- string FW_Version_Check = comboBox_File.Text.Split('_')[2] + "_" + comboBox_File.Text.Split('_')[3];
- string FW_Version_Result = "";
- string TE_FW_Ver_Check = comboBox_File.Text.Split('_')[4] + "_" + comboBox_File.Text.Split('_')[5];
- string TE_FW_Ver_Result = "";
- try
- {
- FW_Version_Result = richTextBox_Ver.Lines[3].Split(':')[1];
- FW_Version_Result = FW_Version_Result.Split('_')[0] + richTextBox_Ver.Lines[4].Split('-')[2].Replace('V', '.') + "_" + FW_Version_Result.Split('_')[1];
- TE_FW_Ver_Result = richTextBox_Ver.Lines[5].Split(':')[1];
- }
- catch (System.Exception)
- {
- //label_Step.Text = "软件版本信息不完整!";
- }
- if (string.Equals(FW_Version_Check.Trim(), FW_Version_Result.Trim()) == false) //主控版本错误,直接结束
- {
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息错误" + "\r\n";
- label_Step.Text = "软件版本错误,测试结束!";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- else
- {
- if (TE_FW_Ver_Check != "N_A") //单MCU主控板不检测TE版本
- {
- if (string.Equals(TE_FW_Ver_Check, TE_FW_Ver_Result) == false) //TE版本错误,给出提示
- {
- if (MessageBox.Show("TE版本错误,请确认主控板是否为HK?", "TE版本错误", MessageBoxButtons.YesNo) == DialogResult.No)
- {
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "TE软件版本错误" + "\r\n";
- label_Step.Text = "TE软件版本错误,测试结束!";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- }
- }
- label_FW_Version.BackColor = Color.Green;
- label_FW_Version.Text = "OK";
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "版本信息正确" + "\r\n";
- }
- Delay_ms(1000);
- //检查Boot版本是否正确
- if (label_Boot_Version.Text != "OK")
- {
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "Bootloader波特率错误" + "\r\n";
- label_Step.Text = "Bootloader波特率错误,测试结束!";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- #endregion
- #region 按照产品信息设置测试文件路径
- ResultPathName = textBox_PDinfo.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_");
- if (System.IO.Directory.Exists(LogSavePath + "log\\" + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ResultPathName) == false)
- System.IO.Directory.CreateDirectory(LogSavePath + "log\\" + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ResultPathName);
- #endregion
- #region Step7:参数查询和保存
- TestStep = TestStep_Enum.Step_Save;
- label_Step.Text = "参数导出";
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "开始导出电机内部参数" + "\r\n";
- LogSaveFileName = LogSavePath + "log\\" + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ResultPathName + "\\ParamsLog" + ".ttlog";
- //开始发送指令
- byte[] SendData = new byte[32];
- //查询校验密钥
- SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null);
- Delay_ms(100);
- //查询版本信息
- //SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1200, null);
- //Delay_ms(100);
- //SendCmd((ushort)0x651, (byte)0x11, (ushort)0x1200, null);
- //Delay_ms(100);
- //查询用户字符串1
- SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null);
- Delay_ms(100);
- //查询用户字符串2
- SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null);
- Delay_ms(100);
- //查询用户字符串3
- SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null);
- Delay_ms(100);
- //查询用户参数1
- SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1A00, null);
- Delay_ms(100);
- //查询马达参数
- SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1C00, null);
- Delay_ms(100);
- //查询历史信息
- SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null);
- Delay_ms(100);
- //查询生产信息
- SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);
- Delay_ms(100);
- //查询力矩传感器零点 Volans
- SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2000, null);
- Delay_ms(100);
- //查询运行信息
- SendData[0] = 0x00;
- SendData[1] = 0xF0;
- SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, SendData);
- Delay_ms(100);
- SendData[0] = 0x01;
- SendData[1] = 0xF0;
- SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, SendData);
- Delay_ms(100);
- SendData[0] = 0x02;
- SendData[1] = 0xF0;
- SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, SendData);
- Delay_ms(100);
- SendData[0] = 0x03;
- SendData[1] = 0xF0;
- SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, SendData);
- Delay_ms(100);
- SendData[0] = 0x04;
- SendData[1] = 0xF0;
- SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, SendData);
- Delay_ms(100);
- SendData[0] = 0x33;
- SendData[1] = 0xF0;
- SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, SendData);
- Delay_ms(100);
- //查询力矩传感器校正信息 Volans
- SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2900, null);
- Delay_ms(100);
- //导出故障日志
- UInt32 Address_Begin;
- UInt32 Addres_End;
- Address_Begin = 0x0801F800;
- Addres_End = 0x0801FBFF;
- UInt32 ReadCount = 0;
- ReadCount = (Addres_End - Address_Begin + 1) / 128;
- for (ushort i = 0; i < ReadCount; i++)
- {
- var SendByte = new byte[8];
- UInt32 Address_Temp_Begin;
- UInt32 Address_Temp_End;
- Address_Temp_Begin = Address_Begin + 128 * (UInt32)i;
- SendByte[0] = (byte)(Address_Temp_Begin >> 24);
- SendByte[1] = (byte)(Address_Temp_Begin >> 16);
- SendByte[2] = (byte)(Address_Temp_Begin >> 8);
- SendByte[3] = (byte)(Address_Temp_Begin);
- Address_Temp_End = Address_Temp_Begin + 127;
- SendByte[4] = (byte)(Address_Temp_End >> 24);
- SendByte[5] = (byte)(Address_Temp_End >> 16);
- SendByte[6] = (byte)(Address_Temp_End >> 8);
- SendByte[7] = (byte)(Address_Temp_End);
- SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2D08, SendByte);
- Delay_ms(100);
- }
- //查询骑行信息
- SendCmd((ushort)0x751, (byte)0x11, (ushort)0x2E00, null);
- Delay_ms(100);
- //查询用户参数2
- SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3000, null);
- Delay_ms(100);
- //查询力矩传感器零点值 Pegasi
- SendData[0] = 1;
- SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3201, SendData);
- Delay_ms(100);
- SendData[0] = 2;
- SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3201, SendData);
- Delay_ms(100);
- SendData[0] = 3;
- SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3201, SendData);
- Delay_ms(100);
- //查询校正系数 Pegasi
- SendData[0] = 1;
- SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3301, SendData);
- Delay_ms(100);
- SendData[0] = 2;
- SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3301, SendData);
- Delay_ms(100);
- SendData[0] = 3;
- SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3301, SendData);
- Delay_ms(100);
- //查询启动值 Pegasi
- SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3500, null);
- Delay_ms(100);
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机参数导出完成" + "\r\n";
- #endregion
- //检查是否有故障
- if (label_error_code.Text != "OK")
- {
- label_Step.Text = "电机存在故障!";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //存储测试数据
- ErrorSaveLog();
- return;
- }
- //显示测试结果
- label_Result.BackColor = Color.Green;
- label_Result.Text = "合格";
- label_Step.Text = "合格,测试结束!";
- label_Step.ForeColor = Color.Green;
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "合格,测试结束" + "\r\n";
- //关机
- Code[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Code);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- button_Start.Enabled = true;
- textBox_PDinfo.Enabled = true;
- Delay_ms(500);
- //关闭串口
- portsettings_form.closePort();
- //合格计数累加和存储
- label_OK_Count.Text = (Convert.ToInt32(label_OK_Count.Text) + 1).ToString();
- string cfg_file = System.IO.Directory.GetCurrentDirectory() + "\\TestSerialNum";
- StreamReader objReader = new StreamReader(cfg_file);
- string sLine = "";
- ArrayList arrText = new ArrayList();//创建一个动态数组
- while (sLine != null)
- {
- sLine = objReader.ReadLine();
- arrText.Add(sLine);
- }
- arrText.RemoveAt(arrText.Count - 1);
- objReader.Close();
- arrText[3] = label_OK_Count.Text;
- using (StreamWriter file = new StreamWriter(cfg_file))
- {
- foreach (var entry in arrText)
- {
- file.WriteLine(entry);
- }
- }
- //导出的参数上传服务器
- if (StartForm.myFtp.IsNetConnected == true)
- {
- string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
- if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/walkTest/log/", DateNow) == false)
- {
- StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow);
- }
- if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow, ResultPathName) == false)
- {
- StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow + "/" + ResultPathName);
- }
- bool result = StartForm.myFtp.UploadFile(LogSaveFileName, StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow + "/" + ResultPathName);
- if (result == true)
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电机配置参数上传服务器成功" + "\r\n";
- }
- //保存测试信息
- //页面存储
- Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
- Graphics g = Graphics.FromImage(bit);
- g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片
- LogSaveFileName = LogSavePath + "log\\" + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ResultPathName + "\\测试页面" + ".png";
- bit.Save(LogSaveFileName);
- //测试页面上传服务器
- if (StartForm.myFtp.IsNetConnected == true)
- {
- string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
- if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/walkTest/log/", DateNow) == false)
- {
- StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow);
- }
- if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow, ResultPathName) == false)
- {
- StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow + "/" + ResultPathName);
- }
- bool result = StartForm.myFtp.UploadFile(LogSaveFileName, StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow + "/" + ResultPathName);
- if (result == true)
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试页面上传服务器成功" + "\r\n";
- }
- //保存测试记录
- LogSaveFileName = LogSavePath + "log\\" + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\" + ResultPathName + "\\测试记录" + ".txt";
- string fileInfo = "";
- fileInfo += "检验记录:\r\n" + richTextBox_TestRecord.Text.Replace("\n", "\r\n") + "\r\n\r\n";
- fileInfo += "电机生产参数:\r\n";
- fileInfo += richTextBox_CfgFile.Text.Replace("\n", "\r\n") + "\r\n\r\n";
- fileInfo += "电机版本信息查询:\r\n";
- fileInfo += richTextBox_Ver.Text.Replace("\n", "\r\n") + "\r\n\r\n";
- fileInfo += "电机故障码:\r\n";
- fileInfo += label_error_code.Text.Replace("\n", "\r\n") + "\r\n\r\n";
- fileInfo += "测试结果:\r\n";
- fileInfo += label_Result.Text.Replace("\n", "\r\n") + "\r\n\r\n";
- System.IO.File.WriteAllText(LogSaveFileName, fileInfo);
- //测试记录上传服务器
- if (StartForm.myFtp.IsNetConnected == true)
- {
- string DateNow = DateTime.Now.ToString("yyyy-MM-dd");
- if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/walkTest/log/", DateNow) == false)
- {
- StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow);
- }
- if (StartForm.myFtp.DirectoryExist(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow, ResultPathName) == false)
- {
- StartForm.myFtp.MakeDir(StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow + "/" + ResultPathName);
- }
- bool result = StartForm.myFtp.UploadFile(LogSaveFileName, StartForm.myServerCfg.RootPath + "/walkTest/log/" + DateNow + "/" + ResultPathName);
- if (result == true)
- richTextBox_TestRecord.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "测试记录上传服务器成功" + "\r\n";
- }
- //测试正常,清空扫码信息
- Delay_ms(1000);
- textBox_PDinfo.Text = "";
- }
- //开始测试
- private void button_Start_Click(object sender, EventArgs e)
- {
- TestStart();
- }
- //测试子函数
- private void TestStart()
- {
- //标签初始化
- label_Init();
- //检查设置
- if ((推行测试执行ToolStripMenuItem.Checked == false) && (推行测试不执行ToolStripMenuItem.Checked == false))
- {
- label_Step.Text = "请先选择是否执行\"推行测试\"!";
- label_Step.ForeColor = Color.Red;
- return;
- }
- if ((系统清除执行ToolStripMenuItem.Checked == false) && (系统清除不执行ToolStripMenuItem.Checked == false))
- {
- label_Step.Text = "请先选择是否执行\"系统清除\"!";
- label_Step.ForeColor = Color.Red;
- return;
- }
- if ((BMS检测执行ToolStripMenuItem1.Checked == false) && (BMS检测不执行ToolStripMenuItem1.Checked == false))
- {
- label_Step.Text = "请先选择是否执行\"BMS通信检测\"!";
- label_Step.ForeColor = Color.Red;
- return;
- }
- #region 检查配置文件
- if (comboBox_File.Items.Count == 0) //配置文件目录为空
- {
- label_Step.Text = "无可用配置文件!";
- label_Step.ForeColor = Color.Red;
- return;
- }
- if (comboBox_File.Text.Trim().Length == 0)//未选择配置文件
- {
- label_Step.Text = "请选择配置文件!";
- return;
- }
- #endregion
- #region 检查产品信息是否符合格式要求
- try
- {
- 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]?$");
- if (textBox_PDinfo.Text.Contains(" "))
- {
- string Mode = textBox_PDinfo.Text.Split(new string[] { " " }, StringSplitOptions.None)[0];
- string Sn = textBox_PDinfo.Text.Split(new string[] { " " }, StringSplitOptions.None)[1];
- if (regex.IsMatch(Sn) == false)
- {
- label_Step.Text = "SN格式错误!";
- label_Step.ForeColor = Color.Red;
- return;
- }
- }
- else if (textBox_PDinfo.Text.Contains("%#"))
- {
- string Mode = textBox_PDinfo.Text.Split(new string[] { "%#" }, StringSplitOptions.None)[0];
- string Sn = textBox_PDinfo.Text.Split(new string[] { "%#" }, StringSplitOptions.None)[1];
- if (regex.IsMatch(Sn) == false)
- {
- label_Step.Text = "SN格式错误!";
- label_Step.ForeColor = Color.Red;
- return;
- }
- }
- else
- {
- label_Step.Text = "标签格式错误!";
- label_Step.ForeColor = Color.Red;
- return;
- }
- }
- catch (System.Exception)
- {
- label_Step.Text = "标签格式错误!";
- label_Step.ForeColor = Color.Red;
- return;
- }
- #endregion
- #region 检查产品型号和配置文件是否一致
- do
- {
- string cfg_mode = "", pd_mode = "";
- cfg_mode = comboBox_File.Text.Split('_')[0];
- if (textBox_PDinfo.Text.Contains(" "))
- {
- pd_mode = textBox_PDinfo.Text.Split(new string[] { " " }, StringSplitOptions.None)[0];
- }
- else if (textBox_PDinfo.Text.Contains("%#"))
- {
- pd_mode = textBox_PDinfo.Text.Split(new string[] { "%#" }, StringSplitOptions.None)[0];
- }
- if (pd_mode != cfg_mode)
- {
- label_Step.Text = "打标信息与配置文件不一致!";
- label_Step.ForeColor = Color.Red;
- return;
- }
- } while (false);
- #endregion
- //连接串口
- if (portsettings_form.openPort() == false)
- {
- label_Step.Text = "串口连接失败!";
- label_Step.ForeColor = Color.Red;
- return;
- }
- //测试状态更新
- TestStep = TestStep_Enum.Step_Init;
- label_Step.Text = "准备开始测试";
- label_Step.ForeColor = Color.Red;
- //流水号累加和存储
- label_SerialNum.Text = (Convert.ToInt32(label_SerialNum.Text) + 1).ToString();
- string cfg_file = System.IO.Directory.GetCurrentDirectory() + "\\TestSerialNum";
- StreamReader objReader = new StreamReader(cfg_file);
- string sLine = "";
- ArrayList arrText = new ArrayList();//创建一个动态数组
- while (sLine != null)
- {
- sLine = objReader.ReadLine();
- arrText.Add(sLine);
- }
- arrText.RemoveAt(arrText.Count - 1);
- objReader.Close();
- arrText[1] = label_SerialNum.Text;
- using (StreamWriter file = new StreamWriter(cfg_file))
- {
- foreach (var entry in arrText)
- {
- file.WriteLine(entry);
- }
- }
- button_Start.Enabled = false;
- textBox_PDinfo.Enabled = false;
- //创建线程,执行测试任务
- Thread th = new Thread(Thread_Task);
- th.Start();
- }
- //1s计时
- private void timer2_Tick(object sender, EventArgs e)
- {
- label_SystemTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- //MC故障信息超时清除
- if (MC_ErrorCode_Refresh == false)
- {
- MC_ErrorCode_Refresh_Cnt++;
- if (MC_ErrorCode_Refresh_Cnt > 5)
- {
- label_error_code.Text = "OK";
- label_error_code.BackColor = Color.Green;
- label_ErrorInfo.Text = "无故障";
- label_ErrorInfo.ForeColor = Color.Green;
- MC_ErrorCode_Refresh_Cnt = 0;
- }
- }
- else
- {
- MC_ErrorCode_Refresh_Cnt = 0;
- }
- MC_ErrorCode_Refresh = false;
- //MC_RunInfo超时清除
- if (MC_RunInfo_Refresh == false)
- {
- MC_RunInfo_Refresh_Cnt++;
- if (MC_RunInfo_Refresh_Cnt > 5)
- {
- MC_RunInfo_Clear();
- MC_RunInfo_Refresh_Cnt = 0;
- }
- }
- else
- {
- MC_RunInfo_Refresh_Cnt = 0;
- }
- MC_RunInfo_Refresh = false;
- //等待反馈指令
- if (Ack_Flag == false)
- {
- Ack_Cnt++;
- if (Ack_Cnt > 2)
- {
- Ack_Flag = true;
- StepTestFlag = StepTestResult_Enum.StepTestResult_Fail;
- }
- }
- //推行测试计时
- if ((TestStep == TestStep_Enum.Step_Walk) || (TestStep == TestStep_Enum.Step_GasMode))
- {
- WalkProcess_Cnt++;
- }
- }
- //打开系统开关
- private void 开ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- byte[] Data = new byte[1];
- if (portsettings_form.serialPort1.IsOpen)
- {
- //开机
- Data[0] = 0xF1;
- SendCmd(0x7FF, 0x16, 0x2201, Data);
- 开ToolStripMenuItem.Checked = true;
- 关ToolStripMenuItem.Checked = false;
- }
- else
- {
- MessageBox.Show("串口未连接");
- return;
- }
- }
- //关闭系统开关
- private void 关ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- byte[] Data = new byte[1];
- if (portsettings_form.serialPort1.IsOpen)
- {
- //关机
- Data[0] = 0xF0;
- SendCmd(0x7FF, 0x16, 0x2201, Data);
- 开ToolStripMenuItem.Checked = false;
- 关ToolStripMenuItem.Checked = true;
- }
- else
- {
- MessageBox.Show("串口未连接");
- return;
- }
- }
- //清除流水号
- private void label8_DoubleClick(object sender, EventArgs e)
- {
- StartForm.EnterForm1.ShowDialog();
- try
- {
- if (StartForm.EnterForm1.textBox_Passwd.Text == StartForm.EnterForm1.UserAccount[StartForm.EnterForm1.comboBox_User.Text])
- {
- if (StartForm.EnterForm1.comboBox_User.Text == "工程Engineer")
- {
- //流水号清零
- if (MessageBox.Show("流水号清零", "确认清零?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- label_SerialNum.Text = "0";
- label_OK_Count.Text = "0";
- //存储
- string cfg_file = System.IO.Directory.GetCurrentDirectory() + "\\TestSerialNum";
- StreamReader objReader = new StreamReader(cfg_file);
- string sLine = "";
- ArrayList arrText = new ArrayList();//创建一个动态数组
- while (sLine != null)
- {
- sLine = objReader.ReadLine();
- arrText.Add(sLine);
- }
- arrText.RemoveAt(arrText.Count - 1);
- objReader.Close();
- arrText[1] = label_SerialNum.Text;
- arrText[3] = label_OK_Count.Text;
- using (StreamWriter file = new StreamWriter(cfg_file))
- {
- foreach (var entry in arrText)
- {
- file.WriteLine(entry);
- }
- }
- }
- }
- else
- {
- MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- catch (Exception)
- {
- MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- private void richTextBox_TestRecord_TextChanged(object sender, EventArgs e)
- {
- richTextBox_TestRecord.SelectionStart = richTextBox_TestRecord.Text.Length;
- richTextBox_TestRecord.ScrollToCaret();
- }
- private void textBox_PDinfo_Click(object sender, EventArgs e)
- {
- textBox_PDinfo.SelectAll();
- }
- private void textBox_PDinfo_KeyUp(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- TestStart();
- }
- }
- private void 屏幕键盘ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- System.Diagnostics.Process.Start("osk.exe");
- }
- private void 端口选择ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- portsettings_form.Show();
- }
- private void BMS检测执行ToolStripMenuItem1_Click(object sender, EventArgs e)
- {
- BMS检测执行ToolStripMenuItem1.Checked = true;
- BMS检测不执行ToolStripMenuItem1.Checked = false;
- label_TestFunsUpdate();
- }
- private void BMS检测不执行ToolStripMenuItem1_Click(object sender, EventArgs e)
- {
- StartForm.EnterForm1.ShowDialog();
- try
- {
- if (StartForm.EnterForm1.textBox_Passwd.Text == StartForm.EnterForm1.UserAccount[StartForm.EnterForm1.comboBox_User.Text])
- {
- if (StartForm.EnterForm1.comboBox_User.Text == "工程Engineer")
- {
- BMS检测不执行ToolStripMenuItem1.Checked = true;
- BMS检测执行ToolStripMenuItem1.Checked = false;
- label_TestFunsUpdate();
- }
- else
- {
- MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- catch (Exception)
- {
- MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- private void 推行测试执行ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- 推行测试执行ToolStripMenuItem.Checked = true;
- 推行测试不执行ToolStripMenuItem.Checked = false;
- label_TestFunsUpdate();
- }
- private void 推行测试不执行ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- StartForm.EnterForm1.ShowDialog();
- try
- {
- if (StartForm.EnterForm1.textBox_Passwd.Text == StartForm.EnterForm1.UserAccount[StartForm.EnterForm1.comboBox_User.Text])
- {
- if (StartForm.EnterForm1.comboBox_User.Text == "工程Engineer")
- {
- 推行测试不执行ToolStripMenuItem.Checked = true;
- 推行测试执行ToolStripMenuItem.Checked = false;
- label_TestFunsUpdate();
- }
- else
- {
- MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- catch (Exception)
- {
- MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- private void 系统清除执行ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- 系统清除执行ToolStripMenuItem.Checked = true;
- 系统清除不执行ToolStripMenuItem.Checked = false;
- label_TestFunsUpdate();
- }
- private void 系统清除不执行ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- StartForm.EnterForm1.ShowDialog();
- try
- {
- if (StartForm.EnterForm1.textBox_Passwd.Text == StartForm.EnterForm1.UserAccount[StartForm.EnterForm1.comboBox_User.Text])
- {
- if (StartForm.EnterForm1.comboBox_User.Text == "工程Engineer")
- {
- 系统清除执行ToolStripMenuItem.Checked = false;
- 系统清除不执行ToolStripMenuItem.Checked = true;
- label_TestFunsUpdate();
- }
- else
- {
- MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- catch (Exception)
- {
- MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- private void label_TestFunsUpdate()
- {
- label_TestFun.Text = "测试功能:";
- if (系统清除执行ToolStripMenuItem.Checked == true)
- label_TestFun.Text += "系统清除 ";
- label_TestFun.Text += "参数写入 ";
- if(推行测试执行ToolStripMenuItem.Checked==true)
- label_TestFun.Text += "推行测试 ";
- if(BMS检测执行ToolStripMenuItem1.Checked==true)
- label_TestFun.Text += "BMS通信检测 ";
- }
- private void 只写入参数ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- if (只写入参数ToolStripMenuItem.Checked == true)
- {
- 系统清除不执行ToolStripMenuItem.Checked = false;
- 系统清除执行ToolStripMenuItem.Checked = true;
- 推行测试不执行ToolStripMenuItem.Checked = false;
- 推行测试执行ToolStripMenuItem.Checked = true;
- BMS检测不执行ToolStripMenuItem1.Checked = false;
- BMS检测执行ToolStripMenuItem1.Checked = true;
- 只写入参数ToolStripMenuItem.Checked = false;
- 推行测试ToolStripMenuItem.Enabled = true;
- bMS通信检测ToolStripMenuItem.Enabled = true;
- 系统清除ToolStripMenuItem.Enabled = true;
- label_TestFunsUpdate();
- }
- else
- {
- StartForm.EnterForm1.ShowDialog();
- try
- {
- if (StartForm.EnterForm1.textBox_Passwd.Text == StartForm.EnterForm1.UserAccount[StartForm.EnterForm1.comboBox_User.Text])
- {
- if (StartForm.EnterForm1.comboBox_User.Text == "工程Engineer")
- {
- 系统清除执行ToolStripMenuItem.Checked = false;
- 系统清除不执行ToolStripMenuItem.Checked = true;
- 推行测试执行ToolStripMenuItem.Checked = false;
- 推行测试不执行ToolStripMenuItem.Checked = true;
- BMS检测执行ToolStripMenuItem1.Checked = false;
- BMS检测不执行ToolStripMenuItem1.Checked = true;
- 只写入参数ToolStripMenuItem.Checked = true;
- 推行测试ToolStripMenuItem.Enabled = false;
- bMS通信检测ToolStripMenuItem.Enabled = false;
- 系统清除ToolStripMenuItem.Enabled = false;
- label_TestFunsUpdate();
- }
- else
- {
- MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- catch (Exception)
- {
- MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
-
- }
- private void 删除配置文件ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- StartForm.EnterForm1.ShowDialog();
- try
- {
- if (StartForm.EnterForm1.textBox_Passwd.Text == StartForm.EnterForm1.UserAccount[StartForm.EnterForm1.comboBox_User.Text])
- {
- if (StartForm.EnterForm1.comboBox_User.Text == "工程Engineer")
- {
- try
- {
- StartForm.myFtp.DeleteFile(StartForm.myServerCfg.RootPath + "/cfg" + "/" + comboBox_cfgFileDate.Text + "/" + comboBox_File.Text);
- 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";
- 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";
- StartForm.myFtp.DeleteFile(StartForm.myServerCfg.RootPath + "/cfg" + "/" + comboBox_cfgFileDate.Text + "/" + pdfFimeName);
- StartForm.myFtp.DeleteFile(StartForm.myServerCfg.RootPath + "/cfg" + "/" + comboBox_cfgFileDate.Text + "/" + xlsFimeName);
- MessageBox.Show("删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- catch (Exception)
- {
- MessageBox.Show("删除异常", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- MessageBox.Show("权限不支持", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- catch (Exception)
- {
- MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- private void 合格ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- System.Diagnostics.Process.Start("explorer.exe", LogSavePath + "log\\");
- }
- private void 不合格ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- System.Diagnostics.Process.Start("explorer.exe", LogSavePath + "errorlog\\");
- }
- private void 备忘录ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- StartForm.NoteForm.ShowDialog();
- }
- }
- }
|