using Aitex.Core.RT.DataCenter; using Aitex.Core.Util; using DocumentFormat.OpenXml; using MECF.Framework.Common.Beckhoff.IOAxis; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MECF.Framework.Common.Beckhoff.ModuleIO { public class BeckhoffModuleIOManager : Singleton { #region 内部变量 private BeckhoffModuleIOCfg _cfg; /// /// 模块IO字典(key-模块名称,value-beckhoff 变量名称 /// private Dictionary _moduleNameIODic = new Dictionary(); /// /// Beckhoff IO-内部模块名称字典 /// private Dictionary _ioModuleNameDic = new Dictionary(); #endregion /// /// 初始化 /// /// public void Initialize(string xmlPath) { _cfg = CustomXmlSerializer.Deserialize(new FileInfo(xmlPath)); if (_cfg != null) { foreach(BeckhoffModule item in _cfg.Modules) { foreach (BeckhoffModuleIOInfo io in item.IOs) { _moduleNameIODic[io.Name] = io.IOName; _ioModuleNameDic[io.IOName] = io.Name; } } } } /// /// 通过获取模块名称获取IO名称 /// /// /// public string GetIoNameByInnerModuleName(string key) { return _moduleNameIODic.ContainsKey(key) ? _moduleNameIODic[key]:""; } /// /// 通过IO名称获取模块名称 /// /// /// public string GetInnerModuleNameByIOName(string key) { return _ioModuleNameDic.ContainsKey(key) ? _ioModuleNameDic[key] : ""; } /// /// 订阅模块IO数值 /// /// /// public void SubscribeModuleIoValue(string ioName,object value) { string key = _moduleNameIODic.Values.FirstOrDefault(O => O == ioName); if(!string.IsNullOrEmpty(key)&&key!=ioName) { DATA.Subscribe(key, () => value, SubscriptionAttribute.FLAG.IgnoreSaveDB); } } } }