PDA

View Full Version : Modbus Protocol



^NyAw^
21st January 2008, 10:37
Hi,

I'm trying to develop the Modbus protocol and I'm having a problem for a while.

I want to know if I'm using a good approach.

I have this classes:
-CModbus(pointer to CModbusTCPTransport)
-CModbusMaster : public CModbus
-CModbusTCPMaster : public CModbusMaster
-CModbusTCPTransport(has a TCP socket)

Also I have a QTimer in the main thread and a worker thread.

CModbusMaster has a QQueue to enqueue Modbus requests.
CModbusMaster has a method "AddRequest" that enqueue a request.
The worker thread does something and emits a signal connected to "AddRequest".
The timer enqueue requests too.
The socket is connected to a slot to recive data.
When the socket slot is called I read the Modbus Header and some other bytes. I dequeue the Modbus request and I compare the transaction of the request(just dequeued) and the response(just arrived). This transaction must match. For a while requests it math but then it don't.

Is this a good approach or maybe I have a bad design?

Thanks,