How do you correctly reference contents of a 'DataAvailable' event?

2 visualizaciones (últimos 30 días)
Eamon
Eamon el 20 de Sept. de 2016
Comentada: Walter Roberson el 29 de Sept. de 2016
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 comentarios
Eamon
Eamon el 29 de Sept. de 2016
Editada: Eamon el 29 de Sept. de 2016
Hi Walter. I used
findobj(gcf,'type','axes')
to find the axes. However, when I incorporate the axes into the plot argument like so:
dataListener2 = addlistener(s, 'DataAvailable', @(src,event) plot(handles.axes1, event.TimeStamps, event.Data));
No plot is generated, even in a separate window, and I get the same error as before, the "Struct contents reference from a non-struct array object" error. I'm not sure why this is but I'm going to experiment with different axes and see if that might work.
Walter Roberson
Walter Roberson el 29 de Sept. de 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.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Graphics Object Properties en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by