| | |
| | | using ConnectionUtil; |
| | | using HMI.AlarmInfoManage.Entity; |
| | | using HMI.AlarmInfoManage.Entity; |
| | | using HMI.Base; |
| | | using HMI.Core.Api; |
| | | using HMI.Core.Setting; |
| | |
| | | using HMI.UI.Util; |
| | | using HMI.Util; |
| | | using Microsoft.Win32; |
| | | using OPCConnection; |
| | | using Sharp7; |
| | | using SimensDriver; |
| | | using S7Driver; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Collections.ObjectModel; |
| | |
| | | private string markPath; |
| | | private string alarmTextPath; |
| | | |
| | | private string opcIP = "127.0.0.1"; |
| | | private int opcPort = 6543; |
| | | private int localPort = 18888; |
| | | |
| | | private volatile bool isClosing = false; |
| | | |
| | | |
| | | private string dbPath; |
| | | private Simens plc = new Simens(); |
| | | |
| | | private bool isHaveAlarm; |
| | | private bool isNewAlarm; |
| | |
| | | /// </summary> |
| | | private MSMQHelper alarmRefershToMain = new MSMQHelper("LTHMI_Alarm_Rrfresh"); |
| | | |
| | | private SCADAApi lTSCADAApi = new OPCClient(); |
| | | //private string opcIP = "127.0.0.1"; |
| | | //private int opcPort = 6543; |
| | | //private int localPort = 18888; |
| | | //private SCADAApi lTSCADAApi = new OPCClient(); |
| | | |
| | | private PLCS7Driver pLCS7Driver; |
| | | |
| | | /// <summary> |
| | | /// 报警 |
| | |
| | | { |
| | | DataContext = this; |
| | | systemSetting = SystemSetting.Instance; |
| | | pLCS7Driver = new PLCS7Driver(systemSetting.PlcIp, systemSetting.PlcPort); |
| | | InitializeComponent(); |
| | | } |
| | | |
| | |
| | | Interval = 1000, |
| | | }; |
| | | MonitorTimer.Elapsed += MonitorTimer_Elapsed; |
| | | if (!lTSCADAApi.Connect2(opcIP, opcPort, localPort, out string errMsg)) |
| | | //if (!lTSCADAApi.Connect2(opcIP, opcPort, localPort, out string errMsg)) |
| | | //{ |
| | | //} |
| | | //else |
| | | //{ |
| | | // this.MonitorTimer.Start(); |
| | | //} |
| | | |
| | | if (pLCS7Driver.Connect(out string errMSg)) |
| | | { |
| | | //MsgBoxHelper.Error(this, errMsg); |
| | | this.MonitorTimer.Start(); |
| | | } |
| | | else |
| | | { |
| | | this.MonitorTimer.Start(); |
| | | log.Error($"PLC Driver Connect Error. {errMSg}"); |
| | | } |
| | | |
| | | PcTimer = new Timer |
| | |
| | | { |
| | | this.MonitorTimer.Enabled = false; |
| | | |
| | | if (!lTSCADAApi.IsConnected(out string errMsg)) |
| | | { |
| | | log.Warn($"OPCServer Connection Error. {errMsg}"); |
| | | if (!lTSCADAApi.Connect2(opcIP, opcPort, localPort, out errMsg)) |
| | | { |
| | | log.Warn($"OPCServer Try ReConnection Error. {errMsg}"); |
| | | return; |
| | | } |
| | | } |
| | | /// 检查连接 |
| | | //if (!lTSCADAApi.IsConnected(out string errMsg)) |
| | | //{ |
| | | // log.Warn($"OPCServer Connection Error. {errMsg}"); |
| | | // if (!lTSCADAApi.Connect2(opcIP, opcPort, localPort, out errMsg)) |
| | | // { |
| | | // log.Warn($"OPCServer Try ReConnection Error. {errMsg}"); |
| | | // return; |
| | | // } |
| | | //} |
| | | |
| | | isHaveAlarm = false; |
| | | List<AlarmText> cache = new List<AlarmText>(); |
| | |
| | | |
| | | foreach (var key in BlockMap.Keys) |
| | | { |
| | | if (lTSCADAApi.DoFctReadSingle(key, out string alarmCode, out errMsg) && BlockMap[key].ContainsKey(alarmCode)) |
| | | if (pLCS7Driver.ReadShort(key, out short alarmVal, out string errMsg) && BlockMap[key].ContainsKey(alarmVal.ToString())) |
| | | { |
| | | //if(BlockReadCache.ContainsKey(key) && alarmCode) |
| | | var alarmCode = alarmVal.ToString(); |
| | | isHaveAlarm = true; |
| | | var text = BlockMap[key][alarmCode]; |
| | | var newAlarm = new AlarmText |
| | |
| | | foreach (var item in markAlarmSetting) |
| | | { |
| | | var name = $"{item.DBAddress}.{item.StartAddress}"; |
| | | if (lTSCADAApi.DoFctReadSingle(name, out string alarmCode, out errMsg) && alarmCode != "0") |
| | | if (pLCS7Driver.ReadShort(name, out short alarmVal, out string errMsg) && alarmVal != 0) |
| | | { |
| | | var alarmCode = alarmVal.ToString(); |
| | | isHaveAlarm = true; |
| | | var newAlarm = new AlarmText |
| | | { |