Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Issue reading data from analog input module
Hi Josh (and others)!

I'm using an analog input module to record sniff signals, and every once in a while (~once every four hours of running the protocol), I run into the following error that crashes my protocol and requires me to start another session: 

Warning: The specified amount of data was not returned within the Timeout period. 'serial' unable to read all requested data.
For more information on possible reasons, see Serial Read Warnings.

Index exceeds the number of array elements. Index must not exceed 18902.

Error in ArCOMObject_Ain/read (line 302)
varargout{i} = typecast(uint8(ByteString(Pos:Pos+(nValues(i)*2)-1)), 'uint16'); Pos = Pos + nValues(i)*2;

Error in BpodAnalogIn/getData (line 427)
RawData =, 'uint16');

Error in DMS_analog (line 522)
analog_data{currentTrial,1} = Ain.getData();

Error in run (line 91)
evalin('caller', strcat(script, ';'));

Error in NewLaunchManager>LaunchProtocol (line 754)

Error while evaluating DestroyedObject Callback.

I haven't been able to identify anything specific precedes this error- it feels more or less random (with different values for the index that is exceeded each time). Do you have any suggestions for how I might resolve this issue? It seems like there are several possible fixes outlined in MATLAB's serial read warnings info but I figured I should probably check here before messing around with any of those parameters. If it helps to know, I'm running v22 and am using the Java serial interface in ArCOMObject_Ain.m. Please let me know if any additional information from me would be helpful in troubleshooting this!

Thanks so much, 

Hi David,

Apologies for the late reply!

If you start Bpod with the 'UseJava' argument and PsychToolbox is installed, ArCOMObject_Bpod will use Java - but the 'Ain' version won't. You need a separate modification: on line 77 of BpodAnalogIn.m, change

obj.Port = ArCOMObject_Ain(portString, 115200);


obj.Port = ArCOMObject_Ain(portString, 115200, 'Java');

Many users have been reporting various Bpod data transfer issues with PsychToolbox on newer versions of MATLAB. Our upcoming release of Bpod console 1.65 (with optional state machine firmware v23) will automatically use MATLAB's new serialport class for r2019b or newer, with PsychToolbox as the fallback.

Hi Josh,

we are experiencing the same exact issues. 
We tried the suggested above workaround but it did not help.

Any additional suggestions,


Hello Roberto,

I think this issue is solved now. Please try the code on the develop branch.



Forum Jump: