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"); }
/*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); }
/// <summary> /// Terminates the application. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OPCDataLogger_FormClosed(object sender, FormClosedEventArgs e) { string Function_Name = "OPCDataLogger_FormClosed"; LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Entered"); OPCDataPointManager.GetInstance().TerminateAndWait(); OPCDataPointManager.ReleaseInstance(); //System.Threading.Thread.Sleep(1000); LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Exited"); }
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"); }
public static OPCDataPointManager GetInstance() { string Function_Name = "GetInstance"; LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Entered"); if (m_instance == null) { lock (s_Singleton) { m_instance = new OPCDataPointManager(); LogHelper.Info(CLASS_NAME, Function_Name, "Create Instance"); } } LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Exited"); return(m_instance); }
/// <summary> /// This method tries to reconnect to database if it got disconnected. /// </summary> /// <returns></returns> private bool CheckDatabaseConnection() { string Function_Name = "CheckDatabaseConnection"; LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Entered"); if (m_dbDisconnected) { LogHelper.Debug(CLASS_NAME, Function_Name, "Reconnecting to Oracle"); if (DBConnection.getInstance().OpenConnection(OPCDataPointManager.GetInstance().m_localConnectionString)) { m_dbDisconnected = false; } else { return(false); } } LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Exited"); return(true); }
/// <summary> /// Checks for the exitence of this process in the system, if not starts logging. /// </summary> public OPCDataLogger() { string Function_Name = "OPCDataLogger"; LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Entered"); System.Diagnostics.Process[] ps = System.Diagnostics.Process. GetProcessesByName(System.Diagnostics.Process.GetCurrentProcess().ProcessName); m_process = Process.GetCurrentProcess(); if (ps.Length > 1) { LogHelper.Error("Already an instance is running"); m_process.Kill(); } InitializeComponent(); OPCDataPointManager.GetInstance().ExitApplicationEvent += CloseApplication; OPCDataPointManager.GetInstance().InitializeOPCSetting(m_process.Id.ToString()); LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Exited"); }
/// <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> /// 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"); }