Reading data from device via QModbusRtuSerialMaster
-
Cheers to everyone!
I've received a quite simple task: develop an app that can read/write data from a MCU-based device utilizing Modbus and COM-port interface. Having absolutely zero experience in Qt development i rushed to doc.qt.io to gather some info and found QModbusRtuSerialMaster class. After having a sigh of relief i began writing my class, inheriting the one listed above.
Then i ran into a problem. Guys from MCU department provided me with some sort of communication table, which has a register to read/write data (e.g. 3001, or 1007:2 for bit data type) and the data type. For example: reading register 2001 will get us serial number of the device (uint16).
QtCreator has an included example of Modbus master app, which is capable of connecting to my device with no problems. But when it comes to reading/writing data, there is no way to use my register codes.
An hour of googling brought me to similar app written in C#, which converts register codes to 16bit before sending them into "read" function.
Any suggestions on further investigation will be highly appreciated.
Also begging your pardon for my english.
UPD: found this topic and trying to implement same way of reading.
-
Hi, @J-Hilk!
Looks like i found desired method in QModbusDataUnit class docs. Don't know how i missed it being mentioned in List of All Members for QModbusRtuSerialMaster. I guess digging into Qt docs about Modbus was a proper way to solve this :)
QModbusDataUnit::QModbusDataUnit(QModbusDataUnit::RegisterType type, int address, const QVector<quint16> &data)
In my case this will be:
QModbusDataUnit input(QModbusDataUnit::InputRegisters, 3001, data);
Thanks for joining my journey!
-
hi @BeaverShallBurn and welcome
I'm sorry but I really fail to see the problem,
The QModbusRtuSerialMaster class allows you to request/read registers and you get a list(vector) of uint16_t back, what's there to convert?can you show what code you actually have so far, and where exactly the problem is with it?
-
Hi, @J-Hilk!
Looks like i found desired method in QModbusDataUnit class docs. Don't know how i missed it being mentioned in List of All Members for QModbusRtuSerialMaster. I guess digging into Qt docs about Modbus was a proper way to solve this :)
QModbusDataUnit::QModbusDataUnit(QModbusDataUnit::RegisterType type, int address, const QVector<quint16> &data)
In my case this will be:
QModbusDataUnit input(QModbusDataUnit::InputRegisters, 3001, data);
Thanks for joining my journey!