Skip to main content

Example: Net Base Services

Product: CODESYS Base Libraries

This package contains several sample projects for the NetBaseService library.

All examples work with or without TLS communication. If a TLS connection is required, then the CODESYS Security Agent add-on is absolutely required in order to create certificates. To open the CODESYS Security Agent, click the Security Agent icon _cds_icon_cyber_screen_grey.png at the bottom right.

On the Devices tab, you can create a new certificate for NBSServer as well as for NBSClient. If information for NBSServer or NBSClient is not available, then a download is required first.

Description

Example: TCP_Server_TCP_Client

The project contains two CODESYS Control Win x64 controllers, each with an application in order to simulate a server–client relationship. Set up the shared client name and the corresponding IP address in the CLIENT_PRG program for the client as well as in the SERVER_PRG program for the server. If TLS communication is not required, then the variable myTLSContext can be removed (SERVER_PRG and CLIENT_PRG). The server application (myServer) should be activated first.

Example: DemoClientServerOptionProvider

The project is based on the TCP_Server_TCP_Client example. In the client program CLIENT_PRG, an instance of the ClientOptions function block is declared. This function block (in the POU pool) contains three options which are set when the socket is opened. In the declaration part of CLIENT_PRG, the options are set using the SetOptionProvider() method. In the server program SERVER_PRG, no option for TCP_Server is set so that the default value is used. If necessary, the option can be set in the same way as for the client. If UDP communication is used, then the options can be set in the UDP peer, as well as with the same SetOptionProvider() method.

Example: TCP_Reader_TCP_Processor_TCP_Writer_Example

The project contains two CODESYS Control Win x64 controllers, each with an application in order to simulate a server–client relationship. The server returns only the values which are sent by the client. The CLIENT_PRG program shows an example of how asynchronous reading, processing, and writing is done by using the NBS.TCP_Reader, NBS.TCP_Processor, and NBS.TCP_Writer function blocks. The NBS.TCP_Processor function block is overridden in this example in order to implement the ProcessStream method. This example also shows the possibility of using the direct TCP client methods Read() and Write() to synchronously read, manipulate, and write when xAsync=FALSE.

Note that this server–client relationship uses a TLS context so that it is absolutely required to import the server certificate into the client and vice-versa. For unencrypted communication, the NBS.TLSContext function block can be deleted.

Example: UDP_Receive_Send_Example

The project contains two CODESYS Control Win x64 controllers, each with an application in order to simulate a synchronous UDP Producer – UDP Consumer relationship. The producer program PRODUCER_PRG returns only the data which has already been previously received. Therefore, the Receive() and Send() interface methods of the IPeer function block are used. At the beginning, the producer creates a string and sends it to the consumer. The consumer controller also contains a peer and this is where the data is received via a direct method call from the peer Receive2(). This is similar to Receive(), but it has an additional output eTransmission in order to show whether the frame is unicast, for example. Between receiving and sending, a ChangeStringValue method is called in order to change the payload of the communication. Because this is UDP, it is recommended to first enable the consumer and then the producer.

Example: UDP_Processor_Example

The project contains two CODESYS Control Win x64 devices, each with an application in order to simulate a UDP Producer – UDP Consumer relationship. In the consumer application, there is a UDP_Processor which extends the NBS.UDP_Processor so that this function block implements the ProcessPacket interface method. Some data is processed in this method (which is called by the interface).

System requirements and restrictions

Programming system

CODESYS Development System (version 3.5.19.0 or higher)

Runtime system

CODESYS Control Win (version 3.5.19.0)

Add-on components

-

Note

_example_icon.png DOWNLOAD Project