Codesys#Add FB for IO Channel

In this Tutorial I will explain how to use the “Add FB for IO Channel” Button in Codesys.

Configuration

In this Tutorial I will use Codesys as the Ethernet/IP Scanner and AXCF 3152 PLCNEXT Controller as a Adapter.

Implementation

By using Add FB for IO Channel options, we need two Attributes in our Function Block.It is ‘io_function_block’ and  ‘io_function_block_mapping’.

io_function_block

io_function_block attribute is an attribute that informs the codesys IDE that this function block can be used in I/O Mapping.

Now you can see the Function Block in the Add FB for IO Channel window.

io_function_block_mapping

Now we can define the io_function_block_mapping inside the Function Block with io_function_block Attribute attribute.Please be careful that although you define servels variables with the io_function_block_mapping attribute, only the first variable that with 100% match the data type and as INPUT or output is assigned.

FB_PLCNEXT_INPUTPROCESS

Let’s create a Function Block First.

VAR

Define {attribute ‘io_function_block’} in the start of your Function Block – Now you can choose “FB_PLCNEXT_INPUTPROCESS” in the Add FB for IO Channel Channel.

Then define {attribute ‘io_function_block_mapping’} before the ByteIN variable.

It means that if you choose “FB_PLCNEXT_INPUTPROCESS” in the Add FB for IO Channel,ByteIN will be automatically assigned to the instance of that Function Block.

{attribute ‘io_function_block’}
FUNCTION_BLOCK FB_PLCNEXT_INPUTPROCESS
VAR_INPUT
{attribute ‘io_function_block_mapping’}
ByteIN:USINT;
END_VAR
VAR_OUTPUT
Encoded:ARRAY[0..7]OF BOOL;
END_VAR
VAR
END_VAR

PROGRAM

Inside the Function Block, we seperated the Bytes as bit and output as bool array.

Encoded[0]:=ByteIN.0;
Encoded[1]:=ByteIN.1;
Encoded[2]:=ByteIN.2;
Encoded[3]:=ByteIN.3;
Encoded[4]:=ByteIN.4;
Encoded[5]:=ByteIN.5;
Encoded[6]:=ByteIN.6;
Encoded[7]:=ByteIN.7;

Assign IO

Insert PLCNEXT AXCF-3152 inside your Ethernet/P Network> go to Ethernet/IP I/O Mapping>Choose the first Input variable>Click the “Add FB for IO Channel”.

Choose the FB_PLCNEXT_INPUTPROCESS>OK.

Codesys IDE will automatically create the instance of that function block and assinged with it.Now you can directly use AXC_F_3152_FB_PLCNEXT_INPUTPROCESS_3.YourVariable inside your program!

Let’s create a little bit more input variables.

You can also view all the Function Block instances in the Ethernet/IP IEC Object Tab, and press the Add button to create the instance directly.

MAIN

VAR

PROGRAM PLC_PRG
VAR
ByteFromPLCNEXT:ARRAY[0..255]OF BYTE;
ByteToPLCNEXT  :ARRAY[0..255]OF BYTE;
a1,a2,a3,a4,a252,a253,a254,a255 :ARRAY[0..7]OF BOOL;
END_VAR

PROGRAM

FB_PLCNEXT_INPUTPROCESS is called in the background and we do not need to call in your user program.

a1:=AXC_F_3152_FB_PLCNEXT_INPUTPROCESS_1.Encoded;
a2:=AXC_F_3152_FB_PLCNEXT_INPUTPROCESS_2.Encoded;
a3:=AXC_F_3152_FB_PLCNEXT_INPUTPROCESS_3.Encoded;
a4:=AXC_F_3152_FB_PLCNEXT_INPUTPROCESS_4.Encoded;
a252:=AXC_F_3152_FB_PLCNEXT_INPUTPROCESS_252.Encoded;
a253:=AXC_F_3152_FB_PLCNEXT_INPUTPROCESS_253.Encoded;
a254:=AXC_F_3152_FB_PLCNEXT_INPUTPROCESS_254.Encoded;
a255:=AXC_F_3152_FB_PLCNEXT_INPUTPROCESS_255.Encoded;

PLCNEXT Side

Let’s write some values on the PLCNEXT side.

Result

We can see the result here;)

Sample Code

Please download the Project from this link; 

https://github.com/soup01Threes/Codesys/blob/main/Codesys-Example-Add%20FB%20IO%20Channel.project

Footer_Basic

Please Support some devices for my blog

Amazon Gift List

Find ME

Twitter:@3threes2
Email:soup01threes*gmail.com (* to @)
YoutubeChannel:https://www.youtube.com/channel/UCQ3CHGAIXZAbeOC_9mjQiWQ

シェアする

  • このエントリーをはてなブックマークに追加

フォローする