Problem with matlab function block in simulink real time windows traget

조회 수: 3 (최근 30일)
I’m using 2 cards to communicate with hardware which are (NI CDAQ 9172 and Advantech PCI 1710). For PCI card I’m using real time window target and for NI CDAQ I wrote a code using matlab R2011a function block to bring the data into simulink, but the problem is I got an error when I try to build model which is:" Attempt to extract field 'addAnalogOutputChannel' from 'MATLAB type'. Function 'NI9265a_AO0_PV101' (#18.242.243), line 6, column 1: "s"Launch diagnostic report".I try using ‘Interpreted MATLAB Function’ but its only works for normal simulation and not for external mode (real time). Can anyone suggest how I can bring the NICDAQ in external mode (rtw mode)?
My code is:
function y = fcn(channel,input)
%#codegen
coder.extrinsic('-sync:off','daq.getDevices','daq.createSession', 's.addAnalogOutputChannel', 's.Rate','s.outputSingleScan','addAnalogOutputChannel');
d=daq.getDevices;
s=daq.createSession('ni');
s.addAnalogOutputChannel('cDAQ1Mod2',channel,'current');
s.Rate = 1;
input=input/1000;
outputSingleValue = input;
s.outputSingleScan(outputSingleValue);
y=input

채택된 답변

Alexander Bottema
Alexander Bottema 2011년 7월 15일
Hello Zakariah,
First, external mode (rtw mode) requires code generation.
Second, anything you declare with 'coder.extrinsic' is going to be exempt from code generation. 'extrinsic' means that instead of doing code generation you'll let MATLAB runtime system handle it.
The error message "Attempt to extract field..." is because calls to 'extrinsic' functions default to a generic "MATLAB Type" for which we cannot generate code for.
If there's no explicit code generation support for cDAQ-9172, and you want to generate code for it, I'm afraid you would have to write your own custom C code that would interface with the hardware.
  댓글 수: 2
zakariah yusuf
zakariah yusuf 2011년 7월 15일
Hi Alex,
Thanks for your answer,if i want to do it in normal simulation which mean write matlab code for cDAQ 9172 card to bring the data to simulink and use the data acquisition toolbox block for PCI 1710 for sampling time at 1 second, can the data consider as a real time?
Alexander Bottema
Alexander Bottema 2011년 7월 15일
Hi Zakariah,
This goes beyond my knowledge domain so hopefully some other expert can chime in. However, you can always try it to see if it is fast enough.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jack pake
Jack pake 2011년 7월 15일
I try to use a USB stick with Simulink's "real-time Windows Traget", but that does not work. I've read in this group use RTWin toolbox "analog input" Block, solve my problem. When I compile, so that real-time operation of the system, the joystick Zero output. In many cases, MATLAB's crashs. Does anyone do this before it? Here I set the joystick
- Data acquisition board: standard device joystick [1H] - Sampling Time: 0.001 - Input Channel: 1 - Input Range: - 1V to 1V - Block output signals: voltage
More : www.cheapergold.co.uk

카테고리

Help CenterFile Exchange에서 Code Generation and Deployment에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by