Example #1
0
        private void SaveSettings()
        {
            //save settings
            iniSettings pid_settings = new iniSettings();

            pid_settings.port             = port_combobox.SelectedItem.ToString();
            pid_settings.set_temp         = (double)setTempNumericUpDown.Value;
            pid_settings.slowCooling      = slowCoolingCheckBox.Checked;
            pid_settings.slowCoolingSpeed = (double)slowCoolingNumericUpDown.Value;
            using (Stream writer = new FileStream(settings_filename, FileMode.Create))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(iniSettings));
                serializer.Serialize(writer, pid_settings);
            }
        }
Example #2
0
        public main_form()
        {
            InitializeComponent();

            rx_buf = new byte[buffer_size];

            //Get data from controller every second
            get_timer          = new System.Timers.Timer(1000); //1 sec
            get_timer.Enabled  = false;
            get_timer.Elapsed += get_timer_tick;

            //Adjust Set Temp for slow cooling every minute
            slowCoolingTimer          = new System.Timers.Timer(60000); //1 min
            slowCoolingTimer.Enabled  = false;
            slowCoolingTimer.Elapsed += slowCoolingTimerTick;

            //
            connectTimer          = new System.Timers.Timer(100); //0.1 sec
            connectTimer.Enabled  = false;
            connectTimer.Elapsed += connectTimerTick;

            //
            setTimer          = new System.Timers.Timer(1200); //1.2 sec
            setTimer.Enabled  = false;
            setTimer.Elapsed += setTimerTick;

            string[] comPorts = SerialPort.GetPortNames();
            for (int i = 0; i < comPorts.Length; i++)
            {
                port_combobox.Items.Add(comPorts[i]);
            }

            //extract port, temperature settings
            if (File.Exists(settings_filename))
            {
                try
                {
                    using (Stream stream = new FileStream(settings_filename, FileMode.Open))
                    {
                        XmlSerializer serializer = new XmlSerializer(typeof(iniSettings));

                        iniSettings pid_settings = (iniSettings)serializer.Deserialize(stream);
                        //check port, temperature validity
                        if (((decimal)pid_settings.set_temp < setTempNumericUpDown.Minimum) || ((decimal)pid_settings.set_temp > setTempNumericUpDown.Maximum))
                        {
                            pid_settings.set_temp = (double)setTempNumericUpDown.Maximum;
                        }
                        setTempNumericUpDown.Value = (decimal)pid_settings.set_temp;
                        if (((decimal)pid_settings.slowCoolingSpeed < slowCoolingNumericUpDown.Minimum) || ((decimal)pid_settings.set_temp > slowCoolingNumericUpDown.Maximum))
                        {
                            pid_settings.slowCoolingSpeed = (double)slowCoolingNumericUpDown.Minimum;
                        }
                        slowCoolingNumericUpDown.Value = (decimal)pid_settings.slowCoolingSpeed;
                        slowCoolingCheckBox.Checked    = pid_settings.slowCooling;

                        for (int i = 0; i < comPorts.Length; i++)
                        {
                            if (comPorts[i] == pid_settings.port)
                            {
                                port_combobox.SelectedIndex = i;
                            }
                        }
                    }
                }
                catch
                {
                    System.Windows.Forms.MessageBox.Show(settings_filename + " damaged, use settings by default.");
                    port_combobox.SelectedIndex    = 0;
                    setTempNumericUpDown.Value     = setTempNumericUpDown.Maximum;
                    slowCoolingCheckBox.Checked    = false;
                    slowCoolingNumericUpDown.Value = slowCoolingNumericUpDown.Minimum;
                }
            }
        }