How to Query the Current State of a Replay Block via COM API
How can I trigger a COM event with the Replay Block in CANoe/CANalyzer?
In general you can control the Replay Block by using the COM object ReplayBlock. However it does not contain any events that can signal the COM client, that the replay was started or stopped.
Such an event can be useful for the COM client so that it knows when to load and start a new replay, stop the measurement, etc.
CAPL programs have the ability to query the current state of a Replay Block. This is achieved by using the CAPL function replayState. Information about the replay state is conveyed via its return value.
Using this function together with a timer, it is possible to periodically query the state of the Replay Block and keep track of it.
Since the return value is a simple unsigned integer, you can just write it to a system variable of the same type.
The following CAPL code example queries the replay state every second and writes the value to the system variable ComVariables::sysState:
const long lPeriod = 1000; //1 second period
on timer tTimer
//write currenty reply state to the system variable
state = replayState("ReplayBlock 1");
Whenever the state of the Replay Block changes, a different value will be written to the system variable causing it to trigger an OnChange event. This event can trigger in both the CAPL program and in the COM client.
You can use the COM object Variable to access the value of the system variable from your COM client…
… and use its OnChange event to trigger a callback function in the COM client.
The state of the Replay Block can now be processed in your COM application.