Trigger.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. using System;
  2. using System.IO;
  3. using System.Reflection;
  4. using System.Runtime.InteropServices;
  5. using System.Xml.Serialization;
  6. namespace Aitex.Core.Util
  7. {
  8. /// <summary>
  9. /// 下降沿信号检测类
  10. ///
  11. /// 设计目的:
  12. /// 用于信号下降沿事件检测
  13. ///
  14. /// 使用场合:
  15. /// 系统输入数字信号,1->0跳变检测
  16. /// </summary>
  17. public class F_TRIG
  18. {
  19. /// <summary>
  20. /// 构造函数
  21. /// </summary>
  22. public F_TRIG()
  23. {
  24. Q = false;
  25. M = true;
  26. }
  27. /// <summary>
  28. /// 检测信号输入
  29. /// </summary>
  30. public bool CLK
  31. {
  32. set
  33. {
  34. if (M != value && !value)
  35. Q = true;
  36. else
  37. Q = false;
  38. M = value;
  39. }
  40. get
  41. {
  42. return M;
  43. }
  44. }
  45. //clear
  46. public bool RST
  47. {
  48. set
  49. {
  50. Q = false;
  51. M = true;
  52. }
  53. }
  54. /// <summary>
  55. /// 检测结果输出
  56. /// </summary>
  57. [XmlIgnore]
  58. public bool Q { get; private set; }
  59. /// <summary>
  60. /// 记录上一次输入信号值
  61. /// </summary>
  62. [XmlIgnore]
  63. public bool M { get; private set; }
  64. }
  65. /// <summary>
  66. /// 上升沿信号检测类
  67. ///
  68. /// 设计目的:
  69. /// 用于信号上升沿事件检测
  70. ///
  71. /// 使用场合:
  72. /// 系统输入数字信号,0->1跳变检测
  73. /// </summary>
  74. public class R_TRIG
  75. {
  76. /// <summary>
  77. /// 构造函数
  78. /// </summary>
  79. public R_TRIG()
  80. {
  81. Q = false;
  82. M = false;
  83. }
  84. /// <summary>
  85. /// 检测信号输入
  86. /// </summary>
  87. public bool CLK
  88. {
  89. set
  90. {
  91. if (M != value && value)
  92. Q = true;
  93. else
  94. Q = false;
  95. M = value;
  96. }
  97. get
  98. {
  99. return M;
  100. }
  101. }
  102. public bool RST
  103. {
  104. set
  105. {
  106. Q = false;
  107. M = false;
  108. }
  109. }
  110. /// <summary>
  111. /// 检测结果输出
  112. /// </summary>
  113. [XmlIgnore]
  114. public bool Q { get; private set; }
  115. /// <summary>
  116. /// 记录上一次输入信号值
  117. /// </summary>
  118. [XmlIgnore]
  119. public bool M { get; private set; }
  120. }
  121. /// <summary>
  122. /// 边沿信号检测类
  123. ///
  124. /// 设计目的:
  125. /// 用于信号上升沿/下降沿事件检测
  126. ///
  127. /// 使用场合:
  128. /// 初始值为0
  129. /// 系统输入数字信号,0->1跳变检测 Q 触发
  130. /// 1->0 R
  131. /// </summary>
  132. public class RD_TRIG
  133. {
  134. /// <summary>
  135. /// 构造函数
  136. /// </summary>
  137. public RD_TRIG()
  138. {
  139. R = false;
  140. T = false;
  141. M = false;
  142. }
  143. /// <summary>
  144. /// 检测信号输入
  145. /// </summary>
  146. public bool CLK
  147. {
  148. set
  149. {
  150. if (M != value)
  151. {
  152. R = value;
  153. T = !value;
  154. }
  155. else
  156. {
  157. R = false;
  158. T = false;
  159. }
  160. M = value;
  161. }
  162. get
  163. {
  164. return M;
  165. }
  166. }
  167. public bool RST
  168. {
  169. set
  170. {
  171. R = false;
  172. T = false;
  173. M = false;
  174. }
  175. }
  176. /// <summary>
  177. /// 检测结果输出, 上升沿触发 rising edge
  178. /// </summary>
  179. [XmlIgnore]
  180. public bool R { get; private set; }
  181. /// <summary>
  182. /// 检测结果输出, 下降沿触发 trailing edge
  183. /// </summary>
  184. [XmlIgnore]
  185. public bool T { get; private set; }
  186. /// <summary>
  187. /// 记录上一次输入信号值
  188. /// </summary>
  189. [XmlIgnore]
  190. public bool M { get; private set; }
  191. }
  192. }