Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bpod_Gen2 fail to read from serial port in some trials
Hi Josh,

I recently tried to use the latest version of Gen2 repository and StateMachine-Bpod0_789 on Arduino Due. I experienced a serial reading error in some cases, similar to For the first day, no error came out (8 animals, 40 minutes every day). On the second day, the error came out for 6th animal after running about 10 minutes. On the third day, the error started to show up for the 2nd animal. The Due board and USB cable are fine, as I even changed with the entire new device and cable. The protocol was running on windows 10 and Matlab 2019a. The Psychtoolbox is well installed.
deliverWater={'PWM4', 255};
ChangeState='BNC1High';  % PWM11

sma = NewStateMatrix();
sma = SetGlobalCounter(sma, 1, ChangeState, N_press(currentTrial));
sma = AddState(sma, 'Name', 'WaitForPress', ...
   'Timer', 0,...
   'StateChangeConditions', {'GlobalCounter1_End', 'WaitForLick'},...
   'OutputActions', {});    % didn't work in previous Bpod version

sma = AddState(sma, 'Name', 'WaitForLick', ...
   'Timer', 0,...
   'StateChangeConditions', {'Port1In', 'Water'},...
   'OutputActions', {});  
sma = AddState(sma, 'Name', 'Water', ...
       'Timer', RewardAmount, ...
       'StateChangeConditions', {'Tup', 'exit'}, ...
       'OutputActions', deliverWater);

Error using ArCOMObject_Bpod/read (line 367)
Error: The USB serial port did not return the requested number of bytes.

Error in RunStateMachine (line 42)
      SMA_Confirmed =, 'uint8');

Error in RunStateMatrix (line 2)
RawEvents = RunStateMachine;
Thank you in advance,
Hi Lei,

If you start Bpod with:
Bpod('COM3', 'ForceJava'); % Where 'COM3' is your state machine's USB serial port name
Does the issue go away?

Anecdotally, there may be stability issues when using our software with PsychToolbox's IOPort serial interface (the Bpod default) on MATLAB r2019a or newer. MATLAB's Java based serial interface speed has been improved in recent releases, so defaulting to PsychToolbox may no longer be the right thing to do.
Please let us know what you find!
If the issue persists, could you please post your entire m file?
(06-15-2020, 03:56 AM)Hi Josh, Wrote: Thank you for your suggestion. Bpod('COM3', 'ForceJava') works perfectly in matlab 2019a. No Serial reading issue any more. I strongly recommed to put this advice in future realse note.


Forum Jump: