/// <summary> /// 取得 PC->PLC 特定寫入位置 /// </summary> /// <param name="BufferName">PLC位置</param> /// <param name="Section">特定位置</param> /// <returns></returns> private bool funGetWritePC2PLCAddress(string BufferName, clsPLC.enuAddressSection Section, ref string Address) { if (clsSystem.gdicPC2PLCMap.ContainsKey(BufferName)) { Address = "D" + (clsSystem.gdicPC2PLCMap[BufferName] + (int)Section).ToString(); return(true); } else { Address = string.Empty; clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC); SystemTraceLog.LogMessage = "Get Write PLC Address Fail!.."; SystemTraceLog.BufferName = BufferName; SystemTraceLog.AddressSection = Section.ToString(); funShowSystemTrace(lsbMPLC, SystemTraceLog, true); SystemTraceLog = null; return(false); } }
/// <summary> /// 從特定位置寫入 PC->PLC /// </summary> /// <param name="BufferName"></param> /// <param name="Section"></param> /// <param name="PLCValues"></param> /// <returns></returns> private bool funWritePC2PLCSingel(int iPLCNo, string BufferName, clsPLC.enuAddressSection Section, params string[] PLCValues) { string strAddress = string.Empty; if (funGetWritePC2PLCAddress(BufferName, Section, ref strAddress)) { switch (iPLCNo) { case 1: if (clsSystem.gobjPLC.funWritePLC(strAddress, PLCValues)) { clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC); SystemTraceLog.LogMessage = "Write PLC Success!"; SystemTraceLog.BufferName = BufferName; SystemTraceLog.AddressSection = Section.ToString(); SystemTraceLog.PLCValues = PLCValues; funShowSystemTrace(lsbMPLC, SystemTraceLog, true); SystemTraceLog = null; return(true); } else { clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC); SystemTraceLog.LogMessage = "Write PLC Fail!"; SystemTraceLog.BufferName = BufferName; SystemTraceLog.AddressSection = Section.ToString(); SystemTraceLog.PLCValues = PLCValues; funShowSystemTrace(lsbMPLC, SystemTraceLog, true); SystemTraceLog = null; return(false); } break; case 2: if (clsSystem.gobjPLC2.funWritePLC(strAddress, PLCValues)) { clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC); SystemTraceLog.LogMessage = "Write PLC Success!"; SystemTraceLog.BufferName = BufferName; SystemTraceLog.AddressSection = Section.ToString(); SystemTraceLog.PLCValues = PLCValues; funShowSystemTrace(lsbMPLC, SystemTraceLog, true); SystemTraceLog = null; return(true); } else { clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC); SystemTraceLog.LogMessage = "Write PLC Fail!"; SystemTraceLog.BufferName = BufferName; SystemTraceLog.AddressSection = Section.ToString(); SystemTraceLog.PLCValues = PLCValues; funShowSystemTrace(lsbMPLC, SystemTraceLog, true); SystemTraceLog = null; return(false); } break; case 3: if (clsSystem.gobjPLC3.funWritePLC(strAddress, PLCValues)) { clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC); SystemTraceLog.LogMessage = "Write PLC Success!"; SystemTraceLog.BufferName = BufferName; SystemTraceLog.AddressSection = Section.ToString(); SystemTraceLog.PLCValues = PLCValues; funShowSystemTrace(lsbMPLC, SystemTraceLog, true); SystemTraceLog = null; return(true); } else { clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC); SystemTraceLog.LogMessage = "Write PLC Fail!"; SystemTraceLog.BufferName = BufferName; SystemTraceLog.AddressSection = Section.ToString(); SystemTraceLog.PLCValues = PLCValues; funShowSystemTrace(lsbMPLC, SystemTraceLog, true); SystemTraceLog = null; return(false); } break; } return(false); } else { return(false); } }
/// <summary> /// 從特定位置寫入PLC /// </summary> /// <param name="BufferName"></param> /// <param name="Section"></param> /// <param name="PLCValues"></param> /// <returns></returns> private bool funWritePC2PLCSingel(string BufferName, clsPLC.enuAddressSection Section, params string[] PLCValues) { string strAddress = string.Empty; if (funGetWritePC2PLCAddress(BufferName, Section, ref strAddress)) { if (BufferName.Substring(0, 1) == "C" || BufferName.Substring(0, 1) == "D" || BufferName.Substring(0, 1) == "E") { if (clsSystem.gobjPLC2.funWritePLC(strAddress, PLCValues)) { if (ShowSystemTrace != null) { clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC); SystemTraceLog.LogMessage = "User Write PLC Success!"; SystemTraceLog.BufferName = BufferName; SystemTraceLog.AddressSection = Section.ToString(); SystemTraceLog.PLCValues = PLCValues; ShowSystemTrace(this, SystemTraceLog); SystemTraceLog = null; } return(true); } else { if (ShowSystemTrace != null) { clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC); SystemTraceLog.LogMessage = "Write PLC Fail!"; SystemTraceLog.BufferName = BufferName; SystemTraceLog.AddressSection = Section.ToString(); SystemTraceLog.PLCValues = PLCValues; ShowSystemTrace(this, SystemTraceLog); SystemTraceLog = null; } return(false); } } else if (BufferName.Substring(0, 1) == "F" || BufferName.Substring(0, 1) == "G") { if (clsSystem.gobjPLC3.funWritePLC(strAddress, PLCValues)) { if (ShowSystemTrace != null) { clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC); SystemTraceLog.LogMessage = "User Write PLC Success!"; SystemTraceLog.BufferName = BufferName; SystemTraceLog.AddressSection = Section.ToString(); SystemTraceLog.PLCValues = PLCValues; ShowSystemTrace(this, SystemTraceLog); SystemTraceLog = null; } return(true); } else { if (ShowSystemTrace != null) { clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC); SystemTraceLog.LogMessage = "Write PLC Fail!"; SystemTraceLog.BufferName = BufferName; SystemTraceLog.AddressSection = Section.ToString(); SystemTraceLog.PLCValues = PLCValues; ShowSystemTrace(this, SystemTraceLog); SystemTraceLog = null; } return(false); } } else { if (clsSystem.gobjPLC.funWritePLC(strAddress, PLCValues)) { if (ShowSystemTrace != null) { clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC); SystemTraceLog.LogMessage = "User Write PLC Success!"; SystemTraceLog.BufferName = BufferName; SystemTraceLog.AddressSection = Section.ToString(); SystemTraceLog.PLCValues = PLCValues; ShowSystemTrace(this, SystemTraceLog); SystemTraceLog = null; } return(true); } else { if (ShowSystemTrace != null) { clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC); SystemTraceLog.LogMessage = "Write PLC Fail!"; SystemTraceLog.BufferName = BufferName; SystemTraceLog.AddressSection = Section.ToString(); SystemTraceLog.PLCValues = PLCValues; ShowSystemTrace(this, SystemTraceLog); SystemTraceLog = null; } return(false); } } } else { return(false); } }