xiaohh
Hi 
 
I'm playing OpenPLC, and I tried to mix LD/ST code and functions in one project. 
But  I found that the returned value of a function call is not correct as shown below, TestVariable should be 3, but it is always 0.
I checked the generated ST code, seems to be OK. 
Can you help to point out the problem?
 
 
 
[203128%2F8703288%2Fmceclip0]
 
[203128%2F8703289%2Fmceclip0]
 
 
[203128%2F8703293%2Fmceclip0]
Reply 0 0
thiagoralves
On your function0, replace "Output0" with "function0". On a function, the value it returns is stored in itself. If you want to use the Output0 variable, then on your main code you should have used TestVariable := function0.Output0.
Reply 0 0
xiaohh
This statemnet is not correct, TestVariable := function0(1,2).Output0;
error: ';' missing at the end of statement in ST statement. In section: PROGRAM STprogram 0098: TestVariable := function0(1,2).Output0;
 
I tried the following, also failed 
function0.Input1 := 1;
function0.Input2 := 2;
TestVariable := function0.Output0;
 
I found that function0(1,2, TestVariable) works. 
Reply 0 0
thiagoralves
What I said is for you to remove the output0 variable from your function, and use just the function itself to store the return value: function0 := input1 + input2
Reply 0 0
Reply