Skip to content

SetElectrodeMode(electrode, Mcs.Usb.ElectrodeModeEnumNet.emManual) works but SetElectrodeMode(electrode, Mcs.Usb.ElectrodeModeEnumNet.emAutomatic) does not in MATLAB #2

@gchassink

Description

@gchassink

Hi,
When I try to stimulate using a MATLAB script based on the example provided by MCS, its works. However if a want to use automatic stimulation in stead of dedicated electrode stimulation, using SetElectrodeMode(electrode, Mcs.Usb.ElectrodeModeEnumNet.emAutomatic) it does not stimulate. (checked with oscilloscope). Strangly, if I :

  1. stop my matlab script (see below)
  2. switch to MC-Rack program a stimulation on stg1
  3. stimulate once
  4. stop mc-rack
  5. run the matlabscript without rebooting the IFB
    It does work!? So I suspect there is a base setting missing in the example script for this.

Is this a simple addition or something more complicated?

Kind regards,

Gerco

function stimEventTime=stimulate_electrode( devicelist, electrode, channelorder, stimtype, amplitude, duration)

electrode=find(channelorder==electrode)-1;% MCS=0:59, matlab=1:60
if devicelist.Count == 0

    Msgbox('No MEA USB Device connected!', 'Error Connecting To Device', 'error');
end

cStgDevice=Mcs.Usb.CStg200xDownloadNet();

% Connect to the stimulator of the device. The lock mask allows multiple connections to the same device
status = cStgDevice.Connect(devicelist.GetUsbListEntry(0),1); % ,1) is the lockmask
if status == 0

    % Make sure that the stimulation is stopped
    cStgDevice.SendStop(uint32(1));

    % ElectrodeMode: emManual: electrode is permanently selected
    % for stimulation or emAutomatic for automatic
    %                 cStgDevice.SetElectrodeMode(electrode,  Mcs.Usb.ElectrodeModeEnumNet.emManual);
    cStgDevice.SetElectrodeMode(electrode, Mcs.Usb.ElectrodeModeEnumNet.emAutomatic);

    % ElectrodeDacMux: DAC to use for stimulation
    % cStgDevice.SetElectrodeDacMux(electrode,listmodeindex,0);% required to reset the dacmux in between stimulations

    cStgDevice.SetElectrodeDacMux(electrode,0, Mcs.Usb.ElectrodeDacMuxEnumNet.Stg1);% (electrode, index=0, dac)


    % 0 = Ground
    % 1 = Stg1
    % 2 = Stg2
    % 3 = Stg3

    % ElectrodeEnable: enable electrode for stimulation
    % cStgDevice.SetElectrodeEnable(electrode, listmodeindex, enable);
    cStgDevice.SetElectrodeEnable(electrode, 0, true);

    % for i=0:59%find(channelorder==32)-1
    %     if  i==14 % the ground electrode itself ||i==electrode
    %     % BlankingEnable: false: do not blank the ADC signal while stimulation is running
    %     cStgDevice.SetBlankingEnable(i, false);
    %     % AmplifierProtectionSwitch: false: Keep ADC connected to electrode even while stimulation is running
    %     cStgDevice.SetEnableAmplifierProtectionSwitch(i, false);
    %     else
    %        cStgDevice.SetBlankingEnable(i, true);
    %        cStgDevice.SetEnableAmplifierProtectionSwitch(i, true);
    %     end
    % end
    % cStgDevice.SetBlankingEnable(electrode, true );
    % cStgDevice.SetEnableAmplifierProtectionSwitch(electrode, true);
    %

    if stimtype=='nA';
        % use current stimulation
        cStgDevice.SetCurrentMode();

    else
        % use voltage stimulation
        cStgDevice.SetVoltageMode();

    end
   
    if stimtype=='nA'
        cStgDevice.PrepareAndSendData(0, NET.convertArray(amplitude, 'System.Int32'), NET.convertArray(duration, 'System.UInt64'), Mcs.Usb.STG_DestinationEnumNet.channeldata_current);
    else
        cStgDevice.PrepareAndSendData(0, NET.convertArray(amplitude, 'System.Int32'), NET.convertArray(duration, 'System.UInt64'), Mcs.Usb.STG_DestinationEnumNet.channeldata_voltage);
    end

    % connect all stimulation channels to the first trigger and repeat the
    % pulse 1 times
    
    cStgDevice.SendStart(uint32(1));
    
    %% bring electrode back in activated state
    % A hack to bring back the electrode to reading mode
    % cStgDevice.SetElectrodeMode(electrode, Mcs.Usb.ElectrodeModeEnumNet.emAutomatic);
    % cStgDevice.SetElectrodeDacMux(electrode,0, Mcs.Usb.ElectrodeDacMuxEnumNet.Stg1);% (electrode, index=0, dac)
    % cStgDevice.SetElectrodeEnable(electrode, 0, true);
    % cStgDevice.SetBlankingEnable(electrode, true);
    % cStgDevice.SetEnableAmplifierProtectionSwitch(electrode, true);
    % amplitude =int32([0, 0]); % nA or uV
    % duration = uint64([0, 0]); % ??s
    % cStgDevice.SetVoltageMode();
    % cStgDevice.PrepareAndSendData(0, NET.convertArray(amplitude, 'System.Int32'), NET.convertArray(duration, 'System.UInt64'), Mcs.Usb.STG_DestinationEnumNet.channeldata_voltage);
    % cStgDevice.SetupTrigger(0, NET.convertArray(255, 'System.UInt32'), NET.convertArray(255, 'System.UInt32'), NET.convertArray(1, 'System.UInt32'));
    % cStgDevice.SendStart(uint32(1));

    %% end session and disconnect
    % TriggerInputs = cStgDevice.GetNumberOfTriggerInputs();
    stimEventTime=datetime;
    cStgDevice.Disconnect(); % ,1)

else
    disp ('connection failed');
    disp (dec2hex(status));
    disp (Mcs.Usb.CMcsUsbNet.GetErrorText(status));
end

end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions