TcpListen

PLCopen motion icon

 Function Block - Creates a new socket by performing the bind and listen operations.

Inputs

Input

Data Type

Range

Unit

Default

Description

Execute

BOOL

0 to 1

N/A

No default

On the rising edge, listen for socket connections.

Port

DINT

N/A

User units

No default

The network port to use.

Backlog

DINT

N/A

N/A

No default

The size of the queue for pending connections.

If more than Backlog number of connection attempts are made prior to a TcpAccept call, the controller may refuse the connections.

Outputs

Output

Data Type

Range

Unit

Description

Done

BOOL

 

 

If TRUE, the command completed successfully.

Error

BOOL

 

 

If TRUE, an error has occurred.

ErrorID

DINT

 

 

Indicates the error if Error output is TRUE.

See the table in File and TCP/IP Function Block ErrorIDs.

ListenID

UDINT

 

 

The ID of the new listen socket.

Remarks

  • This function block uses the default TCP settings.
  • Use the TcpClose function block to release the socket returned by TcpListen.

Figure 1: TcpListen

FBD Language Example

Not available.

FFLD Language Example

Not available.

IL Language Example

Not available.

ST Language Example

(* TcpListen example *)
CASE StepCounter OF
0:
  Inst_TcpListen(TRUE, 1234, 2);
  StepCounter := StepCounter + 1;
1:
  Inst_TcpListen(TRUE, 1234, 2);
  IF Inst_TcpListen.Done THEN
     MyListenID := Inst_TcpListen.ListenID;
     Inst_TcpListen(FALSE, 0, 0);
     StepCounter := StepCounter + 1;
  END_IF;
END_CASE;

See Also