/// <summary> /// 在非UI线程上执行检测 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TestBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker bgWorker = sender as BackgroundWorker; using (PcbTesterClient client = PcbTesterClient.Create(Settings.Default.PortName, Settings.Default.BaudRate)) { client.Open(); progressValue = 0; List <CommandResult> commandResultsList = new List <CommandResult>(); for (int i = 0; i < this.landing1.SelectedTestItems.Count; i++) { TestItemInfo testItem = this.landing1.SelectedTestItems[i]; bgWorker.ReportProgress(i); progressValue = i; var testResult = CommandEngine.Instance.Excute(client, testItem); commandResultsList.Add(testResult); bgWorker.ReportProgress(i, testResult); //在操作的过程中需要检查用户是否取消了当前的操作。 if (bgWorker.CancellationPending == true) { e.Cancel = true; break; } } e.Result = commandResultsList; } }
public static CommandResult ControlRelay(PcbTesterClient client, RelayControlCommandParameter relayParameter) { client.Open(); var relayControlCommand = new RelayControlCommand(); try { CommandResult result = relayControlCommand.Execute(client, relayParameter, null); } catch (CommunicationException ex) { throw new CommunicationException(ex.Message); } return(new CommandResult(true)); }
/// <summary> /// 上模拟电压电流,导通5V 模拟电压 模拟电流继电器 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void onAnalogVolCurrentToolStripMenuItem_Click(object sender, EventArgs e) { using (PcbTesterClient client = PcbTesterClient.Create(Settings.Default.PortName, Settings.Default.BaudRate)) { try { client.Open(); RelayControlHelper.ControlRelay(client, new RelayControlCommandParameter(RelayControlAction.OPEN, "0,1,2,3,4,5,6")); } catch (Exception ex) { MessageBoxHelper.ShowError(ex.Message); return; } } }
/// <summary> /// 断电复位 关闭所有继电器 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void resetToolStripMenuItem_Click(object sender, EventArgs e) { using (PcbTesterClient client = PcbTesterClient.Create(Settings.Default.PortName, Settings.Default.BaudRate)) { try { client.Open(); RelayControlHelper.Reset(client); } catch (Exception ex) { MessageBoxHelper.ShowError(ex.Message); return; } } }