IOCommandReader.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Reflection;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Common
  10. {
  11. public class IOCommandReader
  12. {
  13. private static Dictionary<string, CommandModelConfig> _commandModelConfigDict = new Dictionary<string, CommandModelConfig>();
  14. public static CommandModelConfig GetCommandModelConfig(string hardwarePath, string hardwareName)
  15. {
  16. CommandModelConfig commandModelConfig = null;
  17. if (_commandModelConfigDict.Keys.Contains(hardwareName))
  18. {
  19. commandModelConfig = _commandModelConfigDict[hardwareName];
  20. }
  21. else
  22. {
  23. commandModelConfig = JsonConvert.DeserializeObject<CommandModelConfig>(File.ReadAllText(ConfigPath.HardwareUnitsPath + $"{hardwarePath}\\{hardwareName}\\IOCommands.json"));
  24. _commandModelConfigDict.Add(hardwareName, commandModelConfig);
  25. }
  26. return commandModelConfig;
  27. }
  28. }
  29. public class ConfigPath
  30. {
  31. public static string HardwareUnitsPath
  32. {
  33. get
  34. {
  35. string path = Assembly.GetExecutingAssembly().Location;
  36. FileInfo finfo = new FileInfo(path);
  37. return finfo.DirectoryName + @"\\HardwareUnits\";
  38. }
  39. }
  40. }
  41. }