protected void Run() { try { int plcMPI = 2; CallDave.daveInterface di = CreateDaveInterface_Define(IP, Port); while (IsBeginProcess && di != null) { int res = di.initAdapter(); if (res == 0) { _dVC = new CallDave.daveConnection(di, plcMPI, rack, slot); if (0 == _dVC.connectPLC()) { Status = ePLCStatus.Connected;; int times = 1; if (LoopWrite != null) { do { EArgOnHandle_Process e = new EArgOnHandle_Process(_dVC); LoopWrite(this, e); if (e.result) { times = 0; } else { times++; } Thread.Sleep(this.ProecssSleepTime); } while (times <= MaxReConnTime); } //Log PLCProcesser.ReConnSleep 后重新连接 WLog.WriteLog(Enum_LogType.LogType_Communication, Enum_LogGrade.LogGrade_Nin, Enum_LogMessageType.LogMsgType_Event, "Run", "ReConnSleep", ""); Thread.Sleep(this.ReConnSleep); } Thread.Sleep(this.ReConnSleep); } } if (di != null) { di.disconnectAdapter(); } Status = ePLCStatus.Closed; WLog.WriteLog(Enum_LogType.LogType_Error, Enum_LogGrade.LogGrade_Fiv, Enum_LogMessageType.LogMsgType_Exception, "Run", "Closed", string.Format("IP:{0},Port:{1},Flag:{2}", IP, Port, IsBeginProcess)); } catch (Exception ex) { Status = ePLCStatus.Failed; WLog.WriteLog(Enum_LogType.LogType_Error, Enum_LogGrade.LogGrade_Nin, Enum_LogMessageType.LogMsgType_Exception, "Run", ex.Message, ex.StackTrace); } }
public void WriteLog(Enum_LogGrade logGrade, string funName, string Sql, string Info) { object obj = ConfigurationManager.AppSettings["PrintSQLLOG"]; if (Wlog != null && obj != null && bool.Parse(obj.ToString())) { Wlog.WriteLog(Enum_LogType.LogType_Debug, logGrade, Enum_LogMessageType.LogMsgType_Event, funName, Sql, Info); } }
private static void InitLog() { string logType = ConfigurationManager.AppSettings["logType"].ToString().Trim(); string logGrade = ConfigurationManager.AppSettings["logGrade"].ToString().Trim(); string logMsgType = ConfigurationManager.AppSettings["LogMsgType"].ToString().Trim(); string logFunName = ConfigurationManager.AppSettings["LogFunctionName"].ToString().Trim(); string logMessage = ConfigurationManager.AppSettings["LogMessage"].ToString().Trim(); string logDesp = ConfigurationManager.AppSettings["LogDescription"].ToString().Trim(); string seperator = ConfigurationManager.AppSettings["Seperator"].ToString().Trim(); Log_Agent_CON = new WriteErrorLog(); Log_Agent_CON.SetLogPara(logType, logGrade, logMsgType, logFunName, logMessage, logDesp, seperator); Log_Agent_CON.IsBeginProcess = true; Log_Agent_CON.SleepTime = 500; Log_Agent_CON.logName = "PLCDataAgent_CON"; Log_Agent_CON.Start(Log_Agent_CON); Log_Agent_CON.WriteLog(Enum_LogType.LogType_StartStop, Enum_LogGrade.LogGrade_Nin, Enum_LogMessageType.LogMsgType_Event, "StartLog", "Log Thread Start", ""); Log_Agent_SRM = new WriteErrorLog(); Log_Agent_SRM.SetLogPara(logType, logGrade, logMsgType, logFunName, logMessage, logDesp, seperator); Log_Agent_SRM.IsBeginProcess = true; Log_Agent_SRM.SleepTime = 500; Log_Agent_SRM.logName = "PLCDataAgent_SRM"; Log_Agent_SRM.Start(Log_Agent_SRM); Log_Agent_SRM.WriteLog(Enum_LogType.LogType_StartStop, Enum_LogGrade.LogGrade_Nin, Enum_LogMessageType.LogMsgType_Event, "StartLog", "Log Thread Start", ""); Log_Agent_BUS = new WriteErrorLog(); Log_Agent_BUS.SetLogPara(logType, logGrade, logMsgType, logFunName, logMessage, logDesp, seperator); Log_Agent_BUS.IsBeginProcess = true; Log_Agent_BUS.SleepTime = 500; Log_Agent_BUS.logName = "WMBusniess"; Log_Agent_BUS.Start(Log_Agent_BUS); Log_Agent_BUS.WriteLog(Enum_LogType.LogType_StartStop, Enum_LogGrade.LogGrade_Nin, Enum_LogMessageType.LogMsgType_Event, "StartLog", "Log Thread Start", ""); Log_Agent_DB = new WriteErrorLog(); Log_Agent_DB.SetLogPara(logType, logGrade, logMsgType, logFunName, logMessage, logDesp, seperator); Log_Agent_DB.IsBeginProcess = true; Log_Agent_DB.SleepTime = 500; Log_Agent_DB.logName = "SQLDubug"; Log_Agent_DB.Start(Log_Agent_DB); Log_Agent_DB.WriteLog(Enum_LogType.LogType_Debug, Enum_LogGrade.LogGrade_Nin, Enum_LogMessageType.LogMsgType_Event, "StartLog", "Log Thread Start", ""); Log_Agent_TEMP = new WriteErrorLog(); Log_Agent_TEMP.SetLogPara(logType, logGrade, logMsgType, logFunName, logMessage, logDesp, seperator); Log_Agent_TEMP.IsBeginProcess = true; Log_Agent_TEMP.SleepTime = 500; Log_Agent_TEMP.logName = "TagTemp"; Log_Agent_TEMP.Start(Log_Agent_DB); Log_Agent_TEMP.WriteLog(Enum_LogType.LogType_StartStop, Enum_LogGrade.LogGrade_Nin, Enum_LogMessageType.LogMsgType_Event, "StartLog", "Log Thread Start", ""); }