This a BLDC controller in Qt C++ Based on Qt 5.15.2 purpose is to control ZLTECH ZLAC 8015D a dual BLDC motor driver Protocol use Modbus RTU
we implement only subset for velocity controller as we use this on Autonomous Mobile Robot
Later on we are going to port the code in to ROS 2 Package
The code is written based on QModbus https://github.com/Kefir0192/QModBus
This class is deprecated. It was developed when Qt did not support the work with the ModBus protocol. Now you should use the standard Qt interface to work with ModBus(Since Qt 5.8):Qt Modbus.
QModBus is abstract C++ class for Qt. QModBus is wrapper over libmodbus for Qt. From this abstract class inherited two specific classes: QModBus_TCP and QModBus_RTU. This class provides the opportunity to work with the library (libmodbus ver 3.1.2) in not blocking mode.
The class has the following public methods:
bool is_connected() { return connect_done; }
const char *get_strerror() { return strerror; }
void set_slave(int new_slave);
int get_slave() { return slave; }
void set_response_timeout(uint32_t sec, uint32_t usec);
void get_response_timeout(uint32_t *sec, uint32_t *usec);
The class has the following public signals:
signals:
void connected();
void disconnected();
void error(QModBus::ModBusError error);
void response_to_read_regs(int status);
void response_to_write_reg(int status);
void response_to_write_regs(int status);
The class has the following public slots:
public slots:
virtual void connect();
virtual void disconnect();
virtual void read_regs(int addr, int num_regs, uint16_t *dest);
virtual void write_reg(int addr, uint16_t value);
virtual void write_regs(int addr, int num_regs, const uint16_t *data);
The class has the following public enums:
enum ModBusError
{
NoConnectionError,
CreateError,
ConnectionError,
SetSlaveError,
ReadRegsError,
WriteRegError,
WriteRegsError,
UnknownError = -1
};
More details see: qmodbus.h
To start working, perform the following steps:
- You need to include qmodbus.h file in your .cpp file.
- And add file qmodbus.cpp to list of source files to compile (to qmake project file). (see an example)
- test_tcp - how to work with the class QModBus_TCP
- test_rtu - how to work with the class QModBus_RTU
In OS Linux Device for test_rtu is: /dev/tty* default is: /dev/ttyUSB0
In OS Windows Device for test_rtu is: \\.\COM*
qmake
make
Copyright (C) 2015 Koynov Stas - skojnov@yandex.ru