How do you correctly reference contents of a 'DataAvailable' event?
1 view (last 30 days)
Show older comments
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 Comments
Walter Roberson
on 29 Sep 2016
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.
Answers (0)
See Also
Categories
Find more on Graphics Object Properties in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!