I have a simulink block diagram that interfaces to a force-feedback haptic device:(http://www.sensable.com/haptic-phantom-omni.htm) in Simulink external mode. I can read position commands from this device and output force-feedback to this device (a block in my diagram does this, and it works fine). I can visualize the position signals on a simulink scope. In addition to that, I want to be able to use these position signals from the device to control a slider in my matlab GUI.
I included a gain block in the path of the position signal and tried to use add_exec_event_listener to register an event listener on its output. I understand that the callback registered by add_exec_event_listener is only executed when the corresponding block (in this case the Gain block) in the simulink block diagram is executed. I got errors when I tried to build this, since the diagram is running in external mode.
I found out that since in external mode, blocks are not executed inside simulink, but on the target processor, I cannot simply use add_exec_event_listener to register listeners. So I needed to get this Gain block out from external mode execution. I learnt that by creating an "atomic subsystem" in my block diagram, I can make some blocks in my block diagram to run inside Simulink rather than in external mode. So I created an "atomic subsystem" around this Gain block (there are also a few other blocks in this atomic subsystem), and I can now use add_exec_event_listener on the Gain block output. The diagram now builds and even runs without any errors.
However, add_exec_event_listener does not really work! The handle to the listener returned by h = add_exec_event_listener(blk, event, listener); is empty (very sad)!
If I try to edit the handle 'h' in the Matlab workspace by entering my updateGUI() function into it while the block diagram is executing, I can hit breakpoints inside the function. But this is of no use.
If I add a pushButton on my GUI that reads the current Gain block output and updates the GUI slider position (using runtimeObject), it works. But of course, I cannot click on this button at a rate of 500 Hz for a few minutes, which is what I want the listener to do. But it does not do that currently.
Extremely sorry for the long text, I just wanted to be clear enough. Any ideas on how one could solve my problem?