TwinCAT Connect
This function block establishes a connection to a TwinCAT PLC so other blocks can read from or write to the PLC. Use it to create and maintain the PLC client connection and to report connection status to the rest of your scenario.
π₯ Inputs
This function block does not have any input sockets.
π€ Outputs
Connection The active connection handle (use with downstream communication blocks).
Success Boolean indicating whether a successful connection to the PLC was established.
πΉοΈ Controls
AMS ID Enter the PLC AMS identifier (address). This is typically provided by the PLC configuration or your system administrator.
Port Enter the port number for the TwinCAT connection. A default common port is prefilled (you can change it if needed).
Timeout (ms) Set the connection timeout in milliseconds. Use larger values for slower or remote networks.
Note: If the required TwinCAT support libraries are not present on the system, the block will show a message in its layout indicating that TwinCAT modules are not available and the block cannot connect until required components are installed.
π― Features
Persistent connection output for downstream blocks to reuse without re-initializing.
Displays connection success as a boolean to enable conditional workflows.
Simple, labeled controls to set AMS ID, port and timeout values.
Gracefully reports missing system dependencies so you know when TwinCAT components are required.
βοΈ Running mechanism
When the block runs it attempts to establish a PLC connection using the configured
AMS ID,PortandTimeout (ms).On success it provides the established
Connectionvia its output and setsSuccessto true. On failure it provides a null/empty connection and setsSuccessto false.The connection output can be left connected to other communication blocks so they can use the same established link without re-creating connections repeatedly.
The block also reports clear error messages in the UI if configuration is missing or system dependencies are not available.
π Usage Instructions
Enter your PLC address into
AMS IDand the target port intoPort.Adjust
Timeout (ms)if your network is slow or unreliable.Run the scenario; check the
Successoutput to verify connection.Feed the
Connectionoutput to blocks that perform PLC read/write operations.
π‘ Tips and Tricks
Use
TwinCAT ReadandTwinCAT Writeblocks downstream of this block to perform read and write operations using the providedConnection.Combine
Logic Inputwith theSuccessoutput to gate PLC operations only when the connection is active.Use
Debug Inputor a logging/display block to show connection status or errors during development.For saving or post-processing values read from the PLC, connect readers to
CSV ExportorData Write Globalblocks to persist results.If you need to trigger other actions when the connection appears or disappears, use logic blocks such as
Rising EdgeorSet - Resetwith theSuccessoutput.
π οΈ Troubleshooting
If the block reports that TwinCAT modules are not available, ensure the TwinCAT runtime and required Python packages are installed on the machine, and restart the application.
If
Successremains false, check that theAMS IDandPortfields are correct and reachable from your network.Increase
Timeout (ms)when connecting to remote PLCs or when experiencing intermittent network latency.If connection fails intermittently, use a small logic circuit (e.g.,
Delay Step+Retrylogic withRising Edge) to attempt reconnection only when needed.
Last updated
Was this helpful?