rodbus (C++ API) 1.3.1
Loading...
Searching...
No Matches
rodbus::Server Class Reference

Handle to the running server. The server runs on a background task until this class is destroyed. More...

#include <rodbus.hpp>

Public Member Functions

 Server (Server &&other) noexcept
 Transfer ownership of the underlying C-type to this instance and invalidate the other instance. More...
 
 ~Server ()
 Shutdown and release all resources of a running server. More...
 
void update_database (uint8_t unit_id, DatabaseCallback &transaction)
 Update the database associated with a particular unit id. If the unit id exists, lock the database and call user code to perform the transaction. More...
 
void set_decode_level (const DecodeLevel &level)
 Set the decoding level for the server. More...
 

Static Public Member Functions

static Server create_tcp (Runtime &runtime, const std::string &address, uint16_t port, AddressFilter &filter, uint16_t max_sessions, DeviceMap &endpoints, const DecodeLevel &decode_level)
 Launch a TCP server. More...
 
static Server create_rtu (Runtime &runtime, const std::string &path, const SerialPortSettings &serial_params, const RetryStrategy &retry, DeviceMap &endpoints, const DecodeLevel &decode_level)
 Launch a RTU server. More...
 
static Server create_tls_with_authz (Runtime &runtime, const std::string &address, uint16_t port, AddressFilter &filter, uint16_t max_sessions, DeviceMap &endpoints, const TlsServerConfig &tls_config, std::unique_ptr< AuthorizationHandler > authorization_handler, const DecodeLevel &decode_level)
 Create a Modbus Security (TLS) server. More...
 
static Server create_tls (Runtime &runtime, const std::string &address, uint16_t port, AddressFilter &filter, uint16_t max_sessions, DeviceMap &endpoints, const TlsServerConfig &tls_config, const DecodeLevel &decode_level)
 Create a TLS server that does NOT require the client role extension. More...
 

Friends

class CppServerFriend
 

Detailed Description

Handle to the running server. The server runs on a background task until this class is destroyed.

Constructor & Destructor Documentation

◆ Server()

rodbus::Server::Server ( Server &&  other)
inlinenoexcept

Transfer ownership of the underlying C-type to this instance and invalidate the other instance.

Note
the moved class will now throw an exception if any method is called
Parameters
otherClass from which ownership will be transfer to this instance

◆ ~Server()

rodbus::Server::~Server ( )

Shutdown and release all resources of a running server.

Member Function Documentation

◆ create_rtu()

static Server rodbus::Server::create_rtu ( Runtime runtime,
const std::string &  path,
const SerialPortSettings serial_params,
const RetryStrategy retry,
DeviceMap endpoints,
const DecodeLevel decode_level 
)
static

Launch a RTU server.

Parameters
runtimeruntime on which to spawn the server
pathPath to the serial device. Generally /dev/tty0 on Linux and COM1 on Windows.
serial_paramsSerial port settings
retryParameters that control How long to wait before re-opening the serial port
endpointsmap of endpoints which is emptied upon passing to this function
decode_levelDecode levels for this server
Returns
RTU server instance
Exceptions
ParamException

◆ create_tcp()

static Server rodbus::Server::create_tcp ( Runtime runtime,
const std::string &  address,
uint16_t  port,
AddressFilter filter,
uint16_t  max_sessions,
DeviceMap endpoints,
const DecodeLevel decode_level 
)
static

Launch a TCP server.

Recommended port for Modbus is 502.

When the maximum number of concurrent sessions is reached, the oldest session is closed.

Parameters
runtimeruntime on which to spawn the server
addressLocal IP (v4/v6) address. Accepts '0.0.0.0' (all adapters), '127.0.0.1' (localhost), or the address of a particular network adapter
portPort on which to listen
filterFilter used to limit which IP address(es) can connect
max_sessionsMaximum number of concurrent sessions
endpointsMap of endpoints which is emptied upon passing to this function
decode_levelDecode levels for this server
Returns
TCP server instance
Exceptions
ParamException

◆ create_tls()

static Server rodbus::Server::create_tls ( Runtime runtime,
const std::string &  address,
uint16_t  port,
AddressFilter filter,
uint16_t  max_sessions,
DeviceMap endpoints,
const TlsServerConfig tls_config,
const DecodeLevel decode_level 
)
static

Create a TLS server that does NOT require the client role extension.

This functionality is not standardized by Modbus.org, but nevertheless is commonly implemented

When the maximum number of concurrent sessions is reached, the oldest session is closed.

Parameters
runtimeruntime on which to spawn the server
addressLocal IP (v4/v6) address. Accepts '0.0.0.0' (all adapters), '127.0.0.1' (localhost), or the address of a particular network adapter
portPort on which to listen
filterFilter used to limit which IP address(es) can connect
max_sessionsMaximum number of concurrent sessions
endpointsmap of endpoints which is emptied upon passing to this function
tls_configTLS server configuration
decode_levelDecode levels for this server
Returns
Modbus Security (TLS) server instance
Exceptions
ParamException

◆ create_tls_with_authz()

static Server rodbus::Server::create_tls_with_authz ( Runtime runtime,
const std::string &  address,
uint16_t  port,
AddressFilter filter,
uint16_t  max_sessions,
DeviceMap endpoints,
const TlsServerConfig tls_config,
std::unique_ptr< AuthorizationHandler authorization_handler,
const DecodeLevel decode_level 
)
static

Create a Modbus Security (TLS) server.

This server requires that the client certificate contains the role extension and authorizes each request against the supplied handler.

Recommended port for Modbus Security is 802.

When the maximum number of concurrent sessions is reached, the oldest session is closed.

Parameters
runtimeruntime on which to spawn the server
addressLocal IP (v4/v6) address. Accepts '0.0.0.0' (all adapters), '127.0.0.1' (localhost), or the address of a particular network adapter
portPort on which to listen
filterFilter used to limit which IP address(es) can connect
max_sessionsMaximum number of concurrent sessions
endpointsmap of endpoints which is emptied upon passing to this function
tls_configTLS server configuration
authorization_handlerAuthorization handler
decode_levelDecode levels for this server
Returns
Modbus Security (TLS) server instance
Exceptions
ParamException

◆ set_decode_level()

void rodbus::Server::set_decode_level ( const DecodeLevel level)

Set the decoding level for the server.

Parameters
levelDecoding level
Exceptions
ParamException

◆ update_database()

void rodbus::Server::update_database ( uint8_t  unit_id,
DatabaseCallback transaction 
)

Update the database associated with a particular unit id. If the unit id exists, lock the database and call user code to perform the transaction.

Parameters
unit_idUnit id of the database to update
transactionCallback invoked when a lock has been acquired
Exceptions
ParamException

The documentation for this class was generated from the following file: