API
modbus Class Reference

Modbus Operator Class. More...

#include <modbus.hpp>

Collaboration diagram for modbus:
Collaboration graph

Public Member Functions

 modbus (const std::string &host, uint16_t port)
 
 modbus (const std::string &host)
 
 ~modbus ()
 
bool modbus_connect ()
 
void modbus_close ()
 
void modbus_set_slave_id (int id)
 
void modbus_read_coils (int address, int amount, bool *buffer)
 
void modbus_read_input_bits (int address, int amount, bool *buffer)
 
void modbus_read_holding_registers (int address, int amount, uint16_t *buffer)
 
void modbus_read_input_registers (int address, int amount, uint16_t *buffer)
 
void modbus_write_coil (int address, bool to_write)
 
void modbus_write_register (int address, uint16_t value)
 
void modbus_write_coils (int address, int amount, bool *value)
 
void modbus_write_registers (int address, int amount, uint16_t *value)
 

Private Member Functions

void modbus_build_request (uint8_t *to_send, int address, int func)
 
void modbus_read (int address, int amount, int func)
 
void modbus_write (int address, int amount, int func, uint16_t *value)
 
ssize_t modbus_send (uint8_t *to_send, int length)
 
ssize_t modbus_receive (uint8_t *buffer)
 
void modbus_error_handle (uint8_t *msg, int func)
 

Private Attributes

bool _connected {false}
 
uint16_t PORT {502}
 
int _socket {0}
 
int _msg_id {1}
 
int _slaveid {1}
 
std::string HOST
 
struct sockaddr_in _server
 

Detailed Description

Modbus Operator Class.

Modbus Operator Class Providing networking support and mobus operation support.

Definition at line 63 of file modbus.hpp.

Constructor & Destructor Documentation

◆ modbus() [1/2]

modbus::modbus ( const std::string &  host,
uint16_t  port 
)

Definition at line 6 of file modbus.cpp.

◆ modbus() [2/2]

modbus::modbus ( const std::string &  host)
explicit

Definition at line 10 of file modbus.cpp.

◆ ~modbus()

modbus::~modbus ( void  )

Definition at line 12 of file modbus.cpp.

Member Function Documentation

◆ modbus_build_request()

void modbus::modbus_build_request ( uint8_t *  to_send,
int  address,
int  func 
)
private

Definition at line 54 of file modbus.cpp.

Referenced by modbus_read(), and modbus_write().

◆ modbus_close()

void modbus::modbus_close ( )

Definition at line 49 of file modbus.cpp.

Referenced by MagAOX::app::xt1121Ctrl::appShutdown().

◆ modbus_connect()

bool modbus::modbus_connect ( )

Definition at line 19 of file modbus.cpp.

Referenced by MagAOX::app::xt1121Ctrl::appLogic().

◆ modbus_error_handle()

void modbus::modbus_error_handle ( uint8_t *  msg,
int  func 
)
private

◆ modbus_read()

void modbus::modbus_read ( int  address,
int  amount,
int  func 
)
private

◆ modbus_read_coils()

void modbus::modbus_read_coils ( int  address,
int  amount,
bool *  buffer 
)

Definition at line 153 of file modbus.cpp.

◆ modbus_read_holding_registers()

void modbus::modbus_read_holding_registers ( int  address,
int  amount,
uint16_t *  buffer 
)

Definition at line 109 of file modbus.cpp.

◆ modbus_read_input_bits()

void modbus::modbus_read_input_bits ( int  address,
int  amount,
bool *  buffer 
)

Definition at line 174 of file modbus.cpp.

◆ modbus_read_input_registers()

void modbus::modbus_read_input_registers ( int  address,
int  amount,
uint16_t *  buffer 
)

Definition at line 131 of file modbus.cpp.

Referenced by MagAOX::app::xt1121Ctrl::getState().

◆ modbus_receive()

◆ modbus_send()

ssize_t modbus::modbus_send ( uint8_t *  to_send,
int  length 
)
private

Definition at line 272 of file modbus.cpp.

Referenced by modbus_read(), and modbus_write().

◆ modbus_set_slave_id()

void modbus::modbus_set_slave_id ( int  id)

Definition at line 15 of file modbus.cpp.

Referenced by MagAOX::app::xt1121Ctrl::appLogic().

◆ modbus_write()

void modbus::modbus_write ( int  address,
int  amount,
int  func,
uint16_t *  value 
)
private

◆ modbus_write_coil()

void modbus::modbus_write_coil ( int  address,
bool  to_write 
)

Definition at line 195 of file modbus.cpp.

◆ modbus_write_coils()

void modbus::modbus_write_coils ( int  address,
int  amount,
bool *  value 
)

Definition at line 232 of file modbus.cpp.

◆ modbus_write_register()

void modbus::modbus_write_register ( int  address,
uint16_t  value 
)

Definition at line 214 of file modbus.cpp.

◆ modbus_write_registers()

void modbus::modbus_write_registers ( int  address,
int  amount,
uint16_t *  value 
)

Definition at line 254 of file modbus.cpp.

Referenced by MagAOX::app::xt1121Ctrl::channelSetCallback().

Member Data Documentation

◆ _connected

◆ _msg_id

int modbus::_msg_id {1}
private

Definition at line 68 of file modbus.hpp.

Referenced by modbus_build_request(), and modbus_send().

◆ _server

struct sockaddr_in modbus::_server
private

Definition at line 70 of file modbus.hpp.

Referenced by modbus_connect().

◆ _slaveid

int modbus::_slaveid {1}
private

Definition at line 69 of file modbus.hpp.

Referenced by modbus_build_request(), and modbus_set_slave_id().

◆ _socket

int modbus::_socket {0}
private

Definition at line 67 of file modbus.hpp.

Referenced by modbus_close(), modbus_connect(), modbus_receive(), and modbus_send().

◆ HOST

std::string modbus::HOST
private

Definition at line 70 of file modbus.hpp.

Referenced by modbus_connect().

◆ PORT

uint16_t modbus::PORT {502}
private

Definition at line 66 of file modbus.hpp.

Referenced by modbus_connect().


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