DeviceConfig.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using YG.Config;
  2. using YG.Config.DefaultList;
  3. using YG.DefaultList;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using IMCS.DefaultList;
  10. /// <summary>
  11. /// 设备配置,可以理解为全局的变量
  12. /// </summary>
  13. namespace YG
  14. {
  15. public class DeviceConfig
  16. {
  17. private static DeviceConfig deviceConfig = new DeviceConfig();
  18. public static DeviceConfig Instance { get { return deviceConfig; } }
  19. /// <summary>
  20. /// YG串口配置
  21. /// </summary>
  22. public System.ComponentModel.BindingList<ComConfig> YGConfig { get; set; } = new System.ComponentModel.BindingList<ComConfig>();
  23. /// <summary>
  24. /// PLC的配置信息
  25. /// </summary>
  26. public System.ComponentModel.BindingList<PLCConfig> PLCConfigs { get; set; } = new System.ComponentModel.BindingList<PLCConfig>();
  27. /// <summary>
  28. /// 用户信息配置
  29. /// </summary>
  30. public System.ComponentModel.BindingList<UserDefualtList> UserConfigs { get; set; } = new System.ComponentModel.BindingList<UserDefualtList>();
  31. public System.ComponentModel.BindingList<WeiLiTaskDefaultList> WeiLiTask { get; set; } = new System.ComponentModel.BindingList<WeiLiTaskDefaultList>();
  32. /// <summary>
  33. /// 地轨对应的点位
  34. /// </summary>
  35. public System.ComponentModel.BindingList<TrainPointDefaultList> PointDefaultList { get; set; } = new System.ComponentModel.BindingList<TrainPointDefaultList>();
  36. /// <summary>
  37. /// 版本信息
  38. /// </summary>
  39. public VersionDefaultList version { get; set; } = new VersionDefaultList();
  40. string compath = AppDomain.CurrentDomain.BaseDirectory + "Config\\Com.config";
  41. string plcpath = AppDomain.CurrentDomain.BaseDirectory + "Config\\PLC.config";
  42. string boardpath = AppDomain.CurrentDomain.BaseDirectory + "Config\\Board.config";
  43. string userpath = AppDomain.CurrentDomain.BaseDirectory + "Config\\User.config";
  44. string verpath = AppDomain.CurrentDomain.BaseDirectory + "Config\\Version.config";
  45. string machinepath = AppDomain.CurrentDomain.BaseDirectory + "Config\\Machine.config";
  46. string upath = AppDomain.CurrentDomain.BaseDirectory + "Config\\U.config";
  47. public DeviceConfig()
  48. {
  49. compath.PathIsExist();
  50. plcpath.PathIsExist();
  51. boardpath.PathIsExist();
  52. userpath.PathIsExist();
  53. verpath.PathIsExist();
  54. machinepath.PathIsExist();
  55. upath.PathIsExist();
  56. PointDefaultList.Add(new TrainPointDefaultList() { Train_Index=9, Point={119,120,121,122, } });
  57. PointDefaultList.Add(new TrainPointDefaultList() { Train_Index = 1, Point = { 1,2,3,4 } });
  58. PointDefaultList.Add(new TrainPointDefaultList() { Train_Index = 2, Point = { 5, 6, 7, 8, } });
  59. PointDefaultList.Add(new TrainPointDefaultList() { Train_Index = 3, Point = { 9, 10, 11, 12, } });
  60. PointDefaultList.Add(new TrainPointDefaultList() { Train_Index = 4, Point = { 13, 14, 15, 16, } });
  61. PointDefaultList.Add(new TrainPointDefaultList() { Train_Index = 5, Point = { 17, 18, 19, 20, } });
  62. PointDefaultList.Add(new TrainPointDefaultList() { Train_Index = 6, Point = { 21, 22, 23, 24, } });
  63. PointDefaultList.Add(new TrainPointDefaultList() { Train_Index = 7, Point = { 25, 26, 27, 28, } });
  64. PointDefaultList.Add(new TrainPointDefaultList() { Train_Index = 8, Point = { 29, 30, } });
  65. PointDefaultList.Add(new TrainPointDefaultList() { Train_Index = 15, Point = { 129 } });
  66. PointDefaultList.Add(new TrainPointDefaultList() { Train_Index = 10, Point = { 130 } });
  67. PointDefaultList.Add(new TrainPointDefaultList() { Train_Index = 11, Point = { 131 } });
  68. PointDefaultList.Add(new TrainPointDefaultList() { Train_Index = 12, Point = { 126 } });
  69. PointDefaultList.Add(new TrainPointDefaultList() { Train_Index = 13, Point = { 127 } });
  70. PointDefaultList.Add(new TrainPointDefaultList() { Train_Index =14, Point = { 128 } });
  71. }
  72. public void Open()
  73. {
  74. //Task.Factory.StartNew(() =>
  75. // {
  76. var Tcom = YGConfig.OpenXml(compath);
  77. if (Tcom != null)
  78. {
  79. YGConfig = Tcom;
  80. }
  81. var Tplc = PLCConfigs.OpenXml(plcpath);
  82. if (Tplc != null)
  83. {
  84. PLCConfigs = Tplc;
  85. }
  86. var user = UserConfigs.OpenXml(userpath);
  87. if (user != null)
  88. {
  89. UserConfigs = user;
  90. }
  91. var verus = version.OpenXml(verpath);
  92. if (verus != null)
  93. {
  94. version = verus;
  95. }
  96. // });
  97. }
  98. public void Save()
  99. {
  100. YGConfig.SaveXml(compath);
  101. PLCConfigs.SaveXml(plcpath);
  102. UserConfigs.SaveXml(userpath);
  103. version.SaveXml(verpath);
  104. YG.Log.Instance.WriteLogAdd("Save");
  105. }
  106. }
  107. }