Unsolved Hardware Emulation and Delayed Function Calls
-
I'm wanting to emulate a serial port-based piece of hardware.
What I'm looking for, is a nice way of repeatedly executing a function (in a non-blocking fashion) with varying time-delays, simulating the varying response times of my hardware device. The response times I'm aiming for will be anywhere between 100ms and 1000ms depending on the command sent to the hardware.
In a
live
system where physical hardware is connected, the communication flow is something like this:send command to hardware -> hardware processes command -> hardware sends data to computer
In the emulated environment:
send command to emulator -> emulator thinks for a while -> emulator passes pseudo data out via signal
The key to this is that the system is non-blocking.
Could anyone please suggest a nice Qt mechanism which could help me here?
-
Hi
Will the commands be overlapping ?
I mean, it might get a few commands and need to answer them over time or is it just
one command pr cycle ? And the data reply just need to have various respond times
pr command. One at a time ? -
Hi,
Since QSerialPort is a QIODevice, you can create a subclass of it that you will use in place of your QSerialPort when you need to emulate the hardware.
-
@mrjj The commands won't be overlapping - the commands work in a synchronous nature with the device only replying with data when a command is issued to it.
There is "heartbeat" data sent from the hardware periodically but this is handled elsewhere.
@SGaist I've already got a heirarchy in place which looks something like this:
QObject -> BaseDevice -> SerialDevice -> GpsDevice -> SensorDevice -> ... -> EthernetDevice -> NetworkSensorDevice -> EmulatorDevice -> EmulatedSensorDevice