nigelrogasch / MAGIC

Magnetic stimulator interface controller toolbox
23 stars 9 forks source link

Interrmitent error with setWaveform #25

Open phillipagres opened 6 months ago

phillipagres commented 6 months ago

Hi, I am an experiencing an intermittently recurring error while attempting to set the waveform. The code I'm running is below, where mvObject is my magventure object.

waveform = 'BiphasicBurst';
curDirect = 'Normal';
burstPulses = 3;
ipi = 20;
baRV = 1
mvObject.setPage('Main');
mvObject.setWaveform(waveform,curDirect,burstPulses, ipi, baRV, 0);

The error is :

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

Error in magventure/parseResponse (line 1759)
                  factorAmplitudeB = readData(15);

Error in magventure/processCommand (line 1627)
                                [~,deviceResponse] = self.parseResponse(readData);

Error in magventure/setWaveform (line 962)
               [errorOrSuccess, deviceResponse] =  self.processCommand(commandLength,commandBytes,getResponse,14);

This error occurs infrequently, and I am not always able to reproduce it. It occurs regardless of whether I set varargin for mvObject.setWaveform to 0(False) or 1(True) - refering to getResponse.

I am already aware of a related issue regarding setting 'currentDirection' to 'Normal' instead of '00'. I have previously fixed this issue by editing line 956 of magventure.m from: commandBytes = [commandID;setVal;model;mode;currentDir;waveformN;burstPulseIndex;ipi_M;ipi_L;BARatio_M;BARatio_L];

to:

commandBytes = [commandID;setVal;model;mode;currentDirN;waveformN;burstPulseIndex;ipi_M;ipi_L;BARatio_M;BARatio_L];

Perhaps this edit inadvertently caused my current issue, although the current issue occurs irregularly and is not always reproducible.

Thank you!

umair-hassan commented 5 months ago

Hi Philip,

Sorry gor the error, could yoi point out the matlab version you have been using?

I am not able to reproduce this on a 2018b version. What are you using for serial connection, an RS232 Or a USB?

I assume you are on windows OS?

Best, Umair

phillipagres commented 5 months ago

Hi Umair,

Yes, I'm on windows running matlab 2022b. We are using an RS232 serial cable from the windows PC to connect to a serial splitter, as we need to simultaneously interface between the matlab computer, the magventure stimulator, and a 2nd windows pc that is running our neuronavigation software.

This is the splitter we are using: https://www.amazon.com/gp/product/B07B631G26/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1

The error occurs sporadically. Yesterday I ran an experiment where i utilized the .setWaveform function ~30 times over the course of 2 hours, and I did not receive any error. Other times it can recur several times in the span of a few minutes. It has occurred both when trying to set the waveform to 'Biphasic' and 'BiphasicBurst'.

Thanks for helping!

umair-hassan commented 5 months ago

Hi Phil; can youbtry reproducing this in lower rank version of 2017/2018 and let me know if this occur again?

We have to update the syntax for 2021 and onwards releases but I'll be waiting for the matlab versions to settle a bit since they are going through drastic architecture changes. 2024 seems much stable now after 2021 big wave of change.

All use drawnow() manualy between commands, that'll create a buffer free zone , also add a pause(0.1) if its not causing any inconvinence. Just making sure matlab thread is free.

Best, Umair