123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- using FestoDebugger.Service;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace FestoDebugger.Beckoff
- {
- 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] : "";
- }
- }
- }
|