VIDItem.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Xml.Serialization;
  7. using MECF.Framework.Common.Equipment;
  8. namespace MECF.Framework.Common.FAServices
  9. {
  10. [Serializable]
  11. [XmlRoot("DataItems")]
  12. public class VIDItem
  13. {
  14. private string name;
  15. [XmlAttribute("Name")]
  16. public string Name
  17. {
  18. get { return name; }
  19. set
  20. {
  21. name = value;
  22. AnalyseName(value);
  23. }
  24. }
  25. [XmlAttribute("Index")]
  26. public int Index { get; set; }
  27. [XmlAttribute("DataType")]
  28. public string DataType { get; set; }
  29. [XmlArray("LinkableVID")]
  30. public int[] LinkableVid { get; set; }
  31. [XmlAttribute("Description")]
  32. public string Description { get; set; }
  33. [XmlAttribute("Module")]
  34. public string Module { get; set; } = "";
  35. [XmlAttribute("Type")]
  36. public string Type { get; set; } = "";
  37. [XmlAttribute("Unit")]
  38. public string Unit { get; set; } = "";
  39. [XmlAttribute("Parameter")]
  40. public string Parameter { get; set; }
  41. private int moduleIndex;
  42. [XmlIgnore]
  43. public int ModuleIndex
  44. {
  45. get { return moduleIndex; }
  46. set
  47. {
  48. moduleIndex = value;
  49. }
  50. }
  51. private int typeIndex;
  52. [XmlIgnore]
  53. public int TypeIndex
  54. {
  55. get { return typeIndex; }
  56. set
  57. {
  58. typeIndex = value;
  59. }
  60. }
  61. private int unitIndex;
  62. [XmlIgnore]
  63. public int UnitIndex
  64. {
  65. get { return unitIndex; }
  66. set
  67. {
  68. unitIndex = value;
  69. }
  70. }
  71. private int parameterIndex;
  72. [XmlIgnore]
  73. public int ParameterIndex
  74. {
  75. get { return parameterIndex; }
  76. set
  77. {
  78. parameterIndex = value;
  79. }
  80. }
  81. void AnalyseName(string name)
  82. {
  83. if (string.IsNullOrEmpty(name))
  84. return;
  85. string[] names = name.Split('.');
  86. Module = ModuleName.System.ToString();
  87. if (names.Length >= 1)
  88. {
  89. Parameter = names[names.Length - 1];
  90. if (names.Length >= 2)
  91. {
  92. Module = names[0];
  93. ModuleIndex = (Enum.TryParse(Module, out ModuleName moduleIndex) ? (int)moduleIndex : 0) + 1;
  94. if (names.Length >= 3)
  95. {
  96. Unit = names[names.Length - 2];
  97. if (names.Length >= 4)
  98. {
  99. for (int j = 1; j < names.Length - 2; j++)
  100. {
  101. Type += names[j];
  102. if (j != names.Length - 3)
  103. Type += ".";
  104. }
  105. }
  106. }
  107. }
  108. }
  109. }
  110. }
  111. }