/// <summary>
        /// 断开仪器连接
        /// </summary>
        /// <returns></returns>
        public static bool Disconnect()
        {
            if (instrumentObject == null)
            {
                return(true);
            }

            if (!isConnected)
            {
                return(true);
            }

            errorCode   = instrumentObject.Disconnect();
            isConnected = false;
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName               = "cmd.exe";
            p.StartInfo.CreateNoWindow         = true;  //不显示程序窗口
            p.StartInfo.UseShellExecute        = false; //是否使用操作系统shell启动
            p.StartInfo.RedirectStandardInput  = true;  //接受来自调用程序的输入信息
            p.StartInfo.RedirectStandardOutput = true;  //由调用程序获取输出信息
            p.StartInfo.RedirectStandardError  = true;  //重定向标准错误输出
            p.Start();                                  //启动CMD
            p.StandardInput.WriteLine("taskkill /im eftirPLS.exe /f");
            p.StandardInput.WriteLine("taskkill /im vspecNIR.exe /f");
            System.Threading.Thread.Sleep(100);
            //p.StandardInput.AutoFlush = true;
            // p.WaitForExit();//等待程序执行完退出进程
            p.Close();
            instrumentObject = null;
            return(errorCode == 0);
        }
Esempio n. 2
0
        /// <summary>
        /// 连接光谱仪
        /// </summary>
        public static bool Connect()
        {
            lock (thisLock)
            {
                if (instrumentObject == null)
                {
                    instrumentObject = new VspecNIRObject();
                }

                if (instrumentObject == null)
                {
                    ErrorCode = -10;
                    return(false);
                }
                ErrorCode   = instrumentObject.Connect();
                isConnected = (ErrorCode == 0);
                //判断仪器是否是积分球类型
                string jsonString = GetParametersTable();
                if (jsonString != null)
                {
                    JsonString.ParametersTable par = JsonString.JsonToObj <JsonString.ParametersTable>(jsonString);
                    IsIntegratingSphere = par.systemType == 2;
                }
                return(isConnected);
            }
        }
        /// <summary>
        /// 返回当前执行的错误
        /// </summary>
        /// <returns></returns>
        //public static string GetError() { return ErrorString; }

        /// <summary>
        /// 连接仪器
        /// </summary>
        /// <returns></returns>
        public static bool Connect()
        {
            if (instrumentObject == null)
            {
                instrumentObject = new VspecNIRObject();
            }

            if (instrumentObject == null)
            {
                errorCode = -10;
                return(false);
            }
            errorCode   = instrumentObject.Connect();
            isConnected = (errorCode == 0);
            //判断仪器是否是积分球类型
            string jsonString = "";

            errorCode = instrumentObject.GetParametersTable(ref jsonString);
            if (errorCode == 0 && jsonString != "")
            {
                JsonString.ParametersTable par = JsonString.JsonToObj <JsonString.ParametersTable>(jsonString);
                InitInstrumentObject(par.systemType);
            }
            return(isConnected);
        }
Esempio n. 4
0
        /// <summary>
        /// 断开仪器连接
        /// </summary>
        public static bool Disconnect()
        {
            lock (thisLock)
            {
                if (instrumentObject == null)
                {
                    return(true);
                }

                if (!isConnected)
                {
                    return(true);
                }

                ErrorCode = instrumentObject.Disconnect();

                GC.Collect();
                instrumentObject = null;
                isConnected      = false;

                return(ErrorCode == 0);
            }
        }