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

Abstract representation of a client communication channel. More...

#include <rodbus.hpp>

Public Member Functions

 ClientChannel (ClientChannel &&other) noexcept
 Transfer ownership of the underlying C-type to this instance and invalidate the other instance. More...
 
 ~ClientChannel ()
 Shutdown a ClientChannel and release all resources. More...
 
void enable ()
 Enable channel communications. More...
 
void disable ()
 Disable channel communications. More...
 
void set_decode_level (const DecodeLevel &level)
 Set the decoding level for the channel. More...
 
void read_coils (const RequestParam &param, const AddressRange &range, std::unique_ptr< BitReadCallback > callback)
 Start an asynchronous request to read coils. More...
 
void read_discrete_inputs (const RequestParam &param, const AddressRange &range, std::unique_ptr< BitReadCallback > callback)
 Start an asynchronous request to read discrete inputs. More...
 
void read_holding_registers (const RequestParam &param, const AddressRange &range, std::unique_ptr< RegisterReadCallback > callback)
 Start an asynchronous request to read holding registers. More...
 
void read_input_registers (const RequestParam &param, const AddressRange &range, std::unique_ptr< RegisterReadCallback > callback)
 Start an asynchronous request to read input registers. More...
 
void write_single_coil (const RequestParam &param, const BitValue &value, std::unique_ptr< WriteCallback > callback)
 Write a single coil. More...
 
void write_single_register (const RequestParam &param, const RegisterValue &value, std::unique_ptr< WriteCallback > callback)
 Write a single register. More...
 
void write_multiple_coils (const RequestParam &param, uint16_t start, const std::vector< bool > &items, std::unique_ptr< WriteCallback > callback)
 Write multiple coils. More...
 
void write_multiple_registers (const RequestParam &param, uint16_t start, const std::vector< uint16_t > &items, std::unique_ptr< WriteCallback > callback)
 Write multiple registers. More...
 

Static Public Member Functions

static ClientChannel create_tcp (Runtime &runtime, const std::string &host, uint16_t port, uint16_t max_queued_requests, const RetryStrategy &retry_strategy, const DecodeLevel &decode_level, std::unique_ptr< ClientStateListener > listener)
 Create a new TCP channel instance. More...
 
static ClientChannel create_rtu (Runtime &runtime, const std::string &path, const SerialPortSettings &serial_params, uint16_t max_queued_requests, const RetryStrategy &retry_strategy, const DecodeLevel &decode_level, std::unique_ptr< PortStateListener > listener)
 Create a new RTU channel instance. More...
 
static ClientChannel create_tls (Runtime &runtime, const std::string &host, uint16_t port, uint16_t max_queued_requests, const RetryStrategy &retry_strategy, const TlsClientConfig &tls_config, const DecodeLevel &decode_level, std::unique_ptr< ClientStateListener > listener)
 Create a new TLS channel instance. More...
 

Friends

class CppClientChannelFriend
 

Detailed Description

Abstract representation of a client communication channel.

The underlying channel may be TCP, TLS, or serial.

Constructor & Destructor Documentation

◆ ClientChannel()

rodbus::ClientChannel::ClientChannel ( ClientChannel &&  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

◆ ~ClientChannel()

rodbus::ClientChannel::~ClientChannel ( )

Shutdown a ClientChannel and release all resources.

Member Function Documentation

◆ create_rtu()

static ClientChannel rodbus::ClientChannel::create_rtu ( Runtime runtime,
const std::string &  path,
const SerialPortSettings serial_params,
uint16_t  max_queued_requests,
const RetryStrategy retry_strategy,
const DecodeLevel decode_level,
std::unique_ptr< PortStateListener listener 
)
static

Create a new RTU channel instance.

Parameters
runtimeruntime on which to create the channel
pathPath to the serial device. Generally /dev/tty0 on Linux and COM1 on Windows.
serial_paramsSerial port settings
max_queued_requestsMaximum number of requests to queue before failing the next request
retry_strategyStrategy which controls how long to wait between attempts to open the serial port after failures
decode_levelDecode levels for this client
listenerListener used to receive updates on the status of the serial port
Returns
Pointer to the created channel
Exceptions
ParamException

◆ create_tcp()

static ClientChannel rodbus::ClientChannel::create_tcp ( Runtime runtime,
const std::string &  host,
uint16_t  port,
uint16_t  max_queued_requests,
const RetryStrategy retry_strategy,
const DecodeLevel decode_level,
std::unique_ptr< ClientStateListener listener 
)
static

Create a new TCP channel instance.

Parameters
runtimeRuntime on which to create the channel
hostIP (v4/v6) or host name remote endpoint
portremote port
max_queued_requestsMaximum number of requests to queue before failing the next request
retry_strategyReconnection timing strategy
decode_levelDecode levels for this client
listenerTCP connection listener used to receive updates on the status of the channel
Returns
Pointer to the created channel
Exceptions
ParamException

◆ create_tls()

static ClientChannel rodbus::ClientChannel::create_tls ( Runtime runtime,
const std::string &  host,
uint16_t  port,
uint16_t  max_queued_requests,
const RetryStrategy retry_strategy,
const TlsClientConfig tls_config,
const DecodeLevel decode_level,
std::unique_ptr< ClientStateListener listener 
)
static

Create a new TLS channel instance.

Parameters
runtimeRuntime on which to create the channel
hostIP (v4/v6) or host name remote endpoint
portremote port
max_queued_requestsMaximum number of requests to queue before failing the next request
retry_strategyReconnection timing strategy
tls_configTLS client configuration
decode_levelDecode levels for this client
listenerTCP connection listener used to receive updates on the status of the channel
Returns
Pointer to the created channel or NULL if an error occurred
Exceptions
ParamException

◆ disable()

void rodbus::ClientChannel::disable ( )

Disable channel communications.

Warning
May not be called from within the context of the runtime
Exceptions
ParamException

◆ enable()

void rodbus::ClientChannel::enable ( )

Enable channel communications.

Warning
May not be called from within the context of the runtime
Exceptions
ParamException

◆ read_coils()

void rodbus::ClientChannel::read_coils ( const RequestParam param,
const AddressRange range,
std::unique_ptr< BitReadCallback callback 
)

Start an asynchronous request to read coils.

Parameters
paramParameters for the request
rangeRange of addresses to read
callbackcallback invoked when the operation completes
Exceptions
ParamException

◆ read_discrete_inputs()

void rodbus::ClientChannel::read_discrete_inputs ( const RequestParam param,
const AddressRange range,
std::unique_ptr< BitReadCallback callback 
)

Start an asynchronous request to read discrete inputs.

Parameters
paramParameters for the request
rangeRange of addresses to read
callbackcallback invoked when the operation completes
Exceptions
ParamException

◆ read_holding_registers()

void rodbus::ClientChannel::read_holding_registers ( const RequestParam param,
const AddressRange range,
std::unique_ptr< RegisterReadCallback callback 
)

Start an asynchronous request to read holding registers.

Parameters
paramParameters for the request
rangeRange of addresses to read
callbackcallback invoked when the operation completes
Exceptions
ParamException

◆ read_input_registers()

void rodbus::ClientChannel::read_input_registers ( const RequestParam param,
const AddressRange range,
std::unique_ptr< RegisterReadCallback callback 
)

Start an asynchronous request to read input registers.

Parameters
paramParameters for the request
rangeRange of addresses to read
callbackcallback invoked when the operation completes
Exceptions
ParamException

◆ set_decode_level()

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

Set the decoding level for the channel.

Parameters
levelDecoding level
Exceptions
ParamException

◆ write_multiple_coils()

void rodbus::ClientChannel::write_multiple_coils ( const RequestParam param,
uint16_t  start,
const std::vector< bool > &  items,
std::unique_ptr< WriteCallback callback 
)

Write multiple coils.

Parameters
paramParameters for the request
startStarting address
itemsList of items to write
callbackcallback invoked when the operation completes
Exceptions
ParamException

◆ write_multiple_registers()

void rodbus::ClientChannel::write_multiple_registers ( const RequestParam param,
uint16_t  start,
const std::vector< uint16_t > &  items,
std::unique_ptr< WriteCallback callback 
)

Write multiple registers.

Parameters
paramParameters for the request
startStarting address
itemsList of items to write
callbackcallback invoked when the operation completes
Exceptions
ParamException

◆ write_single_coil()

void rodbus::ClientChannel::write_single_coil ( const RequestParam param,
const BitValue value,
std::unique_ptr< WriteCallback callback 
)

Write a single coil.

Parameters
paramParameters for the request
valueAddress and value to write
callbackcallback invoked when the operation completes
Exceptions
ParamException

◆ write_single_register()

void rodbus::ClientChannel::write_single_register ( const RequestParam param,
const RegisterValue value,
std::unique_ptr< WriteCallback callback 
)

Write a single register.

Parameters
paramParameters for the request
valueAddress and value to write
callbackcallback invoked when the operation completes
Exceptions
ParamException

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