Modbus Operator Class. More...
#include <modbus.hpp>

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 |
Modbus Operator Class.
Modbus Operator Class Providing networking support and mobus operation support.
Definition at line 63 of file modbus.hpp.
| modbus::modbus | ( | const std::string & | host, |
| uint16_t | port | ||
| ) |
Definition at line 6 of file modbus.cpp.
|
explicit |
Definition at line 10 of file modbus.cpp.
| modbus::~modbus | ( | void | ) |
Definition at line 12 of file modbus.cpp.
|
private |
Definition at line 54 of file modbus.cpp.
References _msg_id, and _slaveid.
Referenced by modbus_read(), and modbus_write().
| void modbus::modbus_close | ( | ) |
Definition at line 49 of file modbus.cpp.
References _socket.
Referenced by MagAOX::app::xt1121Ctrl::appShutdown().
| bool modbus::modbus_connect | ( | ) |
Definition at line 19 of file modbus.cpp.
References _connected, _server, _socket, HOST, and PORT.
Referenced by MagAOX::app::xt1121Ctrl::appLogic().
|
private |
Definition at line 281 of file modbus.cpp.
References EX_ACKNOWLEDGE, EX_GATEWAY_PROBLEMP, EX_GATEWYA_PROBLEMF, EX_ILLEGAL_ADDRESS, EX_ILLEGAL_FUNCTION, EX_ILLEGAL_VALUE, EX_SERVER_BUSY, and EX_SERVER_FAILURE.
Referenced by modbus_read_coils(), modbus_read_holding_registers(), modbus_read_input_bits(), modbus_read_input_registers(), modbus_write_coil(), modbus_write_coils(), modbus_write_register(), and modbus_write_registers().
|
private |
Definition at line 100 of file modbus.cpp.
References modbus_build_request(), and modbus_send().
Referenced by modbus_read_coils(), modbus_read_holding_registers(), modbus_read_input_bits(), and modbus_read_input_registers().
| void modbus::modbus_read_coils | ( | int | address, |
| int | amount, | ||
| bool * | buffer | ||
| ) |
Definition at line 153 of file modbus.cpp.
References _connected, MAX_MSG_LENGTH, modbus_error_handle(), modbus_read(), modbus_receive(), and READ_COILS.
| void modbus::modbus_read_holding_registers | ( | int | address, |
| int | amount, | ||
| uint16_t * | buffer | ||
| ) |
Definition at line 109 of file modbus.cpp.
References _connected, MAX_MSG_LENGTH, modbus_error_handle(), modbus_read(), modbus_receive(), and READ_REGS.
| void modbus::modbus_read_input_bits | ( | int | address, |
| int | amount, | ||
| bool * | buffer | ||
| ) |
Definition at line 174 of file modbus.cpp.
References _connected, MAX_MSG_LENGTH, modbus_error_handle(), modbus_read(), modbus_receive(), and READ_INPUT_BITS.
| void modbus::modbus_read_input_registers | ( | int | address, |
| int | amount, | ||
| uint16_t * | buffer | ||
| ) |
Definition at line 131 of file modbus.cpp.
References _connected, MAX_MSG_LENGTH, modbus_error_handle(), modbus_read(), modbus_receive(), and READ_INPUT_REGS.
Referenced by MagAOX::app::xt1121Ctrl::getState().
|
private |
Definition at line 277 of file modbus.cpp.
References _socket, and MAX_MSG_LENGTH.
Referenced by modbus_read_coils(), modbus_read_holding_registers(), modbus_read_input_bits(), modbus_read_input_registers(), modbus_write_coil(), modbus_write_coils(), modbus_write_register(), and modbus_write_registers().
|
private |
Definition at line 272 of file modbus.cpp.
References _msg_id, and _socket.
Referenced by modbus_read(), and modbus_write().
| void modbus::modbus_set_slave_id | ( | int | id | ) |
Definition at line 15 of file modbus.cpp.
References _slaveid.
Referenced by MagAOX::app::xt1121Ctrl::appLogic().
|
private |
Definition at line 66 of file modbus.cpp.
References modbus_build_request(), modbus_send(), WRITE_COIL, WRITE_COILS, WRITE_REG, and WRITE_REGS.
Referenced by modbus_write_coil(), modbus_write_coils(), modbus_write_register(), and modbus_write_registers().
| void modbus::modbus_write_coil | ( | int | address, |
| bool | to_write | ||
| ) |
Definition at line 195 of file modbus.cpp.
References _connected, MAX_MSG_LENGTH, modbus_error_handle(), modbus_receive(), modbus_write(), and WRITE_COIL.
| void modbus::modbus_write_coils | ( | int | address, |
| int | amount, | ||
| bool * | value | ||
| ) |
Definition at line 232 of file modbus.cpp.
References _connected, MAX_MSG_LENGTH, modbus_error_handle(), modbus_receive(), modbus_write(), and WRITE_COILS.
| void modbus::modbus_write_register | ( | int | address, |
| uint16_t | value | ||
| ) |
Definition at line 214 of file modbus.cpp.
References _connected, MAX_MSG_LENGTH, modbus_error_handle(), modbus_receive(), modbus_write(), WRITE_COIL, and WRITE_REG.
| void modbus::modbus_write_registers | ( | int | address, |
| int | amount, | ||
| uint16_t * | value | ||
| ) |
Definition at line 254 of file modbus.cpp.
References _connected, MAX_MSG_LENGTH, modbus_error_handle(), modbus_receive(), modbus_write(), and WRITE_REGS.
Referenced by MagAOX::app::xt1121Ctrl::channelSetCallback().
|
private |
Definition at line 65 of file modbus.hpp.
Referenced by modbus_connect(), modbus_read_coils(), modbus_read_holding_registers(), modbus_read_input_bits(), modbus_read_input_registers(), modbus_write_coil(), modbus_write_coils(), modbus_write_register(), and modbus_write_registers().
|
private |
Definition at line 68 of file modbus.hpp.
Referenced by modbus_build_request(), and modbus_send().
|
private |
Definition at line 71 of file modbus.hpp.
Referenced by modbus_connect().
|
private |
Definition at line 69 of file modbus.hpp.
Referenced by modbus_build_request(), and modbus_set_slave_id().
|
private |
Definition at line 67 of file modbus.hpp.
Referenced by modbus_close(), modbus_connect(), modbus_receive(), and modbus_send().
|
private |
Definition at line 70 of file modbus.hpp.
Referenced by modbus_connect().
|
private |
Definition at line 66 of file modbus.hpp.
Referenced by modbus_connect().