Exemple #1
0
        public void MeasureMeterCurrent(object tu)
        {
            TestUnit tu2 = new TestUnit();

            tu2 = (TestUnit)tu;
            try
            {
                StringBuilder MeterVal      = new StringBuilder();
                string        Datesandhour1 = DateTime.Now.ToString("_hh_mm_ss_");
                MeterConfig.MeterInit(MeterSourceName);
                MeterConfig.SetCurrent(MeterRange, MeterResolution);
                //  MeterConfig.MeasurementInit();
                decimal data        = 0;
                string  danwei      = "A ";
                int     count       = 0;
                int     countrecord = 0;
                float   max         = 1;
                // Random rd1 = new Random();
                while (!IsStop || !IsTestEnd)
                {
                    //  MeterCurrent = rd1.Next(1, 100);
                    MeterCurrent  = MeterConfig.MeasureSinglePoint();
                    Datesandhour1 = DateTime.Now.ToString("hh:mm:ss , ");
                    data          = ChangeDataToD(MeterCurrent);
                    if (data >= (decimal)0.1)
                    {
                        danwei = "A ";
                        max    = 1.5f;
                    }
                    else if (data < (decimal)0.1 && data > (decimal)0.0001)
                    {
                        data   = data * 1000;
                        danwei = "mA ";
                        max    = 0.1f;
                    }
                    else
                    {
                        data   = data * 1000000;
                        danwei = "uA ";
                        max    = 0.0001f;
                    }
                    data = Math.Round(data, 2);

                    tu2.SetScale(max, -0.2f, data.ToString() + danwei);
                    if (MeasureMetertSwitch)
                    {
                        count++;
                        countrecord++;
                        if (countrecord == MeterFileRecordStep)
                        {
                            countrecord = 0;
                            MeterVal.Append(Datesandhour1 + data.ToString().PadLeft(10, ' ') + danwei + ",  " + PowerSourceVal.ToString() + "V  " + Environment.NewLine);
                        }
                        if (count > 120)
                        {
                            count = 0;
                            FileOperation.createFile(MeterFilePath, MeterFileName, MeterVal.ToString());
                            MeterVal.Clear();
                        }
                    }
                    Thread.Sleep(500);
                    tu2.ChartValueFill((float)MeterCurrent);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, ex.Message);
                tu2.ShowInfo(tu2.richTextBox1, ex.Message, Color.Red);
                tu2.Setnoticecolor(Color.Red);
            }
        }