Home

mlamp
There is a newer version of this page. You can find it here.

Download project

PLC Chat

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.

Product description

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:

  • Download the server application to a PLC and execute the program.
  • Enter the IP address for the server in the visualization configuration.
  • Choose a free port for the connection.
  • Give the chat a name (optional)
  • Now click the "Go Online" button.
  • The status bar changes from "not connected" to "waiting for clients".

Client:

  • Download the client to another PLC and run the application (up to 16 PLCs can participate)
  • Change to the configuration tab
  • Choose your nick name.
  • Enter the IP address and port of the server
  • Click the "Go Online" button.
  • The status bar now displays "connection established".

More information

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.