How to call DLL in Level-2 MATLAB S function?

Hello , I am trying to call a DLL in Level 2 MATLAB S function.My simulink block is already created but there is an error and it is *Source 'farhadll/Level-2 MATLAB S-Function' cannot have dynamic frame data setting for its output port 1. All sources should explicitly set all their output ports to be frame or non-frame* How to solve this problem?
function msfuntmpl_basic(block)
setup(block);
function setup(block)
% Register number of ports
block.NumInputPorts = 0;
block.NumOutputPorts = 1;
block.OutputPort(1).SamplingMode = 'sample';
% Setup port properties to be inherited or dynamic
block.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;
% Register parameters
block.NumDialogPrms = 0;
block.SampleTimes = [10 0];
block.SimStateCompliance = 'DefaultSimState';
block.RegBlockMethod('Start', @Start);
block.RegBlockMethod('Outputs', @Outputs); % Required
block.RegBlockMethod('Update', @Update);
%block.RegBlockMethod('Derivatives', @Derivatives);
block.RegBlockMethod('Terminate', @Terminate); % Required
function Start(block)
fullpathToDll = 'Z:\Farha\2015_02_26_photometer_Datenlogger\PC-Software\CGMultChan.dll';
fullpathToHeader = 'Z:\Farha\2015_02_26_photometer_Datenlogger\PC-Software\CGMultChan.h';
fullpathToHeader;
fullpathToDll;
loadlibrary(fullpathToDll, fullpathToHeader);
libfunctions ('CGMultChan');
IP = calllib('CGMultChan','CGMultChan_Connect','192.168.100.158');%Connect to Data Loger
if (IP == 0)
end
out = instrfind('Port','COM1');
%Open Serial COM Port
s = serial(serialPort);
set(s,'BaudRate',57600,'DataBits', 8, 'Parity', 'none','StopBits', 1, 'FlowControl', 'none','Terminator','CR');
set(s,'Timeout',10);
fopen(s);
TI_ms = calllib('CGMultChan','CGMultChan_SetIntTime',.02*100);
tic
block.Dwork(1).Data = 0;
function Outputs(block)
block.OutputPort(1).Data = block.Dwork(1).Data + block.InputPort(1).Data;
function Update(block)
BufferSize=16;
pBuffer = libpointer('singlePtr',zeros(BufferSize,1));
data2 = calllib('CGMultChan','CGMultChan_MeasureAll',pBuffer);%Measurement
output = pBuffer.Value
count = count + 1;
time(count) = toc; %Extract Elapsed Time
data(count) = output(1)
block.Dwork(1).Data = data;
function Terminate(block)
fclose(s);
clear pBuffer;
calllib('CGMultChan','CGMultChan_Disconnect');%Disconnect from Data Logger
%end Terminate

Answers (0)

Categories

Tags

Asked:

on 2 May 2016

Community Treasure Hunt

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

Start Hunting!