예제 #1
0
        void update_gui(power_data data)
        {
            double current_ma = data.current * 1000;

            controlSetPropertyValue(labelVoltage, string.Format("{0:F4} V", data.voltage));
            controlSetPropertyValue(labelCurrent, string.Format("{0:F3} mA", current_ma));
            controlSetPropertyValue(labelSamples, string.Format("{0}", _read_count++));

            update_chart(data);

            double power_mw = data.voltage * current_ma;

            if (power_mw > _power_max_val)
            {
                _power_max_val = power_mw;
            }
            if (power_mw < _power_min_val)
            {
                _power_min_val = power_mw;
            }

            _power_average = (_power_average * (_read_count - 1) + power_mw) / _read_count;

            controlSetPropertyValue(labelPower, string.Format("{0:F6} mW", power_mw));
            controlSetPropertyValue(labelMax, string.Format("{0:F6} mW", _power_max_val));
            controlSetPropertyValue(labelMin, string.Format("{0:F6} mW", _power_min_val));
            controlSetPropertyValue(labelAve, string.Format("{0:F6} mW", _power_average));
        }
예제 #2
0
 void update_chart(power_data data)
 {
     if (chart1.InvokeRequired)
     {
         updateGUICallback d = new updateGUICallback(update_chart);
         this.Invoke(d, new object[] { data });
     }
     else
     {
         try
         {
             chart1.Series["Power"].Points.AddXY(data.time_stamp.ToLongTimeString(), data.current * data.voltage);
         }
         catch (Exception ex)
         {
             string msg = ex.Message;
         }
     }
 }
예제 #3
0
        /// <summary>
        /// Takes meter measurements until cancel
        /// </summary>
        void meter_run()
        {
            _meter.ClearData();
            while (true)
            {
                if (_cancel.Token.IsCancellationRequested)
                {
                    return;
                }

                power_data data = new power_data();
                data.time_stamp = DateTime.Now;

                bool success = false;
                _meter.ClearData();
                _meter.WriteLine("*TRG;MEAS:CURR:DC? 50E-03");
                for (int i = 0; i < 3; i++)
                {
                    string meter_output_current = _meter.WaitForData(50);
                    try
                    {
                        data.current = Convert.ToDouble(meter_output_current);
                        success      = true;
                        break;
                    }
                    catch (Exception ex)
                    {
                        success = false;
                        updateOutputStatus("Current: " + ex.Message + " : " + meter_output_current.Replace("\r\n", ","));
                    }
                }

                if (success)
                {
                    success = false;
                    _meter.ClearData();
                    _meter.WriteLine("*TRG;MEAS2:VOLT:DC? 5");
                    for (int i = 0; i < 3; i++)
                    {
                        string meter_output_voltage = _meter.WaitForData(50);
                        try
                        {
                            data.voltage = Convert.ToDouble(meter_output_voltage);
                            success      = true;
                            break;
                        }
                        catch (Exception ex)
                        {
                            success = false;
                            updateOutputStatus("Voltage: " + ex.Message + " : " + meter_output_voltage.Replace("\r\n", ","));
                        }
                    }
                }

                if (success)
                {
                    data_list.Add(data);
                    update_gui(data);
                }
            }
        }