I would like to simultaneously receive data from the camera (i.e. images) and analog voltage using matlab. For the camera, I use the imaq toolbar, for voltage reading I use the daq toolbar (read NI-USB device) with the following code:
clear all % Prepare camera vid = videoinput('gentl', 1, 'Mono8'); src = getselectedsource(vid); vid.FramesPerTrigger = 1; vid.TriggerRepeat = Inf; triggerconfig(vid, 'hardware', 'DeviceSpecific', 'DeviceSpecific'); src.FrameStartTriggerMode = 'On'; src.FrameStartTriggerActivation = 'RisingEdge'; % prepare DAQ s=daq.createSession('ni'); s.addAnalogInputChannel('Dev1','ai1','Voltage'); fid = fopen('log.txt','w'); lh = s.addlistener('DataAvailable',@(src,event)SaveData(fid,event)); s.IsContinuous = true; % Take data s.startBackground(); start(vid) N=10; for ii=1:N im(:,:,ii)=getsnapshot(vid); end % end code delete(lh ); fclose('all'); stop(vid) delete(vid)
where the SaveData function is:
function SaveData(fid,event) time = event.TimeStamps; data = event.Data; fprintf(fid, '%f,%f\n ', [time data]); end
I get images and a log.txt file with daq trace (time and data), but how can I use an external trigger (which starts the camera) or some other clock to synchronize the two? In this example, daq reads the camera that triggers the TTL signal (@ 50 Hz), so I want to assign each TTL pulse to the image.
Addendum: I searched and found several discussions (for example, one ) on this question and read examples that are on the Mathworks website but did not find an answer. The documentation shows how to start a multi-charge acquisition at an external event , but the acquisition in question is only applicable for DAQ-based entry, and not for (it also works in the foreground).
user2041376
source share