Hi,
To improve the initialization time and overall performance, you can try the following workaround approach:
- Initialize the DAQ session outside of the function block, perhaps in a MATLAB Function block that runs only once at the start of the simulation.
- Use a persistent variable in your function block to maintain the DAQ session across function calls.
Here's how you might modify your code:
- Create a new MATLAB Function block for initialization:
coder.extrinsic('daq', 'addinput');
addinput(d, 'Board0', 0, 'Voltage');
- Modify your existing function block:
data = read(daqSession, 'OutputFormat', 'Matrix');
- In your Simulink model, use the initialization function to create the DAQ session, then pass it to your main function block.
This approach should significantly reduce the initialization time because you're setting up the DAQ session only once at the start of the simulation, rather than every time the function block is called.
I hope this helps!