Description S7-1200 / S7-1500 Function block O2Dxxx_TCP Version 3.1 Object Recognition Sensor O2Dxxx connected to the S7-station via the internal Ethernet-interface of the S7-CPU 2018-06-21 sy-tl Contents Preliminary note .................................................................................................................................................... 3 Disclaimer of Warranties....................................................................................................................................... 3 Demo software and templates .............................................................................................................................. 3 Software written specifically for Customer............................................................................................................ 3 1 Overview ........................................................................................................................................................ 4 2 Setting the connection parameter ................................................................................................................. 4 2.1 Setting the process interface of the sensor .......................................................................................... 4 2.2 Setting the Ethernet interface of the S7-CPU ....................................................................................... 7 2.3 Setting the TCP connection in TIA Portal software .............................................................................. 7 2.4 Hardware connection between the sensor and the Simatic S7-Station ............................................... 7 3 Generate the function block O2Dxxx_TCP in the S7 Project ........................................................................ 8 4 Description of the parameter of the function block O2Dxxx_TCP ................................................................. 9 5 Call of the function block in the user program ............................................................................................. 10 6 5.1 Establish the TCP-connection to the sensor ...................................................................................... 10 5.2 General procedure of a task ............................................................................................................... 11 5.3 Task to trigger the sensor via the process interface ........................................................................... 11 5.4 Task to change the active application in the sensor ........................................................................... 12 Description of the values of the output parameter Status ........................................................................... 13 2 Preliminary note These instructions show the setup of the communication between an object recognition sensor O2Dxxx from ifm electronic and a Simatic S7-1200 or S7-1500 PLC via the integrated Ethernet interface of the S7CPU describe the use of the function block O2Dxxx_TCP in the S7 program Disclaimer of Warranties ifm disclaims to the fullest extent authorized by law any and all warranties, whether express or implied, including, without limitation, any implied warranties of title, non-infringement, quiet enjoyment, integration, merchantability or fitness for a particular purpose. Without limitation of the foregoing, ifm expressly does not warrant that: (a) the software will meet your requirements or expectations; (b) the software or the software content will be free of bugs, errors, viruses or other defects; (c) any results, output, or data provided through or generated by the software will be accurate, up-to-date, complete or reliable; (d) the software will be compatible with third party software; (e) any errors in the software will be corrected Demo software and templates Demo software and templates are provided “as is” and “as available”, without any warranty of any kind, either express or implied. The User acknowledges and agrees to use the software at User’s own risk. In no event shall ifm be held liable for any direct, indirect, incidental or consequential damages arising out of the use of or inability to use the software. User may use the software solely for demonstration purposes and to assess the software functionalities and capabilities. Software written specifically for Customer 1. The software created and used is put together by ifm specially to the customer using modular software components made by ifm for numerous applications (Standard software modules) and adapted to the contractual service required (customer-specific application program). 2. Upon complete payment of the purchase price for the customer-specific application program, ifm transfers the non-exclusive, locally and temporarily unrestricted usage right thereof to the customer, without the customer acquiring any rights of any kind to the standard software module on which the individual or customer-specific adaptation is based. Notwithstanding these provisions, ifm reserves the right to produce and offer customer specific software solutions of the same kind for other customers based on other terms of reference. In any case ifm retains a simple right of usage of the customer–specific solution for internal purposes. 3. Upon acceptance of the program, User acknowledges and agrees to use the software at User’s own risk. User also acknowledges and agrees upon acceptance of the program that the software meets the requirements of the specifications agreed upon. ifm disclaims any and all warranties, in particular regarding fitness of the software for a particular purpose. 3 1 Overview In the user program of the S7-1200 or S7-1500 PLC, the function block O2Dxxx_TCP simplifies the data exchange with an object recognition sensor O2Dxxx from ifm electronic. Following functions are provided: establish a TCP connection to the sensor change the active application in the sensor read the active application No. from the sensor trigger the sensors via the process interface provide the trigger response data in a definable receive buffer The function block O2Dxxx_TCP version 3.1 can be used in following S7-CPUs: S7-1200 CPU with firmware >= V4.1 S7-1500 CPU with firmware >= V1.8 This function block is provided as demo program. It is only intended to serve as an example for the user. Using this demo program for machine control is at your own risk. The designers and holders of rights of this program exclude any liability for reliable function or compatibility of this demo version. For reasons of copyright it is only allowed to pass this program on free of charge. The function block is not know-how-protected. It can be modified and adjusted to the own needs. 2 2.1 Setting the connection parameter Setting the process interface of the sensor This part of the description refers to the efector dualis Parameter setting software E2D200 version 3.5 connect PC and sensor in a network start the Parameter setting software E2D200 and connect to the sensor change to the Applications mode change to tab Global sensor settings the External selection of the application must be set to Off if the active application in the sensor should be selected via the function block O2Dxxx_TCP Figure 1 4 change to tab Network parameters DHCP mode must not be activated set the IP address and possibly the Subnet mask and Gateway (the default values can be seen in Figure 2) set TCP/IP Port (default 50010 is recommended XMLRPC Port and Video Port are irrelevant for the connection to a plc and should not be changed click the [Assign] button to apply the settings Figure 2 change to tab Process interface set Process interface to TCP/IP any Protocol version can be selected set the Output format of the trigger response data click the [Assign] button to apply the settings Figure 3 The output format of the trigger response data is a global sensor setting (see Figure 3) and applies for all applications. The trigger type and the contents of the trigger response data are to set individually for each application in the sensor. 5 when edit the application change to step Process interface click the [Change settings] button Figure 4 in the dialogue change to tab TCP/IP definitions configure the trigger response data of this sensor application Image output should be set to off click the [OK] button to apply the settings Figure 5 when edit the application change to step Trigger configuration In this application, if the sensor should be triggered via the function block O2Dxxx_TCP the Trigger type must be set to Process interface. Figure 6 6 2.2 Setting the Ethernet interface of the S7-CPU This part of the description refers to Siemens TIA Portal software version 14. The description shows the procedure for a S7-1200 CPU. The procedure for a S7 1500 CPU is identical. in TIA Project open the Device configuration of the S7-Station change to the Device view and select the CPU double-click to the symbol of the used Ethernet interface to open the properties of the interface change to the General register in the folder Ethernet addresses set IP address and subnet mask Figure 7 In the folder Hardware identifier the Hardware identifier of the Ethernet interface is shown. Figure 8 2.3 Setting the TCP connection in TIA Portal software In TIA Portal software there is nothing more to configure for the TCP-connection to the sensor. 2.4 Hardware connection between the sensor and the Simatic S7-Station The sensor is connected to the internal Ethernet interface of the S7 CPU using an Ethernet cable M12 connector/RJ45 connector, 4 poles. If the sensor is directly connected to the interface, a crossover cable is recommended. If it is connected to the S7 CPU via a switch, patch cables have to be used 7 3 Generate the function block O2Dxxx_TCP in the S7 Project The function block is created in TIA Portal software version 14 service pack 1. To be independent of existing versions of TIA Portal software, the function block is delivered as SCL source file. From this file the function block can be generated. In the folder External source files double-click Add new external file. A dialogue opens. browse to the source file and add it to the project Figure 9 right-click the added source file in the context menu select Generate blocks from source The function block O2Dxxx_TCP will be generated. Figure 10 8 4 Description of the parameter of the function block O2Dxxx_TCP Figure 11 IN parameters: Name Data type Description LocIF_ID UINT hardware identifier of the used CPU Ethernet-interface (see Figure 8) LocPortNo UINT port number of the CPU to use for this TCP-connection (unused port in the range 2000 .. 5000 is recommended) RemIPAddr1..4 USINT IP address of the sensor RemPortNo UINT TCP/IP port-number of the sensor (see Figure 2) Connect BOOL activate the TCP-connection to the sensor ConnID UINT unique number as internal identifier for this TCP-connection (valid range 1 .. 4096) TimeoutTime TIME max. waiting time for response from the sensor Trigger BOOL rising edge starts a trigger task ChangeApp BOOL rising edge starts a task to change to the application assigned to the input parameter AppNo AppNo UINT application number to activate in the sensor Table 1 9 IN-OUT parameters: Name Data type Description Data VARIANT receive buffer for the trigger response data from the sensor (only data type ARRAY OF CHAR or ARRAY OF BYTE valid) Name Data-type Description Busy BOOL no new task possible Done BOOL task completed without error Error BOOL task terminated with error Status WORD status or error code (see Chapter 6) ExtStatus WORD additional status or error code ActAppNo UINT actual application number active in the sensor RcvdLen UINT data length in the receive buffer Table 2 OUT parameters: Table 3 5 Call of the function block in the user program The function block O2Dxxx_TCP must be called for each connected O2Dxxx sensor once per PLC cycle with different instance data. After start-up of the PLC each instance of the function block must be called first with parameter Connect = FALSE to ensure correct signal flow. Establish the TCP-connection to the sensor Done Figure 12 10 0x7000 0x7804 0x7803 0x7802 Status 0x7801 Error 0x2003 The function block O2Dxxx_TCP uses the Siemens function block TRCV_C to establish a TCP-connection to the process interface of the sensor. The process interface will be set to protocol V3 and the active application number is read from the sensor. After completion the function block resets output Busy = FALSE. The function block is now ready to receive data or execute a task. Busy 0x2002 input parameter Connect = TRUE 0x2001 Connect 0x1002 As long the input parameter Connect = FALSE the output parameter Busy = TRUE. The output parameter Status = 0x1000 shows no connection is established. 0x1000 5.1 Basically, the Siemens function block TRCV_C checks the status of the TCP-connection and re-establish it after an interruption. To detect an interruption faster, while inactivity the function block O2Dxxx_TCP sends periodic a command to the sensor and checks if the process interface responds. Usually the connection to the sensor is established and hold with Connect = TRUE. In case it is necessary the TCP-connection can be terminated with Connect = FALSE. 5.2 General procedure of a task A task is an execution of a single command or a sequence of commands. For example by changing the active application in the sensor, after the changing command is completed the active application number is read from the sensor. Each command is completed only after receiving the response from the sensor. This means a task stretches over several PLC cycles. The actual status of the task processing is displayed in the output parameter Status. The output parameter ExtStatus shows the status of the Siemens function block TRCV_C. In the user program basically it is enough to check the output parameters Busy, Done and Error of the function block O2Dxxx_TCP. Busy = TRUE : no new task possible. Reason: A task is already in process or a permanent error is detected. Busy = FALSE: ready for starting a new task At the end of a task the output parameters Done and Error show the result if the task was completed successfully or not. 5.3 Task to trigger the sensor via the process interface requirement Trigger type of the active application in the sensor = Process interface (see Figure 6) Busy = FALSE start of the task Trigger = FALSE TRUE actions of the function block Busy = TRUE Done = FALSE Error = FALSE Status = status code of the task processing ExtStatus = status code of the Siemens function block TRCV_C RcvdLen = 0 initialize the receive buffer send trigger-command to the sensor receive response data from the sensor end of the task Busy = FALSE result no error occurred Done Status ExtStatus RcvdLen = TRUE = 0x0000 = status code of task processing = length of the response data error occurred Error = TRUE Status = 0x8*** ExtStatus = additional error code receive buffer = trigger response data (see Figure 5) The data is valid only if no error occurred. Table 4 The result is kept as long the input parameter Trigger = TRUE or a task to change the active application is started. Is the input parameter Trigger already reset before the task is finished the result will be displayed for 11 only one PLC cycle. The trigger response data in the receive buffer are kept until a new task is started. As an example the signal flow is shown in in Figure 13. no error occurred error occurred Connect Trigger Busy Done Figure 13 5.4 Task to change the active application in the sensor requirement External selection of the application = Off (see Figure 1) Busy = FALSE AppNo = application number to activate in the sensor start of the task ChangeApp = FALSE TRUE actions of the function block Busy = TRUE Done = FALSE Error = FALSE Status = status code of the task processing ExtStatus = status code of the Siemens function block TRCV_C ActAppNo = 0 RcvdLen =0 initialize the receive buffer send command to activate the assigned application in the sensor receive acknowledge from the sensor read active application from the sensor end of the task Busy = FALSE result no error occurred Done Status ExtStatus ActAppNo = TRUE = 0x0000 = status code of the task processing = active application error occurred Error Status ExtStatus ActAppNo = TRUE = 0x8*** = additional error code = active application Table 5 12 0x7000 0x8*** 0x790* 0x7000 0x8*** 0x790* 0x7000 0x0000 0x790* 0x7000 0x0000 0x790* Status 0x7000 Error The result is kept as long the input parameter ChangeApp = TRUE or a task to trigger the sensor is started. Is the input parameter ChangeApp already reset before the task is finished the result will be displayed for only one PLC cycle. As an example the signal flow is shown in in Figure 13 for a trigger task. For the task to change the active application applies the same behaviour. 6 Description of the values of the output parameter Status Status codes Status Description 0x0000 task completed without error 0x1000 0x1001 0x1002 no TCP-connection (Connect = FALSE) terminate TCP-connection establish TCP-connection 0x2001 0x2002 0x2003 send command to set the protocol version in the sensor wait for response from the sensor wait for protocol version acknowledged from the sensor 0x3000 process interface of the sensor not available 0x7000 wait for start of a task 0x7001 0x7002 0x7003 0x7004 ping: send command ping: receive length information ping: receive response data flush TCP-stack 0x7201 0x7202 0x7203 0x7204 read error code from the sensor: send command read error code from the sensor: receive length information read error code from the sensor: receive response data flush TCP-stack 0x7401 0x7402 0x7403 0x7404 change the active application in the sensor: send command change the active application in the sensor: receive length information change the active application in the sensor: receive response data flush TCP-stack 0x7801 0x7802 0x7803 0x7804 read the active application from the sensor: send command read the active application from the sensor: receive length information read the active application from the sensor: receive response data flush TCP-stack 0x7901 0x7902 0x7903 0x7904 trigger the sensor: send command trigger the sensor: receive length information trigger the sensor: receive and evaluate response data trigger the sensor: receive response data and transfer into the receive buffer 0x8*** error code (see Table 7) Table 6 13 Error codes Status ExtStatus 0x8000 error code of the O2Dxxx sensor for example: Description Command not accepted by the sensor. For complete descriptions of the error codes of the sensor please refer to the Operating instructions of the device. Here a short list of the most common error codes: 0x0100 0x0108 0x0902 0x1000 0x1601 0x1603 0x1604 no application is loaded in the sensor operation mode does not permit the execution of commands application to be activated not found function to trigger the sensor via process interface is not activated (see Figure 6) sensor is currently decoding external selection of application is activated (see Figure 1) trigger cannot be processed (see also error code 0x1000) 0x8001 0x0000 unable to set the sensor to the required protocol Necessary action: Acknowledge the error with input parameter Connect = FALSE. Then establish a new connection to the sensor. 0x8101 0x0000 receive buffer invalid (parameter Data does not point to an ARRAY OF CHAR or an ARRAY OF BYTE) 0x8201 0x8203 error by establishing TCP-connection error code of Siemens function block TRCV_C for example: error by receiving TCP-data For complete descriptions of the error codes of the Siemens function block TRCV_C please refer to the Siemens-Documentation of the function block. Here a short list of the most common error codes: 0x8085 0x8086 0x8087 0x8091 0x809B parameter LEN or DATA changed after first call or out of range parameter ConnID out of range maximum number of connections reached, no additional connection possible maximum nesting depth exceeded parameter LocIF_ID does not point to the CPU Ethernet-interface 0x80A1 - connection or port already being used by the user - the specified connection has not yet been established - the specified connection is being terminated - the interface is being re-initialized 0x80A4 IP-address at parameter RemIPAddr invalid or match the local IP-address 0x80C3 - all connection resources are in use - a block with this ID is already processed in an different priority group 0x80C4 - the connection cannot be established at this time - the connection is being established 0x80C6 0x8922 0x8932 0x8A3A the remote partner cannot be reached (network error) parameter Data invalid target area, the area does not exist in the DB parameter Data DB number is too high parameter Data no access to the data area (e.g. DB does not exist) 14 0x8204 Error code of the Siemens-function block TSEND For example: Error by sending TCP-data For complete descriptions of the error codes of the Siemens function block TSEND please refer to the Siemens-Documentation of the function block. Here a short list of the most common error codes: 0x80A1 - the specified connection has not yet been established - the specified connection is being terminated - the interface is being re-initialized 0x80C3 - internal lack of resources - a block with this ID is already processed in an different priority group 0x80C4 - the connection cannot be established at this time - the connection is being established 0x80C5 0x80C6 0x80C7 connection terminated by the communication partner the remote partner cannot be reached (network error) execution timeout 0x8205 0x0000 The sensor does not respond within the max. waiting time. Check parameter TimeoutTime 0x8206 0x0000 process interface of the sensor not accessible 0x8300 0x0000 The sensor received an unknown or incomplete command. Response from sensor = ? 0x8301 0x0000 start of a task requested while output parameter Busy = TRUE 0x8302 0x0000 start of a task requested while input parameter Connect = FALSE 0x8303 0x0000 start of more than one task simultaneously 0x8400 Error code of the Siemens function MOVE_BLK_ VARIANT for example: 0x8483 0x8534 0x8401 real length of the response data (hexadecimal) 0x8402 0x0000 Error by access to the receive buffer For complete descriptions of the error codes of the Siemens function MOVE_BLK_VARIANT please refer to the Siemens-Documentation of the function. Here a short list of the most common error codes: receive buffer at parameter Data is too small for the response data receive buffer at parameter Data is write protected Receive buffer at parameter Data is too small for the response data. As much as possible data are stored in the receive buffer. The rest will be lost. error by interpreting the length information of the response data Table 7 15