Docs

You are here:
Initializing and running the connection

The connection object.

The central point of the RCM C++ library is the connection object that represents a connection with a single RCM radio module. The connection is represented by rcm::Connection class

The connection object is usually defined by the user. Each instance represents a single RCM radio module (usually there is only one in the system).

Creating the rcm::Connection object automatically opens the connection. The API provides two methods to construct rcm::Connection objects.

Opening the connection using port name.

The easiest method is to use the constructor that allows to specify the system name for the serial port used for communication with the radio module. The following example illustrates the idea:

// Object representing the connection with the RCM radio module, connected to serial port on COM23

Opening the connection using native HAL interface.

Another way to open the connection is to provide the IODevice handle of the serial port, used for communication with the radio module. The following example shows how this can be done.

// Object representing the connection with the RCM radio module, connected to IODevice called USART0

Opening virtual connection.

In addition, the RCM C++ library provides a convenient way of working with virtual connections. In order to create a virtual connection, simply use the "virtual" keyword as serial port name during rcm::Connection object construction.

// Object representing a virtual connection
rcm::Connection rcm("virtual");

The RCM library makes full use of an operating system supported by HALFRED Hardware Abstraction Layer. Constructing the rcm::Connection object causes two new threads to run - one that handles the underlying SCOM protocol, and the other one that handles message filtering.

Handling errors.

All C++ API calls use exceptions to signal connection errors. This applies also to rcm::Connection construction. A proper way to initialize the object is to enclose it with a try..catch block in order to catch a dedicated exception, represented by the rcm::exception class, as shown in the example below:

#include "rcmpp.h"
int rcmpp_init_example(const char* portName)
{
int result = 0;
try {
// construct the connection object
rcm::Connection rcm(portName);
// do something with the object ...
}
catch(rcm::exception &e) {
result = 100;
}
catch(std::exception &e) {
result = 101;
}
catch (...) {
result = 102;
}
return result;
}

Once we have the connection object, we can start using the RCM C++ library API.

Go to Top