Setup
This tutorial provides step by step instructions for connecting an NI Smart Camera to an Anybus X-Gateway that communicates with a simulated EtherCAT Master on the host PC. The tutorial uses TwinCAT System Manager provided by Beckoff to simulate the EtherCAT Master. To complete this tutorial the following hardware and software is required.
-
NI Smart Camera (optional)
-
Vision Builder for Automated Inspection
-
Anybus X-Gateway: Modbus-TCP to EtherCAT
-
Anybus IPconfig Utility (available for download at www.anybus.com)
-
EDS file for the X-Gateway (optional, available for download on the product page at www.anybus.com)
-
TwinCAT (available for download at www.beckhoff.com)
-
Host PC with at least two Ethernet ports
-
Internet Explorer 7.0 or 8.0
Additional configuration manuals and tutorials for the gateway can be located at www.anybus.com.
Figure 2 provides an overview of the fully configured testing setup. This tutorial assumes that an NI Smart Camera hosts the Modbus Server. You can also use an Embedded Vision System or the host PC to host the Modbus Server.
Figure 2.
Test Setup Overview
Starting the Vision Builder AI Modbus Server
Complete the following steps to enable the Modbus Server in Vision Builder AI.
-
Launch Vision Builder AI.
-
Select the Smart Camera that will host the Modbus Server and communicate with the EtherCAT network, as illustrated in Figure 3. The Vision Builder AI welcome screen only lists a target if the same version of Vision Builder AI is installed on the target. Vision Builder AI only lists targets that share a subnet with the host PC and targets explicitly added using the IP address. If no targets are available, you can select My Computer for testing purposes.
Figure 3. Selecting a Vision Target on the Vision Builder AI Welcome Screen
-
Select New Inspection. The Configuration Interface appears.
-
Select Tools»Communication Device Manager to open the Communication Device Manager, as illustrated in Figure 4
Figure 4. Accessing the Communication Device Manager
-
Click New Device to open the New Communicator Device dialog box. Enter a Device Name and select Modbus TCP in the Protocol list, as illustrated in Figure 5.
Figure 5. Configuring a New Modbus TCP Device
-
Click OK to create the device and return to the Communication Device Manager.
-
Click Start Server to start the Modbus Server. The Modbus Server status changes to running, as illustrated in Figure 6.
-
Click OK to close the Communication Device Manager return to the Configuration Interface.
Figure 6. Enabling the Modbus Server
Adding a Modbus Slave Inspection Step
Use a Modbus Slave inspection step to update local registers on the Modbus server in Vision Builder AI. Complete the following steps to add a Modbus Slave step to the current Vision Builder AI inspection.
-
In the Inspection Steps pane, navigate to the Communicate tab and click the Modbus Slave step, as illustrated in Figure 7. The step opens for configuration.
Figure 7. Modbus Slave Step Located on the Communicate Tab
-
Enter a Step Name.
-
Click Write Registers. The Write Local Register dialog box appears.
-
Configure the register with the following settings, as illustrated in Figure 8.
-
Select Numeric Constant and enter a value of 2.
-
Select Holding Registers in the Table list.
-
Enter 0 as the Start Address.
-
Select 16-bit Unsigned Integer in the Type list.
Figure 8. Write Local Register Dialog Box
-
Click OK to close the Write Local Register dialog box.
-
Repeat steps 3, 4, and 5 to add two additional local write registers, specifying unique values for the Numeric Constant and Start Address controls. Figure 9 illustrates three write registers with unique addresses and values.
Figure 9. Modbus Slave Inspection Step Configured to Write Values to Three Unique Registers
-
Click View Local Registers to confirm that the write transactions have been configured correctly. The Modbus Local Registers Terminal dialog box displays the current values of the Modbus server’s registers. If the holding registers are not displayed, select View»Holding Registers. Figure 10 illustrates the holding registers for the local write registers illustrated in Figure 9.
Figure 10. Holding Registers for Three Unique Local Write Registers
-
Close the Modbus Local Registers dialog box.
-
Click OK to save the Modbus Slave step settings.
-
Select File»Save and save the Vision Builder AI inspection to the target.
Configuring the Anybus X-Gateway
Use the Anybus IPconfig utility that ships with the X-Gateway to perform network discovery for the gateway. The utility and user manual are available for download from the Anybus product page. Complete the following steps to perform network discovery and configure the gateway.
-
Install and launch the IPconfig utility.
-
Click Scan. The utility displays the network settings for the gateway, as illustrated in Figure 11.
Figure 11. Gateways Located by Scanning with the Anybus IPconfig Utility
-
Open Internet Explorer. The Anybus web configuration utility requires Internet Explorer 7 or Internet Explorer 8. If you have a different version of Internet Explorer, contact Anybus for support.
-
Type the gateway IP address in the address bar to navigate to the web configuration utility, as illustrated in Figure 12.
Figure 12. X-Gateway Web Configuration Interface
-
Click the Modbus Client link at the left of the page under Configuration.
-
Configure the following settings, as illustrated in Figure 13.
-
Select Enabled in the DHCP list.
-
Select Enabled in the Anybus IPconfig (HICP) list.
-
Select Running in the Start-up operation mode list.
-
Select Freeze data to Modbus servers in the When EtherCAT (Network1) is not exchanging I/O data list.
Figure 13. Modbus Client Configuration Page
-
Click the Modbus Server link at the left of the page under Configuration.
-
Click Add New Server.
-
Click the Edit link for the new server.
-
Configure the following settings as illustrated in Figure 14.
-
Enter SmartCamera as the server Alias.
-
Enter the IP address of the Smart Camera running the Modbus server as the Server address.
Figure 14. Editing the Modbus Server Configuration
-
Click OK to save the server settings.
-
Click the Transactions link for the server. The transactions link is located to the right of the Edit link. Use the Transactions page to configure read and write transactions with the Smart Camera running the Modbus server.
-
Click Add new transaction three times to create three transactions, as illustrated in Figure 15.
Figure 15. Adding Three Server Transactions
-
Click the Edit link for the first transaction.
-
Configure the following settings. Use the default values for all other settings. The final setting configuration is illustrated in Figure 16.
-
Enter Input1 as the transaction Alias.
-
Select 3-Read Holding Registers in the Function code list.
-
Enter 1 as the Starting address.
-
Select uint16 in the Data Type list.
-
Enter 1 as the number of Elements.
-
Click OK to save the transaction settings.
Figure 16. Editing Server Transactions
-
Click Edit and configure the following settings for the second transaction:
-
Enter Output1 as the transaction Alias.
-
Select 6-Write Single Register in the Function code list.
-
Enter 2 as the Starting address.
-
Select uint16 in the Data Type list.
-
Enter 1 as the number of Elements.
-
Click OK to save the transaction settings.
-
Click Edit and configure the following settings for the third transaction:
-
Enter Input2 as the transaction Alias.
-
Select 3-Read Holding Registers in the Function code list.
-
Enter 3 as the Starting address.
-
Select uint16 in the Data Type list.
-
Enter 1 as the number of Elements.
-
Click OK to save the transaction settings. Figure 17 illustrates the updated server transactions.
Figure 17. Server Transactions after Configuration
-
Click the X-gateway Management link at the left of the page under Tools.
-
You must reboot the gateway before your changes can take effect. Click Apply to apply the changes and reboot the gateway.
Figure 18. X-Gateway Management Page
Testing the Modbus-TCP Connection
After restarting the gateway, complete the following steps to confirm communication between the gateway and the Modbus server.
In the Anybus web configuration utility click the Transaction Monitor link, at the left of the page under Tools.
The read transactions should reflect the values in register 1 and register 3, as illustrated in Figure 19. If the read transaction shows a value of 0, confirm that the Modbus server is running on the Smart Camera and that the registers have been updated using the saved Vision Builder AI inspection.
Figure 19. X-Gateway Transaction Monitor Page
Notice that the write transaction writes a default value of 0 to register 2. Complete the following steps to confirm that this write command was successfully received by the Modbus server running on the Smart Camera.
-
Return to Vision Builder AI.
-
In the Configuration Interface, select Tools»Modbus Local Register Terminals to view the local registers. Figure 20 illustrates the Modbus Local Registers Terminal dialog box.
Figure 20. Modbus Local Register Terminal
Registers 0x0000 and 0x0002 retain the values that were written by the Modbus Slave step in the Vision Builder AI inspection. If register 0x0001 holds a value of 0, the gateway and the Modbus server can communicate and the gateway has overwritten the previous value.
Configuring the EtherCAT Master
Complete the following steps to use TwinCAT software to simulate an EtherCAT master on an available Ethernet port on the host PC.
-
Download TwinCAT software from www.beckhoff.com. Install and use the most recent, compatible version of the TwinCAT software. This tutorial uses TwinCAT version 2.11 R3 Build 2224.
-
Select any installation configuration but ensure that TwinCAT System Manager is selected for installation.
-
Place the X-Gateway EDS file in the <TwinCAT>\Io\EtherCAT folder, where <TwinCAT> is the location to which you installed the TwinCAT software. The EDS file is an XML configuration file that is available for download from the X-Gateway product page on the Anybus website.
-
Launch the TwinCAT System Manager.
-
Select Options»Show Real Time Ethernet Compatible Devices, as illustrated in Figure 21.
Figure 21. Selecting Compatible Ethernet Devices in the TwinCAT System Manager
-
In the Ethernet Adapters tree, as illustrated in Figure 22, select the Ethernet device you wish to use for EtherCAT. You can select adapters listed under Compatible devices or Incompatible devices. The categories differ only in performance.
-
Click Install.
Figure 22. Selecting Compatible Ethernet Devices in the TwinCAT System Manager
-
Wait for the EtherCAT driver installation to complete and close the Installation of TwinCAT RT-Ethernet Adapters dialog box.
-
In the TwinCAT System Manager, select I/O Devices, as illustrated in Figure 23.
-
Click Scan sub devices in the toolbar, as illustrated in Figure 23.
Figure 23. Scanning for Sub Devices on the TwinCAT System Manager
- Select the Ethernet interface you wish to use and click OK, as illustrated in Figure 24.
Figure 24. Selecting the Ethernet Interface
-
Select Yes when prompted to scan for boxes (or slaves).
-
Select Yes when prompted to activate free run. Activating free run switches to operational mode.
Complete the following steps If you did not copy the EDS file to the T<TwinCAT>\Io\EtherCAT folder.
-
Select the gateway in the tree control, as illustrated in Figure 25.
-
Click the Process Data tab.
-
Click Load PDO info from device.
-
Click Reload I/O Devices in the toolbar.
-
Select Yes when prompted to activate free run.
Figure 25. Setting Up the EtherCAT Slave I/O without the XML File
Testing the EtherCAT Connection
Complete the following steps to confirm that an output value written to the gateway is updated on the Modbus server.
-
In the TwinCAT System Manager, navigate to I/O – Configuration»I/O Devices»Device #»Box # (gateway) »DO RxPDO-Map»Output1 in the tree control, as illustrated in Figure 26.
-
Click the Online tab.
Figure 26. Accessing the EtherCAT Output
-
Click Write to open the Set Value Dialog dialog box.
-
Enter 7 as the Dec value.
-
Click OK to close the Set Value Dialog dialog box.
Figure 27. Changing the Output Value on the EtherCAT Slave
-
Return to Vision Builder AI.
-
In the Configuration Interface, select Tools»Modbus Local Register Terminals to view the local registers.
If register 0x0001 holds a value of 7, as illustrated in Figure 28, output values written to the gateway are updated on the Modbus server.
Figure 28. Modbus Local Registers with Values Updated from EtherCAT Master