Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Analog Input Module slow serial messaging?
Hey everyone,
I have a problem when I try to send a serial message to the Bpod Analog Input Module.
The summary of the code I am using is as follows:

LoadSerialMessages('AnalogIn1', {['L' 1], ['L' 0]});  % Set serial messages 1+2 to start+stop logging
A = BpodAnalogIn('COM7');

sma = AddState(sma, 'Name', 'S0', ...
        'Timer', 0,...
        'StateChangeConditions', {'Tup', 'S1'},...
        'OutputActions', {'AnalogIn1', 1, 'SoftCode', 1, 'RaspbPi1', 1, 'GlobalTimerTrig', 1});
sma = AddState(sma, 'Name', 'S1', ...
        'Timer', S.GUI.TrialLength,...
        'StateChangeConditions', {'Tup', 'S6'},...
        'OutputActions', {});
sma = AddState(sma, 'Name', 'S6', ...
        'Timer', 0,...
        'StateChangeConditions', {'Tup', 'exit'},...
        'OutputActions', {'SoftCode', 2, 'RaspbPi1', 2, 'AnalogIn1', 2, 'GlobalTimerCancel', 1});

AnalogData = A.getData()

In the first state S0 and the last state S6 there are multiple messages sent out and the GlobalTimer is switched on and off.
S.GUI.TrialLength is initialized at 1.
When I run this code I get the following error message:

Error using ArCOMObject_Ain/read (line 290)
Error: The serial port returned 0 bytes.

Error in BpodAnalogIn/getData (line 381)
            nSamples = double(, 'uint32'));

Error in TPM (line 195)
        AnalogData = A.getData

I checked and the error doesn't occur when S0's Timer is set to 0.025, but starts happening with 0.02 and below.
It also occurs when I move the {'AnalogIn1', 1} OutputAction down to S1, although that state should always be at least 1.0 seconds long.
All the other messages and triggers run as they should: The Raspberry Pi receives its byte, the SoftCodeHandler does its job, and the GlobalTimer runs.

Since this is only the Analog Input Module that is acting up with the Timer and it doesn't work when I move it to the next state I am out of ideas what is happening here.
How can I fix this and what is causing it? Are the serial messages intended to require some time?

Also: Every time this happens, the Analog Input Module crashes and has to be switched off and on again, which I assume is caused by the getData() request when the SD-card is empty.
Am I correct in that assumption?

Thanks in advance,

Forum Jump: