BeckhoffModuleIOManager.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using FestoDebugger.Service;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace FestoDebugger.Beckoff
  9. {
  10. public class BeckhoffModuleIOManager : Singleton<BeckhoffModuleIOManager>
  11. {
  12. #region 内部变量
  13. private BeckhoffModuleIOCfg _cfg;
  14. /// <summary>
  15. /// 模块IO字典(key-模块名称,value-beckhoff 变量名称)
  16. /// </summary>
  17. private Dictionary<string, string> _moduleNameIODic = new Dictionary<string, string>();
  18. /// <summary>
  19. /// Beckhoff (IO-模块名称字典)
  20. /// </summary>
  21. private Dictionary<string, string> _ioModuleNameDic = new Dictionary<string, string>();
  22. #endregion
  23. /// <summary>
  24. /// 初始化
  25. /// </summary>
  26. /// <param name="xmlPath"></param>
  27. public void Initialize(string xmlPath)
  28. {
  29. _cfg = CustomXmlSerializer.Deserialize<BeckhoffModuleIOCfg>(new FileInfo(xmlPath));
  30. if (_cfg != null)
  31. {
  32. foreach (BeckhoffModule item in _cfg.Modules)
  33. {
  34. foreach (BeckhoffModuleIOInfo io in item.IOs)
  35. {
  36. _moduleNameIODic[io.Name] = io.IOName;
  37. _ioModuleNameDic[io.IOName] = io.Name;
  38. }
  39. }
  40. }
  41. }
  42. /// <summary>
  43. /// 通过获取模块名称获取IO名称
  44. /// </summary>
  45. /// <param name="key"></param>
  46. /// <returns></returns>
  47. public string GetIoNameByInnerModuleName(string key)
  48. {
  49. return _moduleNameIODic.ContainsKey(key) ? _moduleNameIODic[key] : "";
  50. }
  51. /// <summary>
  52. /// 通过IO名称获取模块名称
  53. /// </summary>
  54. /// <param name="key"></param>
  55. /// <returns></returns>
  56. public string GetInnerModuleNameByIOName(string key)
  57. {
  58. return _ioModuleNameDic.ContainsKey(key) ? _ioModuleNameDic[key] : "";
  59. }
  60. }
  61. }