/****************************************************************************************** * 函数原型:CloseSpecificInstrument(string strInstruName) * 函数功能:断开指定的仪器的网络连接 * 输入参数:strInstruName,仪器名字 * 输出参数: * 创 建 者:yzx * 创建日期:2016.7.27 * 修改说明: * */ public static int CloseSpecificInstrument(string strInstruName) { int error = 0; if (strInstruName == "电源") { if (CGloabal.g_InstrPowerModule.nHandle > 0) { error = Power_Driver.Close(CGloabal.g_InstrPowerModule.nHandle, 0, strError); if (error < 0) { CCommonFuncs.ShowHintInfor(eHintInfoType.error, "电源断开失败"); } else//断开成功,要将此时的连接状态更新到仪器参数中 { CGloabal.g_InstrPowerModule.bInternet = false; } } } else if (strInstruName == "示波器") { if (CGloabal.g_InstrScopeModule.nHandle > 0) { error = Oscilloscope_Driver.Close(CGloabal.g_InstrScopeModule.nHandle, 0, ref strError); if (error < 0) { CCommonFuncs.ShowHintInfor(eHintInfoType.error, "示波器断开失败"); } else//断开成功,要将此时的连接状态更新到仪器参数中 { CGloabal.g_InstrScopeModule.bInternet = false; } } } else if (strInstruName == "万用表") { if (CGloabal.g_InstrPowerModule.nHandle > 0) { error = Multimeter_Driver.Close(); if (error < 0) { CCommonFuncs.ShowHintInfor(eHintInfoType.error, "信号发生器断开失败"); } else//断开成功,要将此时的连接状态更新到仪器参数中 { CGloabal.g_InstrPowerModule.bInternet = false; } } } else { CCommonFuncs.ShowHintInfor(eHintInfoType.error, "错误的仪器名"); return(-1); } return(error); }
public void bgWork_doWork(object sender, DoWorkEventArgs e) { string ErrMsg = ""; int error; double voltValue = (double)volt.Value; double electValue = (double)elect.Value; error = Signal_Driver.Reset(CGloabal.g_InstrSignalModule.nHandle, ErrMsg); if (error < 0) { MessageBox.Show("命令出错!"); return; } error = Signal_Driver.SetCLS(CGloabal.g_InstrSignalModule.nHandle, ErrMsg); if (error < 0) { MessageBox.Show("命令出错!"); return; } error = Signal_Driver.SetSin(CGloabal.g_InstrSignalModule.nHandle, ErrMsg); if (error < 0) { MessageBox.Show("命令出错!"); return; } error = Signal_Driver.SetAPPL2RateVoltage(CGloabal.g_InstrSignalModule.nHandle, rateValue, voltValue, 0, ErrMsg); if (error < 0) { MessageBox.Show("命令出错!"); return; } error = Signal_Driver.setLoad(CGloabal.g_InstrSignalModule.nHandle, ErrMsg); if (error < 0) { MessageBox.Show("命令出错!"); return; } bgWork.ReportProgress(20); error = Signal_Driver.SetAPPL1RateVoltage(CGloabal.g_InstrSignalModule.nHandle, rateValue, voltValue, electValue, ErrMsg); if (error < 0) { MessageBox.Show("命令出错!"); return; } error = Signal_Driver.SetPRBSAndSTAT(CGloabal.g_InstrSignalModule.nHandle, ErrMsg); if (error < 0) { MessageBox.Show("命令出错!"); return; } //自动测试示波器 error = Oscilloscope_Driver.Reset(CGloabal.g_InstrScopeModule.nHandle, 0, ErrMsg); if (error < 0) { MessageBox.Show("命令出错!"); return; } DialogResult dr = MessageBox.Show(" 1、请确认81160A通道2与示波器通道4相连\n 2、请确认81160A与被测件输入信号相连", "提示", MessageBoxButtons.OK); if (dr == DialogResult.OK) { error = Oscilloscope_Driver.SetTick(CGloabal.g_InstrScopeModule.nHandle, ErrMsg); if (error < 0) { MessageBox.Show("命令出错!"); return; } error = Oscilloscope_Driver.UpdateAxis(CGloabal.g_InstrScopeModule.nHandle, ErrMsg); if (error < 0) { MessageBox.Show("命令出错!"); return; } if (rateValue == 100) { error = Oscilloscope_Driver.UpdateTimeBase(CGloabal.g_InstrScopeModule.nHandle, 25E-9, ErrMsg); } else if (rateValue == 1) { error = Oscilloscope_Driver.UpdateTimeBase(CGloabal.g_InstrScopeModule.nHandle, 2500E-9, ErrMsg); } else if (rateValue == 4) { error = Oscilloscope_Driver.UpdateTimeBase(CGloabal.g_InstrScopeModule.nHandle, 600E-9, ErrMsg); } else if (rateValue == 10.23) { error = Oscilloscope_Driver.UpdateTimeBase(CGloabal.g_InstrScopeModule.nHandle, 200E-9, ErrMsg); } else if (rateValue == 50) { error = Oscilloscope_Driver.UpdateTimeBase(CGloabal.g_InstrScopeModule.nHandle, 50E-9, ErrMsg); } if (error < 0) { MessageBox.Show("命令出错!"); return; } bgWork.ReportProgress(40); } else { } DialogResult dr2 = MessageBox.Show("1、请确认示波器1、3通道与被测件信号相连\n2、请确认被测件信号显示正常", "提示", MessageBoxButtons.OK); if (dr == DialogResult.OK) { error = Oscilloscope_Driver.SetMaxShow(CGloabal.g_InstrScopeModule.nHandle, ErrMsg); if (error < 0) { MessageBox.Show("命令出错!"); return; } error = Oscilloscope_Driver.SetStartRun(CGloabal.g_InstrScopeModule.nHandle, ErrMsg); if (error < 0) { MessageBox.Show("命令出错!"); return; } bgWork.ReportProgress(70); error = Oscilloscope_Driver.SetStopRun(CGloabal.g_InstrScopeModule.nHandle, ErrMsg); if (error < 0) { MessageBox.Show("命令出错!"); return; } PicName = "ED" + System.DateTime.Now.ToString("yyyyMMddHHmmss"); error = Oscilloscope_Driver.SavePictureUrl(CGloabal.g_InstrScopeModule.nHandle, PicName, ErrMsg); if (error < 0) { MessageBox.Show("命令出错!"); return; } bgWork.ReportProgress(90); Thread.Sleep(2000); bgWork.ReportProgress(100); } else { MessageBox.Show("不可取消"); return; } }
/****************************************************************************************** * 函数原型:ConnectSpecificInstrument(string strInstruName,string resourceName) * 函数功能:根据输入的仪器名进行连接。连接后的句柄存储在相应的句柄参数中 * 输入参数:strInstruName,仪器名字;resourceName,资源名字,用于VISA连接 * 输出参数: * 创 建 者:yzx * 创建日期:2016.7.27 * 修改说明: * */ public static int ConnectSpecificInstrument(string strInstruName, string resourceName) { int error = 0; if (strInstruName == "电源") { if (CGloabal.g_InstrPowerModule.nHandle == 0) { error = Power_Driver.Init(resourceName, ref CGloabal.g_InstrPowerModule.nHandle, CGloabal.g_nSimulteFlag, strError); if (error < 0) { CGloabal.g_InstrPowerModule.bInternet = false; CCommonFuncs.ShowHintInfor(eHintInfoType.error, CGloabal.g_InstrPowerModule.strInstruName + "连接失败"); } else { CGloabal.g_InstrPowerModule.bInternet = true; } } else { CCommonFuncs.ShowHintInfor(eHintInfoType.hint, CGloabal.g_InstrPowerModule.strInstruName + "已经处于连接状态"); } } else if (strInstruName == "示波器") { if (CGloabal.g_InstrScopeModule.nHandle == 0) { error = Oscilloscope_Driver.Init(resourceName, CGloabal.g_nSimulteFlag, ref CGloabal.g_InstrScopeModule.nHandle, ref strError); if (error < 0) { CGloabal.g_InstrScopeModule.bInternet = false; CCommonFuncs.ShowHintInfor(eHintInfoType.error, CGloabal.g_InstrScopeModule.strInstruName + "连接失败"); } else { CGloabal.g_InstrScopeModule.bInternet = true; } } else { CCommonFuncs.ShowHintInfor(eHintInfoType.hint, CGloabal.g_InstrScopeModule.strInstruName + "已经处于连接状态"); } } else if (strInstruName == "信号发生器") { if (CGloabal.g_InstrSignalModule.nHandle == 0) { error = Signal_Driver.Init(resourceName, ref CGloabal.g_InstrSignalModule.nHandle, strError); if (error < 0) { CGloabal.g_InstrPowerModule.bInternet = false; CCommonFuncs.ShowHintInfor(eHintInfoType.error, CGloabal.g_InstrN5751AModule.strInstruName + "连接失败"); } else { CGloabal.g_InstrPowerModule.bInternet = true; } } else { CCommonFuncs.ShowHintInfor(eHintInfoType.hint, CGloabal.g_InstrPowerModule.strInstruName + "已经处于连接状态"); } } else if (strInstruName == "N5751A") { if (CGloabal.g_InstrN5751AModule.nHandle == 0) { error = N5751A_Driver.Init(resourceName, ref CGloabal.g_InstrN5751AModule.nHandle, CGloabal.g_nSimulteFlag, strError); if (error < 0) { CGloabal.g_InstrPowerModule.bInternet = false; CCommonFuncs.ShowHintInfor(eHintInfoType.error, CGloabal.g_InstrN5751AModule.strInstruName + "连接失败"); } else { CGloabal.g_InstrPowerModule.bInternet = true; } } else { CCommonFuncs.ShowHintInfor(eHintInfoType.hint, CGloabal.g_InstrPowerModule.strInstruName + "已经处于连接状态"); } } else { CCommonFuncs.ShowHintInfor(eHintInfoType.error, "错误的仪器名"); return(-1); } return(error); }