7.2.1. Binary: Blob

After you have learned a lot about the pre-compiled applications that come with eCAL, let’s create our own! We will see how to create publisher and subscriber applications that send and receive binary data. We will provide samples for all supported programming languages: C++, C, C# and Python.

The most low level publisher and subscriber objects are the binary ones. We will focus on them in this section. As we are just sending an arbitrary “blob” of data (filled with random printable characters), the applications are called “blob sender” and “blob receiver”. For sending structured / typed data, please refer to the following sections.

7.2.1.1. Blob Publisher

Let’s begin with the publisher side of our “Blob” application.

The base initialization of the eCAL publisher is the same in all languages:

  1. Before you do anything else, you need to initialize eCAL with Initialize(..).

  2. Then you create the publisher and send a message in the frequency you want. In our example we will send the message every 500 ms in an infinite loop. You can add a stop condition to the loop, if you want to send just a limited amount of messages.

  3. After you are done with publishing data and you don’t need eCAL anymore, you can call the Finalize() function to clean up the resources and unregister the process.

For simplicity, we will use the same message type in all languages.

|fa-folder-open|
├─ |fa-folder-open| C++
│  └─ |fa-file-alt| blob_send.cpp
│
├─ |fa-folder-open| C
│  └─ |fa-file-alt| blob_send.c
│
├─ |fa-folder-open| C#
│  └─ |fa-file-alt| blob_send.cs
│
├─ |fa-folder-open| Python
│  └─ |fa-file-alt| blob_send.py
│
└─ |fa-folder-open| Python (legacy)
   └─ |fa-file-alt| blob_send.py

7.2.1.2. Blob Subscriber

Now let’s have a look at the subscriber side. Basically, the initialization is the same as for the publisher. Instead of sending data, a callback function is assigned to the subscriber, which will be called every time a new message arrives.

  1. Call Initialize() to initialize eCAL.

  2. Create the subscriber.

  3. Assign a callback function to the subscriber with SetReceiveCallback.

  4. Do something to keep the process alive. In our example we will use a simple infinite loop. Process the incoming messages as you wish.

  5. After you are done with receiving data and you don’t need eCAL anymore, you can call the Finalize() function to clean up the resources and unregister the process.

|fa-folder-open|
├─ |fa-folder-open| C++
│  └─ |fa-file-alt| blob_receive.cpp
│
├─ |fa-folder-open| C
│  └─ |fa-file-alt| blob_receive.c
│
├─ |fa-folder-open| C#
│  └─ |fa-file-alt| blob_receive.cs
│
├─ |fa-folder-open| Python
│  └─ |fa-file-alt| blob_receive.py
│
└─ |fa-folder-open| Python (legacy)
   └─ |fa-file-alt| blob_receive.py