How do you correctly reference contents of a 'DataAvailable' event?
2 次查看(过去 30 天)
显示 更早的评论
I am trying to access the TimeStamps field of a 'DataAvailable' event from a NIDAQ session. I get the error:
Struct contents reference from a non-struct array object.
when I try to refer to the contents using the following code:
s = daq.createSession('ni');
ch = addAnalogInputChannel(s, 'Dev1', 1, 'Voltage');
ch(1).TerminalConfig = 'SingleEnded';
s.Rate = 1000;
s.DurationInSeconds = 10;
dataListener1 = addlistener(s, 'DataAvailable', @(src, event) datamanager(src, event));
startBackground(s)
datamanager(s, 'DataAvailable')
Which refers to the function datamanager:
function datamanager(src, event)
realData=[realData, event.Data, event.TimeStamps];
The "event" is of the class "daq.DataAvailableInfo," which seems to behave like a struct (see below), but I get this problem nonetheless.
The output for "event" is the following:
event =
DataAvailableInfo with properties:
TriggerTime: 7.3659e+05
Data: [100x32 double]
TimeStamps: [100x1 double]
Source: [1x1 daq.ni.Session]
EventName: 'DataAvailable'
The presence of a TimeStamps field inside event makes this error confusing to me. Any thoughts on how I could avoid or fix this would be appreciated. Thanks!
7 个评论
Walter Roberson
2016-9-29
You would have to have handles defined and have an axes1 field at the time you created the listener for that to be valid. When you reference a variable in an anonymous function like you are creating there, the contents of the variable are captured as of the time the anonymous function is created.
... but that might not be the difficulty you are encountering.
I do have access to that toolbox, but unfortunately I do not have a data generating device to test with, or at least not one that comes to mind.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Properties 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!