Back to top

TCP/IP Send and Receive in KAS Project

Starting with the 3.04 release of KAS there are PLC function blocks to send or receive data with TCP/IP communication. The below video goes through the two attached sample programs. One is a program with TCP/IP receive function blocks that in the video is run on a PDMM controller. The other has TCP/IP send function blocks and is run on the simulator on a development computer. Under the video is an application note going through which new function blocks need to be used an in what order in order to send and/or receive TCP/IP data.

New function blocks are found in the KAS IDE Library under the System > TCP/IP Sockets section as shown in the screenshot below.

image

To send TCP/IP data, must first call instance of TcpConnect function block. Need to input the target IP address as a string to the Address input, as well as the target port as a DINT. The function block will output a UDINT ID that needs to be saved to a variable in order to be used as an input to the sending function block. Can also optionally use the TcpIsConnected function block to check that the controller is still connected to the target, and if not you can call the TcpClose function block and recall the TcpConnect function block.

image

Two options to send TCP/IP data, the TcpSend function block that sends String data and TcpBinSend which sends an array of USINT data. Below is an example of TcpSend which uses the ID output of TcpSend for the ID input. Note the string data can be limited by the NbChar input value.

image

Similarly there are a number of function blocks required to receive TCP/IP data. First you must call the TcpListen function block to setup a port on your controller that can receive TCP/IP data. You also must specify the Backlog which is the size of the queue for pending connections. There is a ListenID output which you need to save to a variable for use as the input to the TcpListen function block. You then must call the TcpListen function block which will continue to run until an outside device connects with the PDMM/PCMM controller. Once this happens, the Done output of TcpListen becomes True and it outputs the ID output, which you need to save to a variable to use with the receiving data function blocks.

image

Just like the sending function blocks, there are two options to receive TCP/IP data. TcpReceive saves the incoming data to a String variable through the Data output. TCPBinReceive saves incoming data to a USINT array that may look like an input to the function block, but all array inputs are default read/write so in this case it acts as an output.

image