/// <summary> /// Log 클래스를 초기화 시킨다.프로그램 폴더에 Log_PlcModule폴더에 Log가 기록. /// </summary> /// <param name="strLogFileName">Log파일 생성 이름</param> private void InitClass(string folderPath, string strLogFileName) { strLogFileName = strLogFileName.Trim(); if (strLogFileName == string.Empty) { strLogFileName = "plcModuleLog"; } clsLog = new clsLog(folderPath, strLogFileName, 30, true); dtAddress = new DataTable("PLC Address"); dtAddress.Columns.Add(new DataColumn("Address", System.Type.GetType("System.String"))); dtAddress.Columns.Add(new DataColumn("Value", System.Type.GetType("System.Int16"))); dtAddress.Columns.Add(new DataColumn("Value(HEX)", System.Type.GetType("System.String"))); dtAddress.PrimaryKey = new DataColumn[] { dtAddress.Columns["Address"] }; clsPLC.dtWriteOrder.Columns.Add(new DataColumn("Address", System.Type.GetType("System.String"))); clsPLC.dtWriteOrder.Columns.Add(new DataColumn("Value", System.Type.GetType("System.Int16"))); //변수 및 이벤트 연결.. clsPLC.dtAddress = this.dtAddress; //dtAddress.ColumnChanged += new DataColumnChangeEventHandler(dtAddress_ColumnChanged); strLogHeader = enPLCType.ToString(); }
/// <summary> /// Log 클래스를 초기화 시킨다.프로그램 폴더에 Log_PlcModule폴더에 Log가 기록. /// </summary> /// <param name="strLogFileName">Log파일 생성 이름</param> private void InitClass(string folderPath, string strLogFileName) { strLogFileName = strLogFileName.Trim(); if (strLogFileName == string.Empty) { strLogFileName = "PlcCommLog"; } plc.log = new Log(folderPath, strLogFileName, 30, true); log = plc.log; //변수 및 이벤트 연결.. this.dtAddress = plc.dtAddress; strLogHeader = enPLCType.ToString(); }
/// <summary> /// Exception 처리를 한다. 발생전 Log기록 후 발생. /// </summary> /// <param name="ex"></param> private void ProcException(Exception ex) { string strLog = string.Empty; strLog = string.Format("[{0}]", enPLCType.ToString()); strLog = string.Format("Error : {0} [Msg] {1} - {2}", strLog, ex.Message, ex.ToString()); clsLog.WLog(strLog); }
/// <summary> /// (인증필요)AB Plc 객체 생성. /// </summary> /// <param name="ePlcType">PLC종류 : AB</param> /// <param name="strIPAddress">Remote Gateway를 사용 할 경우 ip address 입력, local gateway 사용 시 공백 입력</param> /// <param name="strProgramID">local : 'RSLinx OPC Server' / 원격 : 'RSLinx Remote OPC Server'</param> /// <param name="strGroupName">Item Group명 : 미입력시'Group'으로 설정 </param> /// <param name="strTopicName">설정되 Topic 이릅</param> /// <param name="intUpdateRate">Value 업데이스 시간(ms)</param> /// <param name="strLogFileName">기록을 쌓을 로그 파일(프로그램 폴더 \Log_PlcModule 폴더에 기록.</param> public clsPLCModule(enPlcType ePlcType, string strIPAddress, string strProgramID, string strGroupName, string strTopicName, int intUpdateRate, string strLogFileName) { enPLCType = ePlcType; try { #if (ABPLC_A || ABPLC_B) if (ePlcType == enPlcType.AB) { clsPLC = new clsABPLC(strIPAddress, strProgramID, strGroupName, strTopicName, intUpdateRate); } else { throw new Exception(string.Format("AB PLC 생성자의 Type이 잘 못 되었니다.(생성 요청 타입 : {0})", enPLCType.ToString())); } #endif enPLCType = ePlcType; InitClass(strLogFileName); } catch (Exception ex) { ProcException(ex); throw ex; } }
public void Set_Module(enPlcType ePlcType, string strIPAddress, int intPort, string strDeviceType, string LogFolderPath, string strLogFileName) { if (clsPLC != null) { return; } try { enPLCType = ePlcType; IPAddress = strIPAddress; Port = intPort; switch (ePlcType) { case enPlcType.Melsec_A: clsPLC = new PLCModule.PLCModules.clsMelsecA(strIPAddress, intPort, strDeviceType); break; case enPlcType.Melsec_Q: clsPLC = new PLCModule.PLCModules.clsMelsecQ(strIPAddress, intPort, strDeviceType); break; case enPlcType.LS_XGT: clsPLC = new PLCModule.PLCModules.clsLS_XGT(strIPAddress, intPort, strDeviceType); break; case enPlcType.LS_XGI: clsPLC = new PLCModule.PLCModules.clsLS_XGI(strIPAddress, intPort, strDeviceType); break; case enPlcType.TEST: clsPLC = new PLCModule.PLCModules.clsTEST(strIPAddress, intPort, strDeviceType); break; default: throw new Exception(string.Format("Melsec A/Q 생성자의 Type이 잘 못 되었니다.(생성 요청 타입 : {0})", enPLCType.ToString())); } InitClass(LogFolderPath, strLogFileName); } catch (Exception ex) { ProcException(ex); } }
/// <summary> /// Melsec A/Q plc 객체 생성 /// </summary> /// <param name="ePlcType"></param> /// <param name="?"></param> /// <param name="intPort"></param> /// <param name="strLogFileName"></param> public clsPLCModule(enPlcType ePlcType, string strIPAddress, int intPort, string strDeviceType, string strLogFileName) { try { enPLCType = ePlcType; if (ePlcType == enPlcType.Melsec_A) { clsPLC = new clsMelsecA(strIPAddress, intPort, strDeviceType); } else if (ePlcType == enPlcType.Melsec_Q) { clsPLC = new clsMelsecQ(strIPAddress, intPort, strDeviceType); } else { throw new Exception(string.Format("Melsec A/Q 생성자의 Type이 잘 못 되었니다.(생성 요청 타입 : {0})", enPLCType.ToString())); } InitClass(strLogFileName); } catch (Exception ex) { ProcException(ex); } }