1

Running Ecostruxure machine expert which is CodeSys 3.5

I've got the following program structure:

Main: two blocks, Init and Step0 linked by a transition.

In the vars of that main:

VAR
   My_Encoder : ENC_REF_M262;
   ...
END_VAR

So then in my Init block I have My_Encoder.FB_Init(...)

But the error message I get points to the variable declaration in Main which says "C0138 No Matching FB_Init method found fo this instantiation of ENC_REF_M262".

David Boshton
  • 2,555
  • 5
  • 30
  • 51

2 Answers2

2

Try using the no_init attribute above your instantiated FB.

VAR
   { attribute 'no_init'}
   My_Encoder : ENC_REF_M262;
   ...
END_VAR

Whenever a function block is instantiated, a matching implementation of the FB_Init method is expected to occur (even inside a wrapping fb).

N.B. You will need to explicitly run the init code (My_Encoder.fb_Init()) somewhere if it has critical functionality

Steve
  • 963
  • 5
  • 16
Guiorgy
  • 1,405
  • 9
  • 26
1

Using the 'no_init' attribute will fix the compile error; however, (IMHO) this may not be the best solution. First, because you'll probably want to initialize the values and secondly because calling FB_Init explicitly, is strongly discouraged. Therefore I would like to explain why the error message occurs as well as giving some insight in how to solve the error.

The error is (AFAIK) due to either one of the two reason listed below.

  1. When you declare and initialize a POU (e.g. an FB between the VAR and END_VAR keywords) and you directly initialize a value to one of it's inputs while this input is not included as VAR_INPUT of the FB_Init of the POU.

I'll clarify this with some code:

 VAR
    myFunctionBlock: FB_FunctionBlock(myInput:= 1);
 END_VAR

.. Above we're initializing input "myInput" of object/instance "myFunctionBlock" with the value 1 and this requires that "myInput" is included in the FB_Init of POU "FB_FunctionBlock":

METHOD FB_init : BOOL 
VAR_INPUT     
   bInitRetains : BOOL; 
   bInCopyCode : BOOL;  
   myInput : INT; // Include the input or else you'll get the error
END_VAR
  1. In the VAR_INPUT-block of an FB_Init you can include inputs of the POU to which the FB_Init belongs. When you do this your are required to initialize these inputs when you declare and initialize the POU. (this is probably the case in your example)

Again I'll clarify this with some code:

METHOD FB_init : BOOL 
VAR_INPUT     
   bInitRetains : BOOL; 
   bInCopyCode : BOOL;  
   myInput : INT;
END_VAR

.. Above input "myInput" is included in the FB_Init of POU "FB_FunctionBlock" and therefore when we create an object/instance of POU "FB_FunctionBlock" then we're required to initialize the input "myInput".

 VAR
    myFunctionBlock: FB_FunctionBlock(myInput:= 1); 
    // Include "myInput:= 1" or else you'll get the error
 END_VAR
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
rick
  • 43
  • 4