Hello, I’m trying to get Psychtoolbox to provide live-input feedback to the screen using a NI USB-6002 DAQ. I’m using Psychtoolbox in conjunction with the Data Acquisition Toolbox’s background acquisition. This allows for continuous reading of data from the DAQ with the option of continuing Matlab function. Using the ScansAvailableFcn property, I can set a function to run after a preset number of scans have been acquired. Through this, I’ve been able to get Matlab to plot live data using it’s own graphical interface. However, when I try to put my PTB screen update code in the function, the screen will update once or twice and then just stop. No errors are sent to the screen, and the rest of the script doesn’t run.
I’ve tried adjusting how many scans that it waits for before Matlab calls the ScansAvailableFcn, but that hasn’t resulted in a different outcome.
Any idea what could be causing this or any advice on how to fix this?
Here is the function that I set as the ScansAvailableFcn to update the screen when new data is acquired:
function associationScreenUpdate(obj,evt,goal, u_limit, zero_limit, window, textXCoord, textYCoord, rectColor, centeredRegion, baseRect, centeredbaseRect, lineWidthPix, white)
data = read(obj,obj.ScansAvailableFcnCount);
b = double(data.Dev4_ai0(end)) - zero_limit;
disp(b);
%Code for establishing fill bar size
assocForcePoints = round(b * 100 /u_limit);
if assocForcePoints > 100
assocForcePoints = 100;
elseif assocForcePoints < 0
assocForcePoints = 0;
end
forceHeight = baseRect(4)*assocForcePoints/100;
%Determine if current hit or miss and set color of goal
%area
if (assocForcePoints <= goal+5) && (assocForcePoints >= goal-5)
regionColor = [0 1 0];
else
regionColor = [1 0 0];
end
%Draw Rectangle and Text to Screen
[normBoundsRect]= Screen('TextBounds', window, num2str(goal));
goalText = CenterRectOnPoint(normBoundsRect, textXCoord, textYCoord);
DrawFormattedText(window, num2str(goal), goalText(3), goalText(4), white)
Screen('FrameRect', window, rectColor, centeredbaseRect, lineWidthPix);
Screen('FillRect', window, rectColor, [centeredbaseRect(1) centeredbaseRect(2)+(baseRect(4)-forceHeight) centeredbaseRect(3:4)]);
Screen('FillRect', window, regionColor, centeredRegion);
Screen('Flip', window);
end
Psychtoolbox Version: 3.0.17 - Flavor: beta - Corresponds to SVN Revision 12153
Matlab Version: 9.10.0.1710957 (R2021a) Update 4
OS: Windows 7 Enterprise Service Pack 1 64-bit
Processor: Intel Core i5-4670 CPU @ 3.40 GHz
Installed Memory: 16.0 GB
Graphics Card: AMD Radeon R7 200 Series running with Adrenaline 2020 21.5.2 driver
Thank you much!
Grace
Chib Neuroeconomics Lab
Johns Hopkins University School of Medicine