Kkula
Pegaia
Hi,
I'm not sure if I understannd your task, but suppose you are using S7-1200: Just a suggestion: make a SCL FBto do it; use peek and poke instruction. In this case the variant data type should be splited in your components (db number, start byte, etc.)
Hi Pegaia, I think I have a similar conceptual problem using S7-1200, SCL and pointers.
Imagine I defined an UDT to access Analog Inputs:
AI_UDT:
AI_man bool (offset 00.0)
AI_per word (offset 02)
AI_scaled real real (offset 04)
AI_man_val real (offset 08)
Imagine I defined a DB with multiple AI_UDT
DB_AI:
AI_00 AI_UDT
AI_01 AI_UDT
AI_02 AI_UDT
Imaginethat DB_AI is 300/400 style,so that I can use direct addressing.
Imagine that I want to handle each AI with a SCL functioncalled _AI_single_read that will recive as a variantthe DB element pointer:
_AI_single_read("DB_AI".AI.00);
_AI_single_read("DB_AI".AI.01);
I did it, and everything works
But now I've to write the SCL code for _AI_single_read andd I really don't know how to use offset inside the function.
I defined the input parameter as "v_pointer" (variant).
Now I should access
v_pointer+00.0 as bool
v_pointer+02 as word
v_pointer+04 as real
v_pointer+08 as real
Any hint on how to do it?
thanks a lot
Hi Pegaia, As a Siemens Self Support assistant integrated with SiePortal, here's how to handle offsets within your SCL function `_AI_single_read`: 1. **Use `PEEK` and `POKE` instructions:** These are crucial for accessing data at specific offsets from a pointer. 2. **Type Conversion:** Since `v_pointer` is a variant, you'll need to convert the `PEEK` results to the correct data types (BOOL, WORD, REAL) using appropriate SCL conversion functions (`BOOL_TO_REAL`, etc.). 3. **Address Calculation:** Directly add the offsets to `v_pointer` within the `PEEK` instruction. **Example Snippet (SCL):** ```scl // Access AI_man (bool at offset 00.0) AI_man_temp : BOOL; AI_man_temp := PEEK(v_pointer + 0.0); // No conversion needed // Access AI_per (word at offset 02) AI_per_temp : WORD; AI_per_temp := WORD_TO_INT(PEEK(v_pointer + 2.0)); // Access AI_scaled (real at offset 04) AI_scaled_temp : REAL; AI_scaled_temp := REAL_TO_REAL(PEEK(v_pointer + 4.0)); // Access AI_man_val (real at offset 08) AI_man_val_temp : REAL; AI_man_val_temp := REAL_TO_REAL(PEEK(v_pointer + 8.0)); ``` **Important Considerations:** * Ensure correct data alignment (offsets in bytes). * Error handling: Validate `v_pointer` to prevent invalid memory access. * Refer to Siemens documentation for `PEEK` and `POKE` for detailed usage. You can find more details and examples on SiePortal using keywords like "SCL pointers", "PEEK POKE", and "variant data types".
Our flexible community website is a platform that allows users to connect, share information, and collaborate on various topics of interest. The website offers a range of features such as discussion forums, messaging, user profiles, event calendars, and more. Users can customize their experience by creating and joining different groups or communities based on their interests or location. The website is designed to be user-friendly and adaptable to the needs and preferences of our diverse user base. Whether you are looking to network professionally, share hobbies and interests, or simply connect with like-minded individuals, our flexible community website has something for everyone. Join us today and become a part of our thriving online community!
India
Copyright ©2025
Share this page with your family and friends.