Hello!
I recently encountered interesting case with Siemens S-7 400 hardware, STEP7 and Siemens PLC-Simulator.
I use a pair of Set and Reset instructions inside of Function subroutine (let's say FC1). They write the result to output variable of a function. When i call the function its output variable is connected to the variable inside of a some data block (DB).
For example code inside of the FC1:
A #in1
S #out1
A #in2
R #out1
That's all.
According to Siemens manual this should work fine. In my case the whole programm has following structure. I call one function (let's say FC2) from main organization block (OB1). And this function calls the FC1 described above (with Set and Reset instructions). Then i tested this programm with Siemens PLC-Simulator. And it didn't work! Set instruction didn't hold it's state like it should! I made some experiments. If I call FC1 directly from OB1 it works. If i use Set and Reset directly from OB1 (without any functions) it also works. But i need the programm structure to be exactly like i said. I thought the problem was in the FC subroutines (because they do not store temporary variables). So i created function block subroutine with S and R instructions (FB1) and the instance DB for it. And yes, it works correctly. But then i tried another thing -- I moved #out1 variable from Out section of the FC1's interface to the In/Out section. It started to work fine Strange, isn't it? But that's not all. I tried the programm with real S7-400 hardware and ALL variants work fine! FC or FB, Out or In/Out -- it doesn't matter!
So the questions are:
-- is it a bug ot the PLC-Simulator?
-- does it have to do something with internal mechanics behind S and R instructions?
-- can i use my programm as i first planned it with nested FC calls?
All opinions are welcome. Thank you in advance
I recently encountered interesting case with Siemens S-7 400 hardware, STEP7 and Siemens PLC-Simulator.
I use a pair of Set and Reset instructions inside of Function subroutine (let's say FC1). They write the result to output variable of a function. When i call the function its output variable is connected to the variable inside of a some data block (DB).
For example code inside of the FC1:
A #in1
S #out1
A #in2
R #out1
That's all.
According to Siemens manual this should work fine. In my case the whole programm has following structure. I call one function (let's say FC2) from main organization block (OB1). And this function calls the FC1 described above (with Set and Reset instructions). Then i tested this programm with Siemens PLC-Simulator. And it didn't work! Set instruction didn't hold it's state like it should! I made some experiments. If I call FC1 directly from OB1 it works. If i use Set and Reset directly from OB1 (without any functions) it also works. But i need the programm structure to be exactly like i said. I thought the problem was in the FC subroutines (because they do not store temporary variables). So i created function block subroutine with S and R instructions (FB1) and the instance DB for it. And yes, it works correctly. But then i tried another thing -- I moved #out1 variable from Out section of the FC1's interface to the In/Out section. It started to work fine Strange, isn't it? But that's not all. I tried the programm with real S7-400 hardware and ALL variants work fine! FC or FB, Out or In/Out -- it doesn't matter!
So the questions are:
-- is it a bug ot the PLC-Simulator?
-- does it have to do something with internal mechanics behind S and R instructions?
-- can i use my programm as i first planned it with nested FC calls?
All opinions are welcome. Thank you in advance
Last edited: