Thanks for the reply, Josh!
I am running Windows 10 Enterprise with Matlab R2021a and PsychToobox Version 3.0.17
The Error Codes are as follows:
Error using ArCOMObject_Ain/read (line 290)
Error: The serial port returned 0 bytes.
Error in BpodAnalogIn/getData (line 423)
nSamples = double(obj.Port.read(1, 'uint32'));
Error in basicProtocol_GUI_SMA (line 85)
BpodSystem.Data.Force(currentTrial) = A.getData();
Error in run (line 91)
evalin('caller', strcat(script, ';'));
Error in NewLaunchManager>LaunchProtocol (line 717)
run(ProtocolPath);
Error while evaluating DestroyedObject Callback.
Error while evaluating TimerFcn for timer 'timer-14'
Error: The USB serial port did not return the requested number of bytes.
Error: Invalid op code received
Error: Invalid op code received
Error: Invalid op code received
Error while evaluating TimerFcn for timer 'timer-14'
Error: The USB serial port did not return the requested number of bytes.
Error: Invalid op code received
Error: Invalid op code received
*********************************************************************
* WARNING *
*********************************************************************
TrialManager reported an inter-trial dead time of >200 microseconds.
This may indicate that inter-trial code (e.g. plotting, saving data)
took MATLAB more than 1 trial duration to execute. MATLAB must reach
TrialManager.getTrialData() before trial end. Please check lines of
your protocol main loop (e.g. with tic/toc) and optimize accordingly.
*********************************************************************
I tried both of the changes you suggested and neither seemed to fix any of these errors. The 'simplest' version of my protocol is as follows. This one waits a shorter amount of time after each trial; it will run till the end without errors, but will show the above warning after the second trial.
function basicProtocol % Main protocol file, runs once when session is launched
global BpodSystem % Import the BpodSystem object (used here to detect when the user ends the protocol)
nTrials = 100; % Number of trials in session
TrialManager = TrialManagerObject; % Create trial manager object
time = 1;
sma = PrepareStateMachine(time); % Prepare first trial's state machine (see function below)
TrialManager.startTrial(sma); % Start first trial
for i = 1:nTrials
time = (100-i)/100;
sma = PrepareStateMachine(time); % Prepare next trial's state machine
SendStateMachine(sma);
RawEvents = TrialManager.getTrialData; % Hangs here until trial end, then returns the trial's raw data
% // Code to update Bpod modules with the next trial's parameters (if necessary) goes here.
if BpodSystem.Status.BeingUsed == 0; return; end % If user hit console "stop" button, end session
TrialManager.startTrial(sma); % Start next trial's state machine
% // Code to compute online behavior metrics goes here.
% // Code to update online plots goes here.
% // Code to format and save data goes here.
end
end
function sma = PrepareStateMachine(time)
sma = NewStateMatrix();
sma = AddState(sma, 'Name', 'MyRandomDelay', ...
'Timer', time,...
'StateChangeConditions', {'Tup', 'exit'},...
'OutputActions', {});
end
Thanks for all your help!
-Matt W.