Beckhoff#TwinCAT3 Using TF6250 As Modbus-TCP Server

This Time I will use TwinCAT3 TF6250 to implement the Modbus TCP Server and then connect to Factory IO. The Server Settings screen is a little bit like TwinCAT2.

Modbus Area

Server Setup

While TF6250 is installed, please access the below Directory:

C;/TwinCAT3/Functions/TF6250-Modbus-TCP/Win32/Server

And then Start the TcModbusSrvCfg Application.

You can see the application below.

IP Address is 127.0.0.1 and Port is 502 as default.

And then TwinCAT3 TF6250 is using XML-Base files to configure the server.

Get Configuration

Let’s get the current Configuration inside the Runtime.

press the Get Configuration Button.

It will stop your Runtime and need your confirmation.

Press yes.

Export Configuration

Then we can export this configuration as XML Files.

Press the Export Configuration Button.

Runtimeが止まることになりますが、いいですかって。

Yesします。

Again, the Runtime System needs your confirmation to stop.

Press Yes.

Choose your Save location.

You can see this XML file.

Edit

Use Notepad or any text editor to edit this file.

Please match all the start address and End address with your applications.

You can see the VarName tag value is GVL.mb_xxxxx.

It means that you can change this tag to match your TwinCAT Project also.

Import Configuration

After you edited the XML files, press Import Configuration to import the setting.

XML修正終わったら次はImport Configurationします。

Again, press yes to stop the runtime.

Choose the files that you edited , and save it.

Set Configuration

Finally, press the Set Configuration button to download the Configuration to Runtime.

Again, Press Yes.

Project For FactoryIO

Now we can connect the TwinCAT Modbus TCP Server to FactoryIO Client. And It is a very simple sense and with 3 step conveyors.we have sensors to detect the box position.

TwinCAT Side

Create the GVL

Create the GVL variables for the Modbus TCP Register Area.

{attribute ‘qualified_only’}

VAR_GLOBAL

mb_Input_Coils    :    ARRAY [0..255] OF BOOL;

mb_Output_Coils :    ARRAY [0..255] OF BOOL;

mb_Input_Registers :    ARRAY [0..255] OF WORD;

mb_Output_Registers :    ARRAY [0..255] OF WORD;

END_VAR


PROGRAM

Then create the Control Program.

VAR

VAR

wEntryConveyorRun :Word;

bCurvedConveyorRun :BOOL;

bConveyorExitSensor :BOOL;

bCurvedConveyorEntrySensor

,bCurvedConveyorCenterSensor

,bCurvedConveyorExitSesnor

,bCurvedConveyorEmpty :BOOL;

bCapactiveSensor :WORD;

rSetPoint :REAL;

R_trig :r_trig;

F_trig :f_Trig;

ton :ton;

END_VAR

Code

//

wEntryConveyorRun:= REAL_TO_WORD( rSetPoint /10.0*5000.0);

gvl.mb_Input_Registers[0]:=wEntryConveyorRun;

//

bConveyorExitSensor:=NOT GVL.mb_Output_Coils[1];

bCurvedConveyorEntrySensor:= GVL.mb_Output_Coils[2];

bCurvedConveyorCenterSensor:= GVL.mb_Output_Coils[3];

bCurvedConveyorExitSesnor:= GVL.mb_Output_Coils[4];

R_Trig(clk:=bConveyorExitSensor);

F_Trig(clk:=bConveyorExitSensor);

ton(

in:=NOT bCurvedConveyorEntrySensor

AND NOT bCurvedConveyorCenterSensor

AND NOT bCurvedConveyorExitSesnor

,PT:=T#1S

,Q=>bCurvedConveyorEmpty

);

IF bCurvedConveyorEmpty THEN

bCurvedConveyorRun:=FALSE;

END_IF

IF R_Trig.q 

OR bConveyorExitSensor 

THEN

bCurvedConveyorRun:=TRUE;

END_IF

gvl.mb_Input_Coils[1]:=bCurvedConveyorRun;


License

Please be careful that while you are using TF6350 Function for Server Only, you need to enter the License manually.

FactoryIO Side

Go to File>Drivers.

Choose the Modbus TCP/IP Client.

Click the Configuration.

Set the Host and Port.

Match the Offset and Count Settings with your TwinCAT Project.

if the Connection is established, you can see the green mark.

And then map the IO.

Finish!

Result

You can see the result in my twitter:

And you can download the project in Github:

https://github.com/soup01Threes/TwinCAT3/blob/main/TwinCAT%20Project_ModbusServer_IOFactory.zip

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

シェアする

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

フォローする