我正在尝试将特定数据包含到DataAvailable侦听器的EventData中,但我找不到方法。
我尝试了以下内容:
首先,创建一个与EventData关联的类并存储在文件MyEventData.m中:
classdef (ConstructorLoad) MyEventData < event.EventData
properties (Access = public)
Data = [];
end
methods
function obj=MyEventData(receiveObject)
obj.Data = receiveObject;
end
end
end
接下来,在我的program.m中:
% Create the session
Session = daq.createSession('nidaq');
% Add a channel
Channels = addAnalogInputChannel(Session, 'PXI1Slot2', 0, 'Voltage');
% Set continuous adquisition
Session.IsContinuous = true;
% Sampling rate
Session.Rate = 1000000;
% in this way two events per second
Session.NotifyWhenDataAvailableExceeds = 500000;
% Add listener
lh=addlistener(Session,'DataAvailable', @(src,event)EventFunction(src,event));
% My counter or any other data to pass to the event
TaskCounter = 0;
% Add my data
notify(Session, 'DataAvailable', MyEventData(TaskCounter);
% Start the session to adquire data
Session.startBackground();
当我运行它时,我在通知行中收到以下错误:
事件'DataAvailable'没有为类'event.listener'定义
我找不到任何方法将数据传递给事件。我发现Matlab的帮助很大,但关于这个问题。