Connecting to a TwinCAT PLC

The Beckhoff ADS plugin allows you to connect a running Beckhoff TwinCAT PLC version 2 or 3 with a loaded program.

Important: Make sure you have installed the necessary ADS components to your device and properly configured the PLC before doing this workflow.

Step 1. Add Server

You can manually add a new PLC connection, import a configuration file or load a layout with a configured PLC connection.

New Configuration

Click the Connectivity tab, and then in the Connectivity Configuration panel, do one of the following:
  • Click the Beckhoff ADS plugin, and then on the Connectivity tab, in the Server group, click Add server.
  • Right-click the Beckhoff ADS plugin, and then click Add Server.

Import Configuration

  1. On the Connectivity tab, in the Configuration group, click Import.
  2. Import the XML or CFG file for your PLC connection.

Load Configuration

  1. Load a layout in the 3D world that has already been configured for a PLC connection.
  2. Click the Connectivity tab, and then in the Connectivity Configuration panel, verify the connection is listed under the Beckhoff ADS plugin.

Step 2. Verify Network Connection

Editing Connection

Click the Connectivity tab, and then in the Connectivity Configuration panel, under the Beckhoff ADS plugin, select your PLC connection and do the following:
  1. Right-click your Server, and then click Edit Connection.
  2. In the Edit Connection task pane, under Server Address, set AMS Net ID and ADS port, and then click Test Connection.
  3. Note:
    • Every time you execute the Edit Connection command, the Beckhoff ADS plugin automatically scans common ports on your local machine to find ADS ports for PLC connections, and then lists them in the Edit Connection task pane.
    • For example, the plugin would check TwinCAT 2 ports {801,811,821,831} and TwinCAT 3 ports 851 to 860.
    • This discovery only works for PLCs running on your local machine.
  4. If you see Connection succeeded click OK and then click Apply.

Troubleshooting

If you experience any connection issues then follow these steps.   Open the Command Prompt or terminal of your device, and then ping the network addresses of the devices running Visual Components Premium 4.9 and the PLC.
  • If you are running a PLC and Visual Components Premium 4.9 on the same computer, do a local test of 127.0.0.1.
  • If you are running a PLC and Visual Components Premium 4.9 on different computers or using a PLC dedicated device, you should have already configured the route of the PLC using the Beckhoff AMS router system, and this needs to be done on both devices. Test by pinging the network addresses of the devices and the routes.

Step 3. Activate Connection

If you have successfully added and verified a connection to a PLC, you are now ready to activate the connection.

Activate Connection

  1. Click the Connectivity tab, and then in the Connectivity Configuration panel, under Beckhoff ADS, click your PLC connection.
  2. To activate the connection, click on the Connect/Disconnect button, and then in the Properties panel, under Server Capabilities, verify Connected is set to True.

Deactivate Connection

To deactivate the connection, click on the Connect/Disconnect button, and then in the Properties panel, under Server Capabilities, verify Connected is set to False.

Troubleshooting

If you are connecting to a TwinCAT project that is not a PLC project, the following error message can appear in the output panel:

Unexpected error occurred in the connection plugin while trying to read from the server. Nullable object must have a value.

The error can be prevented by taking the following steps:

  1. Create a new PLC connection using the Beckhoff ADS plugin.
  2. Connect to the PLC project using ADS port 851.
  3. From the Properties panel uncheck the following properties:
    • Start with simulation
    • Stop with simulation
    • Reset with simulation
  4. Then disconnect from the PLC project.
  5. Edit the connection plugin to use your desired ADS port.
  6. Test if the connection is successful, and activate the connection.
  7. Pair the variables.