standard.fun 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. {REDUND_OK} FUNCTION_BLOCK RF_TRIG (*recognizes both edges of BOOL values*)
  2. VAR_INPUT
  3. CLK :BOOL; (*input signal of the edge to be recognized*)
  4. END_VAR
  5. VAR_OUTPUT
  6. Q :BOOL; (*TRUE if the input signal was FALSE on the last call and is now TRUE*)
  7. END_VAR
  8. VAR
  9. M :BOOL; (*internal variable*)
  10. END_VAR
  11. END_FUNCTION_BLOCK
  12. {REDUND_OK} FUNCTION_BLOCK CTUD (*counts upward or downward*)
  13. VAR_INPUT
  14. CU :BOOL; (*counter CV is increased by 1 by CU when the edge is rising*)
  15. CD :BOOL; (*counter CV is reduced by 1 by CD when the edge is rising*)
  16. RESET :BOOL; (*counter CV is set to 0 if RESET is TRUE*)
  17. LOAD :BOOL; (*if LOAD is TRUE, then counter CV is initialized with the starting value PV*)
  18. PV :INT; (*start value*)
  19. END_VAR
  20. VAR_OUTPUT
  21. QU :BOOL; (*is TRUE if CV is greater than or equal to PV*)
  22. QD :BOOL; (*is TRUE if CV equals 0*)
  23. CV :INT; (*counter*)
  24. END_VAR
  25. VAR
  26. MU :BOOL; (*internal variable*)
  27. MD :BOOL; (*internal variable*)
  28. END_VAR
  29. END_FUNCTION_BLOCK
  30. {REDUND_OK} FUNCTION_BLOCK CTD (*counts downward*)
  31. VAR_INPUT
  32. CD :BOOL; (*counter CV is reduced by 1 by CD when the edge is rising*)
  33. LOAD :BOOL; (*if LOAD is TRUE, then counter CV is initialized with the starting value PV*)
  34. PV :UINT; (*start value*)
  35. END_VAR
  36. VAR_OUTPUT
  37. Q :BOOL; (*is TRUE if CV equals 0*)
  38. CV :UINT; (*counter*)
  39. END_VAR
  40. VAR
  41. M :BOOL; (*internal variable*)
  42. END_VAR
  43. END_FUNCTION_BLOCK
  44. {REDUND_OK} FUNCTION_BLOCK CTU (*counts upward*)
  45. VAR_INPUT
  46. CU :BOOL; (*counter CV is increased by 1 by CU when the edge is rising*)
  47. RESET :BOOL; (*counter CV is set to 0 if RESET is TRUE*)
  48. PV :UINT; (*comparison variable*)
  49. END_VAR
  50. VAR_OUTPUT
  51. Q :BOOL; (*is TRUE if counter CV is greater than or equal to the PV comparison variable*)
  52. CV :UINT; (*counter*)
  53. END_VAR
  54. VAR
  55. M :BOOL; (*internal variable*)
  56. END_VAR
  57. END_FUNCTION_BLOCK
  58. {REDUND_OK} FUNCTION_BLOCK F_TRIG (*recognizes falling edges from BOOL values*)
  59. VAR_INPUT
  60. CLK :BOOL; (*input signal whose edge should be detected*)
  61. END_VAR
  62. VAR_OUTPUT
  63. Q :BOOL; (*is set to TRUE if the input signal was TRUE during the last call and is now FALSE*)
  64. END_VAR
  65. VAR
  66. M :BOOL; (*internal variable*)
  67. END_VAR
  68. END_FUNCTION_BLOCK
  69. {REDUND_OK} FUNCTION_BLOCK R_TRIG (*recognizes rising edges from BOOL values*)
  70. VAR_INPUT
  71. CLK :BOOL; (*input signal whose edge should be detected*)
  72. END_VAR
  73. VAR_OUTPUT
  74. Q :BOOL; (*is set to TRUE if the input signal was FALSE during the last call and is now TRUE*)
  75. END_VAR
  76. VAR
  77. M :BOOL; (*internal variable*)
  78. END_VAR
  79. END_FUNCTION_BLOCK
  80. {REDUND_OK} FUNCTION_BLOCK SR (*sets or resets the output (set has priority)*)
  81. VAR_INPUT
  82. SET1 :BOOL; (*sets output Q1 (priority)*)
  83. RESET :BOOL; (*resets output Q1*)
  84. END_VAR
  85. VAR_OUTPUT
  86. Q1 :BOOL; (*output value *)
  87. END_VAR
  88. END_FUNCTION_BLOCK
  89. {REDUND_OK} FUNCTION_BLOCK RS (*sets or resets the output (reset has priority)*)
  90. VAR_INPUT
  91. SET :BOOL; (*sets output Q1*)
  92. RESET1 :BOOL; (*resets output Q1 (priority)*)
  93. END_VAR
  94. VAR_OUTPUT
  95. Q1 :BOOL; (*output value*)
  96. END_VAR
  97. END_FUNCTION_BLOCK
  98. {REDUND_OK} FUNCTION_BLOCK SEMA (*blocks access within the same task class (simple semaphore)*)
  99. VAR_INPUT
  100. CLAIM :BOOL; (*locks semaphore*)
  101. RELEASE :BOOL; (*releases semaphore*)
  102. END_VAR
  103. VAR_OUTPUT
  104. BUSY :BOOL; (*TRUE if the semaphore was already locked*)
  105. END_VAR
  106. VAR
  107. X :BOOL; (*internal variable*)
  108. END_VAR
  109. END_FUNCTION_BLOCK
  110. {REDUND_OK} FUNCTION_BLOCK TON (*implements a switch on delay*)
  111. VAR_INPUT
  112. IN :BOOL; (*input signal*)
  113. PT :TIME; (*delay time*)
  114. END_VAR
  115. VAR_OUTPUT
  116. Q :BOOL; (*rising edge of the input signal is delayed by PT*)
  117. ET :TIME; (*elapsed time*)
  118. END_VAR
  119. VAR
  120. StartTime :TIME; (*internal variable*)
  121. M :BOOL; (*internal variable*)
  122. Restart : {REDUND_UNREPLICABLE} UDINT; (*internal variable*)
  123. END_VAR
  124. END_FUNCTION_BLOCK
  125. {REDUND_OK} FUNCTION_BLOCK TOF (*implements a switch off delay*)
  126. VAR_INPUT
  127. IN :BOOL; (*input signal*)
  128. PT :TIME; (*delay time*)
  129. END_VAR
  130. VAR_OUTPUT
  131. Q :BOOL; (*falling edge of the input signal is delayed by PT*)
  132. ET :TIME; (*elapsed time*)
  133. END_VAR
  134. VAR
  135. M :BOOL; (*internal variable*)
  136. StartTime :TIME; (*internal variable*)
  137. Restart : {REDUND_UNREPLICABLE} UDINT; (*internal variable*)
  138. END_VAR
  139. END_FUNCTION_BLOCK
  140. {REDUND_OK} FUNCTION_BLOCK TP (*implements a pulse generator*)
  141. VAR_INPUT
  142. IN :BOOL; (*input signal*)
  143. PT :TIME; (*pulse time*)
  144. END_VAR
  145. VAR_OUTPUT
  146. Q :BOOL; (*output signal*)
  147. ET :TIME; (*elapsed time*)
  148. END_VAR
  149. VAR
  150. StartTime :TIME; (*internal variable*)
  151. Restart : {REDUND_UNREPLICABLE} UDINT; (*internal variable*)
  152. END_VAR
  153. END_FUNCTION_BLOCK
  154. {REDUND_OK} FUNCTION_BLOCK TON_10ms (*implements a switch on delay based on 10 ms steps*)
  155. VAR_INPUT
  156. IN :BOOL; (*input signal*)
  157. PT :UDINT; (*delay time in 10 ms steps*)
  158. END_VAR
  159. VAR_OUTPUT
  160. Q :BOOL; (*output signal, the rising edge of the input signal is delayed by PT*)
  161. ET :UDINT; (*elapsed time in 10 ms increments*)
  162. END_VAR
  163. VAR
  164. StartTime :UDINT; (*internal variable*)
  165. M :BOOL; (*internal variable*)
  166. END_VAR
  167. END_FUNCTION_BLOCK
  168. {REDUND_OK} FUNCTION_BLOCK TOF_10ms (*implements a switch off delay based on 10 ms steps*)
  169. VAR_INPUT
  170. IN :BOOL; (*input signal*)
  171. PT :UDINT; (*delay time in 10 ms steps*)
  172. END_VAR
  173. VAR_OUTPUT
  174. Q :BOOL; (*output signal, the falling edge of the input signal is delayed by PT*)
  175. ET :UDINT; (*elapsed time in 10 ms increments*)
  176. END_VAR
  177. VAR
  178. M :BOOL; (*internal variable*)
  179. StartTime :UDINT; (*internal variable*)
  180. END_VAR
  181. END_FUNCTION_BLOCK
  182. {REDUND_OK} FUNCTION_BLOCK TP_10ms (*implements a pulse using 10 ms steps*)
  183. VAR_INPUT
  184. IN :BOOL; (*input signal*)
  185. PT :UDINT; (*pulse time in 10 ms steps*)
  186. END_VAR
  187. VAR_OUTPUT
  188. Q :BOOL; (*output signal*)
  189. ET :UDINT; (*elapsed time in 10 ms increments*)
  190. END_VAR
  191. VAR
  192. StartTime :UDINT; (*internal variable*)
  193. END_VAR
  194. END_FUNCTION_BLOCK
  195. {REDUND_OK} {REDUND_UNREPLICABLE} FUNCTION LEN : INT (*calculates the length of a string*)
  196. VAR_INPUT
  197. IN :STRING[32767]; (*input string*)
  198. END_VAR
  199. END_FUNCTION
  200. {REDUND_OK} {REDUND_UNREPLICABLE} FUNCTION LEFT : STRING[255] (*extracts a certain amount (L) of leftmost characters from a string*)
  201. VAR_INPUT
  202. IN :STRING[32767]; (*input string*)
  203. L :INT; (*number of characters*)
  204. END_VAR
  205. END_FUNCTION
  206. {REDUND_OK} {REDUND_UNREPLICABLE} FUNCTION RIGHT : STRING[255] (*extracts a certain amount (L) of rightmost characters from a string*)
  207. VAR_INPUT
  208. IN :STRING[32767]; (*input string*)
  209. L :INT; (*number of characters*)
  210. END_VAR
  211. END_FUNCTION
  212. {REDUND_OK} {REDUND_UNREPLICABLE} FUNCTION MID : STRING[255] (*extracts L number of characters out of string beginning with position P*)
  213. VAR_INPUT
  214. IN :STRING[32767]; (*string which should be extracted from*)
  215. L :INT; (*number of characters*)
  216. P :INT; (*position of the first character which should be extracted*)
  217. END_VAR
  218. END_FUNCTION
  219. {REDUND_OK} {REDUND_UNREPLICABLE} FUNCTION CONCAT : STRING[255] (*attaches strings to one another*)
  220. VAR_INPUT
  221. IN1 :STRING[32767]; (*first input string*)
  222. IN2 :STRING[32767]; (*second input string*)
  223. END_VAR
  224. END_FUNCTION
  225. {REDUND_OK} {REDUND_UNREPLICABLE} FUNCTION INSERT : STRING[255] (*inserts a string into a string*)
  226. VAR_INPUT
  227. IN1 :STRING[32767]; (*string which should be inserted into*)
  228. IN2 :STRING[32767]; (*string which should be inserted*)
  229. P :INT; (*position where insertion should take place*)
  230. END_VAR
  231. END_FUNCTION
  232. {REDUND_OK} {REDUND_UNREPLICABLE} FUNCTION DELETE : STRING[255] (*deletes L number of characters from the IN string beginning with the Pth character position*)
  233. VAR_INPUT
  234. IN :STRING[32767]; (*input string*)
  235. L :INT; (*number of characters to be deleted*)
  236. P :INT; (*starting position of characters to be deleted*)
  237. END_VAR
  238. END_FUNCTION
  239. {REDUND_OK} {REDUND_UNREPLICABLE} FUNCTION REPLACE : STRING[255] (*replaces characters in a string*)
  240. VAR_INPUT
  241. IN1 :STRING[32767]; (*string which should have characters replaced*)
  242. IN2 :STRING[32767]; (*string used for the replacement*)
  243. L :INT; (*length of the area to be replaced*)
  244. P :INT; (*starting position of replacement*)
  245. END_VAR
  246. END_FUNCTION
  247. {REDUND_OK} {REDUND_UNREPLICABLE} FUNCTION FIND : INT (*determines the position of a string inside a string*)
  248. VAR_INPUT
  249. IN1 :STRING[32767]; (*string which should be looked through*)
  250. IN2 :STRING[32767]; (*string which should be looked for*)
  251. END_VAR
  252. END_FUNCTION