• 沒有找到結果。

Programming instructions 6

6.2 Extended instructions

6.2.4 Communications instructions

6.2.4.1 LEN and DATA parameter usage for communication instructions

LEN and DATA as send parameters for TSEND, TSEND_C, and PTP_SEND

You may use all data types except BOOL and arrays of BOOL for the DATA parameter. The LEN parameter defines the count of transferred bytes.

LEN = 0

The complete data is sent as defined at the DATA parameter. You do not need to specify the number of transmitted bytes when LEN = 0.

DATA reference to

send LEN > 0

Elementary data type: The LEN value must contain the byte count of this data type. Otherwise, nothing is transferred and the error 8088H is returned.

Structure data type The LEN value may contain a byte count less than the complete byte length of the structure. In this case, only the first LEN bytes are transferred.

Array data type The LEN value may contain a byte count that is less than the complete byte length of the array. In this case, only array elements which fit completely in LEN bytes are transferred.

The LEN value must be a multiple of the data element byte count.

Otherwise, STATUS = 8088H, ERROR = 1, and no transmit occurs.

String data type: The complete memory layout of the string format is transferred. The LEN value must include bytes for maximum length, actual length, and the string characters.

For the STRING data type, all lengths and characters have a byte size.

If a string is used as actual parameter at the DATA parameter, the LEN value must also include two bytes for the two length fields.

LEN and DATA as receive parameters for TRCV, TRCV_C, and PTP_RCV

You may use all data types except BOOL and arrays of BOOL for the DATA parameter. The received data is interpreted as if the sender had used the same data type referenced by the receiver DATA parameter.

LEN = 0

Data which fits in the DATA reference can be received. You do not need to specify the number of received bytes when LEN = 0. The actual count of received bytes is returned by the RCVD_LEN parameter.

长沙工控帮教育科技有限公司整理

Programming instructions 6.2 Extended instructions

DATA reference

for received data LEN > 0 Elementary data

type: The LEN value must contain the byte count of this data type. Otherwise, the STATUS parameter is set to 8088H, ERROR is set to 1, and nothing can be received.

Structure data type in DB created with

"Symbolic access only" disabled

The LEN value may contain a byte count less than the complete byte length of the structure. In this case only, the first LEN bytes of the structure are received.

Structure data type in DB created with

"Symbolic access only" enabled

The LEN value must be equal to zero. Otherwise, the data are not transferred, STATUS is set to 8088H, and ERROR is set to 1.

Array data type The LEN value may be a byte count less than the complete byte length of the array.

String data type: If LEN>1, then the received data is interpreted as follows:

Byte 1 - Unchanged maximum length

Byte 2 - Current length will be the smallest of these values – Requested LEN - 2 bytes for max and current lengths – Current length of the received string

– Maximum length of the string

Bytes 3, 4, 5, ..., up to the maximum length - String characters

If LEN = 1 and the DATA parameter references a STRING data type, then the error 8088H is returned. Two bytes, where LEN = 2, are necessary to store the maximum and current string length bytes. Three bytes, where LEN = 3, are necessary to store the two length bytes and one string character.

If a string is used as actual parameter at the DATA parameter, the LEN value must also include two bytes for the two length fields.

6.2.4.2 Open Ethernet Communication

Open Ethernet communication with automatic connect/disconnect (TSEND_C and TRCV_C)

TSEND_C description

TSEND_C establishes a TCP or ISO on TCP communication connection to a partner station, sends data, and can terminate the connection. After the connection is set up and

established, it is automatically maintained and monitored by the CPU. TSEND_C combines the functions of TCON, TDISCON and TSEND.

TSEND_C function

● To establish a connection, execute TSEND_C with CONT = 1.

● After successful establishing of the connection, TSEND_C sets the DONE parameter for one cycle.

长沙工控帮教育科技有限公司整理

Programming instructions 6.2 Extended instructions

● To terminate the communication connection, execute TSEND_C with CONT = 0. The connection will be aborted immediately. This also affects the receiving station. The connection will be closed there and data inside the receive buffer could be lost.

● To send data over an established connection, execute TSEND_C with a rising edge on REQ. After a successful send operation, TSEND_C sets the DONE parameter for one cycle.

● To establish a connection and send data, execute TSEND_C with CONT =1 and REQ = 1. After a successful send operation, TSEND_C sets the DONE parameter for one cycle.

TRCV_C description

TRCV_C establishes a TCP or ISO on TCP communication connection to a partner CPU, receives data, and can terminate the connection. After the connection is set up and established, it is automatically maintained and monitored by the CPU. The TRCV_C instruction combines the functions of the TCON, TDISCON, and TRCV instructions.

TRCV_C function

1. Establish a connection: Execute TRCV_C with parameter CONT = 1.

2. Receive data: Execute TRCV_C with parameter EN_R = 1. Receive data continuously when parameters EN_R = 1 and CONT = 1.

3. Terminate the connection: execute TRCV_C with parameter CONT = 0. The connection will be aborted immediately and data could be lost.

Receive modes

TRCV_C handles the same receive modes as the TRCV instruction.

The following table shows how data is entered in the receive area.

Protocol

variant Entering the data in the receive

area Parameter"

connection_type" Value of the LEN parameter

TCP Ad hoc mode B#16#11 0

TCP Data reception with specified

length B#16#11 <> 0

ISO on TCP protocol-controlled B#16#12 0 (recommended) or <> 0

TCP / ad hoc mode

The ad hoc mode exists only with the TCP protocol variant. You set ad hoc mode by assigning 0 to the LEN parameter.

The receive area is identical to the area formed by DATA. A maximum of 1472 bytes are received.

长沙工控帮教育科技有限公司整理

Programming instructions 6.2 Extended instructions

TCP / data reception with specified length

You set data reception with specified length by assigning a value other than 0 to the LEN parameter.

The receive area is defined by the LEN and DATA parameters.

ISO on TCP / protocol-controlled data transfer

With the ISO on TCP protocol variant, data is transferred protocol-controlled.

The receive area is defined by the LEN and DATA parameters.

Note

Due to the asynchronous processing of TSEND_C, you must keep the data in the sender area consistent until the DONE parameter or the ERROR parameter assumes the values TRUE.

For TSEND_C, a TRUE state at the parameter DONE means that the data was sent successfully. It does not mean that the connection partner CPU actually read the receive buffer.

Due to the asynchronous processing of TRCV_C, the data in the receiver area are only consistent when parameter DONE = 1.

The following table shows the relationships between parameters BUSY, DONE and ERROR.

BUSY DONE ERROR Description

TRUE irrelevant irrelevant The job is being processed.

FALSE TRUE FALSE The job successfully completed.

FALSE FALSE TRUE The job was ended with an error. The cause of the error can be found in the STATUS parameter.

FALSE FALSE FALSE A new job was not assigned.

TSEND_C parameters

LAD FBD

长沙工控帮教育科技有限公司整理

Programming instructions 6.2 Extended instructions

Parameter Parameter

type Data type Description

REQ INPUT BOOL Control parameter REQ starts the send job with the connection described in CONNECT on a rising edge.

CONT INPUT BOOL Control parameter CONT:

0: disconnect

1: establish and hold connection

LEN INPUT INT Maximum number of bytes to be sent with the job.

Refer to Relationship between CPU and Protocol Variant and Transferable Data Length.

CONNECT IN_OUT ANY Pointer to the connection description

DATA IN_OUT ANY Send area; contains address and length of data to be sent.

COM_RST IN_OUT BOOL COM_RST parameter:

1: Complete restart of the function block, existing connection will be terminated.

DONE OUTPUT BOOL DONE status parameter:

0: Job not yet started or still running.

1: Job executed without error.

BUSY OUTPUT BOOL BUSY status parameter:

0: Job is completed.

1: Job is not yet completed. A new job cannot be triggered.

ERROR OUTPUT BOOL ERROR status parameter:

1: Error occurred during processing. STATUS provides detailed information on the type of error.

STATUS OUTPUT WORD STATUS status parameter: Error information

TRCV_C parameters

LAD FBD

长沙工控帮教育科技有限公司整理

Programming instructions 6.2 Extended instructions

Parameter Parameter

type Data type Description

EN_R IN BOOL Control parameter enabled to receive: When EN_R = 1, TRCV_C is ready to receive. The receive job is

processed.

CONT IN BOOL Control parameter CONT:

0: disconnect

1: establish and hold connection

LEN IN INT Length of the receive area in bytes

For the meaning of LEN = 0 or LEN <> 0 see above (receive modes).

For the value ranges, see Relationship between CPU and Protocol Variant (connection_type) and Transferable Data Length.

CONNECT IN_OUT ANY Pointer to the connection description

DATA IN_OUT ANY Receive area contains start address and maximum length of received data.

COM_RST IN_OUT BOOL COM_RST parameter:

1: Complete restart of the function block; existing connection will be terminated.

DONE OUT BOOL Status parameter DONE:

0: Job not yet started or still running.

1: Job executed without error.

BUSY OUT BOOL BUSY status parameter:

0: Job is completed.

1: Job is not yet completed. A new job cannot be triggered.

ERROR OUT BOOL ERROR status parameter:

1: Error occurred during processing. STATUS provides detailed information on the type of error.

STATUS OUT WORD STATUS status parameter: Error information RCVD_LEN OUT INT Amount of data actually received, in bytes

Parameters Error and Status

ERROR STATUS (W#16#...)

Description

0 0000 Job executed without error 0 7000 No job processing active

0 7001 Start job processing, establishing connection, waiting for connection partner 0 7002 Data being sent or received

0 7003 Connection being terminated

0 7004 Connection established and monitored, no job processing active

长沙工控帮教育科技有限公司整理

Programming instructions 6.2 Extended instructions

ERROR STATUS (W#16#...)

Description

1 8085 LEN parameter has the value 0 or is greater than the largest permitted value 1 8086 The CONNECT parameter is outside the permitted range

1 8087 Maximum number of connections reached; no additional connection possible

1 8088 LEN parameter is larger than the memory area specified in DATA; receiving memory area is too small

1 8089 The parameter CONNECT parameter does not point to a data block.

1 8091 Maximum nesting depth exceeded

1 809A The CONNECT parameter points to a field that does not match the length of the connection description.

1 809B The local_device_id in the connection description does not match the CPU.

1 80A1 Communications error:

The specified connection was not yet established

The specified connection is currently being terminated; transmission over this connection is not possible

The interface is being reinitialized

1 80A3 Attempt being made to terminate a nonexistent connection

1 80A4 IP address of the remote partner connection is invalid. For example, the remote partner IP address is the same as the local partner IP address.

1 80A7 Communications error: you have called TDISCON before TCON was complete (TDISCON must first completely terminate the connection referenced by the ID)

1 80B2 The parameter CONNECT parameter points to a data block that was generated with the keyword UNLINKED

1 80B3 Inconsistent parameters:

Error in the connection description

Local port (parameter local_tsap_id) is already present in another connection description

ID in the connection description different from the ID specified as parameter

1 80B4 When using the ISO on TCP (connection_type = B#16#12) to establish a passive connection, condition code 80B4 alerts you that the TSAP entered did not conform to one of the following address requirements:

For a local TSAP length of 2 and a TSAP ID value of either E0 or E1 (hexadecimal) for the first byte, the second byte must be either 00 or 01.

For a local TSAP length of 3 or greater and a TSAP ID value of either E0 or E1 (hexadecimal) for the first byte, the second byte must be either 00 or 01 and all other bytes must be valid ASCII characters.

For a local TSAP length of 3 or greater and the first byte of the TSAP ID does not have a value of either E0 or E1 (hexadecimal), then all bytes of the TSAP ID must be valid ASCII characters.

Valid ASCII characters are byte values from 20 to 7E (hexadecimal).

1 80C3 All connection resources are in use.

长沙工控帮教育科技有限公司整理

Programming instructions 6.2 Extended instructions

ERROR STATUS (W#16#...)

Description

1 80C4 Temporary communications error:

The connection cannot be established at this time

The interface is receiving new parameters

The configured connection is currently being removed by a TDISCON 1 8722 CONNECT parameter: Source area invalid: area does not exist in DB 1 873A CONNECT parameter: Access to connection description not possible (e.g.

DB not available)

1 877F CONNECT parameter: Internal error such as an invalid ANY reference

Open Ethernet communication with connect/disconnect control

Ethernet communication using TCP and ISO on TCP protocols

These program instructions control the communication process:

1. TCON makes a connection.

2. TSEND and TRCV send and receive data.

3. TDISCON breaks the connection.

Use with TCP and ISO on TCP

Both communication partners execute the TCON instruction to set up and establish the communications connection. You use parameters to specify the active and passive communication end point partners.

After the connection is set up and established, it is automatically maintained and monitored by the CPU.

If the connection is terminated due to a line break or due to the remote communications partner, for example, the active partner attempts to reestablish the configured connection.

You do not have to execute TCON again.

An existing connection is terminated and the set-up connection is removed when the TDISCON instruction is executed or when the CPU has gone into STOP mode. To set up and reestablish the connection, you must execute TCON again.

Functional description

TCON, TDISCON, TSEND, and TRCV operate asynchronously, which means that the job processing extends over multiple instruction executions.

For example, you start a job for setting up and establishing a connection by executing an instruction TCON with parameter REQ = 1. Then you use additional TCON executions to monitor the job progress and test for job completion with parameter DONE.

The following table shows the relationships between BUSY, DONE, and ERROR. Use the table to determine the current job status.

长沙工控帮教育科技有限公司整理

Programming instructions 6.2 Extended instructions

TCON, TDISCON, TSEND, and TRCV job status parameters:

BUSY DONE ERROR Description

TRUE irrelevant irrelevant The job is being processed.

FALSE TRUE FALSE The job successfully completed.

FALSE FALSE TRUE The job was ended with an error. The cause of the error can be found in the STATUS parameter.

FALSE FALSE FALSE A new job was not assigned.

TCON

LAD FBD

Parameter Parameter

type Data type Description

REQ IN BOOL Control parameter REQUEST starts the job for establishing the connection specified by ID. The job starts at rising edge.

ID IN CONN_OUC

(WORD) Reference to the connection to be established to the remote partner, or between the user program and the communication layer of the operating system. ID must be identical to the associated parameter ID in the local connection description.

Value range: W#16#0001 to W#16#0FFF CONNECT IN_OUT TCON-Param Pointer to the connection description

DONE OUT BOOL Status parameter DONE:

0: Job not yet started or still running

1: Job executed without error BUSY OUT BOOL BUSY = 1: Job is not yet complete

BUSY = 0: Job is complete

ERROR OUT BOOL Status parameter ERROR:

ERROR = 1: An error occurred in job processing.

STATUS provides detailed information on the type of error.

STATUS OUT WORD Status parameter STATUS: Error information

长沙工控帮教育科技有限公司整理

Programming instructions 6.2 Extended instructions

TDISCON

LAD FBD

Parameter Parameter

type Data type Description

REQ IN BOOL Control parameter REQUEST starts the job for establishing the connection specified by ID. The job starts at rising edge.

ID IN CONN_OUC

(WORD) Reference to the connection to be terminated to the remote partner or between the user program and the communications level of the operating system. ID must be identical to the associated parameter ID in the local connection description.

Value range: W#16#0001 to W#16#0FFF

DONE OUT BOOL Status parameter DONE:

0: Job not yet started or still running

1: Job executed without error BUSY OUT BOOL BUSY = 1: Job is not yet complete

BUSY = 0: Job is complete

ERROR OUT BOOL ERROR = 1: Error occurred during processing.

STATUS OUT WORD Error code

TCP and ISO on TCP

TDISCON terminates a communications connection from the CPU to a communication partner.

长沙工控帮教育科技有限公司整理

Programming instructions 6.2 Extended instructions

TSEND

LAD FBD

Parameter Parameter

type Data type Description

REQ IN BOOL Control parameter REQUEST starts the send job on a rising edge.

The data is transferred from the area specified by DATA and LEN.

ID IN CONN_OUC

(WORD) Reference to the associated connection. ID must be identical to the associated parameter ID in the local connection description.

Value range: W#16#0001 to W#16#0FFF LEN IN INT Maximum number of bytes to be sent with the job DATA IN_OUT VARIANT Pointer to data area to send:

Sender area; contains address and length. The address refers to:

The process image input table

The process image output table

A bit memory A data block

DONE OUT BOOL Status parameter DONE:

0: Job not yet started or still running.

1: Job executed without error.

BUSY OUT BOOL BUSY = 1: The job is not yet complete. A new job cannot be triggered.

BUSY = 0: Job is complete.

ERROR OUT BOOL Status parameter ERROR:

ERROR = 1: Error occurred during processing.

STATUS provides detailed information on the type of error

STATUS OUT WORD Status parameter STATUS: Error information

长沙工控帮教育科技有限公司整理

Programming instructions 6.2 Extended instructions

Note

Due to the asynchronous processing of TSEND, you must keep the data in the sender area consistent until the DONE parameter or the ERROR parameter assumes the value TRUE.

TRCV

LAD FBD

Parameter Parameter

type Data type Description

EN_R IN BOOL Control parameter enabled to receive: With EN_R = 1, TRCV is ready to receive. The receive job is being processed.

ID IN CONN_OUC

(WORD) Reference to the associated connection. ID must be

(WORD) Reference to the associated connection. ID must be