The SOCKET_WRITE instruction sends data on a socket.
Operation details:
SOCKET_WRITE attempts to send the requested number of data bytes specified in the Length parameter. When the send operation completes, SOCKET_WRITE returns the number of data bytes written to the TxLength parameter.
Output is updated asynchronously from the program scan.
Languages supported: Function block diagram, ladder diagram, structured text.
This instruction applies to the L20E, L50E, and L70E controllers.
SOCKET_WRITE
SOCKET_WRITE 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 the returned Socket Handler from a SOCKET_CREATE or SOCKET_ACCEPT instruction.
For UDP and TCP-Client Socket types, copy the returned Socket Handler from a SOCKET_CREATE instruction.
For TCP- Server socket type, copy from returned Socket Handler from a SOCKET_ACCEPT instruction.
Timeout
Input
UDINT
Timeout for SOCKET_WRITE instances. The instruction 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).
The UDP destination address that the data is being written to when a SOCKET_OPEN instruction has not been executed since creating the socket. For TCP, or when the SOCKET_OPEN instruction has been executed for UDP, this structure is not used and should contain all zeros. The TCP connection and the SOCKET_OPEN instruction for UDP convey all of the remote address information.
Example for a UDPAddr of 192.168.2.100 and Port 12000:
UDPAddr.IPAddress[0] = 192
UDPAddr.IPAddress[1] = 168
UDPAddr.IPAddress[2] = 2
UDPAddr.IPAddress[3] = 100
UDPAddr.Port = 12000
Use the SOCKADDR_CFG data type to define UDPAddr.
Data
Input
USINT[1..1]
An Array used to store the data write to respective socket instance using the SOCKET_WRITE Instruction.
Data array size must be >= (Offset + Length).
Data array can be bigger than SOCKET_WRITE Length.
Length
Input
UINT
The number of bytes of data to write.
Maximum is 256 bytes.
Offset
Input
UNIT
Offset into an array of Data. The data write from the SOCKET_WRITE is starting from this location.
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 that an error occurred.
TRUE: An error is detected.
FALSE: No error.
Output is updated synchronously from the program scan.