udt.awl 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. TYPE UDT 1
  2. VERSION : 0.1
  3. STRUCT
  4. VAR1_INT : INT := 11;
  5. VAR2_DINT : DINT := L#22;
  6. VAR3_DWORD : DWORD;
  7. VAR4_REAL : REAL;
  8. VAR5_BOOL : BOOL := TRUE;
  9. VAR6_BOOL : BOOL;
  10. VAR7_INT : INT := 42;
  11. VAR8_UDT2 : UDT 2;
  12. END_STRUCT;
  13. END_TYPE
  14. TYPE UDT 2
  15. VERSION : 0.1
  16. STRUCT
  17. VAR0_INT : INT := 101;
  18. VAR1_BOOL : BOOL;
  19. VAR2_BOOL : BOOL := TRUE;
  20. VAR3_DINT : DINT := L#102;
  21. END_STRUCT;
  22. END_TYPE
  23. DATA_BLOCK DB 1
  24. STRUCT
  25. DBVAR_UDT1 : UDT 1;
  26. DBVAR2 : INT;
  27. END_STRUCT;
  28. BEGIN
  29. DBVAR2 := 99;
  30. END_DATA_BLOCK
  31. FUNCTION FC 1 : VOID
  32. VAR_INPUT
  33. FCINVAR_UDT1 : UDT 1;
  34. FCINVAR_INT : INT;
  35. END_VAR
  36. BEGIN
  37. L #FCINVAR_UDT1.VAR1_INT
  38. __ASSERT== __ACCU 1, 11
  39. L #FCINVAR_UDT1.VAR2_DINT
  40. __ASSERT== __ACCU 1, 22
  41. L #FCINVAR_UDT1.VAR3_DWORD
  42. __ASSERT== __ACCU 1, 0
  43. L #FCINVAR_UDT1.VAR4_REAL
  44. __ASSERT== __ACCU 1, 0.0
  45. U #FCINVAR_UDT1.VAR5_BOOL
  46. __ASSERT== __STW VKE, 1
  47. U #FCINVAR_UDT1.VAR6_BOOL
  48. __ASSERT== __STW VKE, 0
  49. L #FCINVAR_UDT1.VAR7_INT
  50. __ASSERT== __ACCU 1, 42
  51. L #FCINVAR_UDT1.VAR8_UDT2.VAR0_INT
  52. __ASSERT== __ACCU 1, 101
  53. U #FCINVAR_UDT1.VAR8_UDT2.VAR1_BOOL
  54. __ASSERT== __STW VKE, 0
  55. U #FCINVAR_UDT1.VAR8_UDT2.VAR2_BOOL
  56. __ASSERT== __STW VKE, 1
  57. L #FCINVAR_UDT1.VAR8_UDT2.VAR3_DINT
  58. __ASSERT== __ACCU 1, 102
  59. L #FCINVAR_INT
  60. __ASSERT== __ACCU 1, 123
  61. END_FUNCTION
  62. FUNCTION_BLOCK FB 1
  63. VAR_INPUT
  64. FBINVAR_UDT1 : UDT 1;
  65. FBINVAR_INT : INT;
  66. END_VAR
  67. BEGIN
  68. L #FBINVAR_UDT1.VAR1_INT
  69. __ASSERT== __ACCU 1, 11
  70. L #FBINVAR_UDT1.VAR2_DINT
  71. __ASSERT== __ACCU 1, 22
  72. L #FBINVAR_UDT1.VAR3_DWORD
  73. __ASSERT== __ACCU 1, 0
  74. L #FBINVAR_UDT1.VAR4_REAL
  75. __ASSERT== __ACCU 1, 0.0
  76. U #FBINVAR_UDT1.VAR5_BOOL
  77. __ASSERT== __STW VKE, 1
  78. U #FBINVAR_UDT1.VAR6_BOOL
  79. __ASSERT== __STW VKE, 0
  80. L #FBINVAR_UDT1.VAR7_INT
  81. __ASSERT== __ACCU 1, 42
  82. L #FBINVAR_UDT1.VAR8_UDT2.VAR0_INT
  83. __ASSERT== __ACCU 1, 101
  84. U #FBINVAR_UDT1.VAR8_UDT2.VAR1_BOOL
  85. __ASSERT== __STW VKE, 0
  86. U #FBINVAR_UDT1.VAR8_UDT2.VAR2_BOOL
  87. __ASSERT== __STW VKE, 1
  88. L #FBINVAR_UDT1.VAR8_UDT2.VAR3_DINT
  89. __ASSERT== __ACCU 1, 102
  90. L #FBINVAR_INT
  91. __ASSERT== __ACCU 1, 123
  92. END_FUNCTION_BLOCK
  93. DATA_BLOCK DB 2
  94. FB 1
  95. BEGIN
  96. END_DATA_BLOCK
  97. ORGANIZATION_BLOCK OB 1
  98. BEGIN
  99. // Check DB 1 initial values
  100. AUF DB 1
  101. L DBW 0 // DBVAR_UDT1.VAR1_INT
  102. __ASSERT== __ACCU 1, 11
  103. L DBD 2 // DBVAR_UDT1.VAR2_DINT
  104. __ASSERT== __ACCU 1, 22
  105. L DBD 6 // DBVAR_UDT1.VAR3_DWORD
  106. __ASSERT== __ACCU 1, 0
  107. L DBD 10 // DBVAR_UDT1.VAR4_REAL
  108. __ASSERT== __ACCU 1, 0.0
  109. L DBB 14 // DBVAR_UDT1.VAR5/6_BOOL
  110. __ASSERT== __ACCU 1, 1
  111. L DBB 15 // Reserved space after VAR6_BOOL
  112. __ASSERT== __ACCU 1, 0
  113. L DBW 16 // DBVAR_UDT1.VAR7_INT
  114. __ASSERT== __ACCU 1, 42
  115. L DBW 18 // DBVAR_UDT1.VAR8_UDT2.VAR0_INT
  116. __ASSERT== __ACCU 1, 101
  117. L DBB 20 // DBVAR_UDT1.VAR8_UDT2.VAR1/2_BOOL
  118. __ASSERT== __ACCU 1, 2
  119. L DBB 21 // Reserved space after VAR2_BOOL
  120. __ASSERT== __ACCU 1, 0
  121. L DBD 22 // DBVAR_UDT1.VAR8_UDT2.VAR3_DINT
  122. __ASSERT== __ACCU 1, 102
  123. L DBW 26 // DBVAR2
  124. __ASSERT== __ACCU 1, 99
  125. // Check DB 1 initial values (symbolic access)
  126. L DB1.DBVAR_UDT1.VAR1_INT
  127. __ASSERT== __ACCU 1, 11
  128. L DB1.DBVAR_UDT1.VAR2_DINT
  129. __ASSERT== __ACCU 1, 22
  130. L DB1.DBVAR_UDT1.VAR3_DWORD
  131. __ASSERT== __ACCU 1, 0
  132. L DB1.DBVAR_UDT1.VAR4_REAL
  133. __ASSERT== __ACCU 1, 0.0
  134. U DB1.DBVAR_UDT1.VAR5_BOOL
  135. __ASSERT== __STW VKE, 1
  136. U DB1.DBVAR_UDT1.VAR6_BOOL
  137. __ASSERT== __STW VKE, 0
  138. L DB1.DBVAR_UDT1.VAR7_INT
  139. __ASSERT== __ACCU 1, 42
  140. L DB1.DBVAR_UDT1.VAR8_UDT2.VAR0_INT
  141. __ASSERT== __ACCU 1, 101
  142. U DB1.DBVAR_UDT1.VAR8_UDT2.VAR1_BOOL
  143. __ASSERT== __STW VKE, 0
  144. U DB1.DBVAR_UDT1.VAR8_UDT2.VAR2_BOOL
  145. __ASSERT== __STW VKE, 1
  146. L DB1.DBVAR_UDT1.VAR8_UDT2.VAR3_DINT
  147. __ASSERT== __ACCU 1, 102
  148. L DB1.DBVAR2
  149. __ASSERT== __ACCU 1, 99
  150. // Check DB 2 initial values
  151. AUF DB 2
  152. L DBW 0 // FBINVAR_UDT1.VAR1_INT
  153. __ASSERT== __ACCU 1, 11
  154. L DB2.FBINVAR_UDT1.VAR1_INT
  155. __ASSERT== __ACCU 1, 11
  156. L DBD 2 // FBINVAR_UDT1.VAR2_DINT
  157. __ASSERT== __ACCU 1, 22
  158. L DB2.FBINVAR_UDT1.VAR2_DINT
  159. __ASSERT== __ACCU 1, 22
  160. // UDT-passing to FB
  161. CALL FB 1, DB 2 (
  162. FBINVAR_UDT1 := DB1.DBVAR_UDT1,
  163. FBINVAR_INT := 123,
  164. )
  165. // UDT-passing to FC
  166. CALL FC 1 (
  167. FCINVAR_UDT1 := DB1.DBVAR_UDT1,
  168. FCINVAR_INT := 123,
  169. )
  170. CALL SFC 46 // STOP CPU
  171. END_ORGANIZATION_BLOCK