版博士V2.0程序
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 

164 行
6.5 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Xml.Linq;
  8. using Advantech.Motion;
  9. using Newtonsoft.Json;
  10. using Newtonsoft.Json.Linq;
  11. using Newtonsoft.Json.Serialization;
  12. using AssistClient.UI.PropExtend;
  13. using static AssistClient.UI.UIAxisDev;
  14. namespace AssistClient.UI
  15. {
  16. //[TypeConverter(typeof(PropertySorter))] //此属性使类无法序列化和反序列化
  17. public class IOCardDevProp
  18. {
  19. private byte[] _in, _out;
  20. public IOCardDevProp(string deviceNum) {
  21. DeviceNum = deviceNum;
  22. }
  23. [PropertyOrder(1), Browsable(true), Category("1 设备"), DisplayName("设备号"), Description("设备号"), ReadOnly(true), JsonIgnore]
  24. public string DeviceNum { get;private set; }
  25. //
  26. [PropertyOrder(11), Browsable(false), Category("2 时时数据"), DisplayName("输入"), Description("输入"), ReadOnly(true), JsonIgnore]
  27. public byte[] IN
  28. {
  29. get
  30. {
  31. return _in;
  32. }
  33. set
  34. {
  35. _in = value;
  36. if (value == null)
  37. IN_SHOW = null;
  38. else
  39. {
  40. IN_SHOW = new string[value.Length];
  41. IN_OP_SHOW= new string[value.Length];
  42. for (int i = 0; i < IN_OP_SHOW.Length; i++)
  43. {
  44. if (string.IsNullOrWhiteSpace(IN_OP_SHOW[i]))
  45. IN_OP_SHOW[i] = "XXXX XXXX";
  46. }
  47. string s;
  48. for (int i = 0; i < value.Length; i++)
  49. {
  50. s = Convert.ToString(value[i], 2).PadLeft(8, '0').Replace('0', 'L').Replace('1', 'H');
  51. //IN_SHOW[i] = String.Join(" ", s.Reverse());
  52. IN_SHOW[i] = s.Substring(0, 4) + " " + s.Substring(4);
  53. }
  54. }
  55. }
  56. }
  57. [PropertyOrder(12), Browsable(false), Category("2 时时数据"), DisplayName("输出"), Description("输出"), ReadOnly(true), JsonIgnore]
  58. public byte[] OUT
  59. {
  60. get
  61. {
  62. return _out;
  63. }
  64. set
  65. {
  66. _out = value;
  67. if (value == null)
  68. OUT_SHOW = null;
  69. else
  70. {
  71. OUT_SHOW = new string[value.Length];
  72. OUT_OP_SHOW = new string[value.Length];
  73. string s;
  74. for (int i = 0; i < value.Length; i++)
  75. {
  76. s = Convert.ToString(value[i], 2).PadLeft(8, '0').Replace('0', 'L').Replace('1', 'H');
  77. OUT_SHOW[i] = s.Substring(0, 4) + " " + s.Substring(4); //String.Join(" ", s.Reverse());
  78. OUT_OP_SHOW[i] = "XXXX XXXX";
  79. }
  80. }
  81. }
  82. }
  83. [PropertyOrder(11), Browsable(true), Category("2 时时数据"), DisplayName("2.1 输入"), Description("输入"), ReadOnly(true), JsonIgnore]
  84. public string[] IN_SHOW { get; set; }
  85. [PropertyOrder(12), Browsable(true), Category("2 时时数据"), DisplayName("2.2 输出"), Description("输出"), ReadOnly(true), JsonIgnore]
  86. public string[] OUT_SHOW { get; set; }
  87. //IN_OP OUT_OP_INDEX OUT_OP_BIT_INDEX OUT_OP_VALUE
  88. [PropertyOrder(1), Browsable(true), Category("3 指令"), DisplayName("3.1 作业方向"), Description("作业方向")]
  89. public IODirectionEnum Direction { get; set; }
  90. /// <summary>
  91. /// 输入值, XXXX XXHL
  92. /// </summary>
  93. [PropertyOrder(11), Browsable(true), Category("3 指令"), DisplayName("3.2 输入指令值"), Description("输入指令值")]
  94. public string[] IN_OP_SHOW { get; set; }//单改数组属性不触发SET
  95. [PropertyOrder(11), Browsable(true), Category("3 指令"), DisplayName("3.3 输入超时告警(ms)"), Description("自动流程中等待输入指令超时则告警,0则无限期等待")]
  96. public uint IN_Waiting_Timeout { get; set; } = 0;
  97. /// <summary>
  98. /// 输出值, XXXX XXHL
  99. /// </summary>
  100. [PropertyOrder(11), Browsable(true), Category("3 指令"), DisplayName("3.4 输出指令值"), Description("输出指令值")]
  101. public string[] OUT_OP_SHOW { get; set; }
  102. //
  103. [PropertyOrder(25), Browsable(true), Category("4 控制"), DisplayName("4.1 运行前Sleep(ms)"), Description("休息时间")]
  104. public uint SleepPre { get; set; }
  105. [PropertyOrder(26), Browsable(true), Category("4 控制"), DisplayName("4.2 运行后Sleep(ms)"), Description("休息时间")]
  106. public uint SleepLater { get; set; }
  107. [PropertyOrder(27), Browsable(true), Category("4 控制"), DisplayName("4.4 禁用工序"), Description("禁用本工序")]
  108. public bool Disable { get; set; }
  109. /// <summary>
  110. /// 序列化
  111. /// </summary>
  112. /// <param name="obj"></param>
  113. /// <returns></returns>
  114. public string serialize()
  115. {
  116. return JsonConvert.SerializeObject(this);
  117. }
  118. /// <summary>
  119. /// 反序列化
  120. /// </summary>
  121. /// <param name="json"></param>
  122. /// <returns></returns>
  123. public void deserialize(string json)
  124. {
  125. var o= JsonConvert.DeserializeObject<IOCardDevProp>(json);
  126. Type type = o.GetType();
  127. System.Reflection.PropertyInfo[] properties = type.GetProperties();
  128. foreach (System.Reflection.PropertyInfo property in properties)
  129. {
  130. string name = property.Name;
  131. if (!type.GetProperty(name).IsDefined(typeof(JsonIgnoreAttribute), true))
  132. {
  133. var value = property.GetValue(o);
  134. this.GetType().GetProperty(name).SetValue(this, value);
  135. }
  136. }
  137. }
  138. private byte[] inputValue2byte(string[] strList)
  139. {
  140. byte[] result=new byte[strList.Length];
  141. string[] strArr = Utils.Util.IODataFormatBinaryStr(strList,false, 'L');
  142. for (int i=0; i< strArr.Length; i++)
  143. {
  144. strArr[i] = strArr[i].Replace("L", "0").Replace("H", "1").Replace("X", "0");
  145. result[i] = Convert.ToByte(strArr[i], 2);
  146. }
  147. return result;
  148. }
  149. }
  150. }