Communication Configuration and Example Program Usage

You are viewing an old version of the documentation. You can switch to the documentation of the latest version by clicking the top-right corner of the page.

This topic introduces the commands for Modbus TCP communication between a Siemens SIMATIC S7 PLC using the TIA Portal software and the Mech-Mind Vision System.

Hardware and Software Requirements

Hardware

  • Siemens SIMATIC S7-1200, CPU 1211C, DC/DC/DC

  • AC 220 V to DC 24 V power adapter

  • Mech-Mind Vision System IPC

  • Ethernet cables

Software

  • Siemens PLC programming software TIA Portal V15.1

  • Mech-Vision & Mech-Viz versions: 1.7.0 or above

  • PLC Example Programs:

    • MM Modbus TCP.scl (for establishing Modbus TCP communication);

    • MM Modbus TCP Interface Program.scl (for implementing the functions of various interface commands)

    The example files are stored in Communication Component/Robot_Interface/Modbus TCP/Siemens TIA Portal in the installation directory where Mech-Vision and Mech-Viz are installed. Please copy the example file to the computer on which the TIA Portal is installed.

The firewall on the IPC must be turned off.

Configure IPC and Initiate Communication

Set IP Address of the IPC

  1. Open the Control Panel, and click View network status and tasks.

    set ip1
  2. In the “Network and Sharing Center” window, click Change adapter settings.

    set ip2
  3. In the “Network Connections” window, double-click the Ethernet interface connected to the PLC, and select Properties in the pop-up Ethernet Status window.

    set ip3
  4. In the Ethernet Properties window, select Networking in the menu bar, and double-click Internet Protocol Version 4(TCP/IPv4).

    set ip4
  5. In the Internet Protocol Version 4 (TCP/IPv4) window, select “Use the following IP address”, and set the IP address, subnet mask and default gateway (must be in the same subnet as the PLC). Then, click “OK” to save the changes.

    set ip5

Set up “Robot Communication Configuration”

  1. Click Robot Communication Configuration on the toolbar of Mech-Vision.

  2. In the Robot Communication Configuration window, complete the following configurations.

    1. Click the Select robot drop-down menu, and select Listed robot. Click Select robot model, and select the robot model that you use. Then, click Next.

    2. In the Communication mode area, select Standard Interface for Interface service type, MODBUS TCP Slave for Protocol, and ABCD for Byte order. Set the Slave ID to 255.

    3. Set the port number to 2000 for the host IP address.

    4. (Optional) Select Auto enable interface service when opening the solution.

    5. Click Apply.

      modbus tcp s7
  3. On the main interface of Mech-Vision, make sure that the Robot Communication Configuration switch on the toolbar is flipped and turned to blue.

    interface service

Create and Configure the PLC Project

Create PLC Project

If needed, click Save project to save the changes to the project.
  1. Open TIA Portal and click Create new project. Input “Project name” and “Path”, and click Create. Click Open the project view in the pop-up page.

    create plc 1
  2. In the Project tree panel, double-click Add new device. In the new window, click Controllers, and find the CPU module that you are using, and input the name in the blank box under “Device name”. Click OK to confirm adding the device. Here, the device is named PLC_1.

    create plc 2
  3. Select Device configuration under PLC_1 in the Project tree panel, and then click Device view tab on the right. In this tab, double-click ethernet icon in PLC_1. Down in the Properties ‣ General tab, click Ethernet addresses to set the IP address of the PLC. Use the default value for Subnet mask.

    create plc 3

Import Mech-Mind Example Programs

Before you add the example program to a project already in use, it is recommended to import it to a new project and test it first. In the following steps, the project created earlier is used to import and test the example program.
  1. In the Project tree panel, double-click PLC_1[CPU 1211C DC/DC/DC] ‣ External source files, and then double-click Add new external file. In the pop-up window, locate and select the MM Modbus TCP.scl and MM Modbus TCP Interface Program.scl files. Click Open to import these files.

    import file 1
  2. Select MM Modbus TCP.scl first, and then select MM Modbus TCP Interface Program.scl. Next, and right-click these files. In the right-click menu, select Generate blocks from source.

    import file 2
  3. If the warning message saying Blocks can be overwritten pops up, click OK.

    import file 3
  4. The functions and data blocks generated from these external source files are shown below. In terms of the function of the data blocks, Camera_User DB stores user data, MM Modbus TCP Interface stores communication data, and MM Modbus TCP stores communication configuration parameters.

    import file 4
  5. Double-click the MM Modbus TCP function block. Then, click the ToCamera and the FromCamera network No.1~6 sequentially to check that the DB number in the MB_DATA_PTR variable is the same as that of the MM Modbus TCP Interface data block. In this case, the number is 2 as shown in the picture below.

    import file 5

    If the DB number in the MB_DATA_PTR variable does not match the number of the MM Modbus TCP Interface DB, and it is not feasible to change the number of the MM Modbus TCP Interface DB, you can utilize the “Find and replace” function in the Options panel to change the DB in the MB_DATA_PTR variable to the DB number used by MM Modbus TCP Interface.

    import file 6
  6. In the Project tree panel, navigate to PLC_1 ‣ Program blocks ‣ System blocks ‣ Program resources, check if the MB_CLIENT function block and MB_CLIENT_DB data block are automatically generated. If not, refer to the following step to generate the MB_CLIENT FB suitable for the current CPU. If so, skip the next step.

    import file 7
  7. In the Project tree panel, click Program blocks, and double click Main[OB1]. Select the diagram under any of the networks, and then select the Instructions tab to the right. Navigate to Communication  Others  MODBUS TCP, and double-click the MB_CLIENT block. In the pop-up Call options window, click OK.

    import file 8

    In the Project tree panel, navigate to Program blocks ‣ System blocks. The MB_CLIENT FB and MB_CLIENT_DB DB should be generated now. Return to the MM Modbus TCP FC, and click the Compile tab on the toolbar.

    import file 9

    When the following messages are displayed in the Compile tab under the “Info” tab at the bottom, you can delete the MB_CLIENT block under Main[OB1] Network 1 in the Main OB.

    import file 10
    import file 11
  8. To ease the management and maintenance later on, create a new group under Program blocks to organize the blocks: In the Project tree panel, under PLC_1, right-click Program blocks and select Add new group. Here, the new group is named 3D_Camera.

    import file 12
  9. Select all the FCs and DBs generated from the external source files and drag these blocks into the 3D_Camera group.

import file 13

Build Program and Download to PLC

  1. In the Project tree panel, navigate to Program blocks, and double-click Main OB to open it. Then, Drag the MM Modbus TCP FC to Network 1 in the Main OB.

    download configuration 1
  2. Double-click the MM ModbusTCP DB to open it, and then click the expand icon. Under RemoteAddress, check if the 4 hexadecimal numbers in ADDR match the segments of the IP address of the IPC (which is 192.168.1.20 in this example), and if the number in RemotePort matches the port number set in Mech-Vision (which is 2000 in this example).

    download configuration 2
  3. Navigate to System blocks  Program resources, double-click the MB_CLIENT_DB DB to open it, and then click the expand icon. Under Static ‣ TDIAG_Status, check if the hexadecimal number in MB_Unit_ID matches the Slave ID set in Mech-Vision (which is 255 in this example).

    download configuration 3
  4. In the Program tree panel, right-click PLC_1, and select Download to device  Software (all).

    download configuration 4
  5. In the pop-up Extended download to device window, make the following selections: Select the interface connected to the PLC for PG/PC interface. Select Direct at slot ‘1 X1’ for Connection to interface/subnet. Select Show all compatible devices for Select target device. Then, click Start search. Select the corresponding device in the search result, and then click Load.

    download configuration 5
  6. In the pop-up Load results window, click Finish once the download is completed.

    download configuration 6

Check Communication

  1. In the Program tree panel, double-click the MM Modbus TCP Interface DB, and then click the monitor icon. If the monitor value of Heartbeat keeps changing, the connection is successfully established.

    establish communication 1
  2. The PLC is successfully connected if the following message is displayed in the Console tab of Mech-Vision Log panel: client connected. If you don’t see this log message, please check if:

    1. If the hardware is properly connected;

    2. If the Interface Service has been started successfully in Mech-Vision;

    3. If the PLC program has been successfully downloaded to the PLC.

Test with Mech-Vision/Mech-Viz Project

This section introduces how to use the example program function block to trigger the Mech-Vision project to obtain vision points and trigger the Mech-Viz project to obtain the planned path.

Prerequisites

  1. Mech-Vision project(s): Right-click the solution and select Autoload Solution. Projects in the solution are also autoloaded. Meanwhile, the project number will show up before each project name.

  2. Mech-Viz project: Right-click the project name in Resources in Mech-Viz and select Autoload Project.

    The Mech-Viz project used for testing should contain a “Branch by Msg” Step that has been renamed to 1 as shown below.

    preparation 4

Run Mech-Vision Project and Obtain Vision Points

Configure PLC Program

  1. In the Project tree panel, navigate to Program blocks, double-click the Main OB to open it. Then, Drag the MM_Start_Vis FC to Network 2 in the Main OB.

    test vision 1
  2. Set Mech-Vision project ID, namely, the number before the project name in the project list in Mech-Vision. For example, if the value is changed to 1, then project No.1 in Mech-Vision will be started.

  3. Set the number of poses returned by the Mech-Vision project: Set the port value of Req_Pose_Num to 0, indicating that Mech-Vision returns all pose results.

  4. Set the type of pose sent from the robot. Set the value of Robot_Pose_Type to 0, indicating that the project is in Eye-to-Hand mode, and the image-capturing pose is not needed.

    test vision 2
  5. In the Project tree panel, navigate to Program blocks and click the Camera_User DB. From the Details view panel, drag the parameters to the corresponding input ports of the MM_Start_Vis FC.

    test vision 3
  6. Drag the MM_Get_VisData FC to Network 3 in the Main OB.

    test vision 4
  7. Set Mech-Vision project ID, namely, the number before the project name in the project list in Mech-Vision. Set the port value of Vision_Proj_Num to 1, and the vision recognition result of Project No.1 in Mech-Vision will be obtained.

  8. In the Project tree panel, navigate to Program blocks and click the Camera_User DB. From the Details view panel, drag the parameters to the corresponding input ports of the MM_Get_VisData FC.

    test vision 5
  9. In the Program tree panel, right-click PLC_1, and select Download to device ‣ Software (only changes).

    test vision 6
  10. In the pop-up Load preview window, click Load to download the changes to the PLC.

    test vision 7

Trigger the Mech-Vision Project to Run

  1. In the Main OB window, click the Monitoring on/off icon.

    test vision 8
  2. Start the Mech-Vision project: In Network 1, right-click the “Camera_User”.Start_Vis parameter in “MM_Start_Vis”, and select Modify  Modify to 1. Then, reset the value of this parameter.

    test vision 9
  3. Check returned status code: Double-click the MM Modbus TCP Interface DB to open it, and check the monitor value of Status Code. 1102 represents that the project was started successfully. For other values, please refer to Status Codes and Troubleshooting for the corresponding error.

    test vision 10

Obtain Vision Points from Mech-Vision

  1. Right-click the “Camera_User”.Get_VisData parameter in “MM_Get_VisData”, and select Modify  Modify to 1. Then, reset the value of this parameter.

    test vision 11
  2. Check returned status code: Double-click the MM Modbus TCP Interface DB to open it, and check the monitor value of Status Code. 1100 represents that the vision point was received successfully. For other values, please refer to Status Codes and Troubleshooting for the corresponding error.

    test vision 12

The value of “Number of Pose Sent” is 1, indicating that one pose is obtained. The poses are stored in “Target Pose”.

Example Program of Mech-Vision Auto-Control Logic

test vision 13
test vision 14

Test with Mech-Viz Project

Configure PLC Program

  1. Drag the MM_Empty_Target FC to Network 4 in the Main OB.

    test viz 1
  2. Click the Camera_User and MM Modbus TCP Interface DB. From the Details view panel, drag the parameters to the corresponding input ports of the “MM_Empty_Target” FC.

    test viz 2
  3. Drag the MM_Start_Viz, MM_Set_Branch, and MM_Get_VizData FCs to Network 5, Network 6, and Network 7, respectively, in the Main OB.

    test viz 3
  4. Set the type of pose to be sent by the robot. Change the value of the Robot_Pose_Type port. If the value is set to 0, no image-capturing pose will be sent (for the Eye-to-Hand installation). Click the Camera_User DB. From the Details view panel, drag the parameters to the corresponding input ports of “MM_Start_Viz”.

    test viz 4
  5. Set the branch parameters in Mech-Viz project. Set the value of Branch_Name and Branch_Exit_Port to 1, and Mech-Viz will take exit port 1 for the “Branch by Msg” Step whose Step ID is 1. Click the Camera_User DB. From the Details view panel, drag the parameters to the corresponding input ports of the “MM_Set_Branch” FC.

    test viz 5
  6. Set the pose type of the obtained waypoints. Change the value of “Request_Pose_Type” to 1, and Mech-Viz will return data in the format of joint positions (instead of TCP). Click the Camera_User DB. From the Details view panel, drag the parameters to the corresponding input ports of the “MM_Get_VizData” FC.

    The Request_Pose_Type parameter here and the Robot_Pose_Type parameters in the MM_Start_Vis and MM_Start_Viz FCs all correspond to the same Pose Type parameter in the MM Modbus TCP Interface DB. Therefore, if these parameters are set to different values, the programming should ensure that the two values do not take effect at the same time.
    test viz 6
  7. In the Program tree panel, right-click PLC_1, and select Download to device ‣ Software (only changes). In the pop-up Load preview window, click “Load” to download the changes to the PLC.

    test viz 7
  8. In the pop-up Load preview window, click Load to download the changes to the PLC.

    test viz 8

Trigger the Mech-Viz Project to Run

  1. In the Main OB window, click the Monitoring on/off icon.

    test viz 9
  2. Right-click the “Camera_User”.Start_Empty parameter in “MM_Empty_Target”, and select Modify  Modify to 1. Then, reset the value of this parameter.

    test viz 10
  3. In the MM Modbus TCP Interface DB, the monitor values of Target Pose, Target Label and Speed Percentage are reset.

    test viz 11
  4. Right-click the “Camera_User”.Start_Viz parameter in “MM_Start_Viz”, select Modify  Modify to 1, and start the Mech-Viz project. Then, reset the value of this parameter.

    test viz 12
  5. Check returned status code: Double-click the MM Modbus TCP Interface DB to open it, and check the monitor value of Status Code. 2103 represents that the project was started successfully. Otherwise, the corresponding error code will be returned. Please refer to Status Codes and Troubleshooting for troubleshooting.

    test viz 13

Set Mech-Viz Branch Exit Port

  1. Right-click the “Camera_User”.Set_Branch parameter in “MM_Set_Branch”, select Modify  Modify to 1, and select the exit port for the Mech-Viz project. Then, reset the value of this parameter.

    test viz 14
  2. Check returned status code: Double-click the MM Modbus TCP Interface DB to open it, and check the monitor value of Status Code. 2105 represents that the branch was set successfully. Otherwise, the corresponding error code will be returned. Please refer to Status Codes and Troubleshooting for troubleshooting.

    test viz 15

Obtain Planned Path from Mech-Viz

  1. Right-click the “Camera_User”.Get_VizData parameter in “MM_Get_VizData”, select Modify  Modify to 1, and obtain the planned path from Mech-Viz. Then, reset the value of this parameter.

    test viz 16
  2. Check returned status code: Double-click the MM Modbus TCP Interface DB to open it, and check the monitor value of Status Code. 2100 represents that the planned path was successfully obtained. Otherwise, the corresponding error code will be returned. Please refer to Status Codes and Troubleshooting for troubleshooting.

    test viz 17

In the picture above, the value of “Number of Pose Sent” is 6, indicating that 6 groups of joint positions are obtained. The data is stored in “Target Pose”. The value of “Index of Vision Move” is 3, indicating that the vision point is the third waypoint in the entire planned robot path.

Example Program of Mech-Viz Auto-Control Logic

test viz 18
test viz 19
test viz 20

We Value Your Privacy

We use cookies to provide you with the best possible experience on our website. By continuing to use the site, you acknowledge that you agree to the use of cookies. If you decline, a single cookie will be used to ensure you're not tracked or remembered when you visit this website.