SOCKET_OPEN

The SOCKET_OPEN instruction opens the connection for the specified destination address for Transmission Control Protocol (TCP) connections. For User Datagram Protocol (UDP) connections, associates a destination IP address and port number with the specified socket.
Operations details:
  • For User Datagram Protocol (UDP) connections using
    SOCKET_OPEN
    , the IP address and port number are not required each time data is sent.
  • For UDP connections not using
    SOCKET_OPEN
    , the destination address must be specified each time
    SOCKET_WRITE
    is used to send data.
  • When using
    SOCKET_READ
    , in addition to receiving data, the address of the sender is returned. The senders address can be used to send a response using
    SOCKET_WRITE
    .
  • A
    SOCKET_OPEN
    operation might return before the timeout period without creating a Transmission Control Protocol (TCP) connection. This might occur if the destination device is running but is not listening for connections on the specified port number.
    SOCKET_OPEN
    returns with an error before the timeout period.
  • Outputs update synchronously from the program scan.
Languages supported: Function block diagram, ladder diagram, structured text.
This instruction applies to the L20E, L50E, and L70E controllers.
SOCKET_OPEN
SOCKET_OPEN
SOCKET_OPEN parameters
Parameter
Parameter Type
Data Type
Description
Execute
Input
BOOL
Instruction block enable.
  • TRUE: Rising Edge detected; start the instruction block with the precondition that the last operation has been completed.
  • FALSE: No Rising Edge detected.
Instance
Input
UDINT
Copy from the returned Socket Handler from a SOCKET_CREATE function block.
Timeout
Input
UDINT
Timeout for SOCKET_OPEN function block.
The function block returns an Error if the Timeout value is less than the minimum value.
Timeout range: 1000-1800000 milliseconds
Set Timeout to 0 to use the default value 10000 (10 Second).
DestAddr
Input
The address of the destination connection.
A connection between the IP address and the port number of remote host is required.
The following IP Addresses are not supported for DestAddr:
  • Self IP Address
  • Loop back address
  • 0.0.0.0
  • Broadcast address (Only supported for TCP), exception addresses:
  • Class D multicast address (224.x.x.x)
  • Local link address (169.254.x.x)
Example for IP Address of 192.168.2.100 and Port 12000:
  • DestAddr.IPAddress[0]=192
  • DestAddr.IPAddress[1]=168
  • DestAddr.IPAddress[2]=2
  • DestAddr.IPAddress[3]=100
  • DestAddr.Port = 12000
EnUDPRxFilter
Input
BOOL
For UDP socket, when SOCKET_OPEN and Enable EnUDPRxFilter are used, a packet filter for specific IP address and port number is not needed each time to read data.
  • A UDP socket with open is created. DestAddr as IP 192.168.1.157 / Port 161. EnUDPRxFilter Enable, perform Socket_Read.
  • When controller receive data from DestAddr (192.168.1.157 / 161),  Socket_Read completes the operation successfully. If controller receives data from any other IP or Port, socket_Read ignores that packet and waits for DestAddr Packet.
EnUDPRxFilter Disabled:
  • Perform SOCKET_READ. The controller receives any data on configure UDP port, SOCKET_READ completes operation successfully.
  • The application checks whether the incoming packet arrives from the expected device.
  • The application handles filtering based on the SOCKET_READ output parameter UDPAddr.
Done
Output
BOOL
Indicates when operation is complete.
  • TRUE: Operation completed successfully.
  • FALSE: Operation is in progress or encountered an error condition.
Output is updated synchronously from the program scan.
Busy
Output
BOOL
  • TRUE: The operation is not finished.
  • FALSE: The operation is finished.
Output is updated synchronously from the program scan.
Error
Output
BOOL
Indicates an error occurred.
  • TRUE: An error is detected.
  • FALSE: No error.
Output is updated synchronously from the program scan.
Status
Output
SOCK_STATUS
Status is defined using the SOCK_STATUS data type which contains ErrorID, SubErrorID, and StatusBits information.
Output is updated synchronously from the program scan.

SOCKET_OPEN examples

SOCKET_OPEN function block diagram example
SOCKET_OPEN function block diagram example
SOCKET_OPEN ladder diagram example
SOCKET_OPEN ladder diagram example
SOCKET_OPEN structured text example
SOCKET_OPEN structured text example
Results - TCP
Results - TCP
Results - UDP
Results - UDP
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.
Normal