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, Port and Timeout (ms).

  • On success it provides the established Connection via its output and sets Success to true. On failure it provides a null/empty connection and sets Success to 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

  1. Enter your PLC address into AMS ID and the target port into Port.

  2. Adjust Timeout (ms) if your network is slow or unreliable.

  3. Run the scenario; check the Success output to verify connection.

  4. Feed the Connection output to blocks that perform PLC read/write operations.

πŸ’‘ Tips and Tricks

  • Use TwinCAT Read and TwinCAT Write blocks downstream of this block to perform read and write operations using the provided Connection.

  • Combine Logic Input with the Success output to gate PLC operations only when the connection is active.

  • Use Debug Input or 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 Export or Data Write Global blocks to persist results.

  • If you need to trigger other actions when the connection appears or disappears, use logic blocks such as Rising Edge or Set - Reset with the Success output.

πŸ› οΈ 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 Success remains false, check that the AMS ID and Port fields 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 + Retry logic with Rising Edge) to attempt reconnection only when needed.

Last updated

Was this helpful?