First version of RS485 + MODBUS Driver
This commit is contained in:
@@ -46,23 +46,28 @@ namespace drivers
|
||||
{
|
||||
|
||||
static const uint8_t RESP_HEADER_SIZE = 3;
|
||||
static const uint8_t RESP_CRC_SIZE = 1;
|
||||
|
||||
typedef union {
|
||||
uint8_t hi;
|
||||
uint8_t lo;
|
||||
uint16_t reg16;
|
||||
} reg_bytes_t;
|
||||
static const uint8_t RESP_CRC_SIZE = 2;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t device;
|
||||
uint8_t func;
|
||||
reg_bytes_t reg;
|
||||
reg_bytes_t qty;
|
||||
uint16_t crc = 0xFF;
|
||||
uint16_t reg;
|
||||
uint16_t data;
|
||||
} req_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t device;
|
||||
uint8_t func;
|
||||
uint16_t reg;
|
||||
uint16_t qty;
|
||||
uint8_t bytes;
|
||||
} req_multi_t;
|
||||
|
||||
typedef req_t resp_t;
|
||||
typedef uint16_t crc_t;
|
||||
|
||||
public:
|
||||
MODBUS(const uint32_t baud, const SerialConfig conf);
|
||||
|
||||
@@ -85,16 +90,19 @@ namespace drivers
|
||||
const bool writeRegister(const uint8_t device, const uint16_t reg, const uint16_t value);
|
||||
|
||||
// Func 0x0F
|
||||
const bool writeCoils(const uint8_t device, const uint16_t reg, const std::vector<bool> &coils);
|
||||
const bool writeCoils(const uint8_t device, const uint16_t coils, const std::vector<bool> &values);
|
||||
|
||||
// Func 0x10
|
||||
const bool writeRegisters(const uint8_t device, const uint16_t reg, const std::vector<uint16_t> &values);
|
||||
|
||||
private:
|
||||
CRC16 m_crc;
|
||||
const std::vector<uint8_t> buildRequest(const uint8_t device, const uint8_t func, const uint16_t reg, const uint16_t qty);
|
||||
const std::vector<uint8_t> singleRequest(const uint8_t device, const uint8_t func, const uint16_t reg, const uint16_t data);
|
||||
const std::vector<uint8_t> multiRequest(const uint8_t device, const uint8_t func, const uint16_t reg, const uint16_t qty, const std::vector<uint16_t> &data);
|
||||
const bool readBinary(const uint8_t func, const uint8_t device, const uint16_t reg, const uint16_t bits, std::vector<bool> &out);
|
||||
const bool readInteger(const uint8_t func, const uint8_t device, const uint16_t reg, const uint16_t num, std::vector<uint16_t> &out);
|
||||
const bool writeBinary(const uint8_t func, const uint8_t device, const uint16_t reg, const uint16_t bits, const std::vector<bool> &in);
|
||||
const bool writeInteger(const uint8_t func, const uint8_t device, const uint16_t reg, const uint16_t num, const std::vector<uint16_t> &in);
|
||||
const bool verifyCrc(const std::vector<uint8_t> &data);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user