S01: Simple TCP Client (PLC)

This sample implements a TCP client that issues a simple HTTP request and receives the response.

The download available here is preconfigured to call a test website 62.159.14.51:80.

Download

Download the sample: https://github.com/Beckhoff/TF6311_Samples/tree/main/S01-IpStackTcpClientPlc

1. Get the sample from GitHub, unzip the downloaded ZIP file if necessary
2. Open the project with TwinCAT XAE
3. Select your target system
4. Configure the network card (see below) for the target system
5. Build the sample on your local machine (e.g. Build->Build Solution)
6. Activate the configuration

Description

After the startup, the PLC program can be used by setting the variable "bSend" to TRUE. The HTTP request (stored in "sMessage") is sent to the server, once the connection has been established. The first bytes of the incoming response are provided in "sLastReturnedMessage". The "sLastReturnedMessafeLength" indicates the whole length of the response.

The server address is defined in the FB_init method.

The same sample is described in detail for C++ on the Quick Start page.

Preparing the network card

For the TCP/UDP RT module, make sure that the RT Ethernet adapter in the TwinCAT solution is connected with the correct network card (with TwinCAT driver).

S01: Simple TCP Client (PLC) 1:

Local configuration only

Installation of the driver on compatible network cards via the button "Compatible Devices" always takes place locally. On a controller with TwinCAT XAR, the program TcRteInstall.exe can be used. It is included in the installation (usually under C:TwinCAT\3.1\System).

S01: Simple TCP Client (PLC) 2: