Skip to main content

Example: Shared Memory Communication

Product: CODESYS Control

This example shows how to exchange data between a CODESYS controller and other processes by means of shared memory.

_example_img_shared_memory_communication.png

Description

In the example project, the data from a CODESYS control is shared with other processes by means of shared memory. The package includes additional implementation examples in C (Linux), C# (Windows), and C++ (Windows). You can find the examples in the directory %USERPROFILE%\CODESYS Examples\Shared Memory Communication.

The package includes the following examples:

  • SharedMemoryExampleExt.project

    The project uses shared memory to read and write data with the SysShm library. The DataExchange structure is used for data exchange. Values from the shared memory are read to the deInstRead variable. The deInstWrite variable is used for writing values to shared memory. The values of deInstWrite are changed in each cycle.

    The values of both variables are displayed in the visualization.

The following examples read the value of the deInstWrite variable and write to the deInstRead variable:

  • SharedMemoryCLinux

    C program for Linux to read and write data using a shared memory

  • SharedMemoryWinCpp

    C++ program for Windows to read and write data be means of shared memory

  • SharedMemoryWinCSharp

    C# program for Windows to read and write data be means of shared memory

  • SharedMemoryExampleExt.project/SyncExample

    The SyncExample application shows how data is read and written synchronously by means of shared memory.

  • SynchronizationExample

    C++ program for Windows for synchronized reading and writing of data by means of shared memory.

    In this example, the data exchange is done by the SyncExample application.

System requirements and restrictions

Programming system

CODESYS Development System (version 3.5.16.1 or higher)

Runtime system

CODESYS Control Win (version 3.5.16.1)

Add-on components

-

Note

_example_icon.png DOWNLOAD Project