Skip to content

3. Magstim Class

Nicolas McNair edited this page Jun 6, 2019 · 4 revisions

The magstim.m class is used for communicating with the Magstim stimulator. Different built-in methods in this class will empower you to have master control over your device. This class will also act as the parent class for subclasses Bistim.m and Rapid.m.

As previously mentioned in this documentation, altering parameters in a Magstim device is more complicated than the case with MagVenture. This is due to the fact that to maintain your control over the magstim device via a serial port, the device must continuously receive communication from the port. This regular communication must occur at least once every ten seconds in standby and one every second when armed. If one fails to sustain this regular communication, the device will automatically disarm and no longer respond to the future commands sent out to the port. In this toolbox, this constant flow of communication is maintained automatically from the second you establish your control over the device using remoteControl function.

Initialising:

To start working with the magstim class, similar to the magventure class, you need to first create an object of the class. This object will then be passed to each method as the primary input. The object will be constructed by defining the serial port using which you are intending to connect to your device.

magstimObject= magstim('PortID');

Next, to start working with the toolbox you need to connect to the desired port already defined in your magstimObject.

Connecting:

Using the next line of script, you will be connecting to the serial port and maintaining your connection unless an error occurs or until you manually disconnect it yourself. In order to establish the regular communication, this command will automatically call remoteControl after connecting to the serial port.

magstim.connect(magstimObject); or simply magstimObject.connect();

Disconnecting:

As previously mentioned, you can easily disconnect the device from your computer using the following command line:

magstim.disconnect(magstimObject); or simply magstimObject.disconnect();

Outputs:

In all the following commands, you can retrieve two outputs, one indicating the success or failure of the process (errorOrSuccess) and the other would be the device response (deviceResponse) which is a cell struct giving you details on the current parameters of the stimulator.

You can choose to retrieve the device response by setting the getresponse variable, which is the last input in all functions, to 1. The default value for this input is set to 0 in all the functions.

Enabling/Disabling Remote Control:

This class also provides a method for explicitly enabling/disabling remote control of your Magstim device, however usually this would not need to be called directly:

magstimObject.remoteControl(enable);

  • enable {boolean}: is a boolean that can be set to True(1) to enable or False(0) to disable the remote control.

After establishing your communication with the stimulator, you can now easily utilize all the available commands depending on the version and model of your device. In the following, you will find separate introductions for each of the commands.

Enabling and Disabling:

To start your control over your Magstim device, you can arm and therefore also disarm the stimulator.

magstimObject.arm();

magstimObject.disarm();

Setting Amplitude:

To set the desired power for coil A, you can use the following function by defining your desired power amplitude.

magstimObject.setAmplitudeA(power);

  • power {double}: is the desired power amplitude for stimulator A

Sending Single Trigger:

To send a single trigger to the stimulator, you can call:

magstimObject.fire();

Getting Parameters:

To retrieve Magstim status and parameters, you can simply call the following function:

magstimObject.getParameters()

The output will represent the instrument status byte as well as the working power value in the device's current state.

Getting Coil Temperature:

Calling this method will allow you to get information about the device working temperature.

magstimObject.getTemperature()

Note that when MAGIC creates an object of magstim class, it also takes the responsibility of maintaining regular connection with the Magstim device. This is achieved through ending a remoteControl command to the Magstim. Due to this recurrent sending of remoteControl command, there is a possibility of for a time-sensitive command (i.e., to fire) to be sent to the Magstim while the serial port is currently processing one of these polling commands. This will cause a delay of up to 10-15 ms.

To resolve this issue about potential delays in running commands, you can easily create a free time window using the following function:

Poking Device:

This functions will free up a small time window of privileged access to the serial port. Hence by poking the device prior to sending your desired time-sensitive command, the built-in timer in the class will be reset, opening up enough amount of time to process the user-defined command as soon as it is received.

magstimObject.poke(loud);

  • loud {bool}: determines whether to send (True=1) or not send (False=0) an enable remote control command while poking

Pausing Device:

By calling this function, you can pause Matlab while maintaining communication via the previously selected serial COM port.

magstimObject.pause(delay);

  • delay : determines the duration of time for which Matlab is paused while maintaining communication via serial COM port.
Clone this wiki locally