GXworks3: Calling a function in a Function Block

Hi All,
I am currently working with Mitsubishi GXworks3.
I have created a function for analog output scaling with a simple formula, which I want to instance in a created Function Block, however, in the variable list (local label) of the FB it is not possible to instance a function. I can however just type the name of the FC in the FB and it seems to work, but when I want to use the output it says its not a device or label.
1726150566002.png
This is however an existing output
Any idea how to do so?
 
to return a value from an FC the output you use the name of the function to return for example
if you create a function called My_Function
Then in the function let's say declare the variable inputs
Test1 input as float
Test2 input as float
then
the code should be
My_Function := Test1 + Test2; (* Just me testing adding two floats *)
When you call the function in a program block
This_Var := My_Function(Var1, Var2); (* note: you do not need to create an instance unlike FB's *)


1726158672446.png
1726158735413.png
 

Attachments

  • 1726158606854.png
    1726158606854.png
    797 bytes · Views: 0
Hi Parky,

Thank you for your answer.
I do get it , however, this way I cannot use the VAR_OUTPUTS that i declare in the functions that I made, I have made two: o_output and o_Error.
 
You don't have variable outputs in a function those are for function blocks, the idea of a function is to return one value (could be an array but never tried it)
So a function i.e. My_Function requires inputs can have local vars but the result is the function name.
for example as I posted, the inputs are for the calculation,
Lets call the function My_Function
so inside the Function you do the maths or what ever then you return the result i.e. My_Function := xxx (xxx being the result of the calculation or what ever)
Just remember to register the function by right click on the function in the tree on the left hand side & press register it then places it in the right hand side of the function selection menu
If to wish to have more than one output var then use a function block, the function & function block can have or not have an EN & ENO.
Also in function blocks the output variables can be configured as IN/OUT this allows what ever is output can be modified outside the block for example
If you pass a var as an in/out then when the block is called lets say you incremented the var inside the block, as it is passed back to the main program it may be modified i.e. add a value so on the next call the value is passed back into the function block & incremented.
1726223717903.png
 
you can use output vars but those would be inside the brackets
for example
Fun My_Function (Var1,Var2,Var3) Var1 & 2 are input Var3 is an output the variable my_Function return could be the error
so when it is called
Err:= My_Function(Low_In, High_In, Val_Out);
this then returns two values i.e. Err is the function return in this case the error & val_Out which is the analogue value.
Hope this makes sense
 

Similar Topics

IS THERE ANY CLEAR INSTRUCTION IN GXWORKS 3?? SOMEWHAT SIMILAR TO BELOW ONE??
1
Replies
871
Views
IS IT NOT POSSIBLE TO MAKE ARRAY OPF TON OR OTHER PREDEFINED FUNCTION BLOCKS??? I HAVEN'T TRIED WITH OTHER FB BUT WHEN I TRIED CREATING A TON...
4
Replies
1,241
Views
I WANT TO DEMONSTARTE THIS OMRON LOGIC IN MITSUBISHI GXWORKS3 (LADDER) THE PROBLEM I AM FACING IS I CANNOT DO EXACT SAME IN GXWORKS3 I...
6
Replies
1,120
Views
If I have a DINT which has a walking 1 in it (vWalk) how can I access the individual Bits use in ladder this is for driving a state machine...
3
Replies
1,077
Views
I was facing the problem that whenever i was resetting the counters while their i/p were ON, the reset value was set at 1 instead of 0. So, to...
1
Replies
1,010
Views
Top