31 #ifndef LIBHOMEGEAR_BASE_MODBUS_H 32 #define LIBHOMEGEAR_BASE_MODBUS_H 34 #include "../Exception.h" 49 ModbusException(
const std::string& message, uint8_t code, std::vector<char> packet) :
Exception(message), _code(code), _packet(std::move(packet)) {}
52 std::vector<char>
getPacket()
const {
return _packet; }
55 std::vector<char> _packet;
129 bool keepAlive =
true;
133 std::shared_ptr<Security::SecureVector<uint8_t>>
keyData;
134 bool verifyCertificate =
true;
137 uint32_t timeout = 5000;
149 std::map<uint8_t, std::vector<uint8_t>>
objects;
199 void readCoils(uint16_t startingAddress, std::vector<uint8_t>& buffer, uint16_t coilCount);
214 void readDiscreteInputs(uint16_t startingAddress, std::vector<uint8_t>& buffer, uint16_t inputCount);
229 void readHoldingRegisters(uint16_t startingAddress, std::vector<uint16_t>& buffer, uint16_t registerCount);
244 void readInputRegisters(uint16_t startingAddress, std::vector<uint16_t>& buffer, uint16_t registerCount);
257 void writeSingleCoil(uint16_t address,
bool value);
270 void writeSingleRegister(uint16_t address, uint16_t value);
284 void writeMultipleCoils(uint16_t startAddress,
const std::vector<uint8_t>& values, uint16_t coilCount);
298 void writeMultipleRegisters(uint16_t startAddress,
const std::vector<uint16_t>& values, uint16_t registerCount);
315 void readWriteMultipleRegisters(uint16_t readStartAddress, std::vector<uint16_t>& readBuffer, uint16_t readRegisterCount, uint16_t writeStartAddress,
const std::vector<uint16_t>& writeValues, uint16_t writeRegisterCount);
328 static const uint8_t _reverseByteMask[256];
333 uint8_t _slaveId = 0xFF;
343 bool _keepAlive =
true;
355 std::mutex _socketMutex;
360 std::unique_ptr<TcpSocket> _socket;
365 std::string _hostname;
375 std::unique_ptr<std::vector<char>> _readBuffer;
380 uint16_t _transactionId = 0;
388 void insertHeader(std::vector<char>& packet, uint8_t functionCode, uint16_t payloadSize);
390 std::vector<char> getResponse(std::vector<char>& packet);
std::map< uint8_t, std::vector< uint8_t > > objects
Definition: Modbus.h:149
std::string vendorName
Definition: Modbus.h:142
std::string certData
Definition: Modbus.h:131
std::string userApplicationName
Definition: Modbus.h:148
ModbusException(const std::string &message)
Definition: Modbus.h:48
This is the base library main class.
Definition: BaseLib.h:95
void setDebug(bool value)
Enables or disables debug mode (disabled by default).
Definition: Modbus.h:167
std::string majorMinorRevision
Definition: Modbus.h:144
std::shared_ptr< Security::SecureVector< uint8_t > > keyData
Definition: Modbus.h:133
Exception class for the Modbus server.
Definition: Modbus.h:45
Definition: BaseLib.cpp:34
Exception class thrown when the Modbus server is busy.
Definition: Modbus.h:63
ModbusServerBusyException(std::string message)
Definition: Modbus.h:66
bool isConnected()
Checks if the socket is connected.
Definition: Modbus.h:184
std::string caFile
Definition: Modbus.h:135
std::string vendorUrl
Definition: Modbus.h:145
PVariable value
Definition: UiElements.h:217
std::string modelName
Definition: Modbus.h:147
std::string caData
Definition: Modbus.h:136
std::string productCode
Definition: Modbus.h:143
ModbusServerBusyException(std::string message, uint8_t code, std::vector< char > packet)
Definition: Modbus.h:67
ModbusException(const std::string &message, uint8_t code, std::vector< char > packet)
Definition: Modbus.h:49
std::string certFile
Definition: Modbus.h:130
This class provides a Modbus client.
Definition: Modbus.h:121
std::string productName
Definition: Modbus.h:146
std::string hostname
Definition: Modbus.h:126
Base class for all exceptions defined in Homegear.
Definition: Exception.h:41
std::string keyFile
Definition: Modbus.h:132
std::vector< char > getPacket() const
Definition: Modbus.h:52
void setSlaveId(uint8_t value)
Sets the slave ID.
Definition: Modbus.h:162
uint8_t getCode() const
Definition: Modbus.h:51