L
L
LeonidPr2019-10-11 17:38:19
Qt
LeonidPr, 2019-10-11 17:38:19

How to ensure the processing of a set of requests via ModBus?

I am writing a program to work with a device I am developing using ModBus RTU.
At the moment, the exchange is arranged in such a way that there is a ModBus client class that provides sending requests and processing responses via ModBus.
Its interface is:

class IModBusClient {
    virtual void ReadHoldingRegs(uint16_t startRegAddres, uint16_t RegsCount, IModBusReponseListener *listener) = 0;
    ...
}

Those. the names of the functions duplicate the names of the requests from the documentation for the protocol.
The key point here is listener.
All requests are queued and processed one at a time.
When the request is processed (it doesn’t matter successfully or a timeout occurred or the device returned an error), the corresponding function of the listener twitches.
When I send one request, well, or a bunch of independent requests, everything is fine.
But there are tasks when, for example, you need to make sure that the success of a group of requests, for example, I write a bunch of disparate registers (some kind of config write to the device), I need to know that they all successfully signed in.
Here I'm trying to figure out how to make it more convenient?
My idea is to assign some ID to the request and use it as a key. Those. we pull ReadHoldingRegs, it returns the request ID. Then when the listener's callback is called, this ID will be passed there and the listener will know which request was completed.
The second is to organize objects that perform higher-level functions. Conditionally - write down the config, read the config (it is more complex to assemble from several requests), and so on. And then operate on them.
Tell me, what other ideas do you have? maybe some patterns are comfortable?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question