Пример #1
0
        public CalibrationForm(ActiveLoadDevice activeLoadDevice)
        {
            InitializeComponent();

            this.activeLoadDevice = activeLoadDevice;
            Calibration           = activeLoadDevice.Calibration;

            // current calibration data
            if (Calibration.Current != null)
            {
                // copy current values to form
                nuSetpointCurrent1.Value = (decimal)Calibration.Current.DeviceCurrentSetpoint[0];
                nuSetpointCurrent2.Value = (decimal)Calibration.Current.DeviceCurrentSetpoint[1];
                nuRealCurrent1.Value     = (decimal)Calibration.Current.ActualCurrent[0];
                nuRealCurrent2.Value     = (decimal)Calibration.Current.ActualCurrent[1];
                nuDeviceCurrent1.Value   = (decimal)Calibration.Current.DeviceMeasuredCurrent[0];
                nuDeviceCurrent2.Value   = (decimal)Calibration.Current.DeviceMeasuredCurrent[1];
            }
            else
            {
                // default values
                nuSetpointCurrent1.Value = (decimal)0.1;
                nuSetpointCurrent2.Value = (decimal)1.0;
                nuRealCurrent1.Value     = nuSetpointCurrent1.Value;
                nuRealCurrent2.Value     = nuSetpointCurrent2.Value;
                nuDeviceCurrent1.Value   = nuSetpointCurrent1.Value;
                nuDeviceCurrent2.Value   = nuSetpointCurrent2.Value;
            }

            btApplyCurrent1.Enabled = true;
            btApplyCurrent2.Enabled = false;
            btReadCurrent1.Enabled  = false;
            btReadCurrent2.Enabled  = false;
            btRealCurrent1.Enabled  = false;
            btRealCurrent2.Enabled  = false;

            // voltage calibration data
            if (Calibration.Voltage != null)
            {
                // copy current values to form
                nuDeviceVoltage1.Value = (decimal)Calibration.Voltage.DeviceMeasuredVoltage[0];
                nuDeviceVoltage2.Value = (decimal)Calibration.Voltage.DeviceMeasuredVoltage[1];
                nuRealVoltage1.Value   = (decimal)Calibration.Voltage.ActualVoltage[0];
                nuRealVoltage2.Value   = (decimal)Calibration.Voltage.ActualVoltage[1];
            }
            else
            {
                // default values
                nuDeviceVoltage1.Value = 10;
                nuDeviceVoltage2.Value = 30;
                nuRealVoltage1.Value   = nuDeviceVoltage1.Value;
                nuRealVoltage2.Value   = nuDeviceVoltage2.Value;
            }
        }
Пример #2
0
        public static GraphForm GetForm(ActiveLoadDevice activeLoadDevice)
        {
            if (inst == null || inst.IsDisposed)
            {
                inst = new GraphForm(activeLoadDevice);
            }

            // set (new) active load device instance
            inst.ActiveLoadDevice = activeLoadDevice;

            return(inst);
        }
Пример #3
0
        private GraphForm(ActiveLoadDevice activeLoadDevice)
        {
            InitializeComponent();

            this.ActiveLoadDevice = activeLoadDevice;

            // fill interval combo box
            cbInterval.DisplayMember = "Name";
            cbInterval.ValueMember   = "Value";

            List <ComboBoxItem <int> > listIntervals = new List <ComboBoxItem <int> >();

            listIntervals.Add(new ComboBoxItem <int>(100));
            listIntervals.Add(new ComboBoxItem <int>(250));
            listIntervals.Add(new ComboBoxItem <int>(500));
            listIntervals.Add(new ComboBoxItem <int>(1000));
            listIntervals.Add(new ComboBoxItem <int>(5000));
            listIntervals.Add(new ComboBoxItem <int>(10000));

            foreach (var item in listIntervals)
            {
                item.Name = item.Value + " ms";
            }

            cbInterval.DataSource = listIntervals;

            // fill samples combo box
            cbSamples.DisplayMember = "Name";
            cbSamples.ValueMember   = "Value";

            List <ComboBoxItem <int> > listSamples = new List <ComboBoxItem <int> >();

            listSamples.Add(new ComboBoxItem <int>(10));
            listSamples.Add(new ComboBoxItem <int>(25));
            listSamples.Add(new ComboBoxItem <int>(50));
            listSamples.Add(new ComboBoxItem <int>(500));
            listSamples.Add(new ComboBoxItem <int>(1000));

            foreach (var item in listSamples)
            {
                item.Name = item.Value + " samples";
            }

            cbSamples.DataSource = listSamples;
        }
Пример #4
0
        private async void btAutoProbe_Click(object sender, EventArgs e)
        {
            // cancel running refresh task
            if (ctsRefreshTask != null)
            {
                ctsRefreshTask.Cancel();
            }

            // close device
            if (activeLoadDevice != null)
            {
                activeLoadDevice.Close();
                connected      = false;
                btConnect.Text = "Connect";
            }

            // try to find all Active Load devices
            activeLoadDevice = new ActiveLoadDevice();

            btAutoProbe.Enabled = false;
            string[] comPorts = await activeLoadDevice.FindDevicesAsync();

            btAutoProbe.Enabled = true;

            cbDevices.Items.Clear();

            foreach (string comPort in comPorts)
            {
                cbDevices.Items.Add(comPort);
            }

            // select first device
            if (cbDevices.Items.Count > 0)
            {
                cbDevices.SelectedIndex = 0;
            }
        }
Пример #5
0
        private async void btConnect_Click(object sender, EventArgs e)
        {
            if (!connected)
            {
                if (cbDevices.SelectedIndex < 0)
                {
                    MessageBox.Show("Connect a device and select it in the dropdown list.", "Device selection", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                // close device as a precaution (if it is open for some reason)
                if (activeLoadDevice != null)
                {
                    activeLoadDevice.Close();
                }

                // try to open specified device
                activeLoadDevice = new ActiveLoadDevice(cbDevices.Text);
                ctsRefreshTask   = new CancellationTokenSource();

                try
                {
                    await activeLoadDevice.OpenAsync();

                    connected = true;
                }
                catch (UnexpectedResponseException)
                {
                    MessageBox.Show("Device is probably not an Active Load device", "Unexpected response", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (TimeoutException)
                {
                    MessageBox.Show("Device is probably not an Active Load device", "Timeout", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                // close device again if not successful above
                if (!connected)
                {
                    activeLoadDevice.Close();
                }
            }
            else
            {
                // cancel running refresh task
                if (ctsRefreshTask != null)
                {
                    ctsRefreshTask.Cancel();
                }

                connected = false;
            }

            // update button text
            if (connected)
            {
                btConnect.Text = "Disconnect";

                gbProcessImage.Text = "Active load device (version: " + activeLoadDevice.Identity.Version + ")";

                if (!activeLoadDevice.IsCalibrated)
                {
                    MessageBox.Show("Device is not fully calibrated. Measurements and setpoints may be inaccurate. Consider calibration of device!", "Device calibration", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                // save COM port
                Properties.Settings.Default.LastComPort = activeLoadDevice.PortName;
                Properties.Settings.Default.Save();

                calibrateToolStripMenuItem.Enabled = true;
                showgraphToolStripMenuItem.Enabled = true;

                // start asynchronous polling loop task
                try
                {
                    await RefreshProcessImageAsync();
                }
                catch
                {
                }

                // polling task cancelled or error
                btConnect.Text = "Connect";

                // connection lost, disconnect and close device
                if (activeLoadDevice != null)
                {
                    activeLoadDevice.Close();
                }

                calibrateToolStripMenuItem.Enabled = false;
                showgraphToolStripMenuItem.Enabled = false;

                connected = false;

                // close graph form if open
                Form graphForm = Application.OpenForms["GraphForm"];
                if (graphForm != null)
                {
                    graphForm.Close();
                }
            }
            else
            {
                btConnect.Text = "Connect";
            }
        }