1. TCP receive TCP-RECV

1. TCP receive TCP-RECV

1.1. Instruction Description

Free port data receiving instruction, which can be used for the data receiving function of the free port after successful connection using TCP-CONNECT

1.2. Instruction parameters

1. Socket: Set the number of the connection established between the local IP and the remote IP, ranging from K0 (seckcot0) to K5 (seckcot5)

2. Data: Store the received data in an area starting from Dn, and this operand can only select the D data register;

3. Reception length: This parameter does not need to be set. During the data reception process, it will automatically return the actual received data length and store it in the set D register. It can receive up to 1460Byte of data

4. Completion bit: After completing one data reception, set this register to 1. Reset this register when starting the second reception, and pass NULL to not retrieve the completion status

5. Error bit: When an error occurs using this instruction, set this register to 1 and pass NULL to retrieve the status

6. Error Code: Returns error code values for different errors, as shown in the table below, which can be passed in as NULL but not retrieved

Error code Error description
0x00 No errors
0x01 Reception failed

1.3. The valid operands of the instruction

Input/Output Data Type operand Description
SOCKET 16 bit unsigned integer K/H Socket
DATA 16 bit unsigned integer D Data
LEN 16 bit unsigned integer D/CV/TV/AO/V/Z, bit composite word (Y/M/C/T/S), local variable (LW) accepted length
DONE ON/OFF M/NULL Finish bit
E ON/OFF M/NULL Error bit
C 16 bit unsigned integer D/NULL Error code

1.4. Example

As shown in the figure below, before using TCP-RECV, it is also necessary to use the TCP-CONNECT command to establish a connection. The TCP-CONNECT command uses the settings parameters described earlier to establish a client (active connection). The socket is K0, which is used in conjunction with the TCP-SEND instruction to demonstrate the sending and receiving function. This function is to return the received data to the remote server every time a frame of data is received after the connection is successfully established (M1000 register is the connection completion bit).

command table:

NETWORK 000

LD M0

MPS

MEP

MOV K192 D5000

MOV K168 D5001

MOV K1 D5002

MOV K11 D5003

MPP

TCP-CONNECT K0 D5000 K2000 K0 K65535 M1000 M1001 D5006

POP

LD M1000

MPS

ANDP M1004

TCP-SEND K0 D1000 D3000 M1002 M1003 D5007

MPP

TCP-RECV K0 D1000 D3000 M1004 M1005 D5008

POP

TCPRECV1

图1 TCPRECV1

TCPRECV2

图2 TCPRECV2

TCPRECV3

图3 TCPRECV3