Download project
The PLC Chat includes a chat server which can handle up to 16 PLC clients and the client program.
The chat UI is displayed on a CODESYS TargetVisu and can be accessed by the CODESYS Web Visualization.
The PLC Chat includes a chat server which can handle up to 16 PLC clients and the client program.
The chat UI is displayed on a CODESYS TargetVisu and can be accessed by the CODESYS WebVisu.
This example demonstrates the usage of the library NetBaseServices.
Server:
Client:
Server and client use the library NetBaseServices for their connections.
TCP_Server (PRG)
:The server is initialized with the IP address and the port number of the configuration in the visualization. All incoming connections are stored in the array "a_tcp_connections"
. Up to 16 clients can be handled by the server.
When the program reaches the state STATE.WAITE_FOR_MESSAGE
all connections are checked for incoming messages. A received message will be stored in an instance of MessageBuffer(FB)
.
The server passes all received messages to the connected clients. Sent messages are marked by setting a flag in "axSentFlags"
.
If a client goes offline the server will then close all open connections to that client.
In case of a server reset all clients are removed and their connections closed.
MessageBuffer (FB)
:The MessageBuffer is a FIFO buffer. Incoming messages are stored here by the server and loaded when they get distributed to the connected clients.
TCP_Client (PRG)
:The client will be initialized with the data entered in the configuration of the visualization. When a connection to a server was established the client waits for incoming messages. If there is a message it will be saved in the clients MessageQueue instance.
If the user enters a message in the visualization the client sends the text with the users nick name to the server.
In case of a log out the connection to the server will be closed.
MessageQueue(FB)
:The MessageQueue stores all incoming messages. The last 10 messages will be displayed in the chat client visualization.
System requirements and restrictions | Info |
---|---|
Programming System | CODESYS Development System Version 3.5.14.0 or higher |
Runtime System | CODESYS Control Version 3.5.14.0 |
Required Accessories | - |