TcpConnect

PLCopen motion icon

 Function Block - Creates a new socket and performs the connect operation.

Inputs

Input

Data Type

Range

Unit

Default

Description

Execute

BOOL

0 to 1

N/A

No default

On the rising edge, request to connect a socket to a server.

Address

STRING

N/A

N/A

No default

The IP Address of the remote server.

Port

DINT

N/A

User units

No default

The network port to use.

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.

ID

UDINT

 

 

The ID of the client socket.

Remarks


  • It is possible that the function returns a valid socket ID even if the connection to the server is not yet actually performed.
    After calling this function, use the TcpIsConnected function block to know if the connection is ready.
  • Use the TcpClose function block to release the socket returned by TcpConnect.
  • This function block uses the default TCP settings and a specified server address and port.

Figure 1: TcpConnect

FBD Language Example

Not available.

FFLD Language Example

Not available.

IL Language Example

Not available.

ST Language Example

(* TcpConnect example *)
CASE StepCounter OF
0:
  Inst_TcpConnect(TRUE, '192.168.1.1', 1234);
  StepCounter := StepCounter + 1;
1:
  Inst_TcpConnect(TRUE, '192.168.1.1', 1234);
  IF Inst_TcpConnect.Done THEN
     MySocketID := Inst_TcpConnect.ID;
     Inst_TcpConnect(FALSE, '', 0);
     StepCounter := StepCounter + 1;
  END_IF;
END_CASE;

See Also