QModbusTcpServer (Qt 5.7) calling readData before writeData
-
Hello,
i am implementing a ModbusTcpServer. So i derived a class from QModbusTcpServer and implemented the functions writeData and readData to access my own backing store. Generally the communication works fine but reading Data starts a different process than writing Data. My problem is the following:
Reading holding Reagisters from the server via Modbus calls the function readData. Writing the same holding Registers, calls readData first and then writeData, so i can't decide inside the readData function if this request is a read or a write out of the QModbusDataUnit-Object. Is there any other possibility to get the information or to avoid calling readData?
Best Regards.
Bart
-
Hello,
i am implementing a ModbusTcpServer. So i derived a class from QModbusTcpServer and implemented the functions writeData and readData to access my own backing store. Generally the communication works fine but reading Data starts a different process than writing Data. My problem is the following:
Reading holding Reagisters from the server via Modbus calls the function readData. Writing the same holding Registers, calls readData first and then writeData, so i can't decide inside the readData function if this request is a read or a write out of the QModbusDataUnit-Object. Is there any other possibility to get the information or to avoid calling readData?
Best Regards.
Bart
Hi @BartBart,
first thing: QtSerialBus was Technology Preview in Qt 5.7, so you should update to a newer Qt version to use the Modbus classes.
To your problem: So you have a class derived from
QModbusTcpServer
, right? And then you re-implemented theQModbusResponse processRequest(const QModbusPdu &request)
function, correct?So can you show us where your problem arises? It's not 100 % clear for me at the moment.
Regards.
-
Hi and thanks for your reply!
Yes my class is derived from QModbusTcpServer which is derived from QModbusServer. The class QModbusServer has the following virtual functions:
virtual bool readData(QModbusDataUnit *newData) const virtual bool writeData(const QModbusDataUnit &newData)
I have reimplemented these to store the data to an own backing store and to read data from it. When data is written to the ModbusServer it calls at first the readData function and then the writeData. My reimplemented readData function looks in pseudocode like this:
bool ModbusServer::readData(QModbusDataUnit * newData) const { if(!updateData(newData)) { return false; } emit dataWasRequested(); return true; }
I need to know in in this function if it was called because of an request or an write for further handling.
Regards.
-
Hi and thanks for your reply!
Yes my class is derived from QModbusTcpServer which is derived from QModbusServer. The class QModbusServer has the following virtual functions:
virtual bool readData(QModbusDataUnit *newData) const virtual bool writeData(const QModbusDataUnit &newData)
I have reimplemented these to store the data to an own backing store and to read data from it. When data is written to the ModbusServer it calls at first the readData function and then the writeData. My reimplemented readData function looks in pseudocode like this:
bool ModbusServer::readData(QModbusDataUnit * newData) const { if(!updateData(newData)) { return false; } emit dataWasRequested(); return true; }
I need to know in in this function if it was called because of an request or an write for further handling.
Regards.
Hi @BartBart:
When data is written to the ModbusServer it calls at first the readData function and then the writeData.
Without deeper understanding of the Modbus classes, this looks strange for me. Can you please provide a stacktrace in readData and writeData so I can see where the functions are called from? Thanks.