In this tutorial I will show you how to configure a Profinet RT Device in TwinCAT, and test the connectivity with Codesys PN Controller.
Here is a Reference link to show you how to use TF6271 as a PN Controller.
System Requirement
Configration
Add the PN Device
Go to I/O>Device>Add New Item.
Select Profinet I/O Device(RT) and Ok.
PN Device is added in your configuration.
Add Slot
Select the Profinet device that was inserted in the previous step>Right Click>Add New Item.
Choose Beckhoff Automation GmbH>PNTC Device(TwinCAT Supplment)>OK.
TwinCAT Device V23.1 Port is used in this tutorial.
Slot is inserted in your configuration.
Add SubSlot
Now we can insert the SubSlot inside our API, please expand Tcpniodevice>Select API> Right Click>Add New Item.
The Device Configuration screen is shown and we can set up the Exchange data slot here.
if you insert In/out 32 Bytes in the Module modules, twincat will exchange 32 bytes of in/out data with the controller. In this tutorial, 32 bytes inout data is used.
a 32 bytes inout slot is inserted in Term2.
GSDML Export
By using profinet, a GSDML file is necessary. We can export the GSDML from TwinCAT3.
You can go to General>GSDML Generator> and click the “Create GSDML from original” to generate the GSDML File.
Configuration
Check the “Legacy config” and “Get Station Name from tree.”
Mult Mapping
Finally we need to map the data between the user program and process io.
For example, we can click the Inputs item.
Select all variables and Right Click> Change Multi link.. to link all variables in one time.
Codesys Side-PN Controller
You can use the Pn Controller with Codesys:
Or use a siemens PN Coupler:
Please make sure the slave that you inserted in the master is TwinCAT Device V2.3.1 Port.
Done!Codesys PN Controller is connected to TwinCAT PN Devices.
Please do nor forget to map the variable!
Status
After we downloaded the project on both sides, please check the status in TwinCAT Side.
Go to Inputs>PnioBoxState:
Status=5 is normal because status 4+1.
The device is in I/O Exchange and Provider State is running.
And we can check the connection status on Codesys side also from the Log View.
You can see an “OK” Status in the General>Station Status.