5/8/2024 1:53 PM | |
Joined: 1/5/2018 Last visit: 5/14/2024 Posts: 8 Rating: (0) |
Hello everyone, I am currently working with a Siemens S7-312 PLC and facing a peculiar issue related to function parameter handling. I have two functions: one to calculate the area in meters, and another to calculate the perimeter in centimeters. Both functions take two input parameters: length and width, originally given in centimeters. Here’s a breakdown of what happens: 1. In the **Area function** FC4, I divide the input parameters (length and width) by 100 to convert them from centimeters to meters. I noticed that if these parameters are sourced directly from the **M area** (e.g., `MD200` for length and `MD204` for width), the original values in `MD200` and `MD204` are altered by the function on every scan cycle, despite being input parameters which should ideally be called by value (hence should not modify the original variables). 2. However, when I switch the input parameters to source from a **Data Block (DB)** instead of the M area, the original values in the DB are not affected by the function, which is the expected behavior since the parameters should be used by value within the function. This behavior leads me to question how the PLC handles parameter passing from the M area versus the DB. Specifically, I want to understand: - Why does the function modify the original M area values even though they are passed as input parameters? - Why does this issue not occur when using values stored in a DB? Any insights into how parameter passing is managed differently between these memory areas in the S7-312 CPU would be greatly appreciated. Additionally, if anyone has suggestions on how to ensure that the M area values remain unmodified when used as function parameters, that would be very helpful. Thank you! Attachment1.pdf (1 Downloads) |
5/8/2024 2:20 PM | |
Joined: 8/21/2014 Last visit: 5/24/2024 Posts: 961 Rating: (13) |
Closed cause question posted twice. The second thread with the subject Call by reference VS Call by Value is published within the conference STEP 7 (TIA Portal) Best regards, |
My Forum is the place to personalize your profile, |
|
Follow us on