Example #1
0
        /*private void LogFaileDataPTQuene()
         * {
         *  if (m_FailedDataPTQuene.Count != 0)
         *  {
         *      foreach (EtyTrendLog etyLog in m_FailedDataPTQuene)
         *      {
         *          if (!TrendLogDAO.GetInstance().InsertTrendViewerLog(etyLog))
         *          {
         *              m_dbDisconnected = true;
         *              break;
         *          }
         *          m_FailedDataPTQuene.Remove(etyLog);
         *      }
         *  }
         * }
         *
         * private void AddToQuene(EtyTrendLog etyLog)
         * {
         *  if (m_FailedDataPTQuene.Count != QUENECAPACITY)
         *  {
         *      m_FailedDataPTQuene.Add(etyLog);
         *  }
         *  else
         *  {
         *      m_FailedDataPTQuene.RemoveAt(0);
         *      m_FailedDataPTQuene.Add(etyLog);
         *  }
         * }*/

        /// <summary>
        /// Gets the curretn DataPoint value from OPC server.
        /// </summary>
        /// <param name="dataPointname"></param>
        /// <returns></returns>
        private string GetOPCValue(string dataPointname)
        {
            string Function_Name = "GetOPCValue";

            LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Entered");

            string dpValue    = "";
            object dpValueObj = OPCServerProxy.GetInstance().GetDataItemValue(dataPointname);

            //check if opc server is connect and quality is good.
            if (dpValueObj != null && dpValueObj.ToString() != "BLANK" && dpValueObj.ToString() != "NOTCONNECTED")
            {
                if (OPCDataPointManager.GetInstance().isNumeric(dpValueObj.ToString(), System.Globalization.NumberStyles.Number))
                {
                    dpValue = dpValueObj.ToString();
                }
                else if (OPCDataPointManager.GetInstance().isBoolean(dpValueObj.ToString()))
                {
                    dpValue = "0";
                    if (Convert.ToBoolean(dpValueObj.ToString()))
                    {
                        dpValue = "1";
                    }
                }
                else
                {
                    dpValue = "0";
                }
            }
            LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Exited");
            return(dpValue);
        }
        public void RestoreMenuStrip_Click(object sender, System.EventArgs e)
        {
            string Function_Name = "RestoreMenuStrip_Click";

            LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Entered");
            //restart the DataLogger.
            // terminate the data logging thread first.
            //OPCDataPointManager.GetInstance().TerminateThread();
            OPCDataPointManager.GetInstance().TerminateAndWait();
            //OPCServerProxy.ReleaseInstance();
            try
            {
                OPCServerProxy.GetInstance().RemoveAllOPCItem();
            }
            catch (Exception Ex)
            {
                LogHelper.Error(CLASS_NAME, Function_Name, Ex);
                //OPCBridge service is shutdown/crashed.
                //@todo
            }
            OPCDataPointManager.ReleaseInstance();
            System.Threading.Thread.Sleep(1000);
            OPCDataPointManager.GetInstance().ExitApplicationEvent += CloseApplication;
            OPCDataPointManager.GetInstance().InitializeOPCSetting(m_process.Id.ToString());

            //show the GUI to user to indicate restore is done.
            Show();
            this.WindowState = System.Windows.Forms.FormWindowState.Normal;
            LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Exited");
        }
Example #3
0
        /// <summary>
        /// Reconnects to OPC Server if the disconnection flag is set.
        /// </summary>
        /// <returns></returns>
        private bool CheckOPCConnection()
        {
            string Function_Name = "CheckOPCConnection";

            LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Entered");

            if (/*m_opcDisconnected || */ !(OPCServerProxy.GetInstance().IsOPCServerConnected()))
            {
                LogHelper.Debug(CLASS_NAME, Function_Name, "Reconnecting to OPC Server");
                bool result = OPCServerProxy.GetInstance().ReconnectAndAddToOPC();
                // if(result)
                //     m_opcDisconnected = false;
                return(result);
            }
            LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Exited");
            return(true);
        }
        public static void ReleaseInstance()
        {
            string Function_Name = "ReleaseInstance";

            LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Entered");
            if (m_instance != null)
            {
                lock (s_Singleton)
                {
                    m_instance.ClearDataPoints();
                    OPCServerProxy.ReleaseInstance();
                    DBConnection.ReleaseInstance();
                    m_instance = null;
                }
            }
            LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Exited");
        }
        /// <summary>
        /// Connects the configured datapoints to the OPC Group in OPC Server.
        /// </summary>
        public void ConnectDPToOPC()
        {
            string Function_Name = "ConnectDPToOPC";

            LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Entered");

            try
            {
                foreach (KeyValuePair <string, OPCDPGrpDetails> pair in m_DataPointdic)
                {
                    OPCServerProxy.GetInstance().AddOPCItem(pair.Key);
                }
            }
            catch (Exception localException)
            {
                LogHelper.Error(CLASS_NAME, Function_Name, localException.ToString());
            }

            LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Exited");
        }
Example #6
0
        /// <summary>
        /// Checks the Config_vars variable value. Based on value,
        /// Restarts logging by reloading datapoints.
        /// </summary>
        private void CheckSampleGroupFlag()
        {
            string Function_Name = "CheckSampleGroupFlag";

            LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Entered");

            try
            {
                if (!m_dbDisconnected)
                {
                    string resetFlag = m_checkConfigVars.GetOPCDTSmplFlagValue();
                    if (resetFlag == "Y")
                    {
                        LogHelper.Info(CLASS_NAME, Function_Name, "Reset Flag Set");
                        try
                        {
                            OPCServerProxy.GetInstance().RemoveAllOPCItem();
                        }
                        catch (Exception Ex)
                        {
                            LogHelper.Error(CLASS_NAME, Function_Name, Ex);
                            //OPCBridge service is shutdown/crashed.
                        }
                        OPCDataPointManager.GetInstance().ClearDataPoints();
                        Thread.Sleep(1000);
                        OPCDataPointManager.GetInstance().InitializeDataLogger(true);
                    }
                }
            }
            catch (Exception localException)
            {
                LogHelper.Error(CLASS_NAME, Function_Name, localException.ToString());
                CheckOracleConnection(localException.ToString());
            }
            LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Exited");
        }
        /// <summary>
        /// Connects to OPC server and connects the loadded datapoints.
        /// </summary>
        /// <returns></returns>
        public bool InitializeAndConnectOPCServer()
        {
            string Function_Name = "InitializeAndConnectOPCServer";

            LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Entered");

            if (m_opcSrv1Name.Trim() != "" && OPCSVR1HOST.Trim() != "")
            {
                OPCServerProxy.GetInstance().InitializeServer(m_opcSrv1Name, m_processID);
            }

            if (OPCServerProxy.GetInstance().ReconnectAndAddToOPC())
            {
                ConnectDPToOPC();
            }
            else
            {
                LogHelper.Error("No Connection to OPC Server");
                return(false);
            }

            LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Exited");
            return(true);
        }
 public override void AttachCallBack(IModel model, IView view)
 {
     m_Model = (TrendViewModel)model;
     m_View  = (TrendViewer.View.TrendView)view;
     OPCServerProxy.GetInstance().AddObserver(this);
 }
Example #9
0
        /// <summary>
        /// The main function for logging the datapoints value from OPC Server in database.
        /// </summary>
        public void Run()
        {
            string Function_Name = "Run";

            LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Entered");

            //store current thread instance
            m_thread = Thread.CurrentThread;

            //Initiliase the Datalogger here to avoid different thread COM Object issue.
            OPCDataPointManager.GetInstance().InitializeDataLogger(false);

            //till the thread is running
            while (m_serviceStarted)
            {
                try
                {
                    // Start ID 0001170
                    if (TestOracleConnection() && CheckOPCConnection())
                    {
                        //LogFaileDataPTQuene();

                        // Add Datapoints which failed to be added to OPCGroup since OPCServer didnot intialize at that time properly.
                        OPCServerProxy.GetInstance().AddFailedOPCItems();

                        // End ID 0001170
                        CheckSampleGroupFlag();

                        OPCDPGrpDetails opcDetails = null;
                        Dictionary <string, OPCDPGrpDetails> opcDataPTsDic = OPCDataPointManager.GetInstance().GetOPCLoggerDataPoints();
                        foreach (KeyValuePair <string, OPCDPGrpDetails> pair in opcDataPTsDic)
                        {
                            try
                            {
                                opcDetails = pair.Value;
                                //bOPCItemQualityNotGood = false;

                                if (CanLogDataPT(opcDetails))
                                {
                                    DateTime plannedLogTime = System.Convert.ToDateTime(opcDetails.NextSampleTime);
                                    DateTime currenttime    = DateTime.Now;
                                    opcDetails.NextSampleTime = OPCDataPointManager.GetInstance().GetNextSampleTime(plannedLogTime, opcDetails.Interval, false);
                                    string opcvalue = GetOPCValue(opcDetails.DT_PT_Name);
                                    if (opcvalue.Trim() != "")
                                    {
                                        opcDetails.Value = opcvalue;
                                    }
                                    else
                                    {
                                        LogHelper.Debug(CLASS_NAME, Function_Name, string.Format("DataPoint: {0}- DataPoint value: invalid", opcDetails.DT_PT_Name));
                                        //bOPCItemQualityNotGood = true;
                                        continue;
                                    }
                                    string value     = "";
                                    double delta     = 0;
                                    bool   writeFlag = false;

                                    EtyTrendLog etyTrendLog = new EtyTrendLog();
                                    etyTrendLog.Data_PT_Name   = opcDetails.DT_PT_Name;
                                    etyTrendLog.Data_PT_Host   = m_opcSvrHost;
                                    etyTrendLog.Data_PT_Server = m_opcSrvName;
                                    etyTrendLog.Data_PT_Time   = currenttime;

                                    //first time logging
                                    if (opcDetails.OldValue.ToString() == "null")
                                    {
                                        opcDetails.OldValue       = value = opcDetails.Value;
                                        etyTrendLog.Data_PT_Value = Convert.ToDouble(value);
                                        writeFlag = true;
                                    }
                                    else
                                    {
                                        // check delta
                                        delta = Math.Abs(Convert.ToDouble(opcDetails.Value.ToString()) -
                                                         Convert.ToDouble(opcDetails.OldValue.ToString()));
                                        //log only if the value is >= delta value.
                                        if (delta >= Convert.ToDouble(opcDetails.Delta.ToString()))
                                        {
                                            opcDetails.OldValue       = value = opcDetails.Value;
                                            etyTrendLog.Data_PT_Value = Convert.ToDouble(value);
                                            writeFlag = true;
                                        }
                                    }
                                    if (writeFlag)
                                    {
                                        OPCDataPointManager.GetInstance().PushToWriteQuene(etyTrendLog);
                                    }
                                }
                            }
                            catch (Exception localException)
                            {
                                LogHelper.Error(opcDetails.DT_PT_Name.ToString() + " Fail");
                                CheckOracleConnection(localException.ToString());
                            }
                        }
                    }
                }
                catch (Exception localException)
                {
                    LogHelper.Error(CLASS_NAME, Function_Name, localException.ToString());
                    CheckOracleConnection(localException.ToString());
                }

                if (m_serviceStarted)
                {
                    Thread.Sleep(new TimeSpan(0, 0, 0, 0, OPCDataPointManager.GetInstance().GetLoggerInterval()));
                }
            }

            // time to end the thread
            Thread.CurrentThread.Abort();
            LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Exited");
        }
Example #10
0
        public void TestCreateOPCServerProxy02()
        {
            OPCServerProxy oPCServerProxy = CreateOPCServerProxy02();

            Assert.IsNotNull(oPCServerProxy);
        }
Example #11
0
        public static OPCServerProxy CreateOPCServerProxy02()
        {
            OPCServerProxy oPCServerProxy = (OPCServerProxy)ReflectionAccessor.Construct("STEE.ISCS.OPCProxy.OPCServerProxy");

            return(oPCServerProxy);
        }
Example #12
0
        public static OPCServerProxy CreateOPCServerProxy01()
        {
            OPCServerProxy oPCServerProxy = OPCServerProxy.GetInstance();

            return(oPCServerProxy);
        }