Exemple #1
0
    public static void Main()
    {
        Console.WriteLine(InstCount.instanceCount);

        InstCount ic1 = new InstCount();

        Console.WriteLine(InstCount.instanceCount);

        InstCount ic2 = new InstCount();

        Console.WriteLine(InstCount.instanceCount);
    }
Exemple #2
0
        /// <summary>
        /// 初始化仪器设备,通过 Info 信息及 cfg 包含的端口信息
        /// </summary>
        /// <param name="cfg"></param>
        /// <returns></returns>
        public override bool InitWithInfo()
        {
            bool confOK = true;

            if (this.InstIdx >= MaxInstNum)
            {
                nlogger.Error("the InstIdx exceed the maxInstNum: " + InstCount.ToString());
                return(false);
            }

            // 记录设备的编号
            Info.InstIdx_NotUsed = this.InstIdx;

            if (Info.InstType == TypeInst.Undefined)
            {
                nlogger.Error("the Info.InstType undefined.");
                return(false);
            }

            try
            {
                // 设置波特率
                confOK &= SetPortName(Info.PortName, Info.BaudRate);
            }
            catch (Exception ex)
            {
                nlogger.Error("exception occur when SetPortName: " + ex.Message);
                return(false);
            }

            // 配置端口失败
            if (confOK == false)
            {
                nlogger.Error("failed to config the serial port.");
                return(false);
            }

            // 使能
            if (confOK == true)
            {
                Enable = true;
            }
            return(confOK);
        }