| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 | 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<BeckhoffModuleIOManager>    {        #region 内部变量        private BeckhoffModuleIOCfg _cfg;        /// <summary>        /// 模块IO字典(key-模块名称,value-beckhoff 变量名称        /// </summary>        private Dictionary<string, string> _moduleNameIODic = new Dictionary<string, string>();        /// <summary>        /// Beckhoff IO-内部模块名称字典        /// </summary>        private Dictionary<string, string> _ioModuleNameDic = new Dictionary<string, string>();        #endregion        /// <summary>        /// 初始化        /// </summary>        /// <param name="xmlPath"></param>        public void Initialize(string xmlPath)        {            _cfg = CustomXmlSerializer.Deserialize<BeckhoffModuleIOCfg>(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;                    }                }            }        }        /// <summary>        /// 通过获取模块名称获取IO名称        /// </summary>        /// <param name="key"></param>        /// <returns></returns>        public string GetIoNameByInnerModuleName(string key)        {            return _moduleNameIODic.ContainsKey(key) ? _moduleNameIODic[key]:"";        }        /// <summary>        /// 通过IO名称获取模块名称        /// </summary>        /// <param name="key"></param>        /// <returns></returns>        public string GetInnerModuleNameByIOName(string key)        {            return _ioModuleNameDic.ContainsKey(key) ? _ioModuleNameDic[key] : "";        }        /// <summary>        /// 订阅模块IO数值        /// </summary>        /// <param name="ioName"></param>        /// <param name="value"></param>        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);            }        }    }}
 |