访问类值并在Form1.cs中使用它

时间:2019-07-16 19:38:50

标签: c# .net

我试图从类中访问一个值,并在form1.cs文件的循环中使用该值,但是每次运行程序时,该值似乎都不会传递。我连接了需要一定电压的硬件DAC,并且试图将其返回到一个叫做CountValue的变量中。但是,当我设置while循环只是为了测试并查看该值是否实际传递时,该循环将不起作用。这是我尝试过的:

//Form1.cs code
private void AdjustLaser()
        {


            double intensity;

            while (labjackT4.CountValue < 2000)

            labjackT4.ConvertFromDAC();
            if (labjackT4.CountValue > 500)
            {
                intensity = 0.3;
                laser.setLdCurrSetpoint(intensity);
            }
            else
            {
                //intensity = 0.2;
                //laser.setLdCurrSetpoint(intensity);
            }
        }

//labjackT4.cs class code
public LabJackT4()
        {
            //Set Default Value
            this.CountValue = 0;
        }
        #endregion

        #region T4 Handle Definitions
        int handle = 0;
        int devType = 0;
        int conType = 0;
        int serNum = 0;
        int ipAddr = 0;
        int port = 0;
        double voltage = 0;
        public double CountValue = 0;
        int maxBytesPerMB = 0;
        string ipAddrStr = "";
        #endregion

        #region Public Methods
        public void ConvertFromDAC()
        {
            try
            {
                LJM.OpenS("ANY", "ANY", "ANY", ref handle);
                LJM.GetHandleInfo(handle, ref devType, ref conType, ref serNum, ref ipAddr, ref port, ref maxBytesPerMB);
                LJM.NumberToIP(ipAddr, ref ipAddrStr);


            }
            catch (LJM.LJMException c)
            {
                showErrorMessage(c);
            }
            if (devType == LJM.CONSTANTS.dtT4)
            {
                string name = "AIN0";
                LJM.eReadName(handle, name, ref voltage);
                CountValue = voltage / 0.0048828125;
            }
        }
        #endregion

0 个答案:

没有答案