private void Form_Register_Load(object sender, EventArgs e) { ClassVisa._Visa_Init(); this.textBox_DevInfo.ReadOnly = true; this.radioButton_LAN.Checked = true; this.iconButton_Refresh.Visible = false; }
private void iconButton_Run_Click(object sender, EventArgs e) { if (this.iconButton_Collect.IconChar == FontAwesome.Sharp.IconChar.Play) { this.iconButton_Collect.IconChar = FontAwesome.Sharp.IconChar.Stop; this.iconButton_Collect.IconColor = Color.Red; this.bCollect = true; this.bUpdate = false; } else { this.iconButton_Collect.IconChar = FontAwesome.Sharp.IconChar.Play; this.iconButton_Collect.IconColor = Color.Green; this.bCollect = false; this.bUpdate = false; } if (bCollect) { ClassVisa._Visa_Init(); //初始化句柄 CancellationToken collectToken = collectTaskCancel.Token; //令牌 collectTask = new Task(() => { getData(collectToken); }, collectToken); //新建循环测试任务 try { collectTask.Start(); } catch (Exception ex) { Console.WriteLine("\n OperationCanceledException:{0}\n", ex.Message); } } else { //结束屏幕绘制线程 Task.Run(() => FinishPaintingTask()); } }
/// <summary> /// 配置 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void iconButton_Config_Click(object sender, EventArgs e) { if (IsEmptyCheckout()) //空值判断 { MessageBox.Show("Null value or no device information, please enter or register the instrument and click pply"); return; } else { if (IsValidCheck()) //参数有效性判断 { MessageBox.Show("Invalid parameters exist, please check.", "Warnning!"); return; } Form_Progressbar form_Progressbar = new Form_Progressbar(); /* 开启进度条 */ CancellationTokenSource cancelTokenSource = new CancellationTokenSource(); cancelTokenSource.Token.Register(() => { form_Progressbar.CloseProcess();//委托方法调用进度条关闭 DialogResult res = MessageBox.Show("Channel configuration is complete", "Configuration", MessageBoxButtons.OK); if (res == DialogResult.OK) { //RaiseEvent("ProcessClose"); return; } }); bConfig = true; Task.Run(() => { form_Progressbar.ProcessMarquee("Configuring..."); //设置进度条显示为左右转动 form_Progressbar.StartPosition = FormStartPosition.CenterScreen; //程序中间 form_Progressbar.ShowDialog(); }, cancelTokenSource.Token); /* 仪器设备信息 */ Dictionary <string, string> device_CommonSCPI = new Dictionary <string, string>(); device_CommonSCPI.Add("TriggerSource", comboBox_TriggeSource.Text); //触发源 device_CommonSCPI.Add("TriggerMode", comboBox_TrigStyle.Text); //触发方式 device_CommonSCPI.Add("MemDepth", comboBox_StorgeDepth.Text); //存储深度 device_CommonSCPI.Add("HoldOff", CUnitTransform.UnitTransF(comboBox_TrigHoldUnit, textBox_TrigHold)); //触发释抑 device_CommonSCPI.Add("HorizontalTimebase", CUnitTransform.UnitTransF(comboBox_HorTimeUnit, textBox_HorTime)); //水平时基 device_CommonSCPI.Add("HorizontalOffset", CUnitTransform.UnitTransF(comboBox_HoriOffsetUnit, textBox_HoriOffset)); //水平偏移 device_CommonSCPI.Add("TriggerLevel", CUnitTransform.UnitTransF(comboBox_TriggerLevelUnit, textBox_TriggerLevel)); //触发电平 DataTable dataTable_DeviceChannel = dataGridView_ChanSet.DataSource as DataTable; //将DataGridView转换为DataTable /* 赋值给单例 */ Module_DeviceManage.Instance.AssignDeviceAndChannel(device_CommonSCPI, dataTable_DeviceChannel); /* 建立Visa连接 */ ClassVisa._Visa_Init();//初始化句柄 Parallel.For(0, Module_DeviceManage.Instance.Devices.Count, i => { Module_Device module_Device = Module_DeviceManage.Instance.Devices[i]; if (module_Device.Status == true) { if (module_Device.deviceVisa == null) { try { module_Device.deviceVisa = new CVisa(module_Device.visaResource); } catch (Exception) { module_Device.Status = false; } } } else { module_Device.deviceVisa.Close(); module_Device.deviceVisa = null; } }); /* 发送指令 */ Module_DeviceManage.Instance.SetDevices(); Module_DeviceManage.Instance.MaxChannelModel = Module_DeviceManage.Instance.GetMaxChannelMode(); /* 设置延时,每台设备设置5s延时用于Visa传输指令 */ Thread.Sleep(5000 * Module_DeviceManage.Instance.Devices.Count); cancelTokenSource.Cancel(); } }