Exemple #1
0
        private void backgroundWorkerOpen_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                for (short i = 0; i < objSwitch.MaxSwitch; i++)
                {
                    if (backgroundWorker_Open.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }
                    objSwitch.SetSwitch(i, SHUTTER_DIR);

                    backgroundWorker_Open.ReportProgress(i);
                }

            }
            catch (Exception Ex)
            {
                stBuffer += Ex.ToString() + Environment.NewLine;
            }
        }
Exemple #2
0
        private void chkOut_Click(object sender, EventArgs e)
        {
            string chkName = ((CheckBox)sender).Name;
            short  chkNum  = Convert.ToInt16(chkName.Substring(6, 1)); //chkOut1 -> 0

            chkNum--;

            if (driver != null)
            {
                driver.SetSwitch(chkNum, ((CheckBox)sender).Checked);
            }

            txtLog.AppendText("Swtich " + chkNum + ": set state [" + ((CheckBox)sender).Checked + "]" + Environment.NewLine);
        }
Exemple #3
0
        /// <summary>
        /// Set switch power wrapper
        /// </summary>
        /// <param name="PORT_NUM"></param>
        /// <param name="PORT_NAME"></param>
        /// <param name="set_value"></param>
        /// <returns>true if ok, false if error</returns>
        public bool PowerSet(byte PORT_NUM, string PORT_NAME, bool set_value, out bool?power_flag)
        {
            //log enter
            Logging.AddLog(PORT_NAME + " switching " + ((bool)set_value ? "ON" : "OFF"), LogLevel.Activity);
            bool retval = false;

            //if previously switch was connected, try to set value
            if (Connected_flag)
            {
                try
                {
                    objSwitch.SetSwitch(PORT_NUM, (bool)set_value);
                    retval = true;
                }
                catch (NotConnectedException ex)
                {
                    //MessageBox.Show(ex.ToString());
                    Logging.AddLog("Switch driver notconnected exception [" + ex.Message + "]. Try to reconnect", LogLevel.Activity, Highlight.Error);
                    bool reconnF = true; int i = 1;
                    while (reconnF)
                    {
                        Logging.AddLog("Switch driver reconnect attempt " + i, LogLevel.Activity);
                        Connect = true; //connect
                        reconnF = (i++ <= SWITCH_MAX_RECCONNECT_ATTEMPTS) && !Connected_flag;
                    }
                    if (Connected_flag)
                    {
                        Logging.AddLog("Switch driver reconnected", LogLevel.Activity);
                        try
                        {
                            objSwitch.SetSwitch(PORT_NUM, (bool)set_value);
                            retval = true;
                        }
                        catch (Exception ex2)
                        {
                            //if again exception - give up
                            retval = false;
                            Logging.AddLog("Couldn't get switch [" + PORT_NUM + "] value [" + ex2.Message + "]", LogLevel.Important);
                            Logging.AddLog(MethodBase.GetCurrentMethod().Name + " exception [" + ex2.ToString() + "]", LogLevel.Debug, Highlight.Error);
                        }
                    }
                    else
                    {
                        Logging.AddLog("Switch driver couldn't be reconnected after " + SWITCH_MAX_RECCONNECT_ATTEMPTS + " attempts", LogLevel.Activity);
                        retval = false;
                    }
                }
                catch (Exception ex)
                {
                    Logging.AddLog("Get " + PORT_NAME + " unknown exception [" + ex.Message + "]!", LogLevel.Important, Highlight.Error);
                    Logging.AddLog("" + PORT_NAME + " exception details: " + ex.ToString(), LogLevel.Debug, Highlight.Debug);
                    retval = false;
                }
            }
            else
            {
                retval = false;
                Logging.AddLog(System.Reflection.MethodBase.GetCurrentMethod().Name + " [" + PORT_NAME + "]: switch was not connected, exiting" + retval, LogLevel.Trace);
            }


            //set appropriate var
            if (retval)
            {
                power_flag = set_value;
            }
            else
            {
                power_flag = null;
            }

            Logging.AddLog(System.Reflection.MethodBase.GetCurrentMethod().Name + " [" + PORT_NAME + "] exit. Result :" + retval, LogLevel.Trace);
            return(retval);
        }