Data Acquisition Toolbox with Simulink: Counter Input Channel

3 次查看(过去 30 天)
Hi,
We are trying to use an NI USB-6009 device to conduct I/O within a Simulink model. The model is already well developed and running on Simulink Real Time with another DAQ, and so we want to change the structure as little as possible. From my understanding, there is no support for the NI device with the Real Time package. Instead, we are trying to implement the data aquisition with the Data Aquisition Toolbox. This will be acceptable as we don't need hard real time and can run the model from a computer with MATLAB/Simulink running.
I need to count pulses from an encoder using the USB-6009 counter channel. I can do this in MATLAB using the following code:
s = daq.createSession('ni');
addCounterInputChannel(s,'Dev1', 'ctr0', 'EdgeCount');
s.inputSingleScan()
What is the equivalent to this in Simulink? The Data Acquisition Toolbox in Simulink does not include a counter input/output block. I find it strange that such a simple function would be available in MATLAB but not implemented in Simulink. When running the first line of the above code in Simulink through a MATLAB function blocks I get the following error:
Function 'createSession' not supported for code generation.
Function 'MATLAB Function' (#35.23.46), line 2, column 5:
"daq.createSession('ni')"

回答(2 个)

Walter Roberson
Walter Roberson 2020-8-7
编辑:Walter Roberson 2020-8-10
turn off rapid acceleration. You can have normal acceleration but you will probably need to mark a number of functions as external. If you turn off acceleration completely you can call normal matlab functions from a matlab function block.
  3 个评论

请先登录,再进行评论。


Rutvik Shete
Rutvik Shete 2020-8-7
facing same issue with NI USB 6251. Cant use commands when I code using Function block in Simulink.
Error is "Function 'daq' not supported for code generation. "
  2 个评论
Walter Roberson
Walter Roberson 2020-8-10
This is correct. The Data Acquisition Toolbox is not supported for Code Generation.
It is supported by MATLAB Compiler.
I am not clear as to whether it is supported by Simulink Coder.
If you happened to be trying to use it from MATLAB Function Blocks, then you could use No Acceleration, or Normal Acceleration, and use coder.extrinsic() to have the interpreted engine invoke the functions. You might not be able to use Rapid Acceleration. There are probably a series of alternatives to use with Real Time Workshop.
Rutvik Shete
Rutvik Shete 2020-8-11
Well that helped me use external functions with sacrifice of simulation speed. Thanx a lot.

请先登录,再进行评论。

产品


版本

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by