123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- TYPE UDT 1
- VERSION : 0.1
- STRUCT
- VAR1_INT : INT := 11;
- VAR2_DINT : DINT := L#22;
- VAR3_DWORD : DWORD;
- VAR4_REAL : REAL;
- VAR5_BOOL : BOOL := TRUE;
- VAR6_BOOL : BOOL;
- VAR7_INT : INT := 42;
- VAR8_UDT2 : UDT 2;
- END_STRUCT;
- END_TYPE
- TYPE UDT 2
- VERSION : 0.1
- STRUCT
- VAR0_INT : INT := 101;
- VAR1_BOOL : BOOL;
- VAR2_BOOL : BOOL := TRUE;
- VAR3_DINT : DINT := L#102;
- END_STRUCT;
- END_TYPE
- DATA_BLOCK DB 1
- STRUCT
- DBVAR_UDT1 : UDT 1;
- DBVAR2 : INT;
- END_STRUCT;
- BEGIN
- DBVAR2 := 99;
- END_DATA_BLOCK
- FUNCTION FC 1 : VOID
- VAR_INPUT
- FCINVAR_UDT1 : UDT 1;
- FCINVAR_INT : INT;
- END_VAR
- BEGIN
- L #FCINVAR_UDT1.VAR1_INT
- __ASSERT== __ACCU 1, 11
- L #FCINVAR_UDT1.VAR2_DINT
- __ASSERT== __ACCU 1, 22
- L #FCINVAR_UDT1.VAR3_DWORD
- __ASSERT== __ACCU 1, 0
- L #FCINVAR_UDT1.VAR4_REAL
- __ASSERT== __ACCU 1, 0.0
- U #FCINVAR_UDT1.VAR5_BOOL
- __ASSERT== __STW VKE, 1
- U #FCINVAR_UDT1.VAR6_BOOL
- __ASSERT== __STW VKE, 0
- L #FCINVAR_UDT1.VAR7_INT
- __ASSERT== __ACCU 1, 42
- L #FCINVAR_UDT1.VAR8_UDT2.VAR0_INT
- __ASSERT== __ACCU 1, 101
- U #FCINVAR_UDT1.VAR8_UDT2.VAR1_BOOL
- __ASSERT== __STW VKE, 0
- U #FCINVAR_UDT1.VAR8_UDT2.VAR2_BOOL
- __ASSERT== __STW VKE, 1
- L #FCINVAR_UDT1.VAR8_UDT2.VAR3_DINT
- __ASSERT== __ACCU 1, 102
- L #FCINVAR_INT
- __ASSERT== __ACCU 1, 123
- END_FUNCTION
- FUNCTION_BLOCK FB 1
- VAR_INPUT
- FBINVAR_UDT1 : UDT 1;
- FBINVAR_INT : INT;
- END_VAR
- BEGIN
- L #FBINVAR_UDT1.VAR1_INT
- __ASSERT== __ACCU 1, 11
- L #FBINVAR_UDT1.VAR2_DINT
- __ASSERT== __ACCU 1, 22
- L #FBINVAR_UDT1.VAR3_DWORD
- __ASSERT== __ACCU 1, 0
- L #FBINVAR_UDT1.VAR4_REAL
- __ASSERT== __ACCU 1, 0.0
- U #FBINVAR_UDT1.VAR5_BOOL
- __ASSERT== __STW VKE, 1
- U #FBINVAR_UDT1.VAR6_BOOL
- __ASSERT== __STW VKE, 0
- L #FBINVAR_UDT1.VAR7_INT
- __ASSERT== __ACCU 1, 42
- L #FBINVAR_UDT1.VAR8_UDT2.VAR0_INT
- __ASSERT== __ACCU 1, 101
- U #FBINVAR_UDT1.VAR8_UDT2.VAR1_BOOL
- __ASSERT== __STW VKE, 0
- U #FBINVAR_UDT1.VAR8_UDT2.VAR2_BOOL
- __ASSERT== __STW VKE, 1
- L #FBINVAR_UDT1.VAR8_UDT2.VAR3_DINT
- __ASSERT== __ACCU 1, 102
- L #FBINVAR_INT
- __ASSERT== __ACCU 1, 123
- END_FUNCTION_BLOCK
- DATA_BLOCK DB 2
- FB 1
- BEGIN
- END_DATA_BLOCK
- ORGANIZATION_BLOCK OB 1
- BEGIN
- // Check DB 1 initial values
- AUF DB 1
- L DBW 0 // DBVAR_UDT1.VAR1_INT
- __ASSERT== __ACCU 1, 11
- L DBD 2 // DBVAR_UDT1.VAR2_DINT
- __ASSERT== __ACCU 1, 22
- L DBD 6 // DBVAR_UDT1.VAR3_DWORD
- __ASSERT== __ACCU 1, 0
- L DBD 10 // DBVAR_UDT1.VAR4_REAL
- __ASSERT== __ACCU 1, 0.0
- L DBB 14 // DBVAR_UDT1.VAR5/6_BOOL
- __ASSERT== __ACCU 1, 1
- L DBB 15 // Reserved space after VAR6_BOOL
- __ASSERT== __ACCU 1, 0
- L DBW 16 // DBVAR_UDT1.VAR7_INT
- __ASSERT== __ACCU 1, 42
- L DBW 18 // DBVAR_UDT1.VAR8_UDT2.VAR0_INT
- __ASSERT== __ACCU 1, 101
- L DBB 20 // DBVAR_UDT1.VAR8_UDT2.VAR1/2_BOOL
- __ASSERT== __ACCU 1, 2
- L DBB 21 // Reserved space after VAR2_BOOL
- __ASSERT== __ACCU 1, 0
- L DBD 22 // DBVAR_UDT1.VAR8_UDT2.VAR3_DINT
- __ASSERT== __ACCU 1, 102
- L DBW 26 // DBVAR2
- __ASSERT== __ACCU 1, 99
- // Check DB 1 initial values (symbolic access)
- L DB1.DBVAR_UDT1.VAR1_INT
- __ASSERT== __ACCU 1, 11
- L DB1.DBVAR_UDT1.VAR2_DINT
- __ASSERT== __ACCU 1, 22
- L DB1.DBVAR_UDT1.VAR3_DWORD
- __ASSERT== __ACCU 1, 0
- L DB1.DBVAR_UDT1.VAR4_REAL
- __ASSERT== __ACCU 1, 0.0
- U DB1.DBVAR_UDT1.VAR5_BOOL
- __ASSERT== __STW VKE, 1
- U DB1.DBVAR_UDT1.VAR6_BOOL
- __ASSERT== __STW VKE, 0
- L DB1.DBVAR_UDT1.VAR7_INT
- __ASSERT== __ACCU 1, 42
- L DB1.DBVAR_UDT1.VAR8_UDT2.VAR0_INT
- __ASSERT== __ACCU 1, 101
- U DB1.DBVAR_UDT1.VAR8_UDT2.VAR1_BOOL
- __ASSERT== __STW VKE, 0
- U DB1.DBVAR_UDT1.VAR8_UDT2.VAR2_BOOL
- __ASSERT== __STW VKE, 1
- L DB1.DBVAR_UDT1.VAR8_UDT2.VAR3_DINT
- __ASSERT== __ACCU 1, 102
- L DB1.DBVAR2
- __ASSERT== __ACCU 1, 99
- // Check DB 2 initial values
- AUF DB 2
- L DBW 0 // FBINVAR_UDT1.VAR1_INT
- __ASSERT== __ACCU 1, 11
- L DB2.FBINVAR_UDT1.VAR1_INT
- __ASSERT== __ACCU 1, 11
- L DBD 2 // FBINVAR_UDT1.VAR2_DINT
- __ASSERT== __ACCU 1, 22
- L DB2.FBINVAR_UDT1.VAR2_DINT
- __ASSERT== __ACCU 1, 22
- // UDT-passing to FB
- CALL FB 1, DB 2 (
- FBINVAR_UDT1 := DB1.DBVAR_UDT1,
- FBINVAR_INT := 123,
- )
- // UDT-passing to FC
- CALL FC 1 (
- FCINVAR_UDT1 := DB1.DBVAR_UDT1,
- FCINVAR_INT := 123,
- )
- CALL SFC 46 // STOP CPU
- END_ORGANIZATION_BLOCK
|