Trigger.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Reflection;
  5. using System.Runtime.InteropServices;
  6. using System.Xml.Serialization;
  7. namespace Aitex.Core.Util
  8. {
  9. /// <summary>
  10. /// 下降沿信号检测类
  11. ///
  12. /// 设计目的:
  13. /// 用于信号下降沿事件检测
  14. ///
  15. /// 使用场合:
  16. /// 系统输入数字信号,1->0跳变检测
  17. /// </summary>
  18. public class F_TRIG
  19. {
  20. /// <summary>
  21. /// 构造函数
  22. /// </summary>
  23. public F_TRIG()
  24. {
  25. Q = false;
  26. M = true;
  27. }
  28. /// <summary>
  29. /// 检测信号输入
  30. /// </summary>
  31. public bool CLK
  32. {
  33. set
  34. {
  35. if (M != value && !value)
  36. Q = true;
  37. else
  38. Q = false;
  39. M = value;
  40. }
  41. get
  42. {
  43. return M;
  44. }
  45. }
  46. //clear
  47. public bool RST
  48. {
  49. set
  50. {
  51. Q = false;
  52. M = true;
  53. }
  54. }
  55. /// <summary>
  56. /// 检测结果输出
  57. /// </summary>
  58. [XmlIgnore]
  59. public bool Q { get; private set; }
  60. /// <summary>
  61. /// 记录上一次输入信号值
  62. /// </summary>
  63. [XmlIgnore]
  64. public bool M { get; private set; }
  65. }
  66. /// <summary>
  67. /// 实现滤波功能
  68. /// </summary>
  69. public class FR_TRIG
  70. {
  71. private bool lastValue;
  72. private bool currentValue;
  73. private bool output;
  74. /// <summary>
  75. /// 构造函数
  76. /// </summary>
  77. public FR_TRIG()
  78. {
  79. lastValue = false;
  80. currentValue = false;
  81. output = false;
  82. }
  83. /// <summary>
  84. /// 检测信号输入
  85. /// </summary>
  86. public bool CLK
  87. {
  88. set
  89. {
  90. currentValue = value;
  91. if (currentValue != lastValue)
  92. {
  93. output = true; // 信号变化时立即输出 true
  94. }
  95. else
  96. {
  97. output = false; // 信号不变时输出 false
  98. }
  99. lastValue = currentValue;
  100. }
  101. get
  102. {
  103. return currentValue;
  104. }
  105. }
  106. public bool RST
  107. {
  108. set
  109. {
  110. currentValue = false;
  111. lastValue = false;
  112. output = false;
  113. }
  114. }
  115. /// <summary>
  116. /// 检测结果输出
  117. /// </summary>
  118. [System.Xml.Serialization.XmlIgnore]
  119. public bool Q { get => output; private set => output = value; }
  120. /// <summary>
  121. /// 记录上一次输入信号值
  122. /// </summary>
  123. [System.Xml.Serialization.XmlIgnore]
  124. public bool M { get => currentValue; private set => currentValue = value; }
  125. }
  126. /// <summary>
  127. /// 上升沿信号检测类
  128. ///
  129. /// 设计目的:
  130. /// 用于信号上升沿事件检测
  131. ///
  132. /// 使用场合:
  133. /// 系统输入数字信号,0->1跳变检测
  134. /// </summary>
  135. public class R_TRIG
  136. {
  137. /// <summary>
  138. /// 构造函数
  139. /// </summary>
  140. public R_TRIG()
  141. {
  142. Q = false;
  143. M = false;
  144. }
  145. /// <summary>
  146. /// 检测信号输入
  147. /// </summary>
  148. public bool CLK
  149. {
  150. set
  151. {
  152. if (M != value && value)
  153. Q = true;
  154. else
  155. Q = false;
  156. M = value;
  157. }
  158. get
  159. {
  160. return M;
  161. }
  162. }
  163. public bool RST
  164. {
  165. set
  166. {
  167. Q = false;
  168. M = false;
  169. }
  170. }
  171. /// <summary>
  172. /// 检测结果输出
  173. /// </summary>
  174. [XmlIgnore]
  175. public bool Q { get; private set; }
  176. /// <summary>
  177. /// 记录上一次输入信号值
  178. /// </summary>
  179. [XmlIgnore]
  180. public bool M { get; private set; }
  181. }
  182. /// <summary>
  183. /// 边沿信号检测类
  184. ///
  185. /// 设计目的:
  186. /// 用于信号上升沿/下降沿事件检测
  187. ///
  188. /// 使用场合:
  189. /// 初始值为0
  190. /// 系统输入数字信号,0->1跳变检测 Q 触发
  191. /// 1->0 R
  192. /// </summary>
  193. public class RD_TRIG
  194. {
  195. /// <summary>
  196. /// 构造函数
  197. /// </summary>
  198. public RD_TRIG()
  199. {
  200. R = false;
  201. T = false;
  202. M = false;
  203. }
  204. /// <summary>
  205. /// 检测信号输入
  206. /// </summary>
  207. public bool CLK
  208. {
  209. set
  210. {
  211. if (M != value)
  212. {
  213. R = value;
  214. T = !value;
  215. }
  216. else
  217. {
  218. R = false;
  219. T = false;
  220. }
  221. M = value;
  222. }
  223. get
  224. {
  225. return M;
  226. }
  227. }
  228. public bool RST
  229. {
  230. set
  231. {
  232. R = false;
  233. T = false;
  234. M = false;
  235. }
  236. }
  237. /// <summary>
  238. /// 检测结果输出, 上升沿触发 rising edge
  239. /// </summary>
  240. [XmlIgnore]
  241. public bool R { get; private set; }
  242. /// <summary>
  243. /// 检测结果输出, 下降沿触发 trailing edge
  244. /// </summary>
  245. [XmlIgnore]
  246. public bool T { get; private set; }
  247. /// <summary>
  248. /// 记录上一次输入信号值
  249. /// </summary>
  250. [XmlIgnore]
  251. public bool M { get; private set; }
  252. }
  253. }