/*************************************************
         * 函数原型: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_InstrSignalModule.ipAdress = GetValueFromIniFile(strFilePath, "信号发生器", "IP地址");
                strPort = GetValueFromIniFile(strFilePath, "信号发生器", "端口号");
                CGloabal.g_InstrSignalModule.port = int.Parse(strPort);

                CGloabal.g_InstrN5751AModule.ipAdress = GetValueFromIniFile(strFilePath, "N5751A", "IP地址");
                strPort = GetValueFromIniFile(strFilePath, "N5751A", "端口号");
                CGloabal.g_InstrN5751AModule.port = int.Parse(strPort);

                strPort = GetValueFromIniFile(strFilePath, "N3300A", "GPIB地址");
                CGloabal.g_InstrN3300AModule.port = int.Parse(strPort);
            }
            else
            {
                CCommonFuncs.ShowHintInfor(eHintInfoType.error, "APP_INFOS.ini文件不存在!");
            }
        }
        /*************************************************
         * 函数原型: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_InstrSignalModule.ipAdress);
                WriteValueToIniFile(strFilePath, "信号发生器", "端口号", CGloabal.g_InstrSignalModule.port.ToString());

                WriteValueToIniFile(strFilePath, "N5751A", "IP地址", CGloabal.g_InstrN5751AModule.ipAdress);
                WriteValueToIniFile(strFilePath, "N5751A", "端口号", CGloabal.g_InstrN5751AModule.port.ToString());

                WriteValueToIniFile(strFilePath, "N3300A", "IP地址", CGloabal.g_InstrN3300AModule.ipAdress);
                WriteValueToIniFile(strFilePath, "N3300A", "端口号", CGloabal.g_InstrN3300AModule.port.ToString());
            }
            else
            {
                CCommonFuncs.ShowHintInfor(eHintInfoType.error, "APP_INFOS.ini文件不存在!");
            }
        }
        /******************************************************************************************
         * 函数原型: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 = Signal_Driver.Close(CGloabal.g_InstrSignalModule.nHandle, strError);
                    if (error < 0)
                    {
                        CCommonFuncs.ShowHintInfor(eHintInfoType.error, "信号发生器断开失败");
                    }
                    else//断开成功,要将此时的连接状态更新到仪器参数中
                    {
                        CGloabal.g_InstrPowerModule.bInternet = false;
                    }
                }
            }
            else if (strInstruName == "N5751A")
            {
                if (CGloabal.g_InstrPowerModule.nHandle > 0)
                {
                    error = N5751A_Driver.Close(CGloabal.g_InstrN5751AModule.nHandle, 0, strError);
                    if (error < 0)
                    {
                        CCommonFuncs.ShowHintInfor(eHintInfoType.error, "N5751A断开失败");
                    }
                    else//断开成功,要将此时的连接状态更新到仪器参数中
                    {
                        CGloabal.g_InstrPowerModule.bInternet = false;
                    }
                }
            }
            else
            {
                CCommonFuncs.ShowHintInfor(eHintInfoType.error, "错误的仪器名");
                return(-1);
            }
            return(error);
        }
        /******************************************************************************************
         * 函数原型: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);
        }