SOCKET_CREATE

Creates an instance of the socket and returns an instance number that is used as an input in any follow-on socket operations.
Operation details:
  • Sockets instructions support full-duplex communication with remote devices.
  • User Datagram Protocol (UDP) connections support a maximum of eight queued UDP datagrams packets. The queue contains the most recent packets.
  • Micro820 controllers of revision 9 or later support up to eight Socket Instances. The Socket instances support UDP and TCP Sockets:
    • Use all eight instances for client Transmission Control Protocol (TCP) connections.
    • Use all eight instances to listen for incoming TCP connections, and then accept eight connections from other devices.
    • Perform both TCP client and server operations.
    • Perform both TCP and UDP operations.
  • To accept incoming TCP connections to the same port, create a Socket Instance.
  • TCP Connection Loss:
    • User application program should detect the loss of TCP connections and handle the event. Depending on the user application, consider the option to Fault the controller.
      • Fault the controller.
      • Try to re-establish the connection.
  • To re-establish communications with another device:
    • Delete the Socket Instance for the lost connection.
    • If the connection is a TCP client, create a Socket Instance using SOCKET_CREATE and execute SOCKET_OPEN to the target device.
    • If the connection is a TCP server, create a Socket Instance using SOCKET_CREATE and execute SOCKET_ACCEPT to wait for another connection from the remote device.
  • Application Messages for TCP connections:
    • A TCP connection is a byte stream between two applications. The application protocol determines the message formats.
    • Messages can be fixed size or variable size.
Languages supported: Function block diagram, ladder diagram, structured text.
This instruction applies to the L20E, L50E, and L70E controllers.
SOCKET_CREATE
SOCKET_CREATE
SOCKET_CREATE 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.
Type
Input
USINT
Specify the Type of Socket:
  • Transmission Control Protocol (TCP)
  • User Datagram Protocol (UDP)
SockAddr
Input
SOCKADDR_CFG
Specify the address configuration for the socket.
The EtherNet/IP module to choose the local port number, set SockAddr to 0.
Specify the local port number where an application is listening and receiving, or :
  • Array elements must all be zero.
  • For TCP client operations, specify 0 unless you want a specific local port number.
  • For TCP server communication, specify the port number to accept incoming connection requests.
  • For UDP, specify a local port number to receive datagrams on a specific port.
Local port range: From 1 through 65535.
An error occurs if the specified local port number is already in use by the L20E or L50E controller.
The controller uses the following port numbers:
TCP Ports:
  • EtherNet/IP: 44818
  • ModbusTCP: 502
  • DHCP Server: 67
  • DHCP Client: 68
UDP Ports:
  • EtherNet/IP: 2222
  • DHCP Server: 67
  • DHCP Client: 68
Timeout
Input
UDINT
Specify the Timeout for Socket inactivity.
If a socket instance does not receive any requests within the specified inactivity timeout, the socket instance is deleted.
If a request is sent after the sock instance is deleted an error, Socket instance not supported, is returned.
The instruction block returns an error when the timeout value is less than the minimum value.
Set Timeout so that it is longer than the longest interval between socket operations. If the inactivity Timeout is too short, socket instances might time out. Timeout range: 1000-86400000 milliseconds.
Set Timeout to 0 to use the default value 300000 (5 minutes).
Done
Output
BOOL
Indicates when operation is complete.
  • TRUE: Operation completed successfully.
  • FALSE: Operation is in progress or encountered an error condition.
Busy
Output
BOOL
  • TRUE: The operation is incomplete.
  • FALSE: The operation is complete.
Error
Output
BOOL
Indicates that an error occurred.
  • TRUE: An error is detected.
  • FALSE: No error.
Status
Output
SOCK_STATUS
Status is defined using the SOCK_STATUS data type, which contains ErrorID, SubErrorID, and StatusBits information.
Instance
Output
UDINT
Contains Socket Handler.
Use the Instance parameter for subsequent Socket instructions.

SOCKET_CREATE examples

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