Beispiel #1
0
 /// <summary>
 /// Invokes the settings dialog
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void toolStripMenuItem_Settings(object sender, EventArgs e)
 {
     Form_Settings dlg = new Form_Settings();
     DialogResult rc = dlg.ShowDialog();
     if (rc == DialogResult.OK)
     {
         // DIO controller type
         Properties.Settings.Default.Relay_Controller_Type = dlg.comboBox_DIOCtrollerTypes.Text;
         RelayControler.Device_Types rdevtype = (RelayControler.Device_Types)Enum.Parse(typeof(RelayControler.Device_Types),
             Properties.Settings.Default.Relay_Controller_Type);
         _relay_ctrl = new RelayControler(rdevtype);
     }
     else
     {
         Properties.Settings.Default.Reload();
     }
 }
Beispiel #2
0
        /// <summary>
        /// Initializes the relay controller
        /// </summary>
        void initRelayController()
        {
            string msg;
            RelayControler.Device_Types rdevtype = (RelayControler.Device_Types)Enum.Parse(
                typeof(RelayControler.Device_Types), Properties.Settings.Default.Relay_Controller_Type);
            try
            {
                _relay_ctrl = new RelayControler(rdevtype);

                // In this version we are adding a new lines for Honeycomb
                // So lets refresh the file as to not to have conflicts with older versions
                // Should not cause any problems unless someone rewired the relay controller
                _relay_ctrl.ClearDictionaries();
                _relay_ctrl.RecreateSettingsFile();

                _relay_ctrl.Open();
                initRelayController_Lines();
                msg = string.Format("Relay controller \"{0}:{1}\" ready.", rdevtype, _relay_ctrl.SerialNumber);
                updateOutputStatus(msg);
            }
            catch (Exception ex)
            {
                msg = string.Format("{0}\r\nTry unplugging and re-plugging the USB device.\r\nThen try to change relay controller in settings dialog", ex.Message);
                showDialogMsg(msg);

                msg = string.Format("Unable to init relay controller \"{0}\".  Switching to Manual relay mode", rdevtype);
                updateOutputStatus(msg);

                _relay_ctrl = new RelayControler(RelayControler.Device_Types.Manual);
                initRelayController_Lines();
                Properties.Settings.Default.Relay_Controller_Type = _relay_ctrl.Device_Type.ToString();
                Properties.Settings.Default.Save();

                Form_Settings dlg = new Form_Settings();
                dlg.TabControl.SelectedTab = dlg.TabControl.TabPages["tabPageDIO"];
                DialogResult rc = dlg.ShowDialog();
                if (rc == DialogResult.OK)
                {
                    // DIO controller type
                    Properties.Settings.Default.Relay_Controller_Type = dlg.comboBox_DIOCtrollerTypes.Text;
                    rdevtype = (RelayControler.Device_Types)Enum.Parse(typeof(RelayControler.Device_Types),
                        Properties.Settings.Default.Relay_Controller_Type);
                    _relay_ctrl = new RelayControler(rdevtype);
                }
                else
                {
                    Properties.Settings.Default.Reload();
                }

            }
            //_relay_ctrl.WriteAll(false);
            _relay_ctrl.Close();
        }