Yes, in TIA Portal V20, you can pass an address (pointer) as an output from one function block (FB) and use it as an input to another function block. This is possible using pointer data types in Structured Text (ST) or by using indirect addressing techniques.
Methods to Pass an Address Between Function Blocks:
1. Using Pointers in Structured Text (ST)
You can declare a pointer variable in the FB's interface and pass it as an output. The receiving FB can then use this pointer to access the data indirectly.
Example:
FUNCTION_BLOCK FB_Source
VAR_OUTPUT
pData : POINTER TO BYTE; // Output pointer
END_VAR
FUNCTION_BLOCK FB_Destination
VAR_INPUT
pData : POINTER TO BYTE; // Input pointer
END_VAR
Usage:
- In
FB_Source, assign a pointer to a variable (e.g., pData := ADR(myData);).
- Pass
pData to FB_Destination, where it can be used to read/write data indirectly.
2. Using Indirect Addressing (DPTR, DINT, etc.)
If you're working with S7-1200/1500, you can use indirect addressing with DPTR (Data Pointer) or DINT (Double Word Integer) to pass memory addresses.
Example:
FUNCTION_BLOCK FB_Source
VAR_OUTPUT
pAddress : DINT; // Output address (e.g., DB1.DBW0)
END_VAR
FUNCTION_BLOCK FB_Destination
VAR_INPUT
pAddress : DINT; // Input address
END_VAR
Usage:
- In
FB_Source, store the address (e.g., pAddress := ADR(myData) or pAddress := 16#1000 for DB1.DBW0).
- In
FB_Destination, use pAddress with indirect addressing (e.g., DPTR := pAddress; DPTR^ := 123;).
3. Using Structs with Pointers
You can define a struct containing a pointer and pass it between FBs.
Example:
TYPE MyStruct :
STRUCT
pData : POINTER TO BYTE;
END_STRUCT
END_TYPE
FUNCTION_BLOCK FB_Source
VAR_OUTPUT
myStruct : MyStruct;
END_VAR
FUNCTION_BLOCK FB_Destination
VAR_INPUT
myStruct : MyStruct;
END_VAR
Usage:
- Assign
myStruct.pData := ADR(myData); in FB_Source.
- Use
myStruct.pData^ in FB_Destination to access the data.
Important Notes:
- Pointers are not directly supported in LAD/FBD (only in ST).
- Indirect addressing (DPTR) is CPU-dependent (works on S7-1200/1500 but not on S7-300/400).
- Ensure proper memory management to avoid invalid pointer access.
Conclusion:
Yes, you can pass an address (pointer) between function blocks in TIA Portal V20 using Structured Text (ST) with pointers or indirect addressing techniques. The best method depends on your CPU type and programming language.
Would you like a specific example for your use case?