Communication with Beckhoff TwinCat

From CPR Wiki
Jump to: navigation, search

The robot control can receive data from the TwinCat PLC



  • robot control: CPRog. TinyCtrl will follow
  • Plugins for the robot control. Please download the following files (right click, save as) and save both of them in the directory C:\CPRog\Data\Plugins.
  • CPRog example program
  • Beckhoff TwinCat3 PLC with TCP/IP module
  • TwinCat Code following the TCP/IP example from the Beckhoff documentation


  • TwinCat sets up a server, CPRog connects as client
    • Standard server IP: (can be changed)
    • Standard server port: 9081 (can be changed)
  • CPRog requests a target position: "T1" (5 byte: 'T', '1', LR, CF, Null)
  • TwinCat sends target positions and a model type:
    • PartCnt: if zero then the following will not be evaluated, modelclass is set to -1
    • PosX to PosZ: Integer values. The target position in 1/10 mm in the robot base coordinate system.
    • RotA to RotC: Integer values. The target orientation in 1/10 degree in ABC euler angles.
    • Modelclass: Integer value. This value is handed over to the robot program for further evaluation.

  • During the execution of the robot program the target position and model type are stored in variables
  • The robot can then approach these variables

Usage in CPRog

Please see the example program for guidance.

  • In the robot program two variables have to be defined:
    • A position variable, e.g. "target"
    • A number variable, e.g. "type"
  • The plugin has to be executed with the two variables as parameter
  • The variables are used:
    • The robot can aproach the target position with a LinByVariable command
    • The modelclass value can be used in e.g. if-then-else statements

For further explanation on the commands please see the CPRog Command Reference.


For testing purposes a simulation mode can be switched on in the plugin window.

When using the exmaple program the replay mode should be set to "Replay" to have constant communication.

The log window shows messages from the pluin, e.g. connection failures.