//中止线程 private void TerminateTask(object sender, Task_Level level) { if (TaskDoneHandler != null) { TaskArgs mArgs = new TaskArgs(); mArgs.level = level; TaskDoneHandler(sender, mArgs); } }
private void TaskStatusNotify(object sender, string msg, int value, Task_Level level) { if (level == Task_Level.TASK_INIT) { mTaskStatus = Task_Level.TASK_INIT; mPcuUpgradeStartTask.InitTask(); mPcuUpgradeProcessTask.InitTask(); mPcuUpgradeDoneTask.InitTask(); mPcuUpgradeRunningTask.InitTask(); mPcuUpgradeRequestTask.InitTask(); mPcuEvent.Reset(); if (mPcuStream != null) { mPcuStream.Dispose(); if (mPcuStream != null) { mPcuStream.Close(); } else { mPcuStream = null; } } mPcuStream = new FileStream(this.mfilePath, FileMode.Open, FileAccess.Read); PCU_FILE_LENGTH = (int)mPcuStream.Length; } else if (level == Task_Level.TASK_PROGRESS) { if (pcuProgressBarHandler != null) { ProgressArgs mArgs = new ProgressArgs(); mArgs.percentage = value; pcuProgressBarHandler(sender, mArgs); } } else if (level == Task_Level.TASK_DONE) { if (TaskDoneHandler != null) { TaskArgs mArgs = new TaskArgs(); mArgs.level = mTaskStatus; TaskDoneHandler(sender, mArgs); } } }
private void UpdateLviStatus(object sender, string msg, Task_Level level) { if (level == Task_Level.TASK_PASS) { mTaskStatus = level; } if (level == Task_Level.TASK_FAIL) { mTaskStatus = level; this.pcuWorkTask.CancelAsync(); Thread.Sleep(5); mPcuEvent.Set(); } if (PcuLviHandler != null) { TaskArgs mArgs = new TaskArgs(); mArgs.msg = msg; mArgs.level = level; PcuLviHandler(sender, mArgs); } }
private void TaskBuilder() { //停止同步报文 mStopSyncTask = new SimpleSerialPortTask <pcTakeOverRsp, NullEntity>(); mStopSyncParam = mStopSyncTask.GetRequestEntity(); mStopSyncTask.RetryMaxCnts = 0; mStopSyncTask.Timerout = 1000; mStopSyncParam.DeviceType = 0xF1; mStopSyncParam.HardWareID = 0xF1; // mStopSyncParam.FirmID = 17; //mStopSyncParam.FirmID1 = 35; //mStopSyncParam.FirmID2 = 4; //重启指令 mResetEcuTask = new SimpleSerialPortTask <ResetEcuReq, NullEntity>(); mResetEcuParam = mResetEcuTask.GetRequestEntity(); mResetEcuTask.RetryMaxCnts = 0; mResetEcuTask.Timerout = 1000; mResetEcuParam.deviceType = 0XF1; mResetEcuParam.cmdCode = 0x02; mResetEcuParam.param1 = 0x11223344; //等待同步报文 mBroadCastTask = new SimpleSerialPortTask <NullEntity, pcTakeoverReq>(); mBroadCastTask.RetryMaxCnts = 0; mBroadCastTask.Timerout = 500; mBroadCastTask.SimpleSerialPortTaskOnPostExecute += (object sender, EventArgs e) => { SerialPortEventArgs <pcTakeoverReq> mEventArgs = e as SerialPortEventArgs <pcTakeoverReq>; if (mEventArgs.Data != null) { byte hw1 = (byte)(mEventArgs.Data.hardwareID >> 24); byte hw2 = (byte)(mEventArgs.Data.hardwareID >> 16); byte hw3 = (byte)(mEventArgs.Data.hardwareID >> 8); string softVersion = String.Format("W{0}{1:D2}.{2:D2}", (byte)(mEventArgs.Data.hardwareID >> 24), (byte)(mEventArgs.Data.hardwareID >> 16), (byte)(mEventArgs.Data.hardwareID >> 8)); mStopSyncParam.FirmID = hw1; mStopSyncParam.FirmID1 = hw2; mStopSyncParam.FirmID2 = hw3; //PC接管报文的响应 mStopSyncTask.Excute(); Thread.Sleep(5); mStopSyncTask.Excute(); Thread.Sleep(5); mStopSyncTask.Excute(); Thread.Sleep(5); if (mParam.bPCU) { mPcuTask.ExcuteTask();//开始升级PCU } else if (mParam.bCCU) { mCcuTask.ExcuteTask();//开始升级CCU } } else { if (mParam.bPCU) { mPcuTask.ExcuteTask();//开始升级PCU } else if (mParam.bCCU) { //设备未上电 TaskArgs mArgs = new TaskArgs(); mArgs.msg = "中控未上电"; mArgs.level = Task_Level.TASK_FAIL; ccuListViewItemHandler(sender, mArgs); bTaskRunning = false; mResetEcuParam.cmdCode = 0x02; //升级失败或者其他,恢复同步指令 mResetEcuTask.Excute(); Thread.Sleep(10); mResetEcuTask.Excute(); Thread.Sleep(10); mResetEcuTask.Excute(); Thread.Sleep(10); mBroadCastTask.ClosePort(); } } }; mPcuTask = new PcuTask(this.mParam.mPcuFilePath); //执行结束回调 mPcuTask.TaskDoneHandler += (object sender, EventArgs e) => { TaskArgs mArgs = e as TaskArgs; if (mParam.bCCU && mArgs.level == Task_Level.TASK_PASS) { if (mCcuTask != null) { mCcuTask.ExcuteTask(); } } else { bTaskRunning = false; mResetEcuParam.cmdCode = 0x02; //升级失败或者其他,恢复同步指令 mResetEcuTask.Excute(); Thread.Sleep(10); mResetEcuTask.Excute(); Thread.Sleep(10); mResetEcuTask.Excute(); Thread.Sleep(10); mBroadCastTask.ClosePort(); } }; //PCU Item mPcuTask.PcuLviHandler += (object sender, EventArgs e) => { pcuListViewItemHandler(sender, e); }; //PCU 进度回调 mPcuTask.pcuProgressBarHandler += (object sender, EventArgs e) => { pcuProgressBarHandler(sender, e); }; mCcuTask = new CcuTask(this.mParam.mCcuFilePath); //执行结束后回调 mCcuTask.TaskDoneHandler += (object sender, EventArgs e) => { bTaskRunning = false; TaskArgs mArgs = e as TaskArgs; if (mArgs.level == Task_Level.TASK_PASS) { mResetEcuParam.cmdCode = 0x01; //升级成功后,进行重启 } else { mResetEcuParam.cmdCode = 0x02; //升级失败或者其他,恢复同步指令 } mResetEcuTask.Excute(); Thread.Sleep(10); mResetEcuTask.Excute(); Thread.Sleep(10); mResetEcuTask.Excute(); Thread.Sleep(10); mBroadCastTask.ClosePort(); }; //CCU Item mCcuTask.CcuLviHandler += (object sender, EventArgs e) => { ccuListViewItemHandler(sender, e); }; //CCU 进度回调 mCcuTask.CcuProgressBarHandler += (object sender, EventArgs e) => { ccuProgressBarHandler(sender, e); }; }