The following communication functions are available for open user communica- tion with the protocols TCP, ISO-on-TCP, and UDP:
b TCON Establish a connection to the partner station or to the operating system
b TDISCON Disconnect
b TSEND Send data with TCP or ISO-on-TCP b TRCV Receive data with TCP or ISO-on-TCP
b TSEND_C Establish connection and send data with TCP or ISO-on-TCP (replaces TCON, TDISCON, and TSEND)
b TRCV_C Establish connection and receive data with TCP or ISO-on-TCP (replaces TCON, TDISCON, and TRCV)
b TUSEND Send data with UDP b TURCV Receive data with UDP
Fig. 15.5 shows the calls of the functions in ladder logic representation.
Fig. 15.5 Calls of the communication functions for open user communication (LAD) Calling of functions for open communication
Establish connection
Terminate connection
Receiving data with UDP
Establish connection and send data with TCP and ISO-on-TCP
Establish connection and receive data with TCP and ISO-on-TCP
Sending data with TCP and ISO-on-TCP (alternative to TSEND_C) Receiving data with TCP and ISO-on-TCP (alternative to TSEND_C)
Sending data with UDP
Description of common parameters
The communication functions for open user communication work asynchronously, i.e. job processing may require several program cycles under certain circumstanc- es. Use the REQ and EN_R parameters to control the data transmission The status of data transmission is shown by the BUSY, NDR, DONE, ERROR and STATUS parame- ters. You must evaluate these parameters immediately following each processing of the communication function since they are only valid up to the next call.
The CONT parameter with signal state “1” establishes a connection and retains it.
Data transmission – the sending or receiving of data – only functions with the con- nection established. Signal state “0” on this parameter cancels the connection again.
If a rising signal edge occurs at parameter REQ, the task to send data starts. As long as the signal state is “1”, no other task for the specified connection is accepted. Only when the communication function recognizes signal state “0” at REQ, can a new task be started with the change to “1”.
The EN_R parameter activates data reception with signal state “1”. Data receipt is blocked if EN_R has the signal state “0”.
The DONE parameter shows with signal state “1” that the started job has been com- pleted without errors. It is only set for the duration of one program cycle.
The NDR parameter (New Data Ready) shows with signal state “1” that the started job has been completed without errors and that new data has been received. It is only set for the duration of one program cycle.
The BUSY parameter shows with signal state “1” that job processing has not yet been completed and that a new job cannot be started.
The ERROR parameter shows with signal state “1” that the started job has been com- pleted with an error. It is only set for the duration of one program cycle.
The STATUS parameter contains intermediate states or error information.
b If DONE or NDR = “1”, STATUS is occupied by 16#0000.
b If ERROR = “1”, STATUS is occupied by error information.
b If none of these bits is set, STATUS may contain intermediate states which indicate the progress of the started job.
The following parameters specify the data transmission:
The ID parameter identifies the communication connection between the transmit- ting and receiving station, or for UDP the connection between the user program and the communication access point in the CPU operating system.
The CONNECT parameter points to a data block with the data structure of the sys- tem data type TCON_Param, which contains the description of the connection parameters.
The DATA parameter contains the send or receive mailbox for the transferred data.
The send and receive mailbox is a tag, e.g. an ARRAY tag in a data block, or an abso-
lutely addressed range, e.g. a range of 32 bytes in the data block DB 10 starting at byte 64: P#DB10.DBX64.0 BYTE 32.
The ADDR parameter contains the IP address and the port number of the partner station with the data structure of the system data type ADDR_Param.
TSEND_C Establish connection and send data
The communication function TSEND_C establishes a connection, and sends data with the TCP or ISO-on-TCP protocol. TSEND_C can also cancel the connection again.
Establishment of the connection is started if TSEND_C is processed with CONT = “1”.
Following successful establishment, the DONE parameter is set to “1” for the dura- tion of one program cycle. Data is sent via an established connection when a rising edge occurs at the REQ parameter. Following successful transmission, DONE is set to “1” for the duration of one program cycle.
With CONT = “0” the connection is canceled immediately in both the send station and the partner station.
If the COM_RST parameter has signal state “1”, TSEND_C is started again: an exist- ing connection is canceled, and a new one established.
The LEN parameter specifies the maximum number of bytes which are sent.
TRCV_C Establishing a connection and receiving data
The communication function TRCV_C establishes a connection, and receives data with the TCP or ISO-on-TCP protocol. TRCV_C can also cancel the connection again.
Establishment of the connection is started if TRCV_C is processed with CONT = “1”.
Following successful establishment, the DONE parameter is set to “1” for the dura- tion of one program cycle. TRCV_C only receives data when the EN_R parameter has signal state “1”. Following successful receipt of data, the DONE parameter is set to
“1” for the duration of one program cycle. Data is received continuously if CONT =
“1” and EN_R = “1”.
With CONT = “0” the connection is canceled immediately in both the send station and the partner station.
If the COM_RST parameter has signal state “1”, TRCV_C is started again: an existing connection is canceled, and a new one established.
The parameter LEN specifies the number of bytes received. If LEN is filled with zero, as many bytes are received as contained in the tag at the DATA parameter. After suc- cessful data transmission, the parameter RCVD_LEN contains the number of bytes actually transmitted.
Data transmission with TCON, TDISCON, TSEND and TRCV
TCON establishes a communication connection to the partner device. The ID parameter identifies the connection. The specification must correspond to the id tag in the connection data at the parameter CONNECT.
The TSEND function sends data with the TCP or ISO-on-TCP protocol over an existing communication connection specified by the ID parameter. The DATA parameter contains a pointer to the send mailbox. You can use the LEN parameter to specify the maximum number of bytes to be sent.
The TRCV function receives data with the TCP or ISO-on-TCP protocol over an exist- ing communication connection specified by the ID parameter. The DATA parameter contains a pointer to the receive mailbox. You can use the LEN parameter to specify the number of bytes to be received. If LEN is “0”, the number of bytes received cor- responds to the tag at the DATA parameter. Following successful data transmission, the RCVD_LEN parameter contains the number of actually transmitted bytes.
TDISCON terminates the communication connection specified at the ID parameter and releases the connection resources.
TUSEND Send data with the UDP protocol
The TUSEND communication function sends data with the UDP protocol. A prereq- uisite is the previous establishment of a communication access point by TCON.
The assignment of the ID parameter designates the connection between the user program and the communication access point of the operating system. The value must agree with the id tag in the connection data. Specify the send mailbox with a pointer at the DATA parameter.
The information on the communication partner is located in a data area to which the pointer at the ADDR parameter points. With each new send job, the address and thus the partner can be changed without having to redefine the communication access point with TCON.
In the initial state, the REQ, BUSY, DONE, and ERROR parameters have signal state
“0”. Start data transfer with a rising edge at the REQ parameter. On the initial call with “1”, the data is fetched from the area specified by the DATA parameter. The number of bytes specified at the LEN parameter is sent (1 to max. 1460).
While the job is running, BUSY = “1”. The job has been successfully completed if BUSY = “0”, DONE = “1”, and ERROR = “0”. If the job contains errors, then BUSY =
“0”, DONE = “0”, and ERROR = “1”. The error is then specified at the STATUS param- eter. BUSY, DONE, and ERROR are reset to “0” if REQ is returned to “0”.
The data in the send area can then be modified again when either DONE or ERROR has signal state “1”.
TURCV Receive data with the UDP protocol
The communication function TURCV receives data with the UDP protocol. A prereq- uisite is the previous establishment of a communication access point by TCON.
The assignment of the ID parameter designates the connection between the user program and the communication access point of the operating system. The value must agree with the id tag in the connection data. Specify the receive mailbox with a pointer at the DATA parameter.
The information on the communication partner is located in a data area to which the pointer at the ADDR parameter points. The number of bytes to be received is set at the LEN parameter (1 to max. 1460). After a data block has been received, the number of bytes received is made available at the RCVD_LEN parameter and NDR is set to signal state “1”. Data is only received if the EN_R parameter has signal state
“1”.
While the job is running, BUSY = “1”. The job has been successfully completed if BUSY = “0”, NDR = “1”, and ERROR = “0”. If the job contains errors, BUSY = “0”, NDR
= “0”, and ERROR = “1”. The error is then specified at the STATUS parameter. BUSY, NDR, and ERROR are reset to “0” if EN_R is returned to “0”.
The data in the receive area is consistent if NDR has signal state “1”.