Esempio n. 1
0
        /// <summary>
        /// Checks whether the datapoints next time is >= current time.
        /// </summary>
        /// <param name="opcDPGrp">OPCDP Grp Details</param>
        /// <returns>true - can log, false - cannot log</returns>
        private bool CanLogDataPT(OPCDPGrpDetails opcDPGrp)
        {
            string Function_Name = "CanLogDataPT";

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

            DateTime timeStamp = DateTime.Now;

            timeStamp = new DateTime(timeStamp.Year, timeStamp.Month, timeStamp.Day, timeStamp.Hour, timeStamp.Minute, timeStamp.Second, 0);
            if (opcDPGrp.NextSampleTime == null)
            {
                opcDPGrp.NextSampleTime = timeStamp;
                return(true);
            }
            else
            {
                if (DateTime.Compare(timeStamp, System.Convert.ToDateTime(opcDPGrp.NextSampleTime)) >= 0)
                {
                    return(true);
                }
            }

            LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Exited");
            return(false);
        }
        /// <summary>
        /// Loads the Enabled Datapoints of the logger servername.
        /// </summary>
        public void LoadDataPointTimeStamp()
        {
            string Function_Name = "LoadDataPointTimeStamp";

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

            //get unique Datapoint of this servername and host which is enabled in both table - opc_dt_pt & opc_sample_grp
            List <EtyOPCDataPoint> etyDataPointList = OPCNodeNDataPointDAO.GetInstance().GetUniqueEnabledOPCDataPoint(OPCSVR1HOST, m_opcSrv1Name);

            //get all Sample Groups
            List <EtyOPCSampleGroup> etySampleGrpList = OPCSampleGroupDAO.GetInstance().GetAllEnabledSampleGrp();

            foreach (EtyOPCDataPoint etyDP in etyDataPointList)
            {
                OPCDPGrpDetails opcDPGrp = new OPCDPGrpDetails();
                opcDPGrp.DT_PT_Name = etyDP.OPCDataPointName;
                EtyOPCSampleGroup etySampleGrp = etySampleGrpList.Find(delegate(EtyOPCSampleGroup obj) { return(obj.SampleGrpID == etyDP.OPCSampleGrpId); });
                //add only if the sample group is also enabled.
                if (etySampleGrp != null)
                {
                    opcDPGrp.Delta = etySampleGrp.DeltaValue;
                    double interval = etySampleGrp.Interval;
                    if (etySampleGrp.IntervalType == DAOHelper.HOUR)
                    {
                        interval = etySampleGrp.Interval * MINUTES_UNIT * SECONDS_UNIT;
                    }
                    else if (etySampleGrp.IntervalType == DAOHelper.MINITE)
                    {
                        interval = etySampleGrp.Interval * SECONDS_UNIT;
                    }
                    opcDPGrp.Interval = interval;
                    if (etySampleGrp.StartTime.Trim() != "")
                    {
                        DateTime currentTime   = System.DateTime.Now;
                        DateTime startDatetime = new DateTime(currentTime.Year, currentTime.Month, currentTime.Day, int.Parse(etySampleGrp.StartTime.Substring(0, 2)), int.Parse(etySampleGrp.StartTime.Substring(3, 2)), 0);

                        //calculate the next time for logging.
                        opcDPGrp.NextSampleTime = GetNextSampleTime(startDatetime, interval, true);
                    }
                    m_DataPointdic.Add(etyDP.OPCDataPointName, opcDPGrp);
                }
            }
            LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Exited");
        }
Esempio n. 3
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");
        }