Esempio n. 1
0
        /*************************************************
         * 函数原型:private void GetAlltheInstumentsParasFromImiFile()
         * 函数功能:从ini文件中获取所有的仪器的参数信息.
         * 输入参数:
         * 输出参数:
         * 创 建 者:yzx
         * 创建日期:2016.7.23
         * 修改说明:
         */
        public static void GetAlltheInstumentsParasFromIniFile()
        {
            string strPort;
            string strFilePath;
            string strBusType;

            //获取ini文件的相对路径
            strFilePath = System.Windows.Forms.Application.StartupPath + "\\APP_INFOS.ini";
            if (File.Exists(strFilePath))//首先判读INI文件是否存在
            {
                CGloabal.g_InstrPowerModule.ipAdress = GetValueFromIniFile(strFilePath, "电源", "IP地址");
                strPort = GetValueFromIniFile(strFilePath, "电源", "端口号");
                CGloabal.g_InstrPowerModule.port = int.Parse(strPort);

                CGloabal.g_InstrScopeModule.ipAdress = GetValueFromIniFile(strFilePath, "示波器", "IP地址");
                strPort = GetValueFromIniFile(strFilePath, "示波器", "端口号");
                CGloabal.g_InstrScopeModule.port = int.Parse(strPort);

                CGloabal.g_InstrMultimeterModule.ipAdress = GetValueFromIniFile(strFilePath, "万用表", "GPIB地址");
                strPort = GetValueFromIniFile(strFilePath, "万用表", "GPIB地址");
                CGloabal.g_InstrMultimeterModule.port = int.Parse(strPort);
            }
            else
            {
                CCommonFuncs.ShowHintInfor(eHintInfoType.error, "APP_INFOS.ini文件不存在!");
            }
        }
Esempio n. 2
0
        /*************************************************
         * 函数原型:private void StoreAlltheInstumentsParas2IniFile()
         * 函数功能:将仪器的参数信息保存在ini文件中
         * 输入参数:
         * 输出参数:
         * 创 建 者:yzx
         * 创建日期:2016.7.23
         * 修改说明:
         */
        private static void StoreAlltheInstumentsParas2IniFile()
        {
            string strFileName;
            string strFilePath;

            //获取ini文件的相对路径
            strFilePath = System.Windows.Forms.Application.StartupPath + "\\APP_INFOS.ini";
            if (File.Exists(strFilePath))                                    //先判断INI文件是否存在
            {
                strFileName = Path.GetFileNameWithoutExtension(strFilePath); //获得ini文件名

                WriteValueToIniFile(strFilePath, "电源", "IP地址", CGloabal.g_InstrPowerModule.ipAdress);
                WriteValueToIniFile(strFilePath, "电源", "端口号", CGloabal.g_InstrPowerModule.port.ToString());

                WriteValueToIniFile(strFilePath, "示波器", "IP地址", CGloabal.g_InstrScopeModule.ipAdress);
                WriteValueToIniFile(strFilePath, "示波器", "端口号", CGloabal.g_InstrScopeModule.port.ToString());

                WriteValueToIniFile(strFilePath, "万用表", "IP地址", CGloabal.g_InstrMultimeterModule.ipAdress);
                WriteValueToIniFile(strFilePath, "万用表", "端口号", CGloabal.g_InstrMultimeterModule.port.ToString());
            }
            else
            {
                CCommonFuncs.ShowHintInfor(eHintInfoType.error, "APP_INFOS.ini文件不存在!");
            }
        }
Esempio n. 3
0
        /******************************************************************************************
         * 函数原型: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);
        }
Esempio n. 4
0
        //串口读
        public static int ReadCom(SerialPort comPort, byte[] cmdBuf, int ReadLen)
        {
            try
            {
                comPort.Read(cmdBuf, 0, ReadLen);
            }
            catch
            {
                CCommonFuncs.ShowHintInfor(eHintInfoType.error, "串口读出错!");
                return(-1);
            }

            return(0);
        }
Esempio n. 5
0
        //向串口写入数据
        public static int WriteToCom(SerialPort comPort, byte[] cmdBuf, int WriteLen)
        {
            try
            {
                comPort.Write(cmdBuf, 0, WriteLen);
            }
            catch
            {
                CCommonFuncs.ShowHintInfor(eHintInfoType.error, "串口写出错!");
                return(-1);
            }

            return(0);
        }
Esempio n. 6
0
        /******************************************************************************************
         * 函数原型: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, 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, 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_InstrMultimeterModule.nHandle == 0)
                {
                    error = Multimeter_Driver.Connect_Multimeter(resourceName);
                    if (error < 0)
                    {
                        CGloabal.g_InstrPowerModule.bInternet = false;
                        CCommonFuncs.ShowHintInfor(eHintInfoType.error, CGloabal.g_InstrMultimeterModule.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);
        }