#Python interface for Magstim TMS devices
I assume you have Python installed and on the system path.
Install pyserial.
In the magstim-python folder, run python setup.py install
.
#Import your stimulator class
from Magstim.MagstimInterface import Magstim, Bistim, Rapid2
#Define your serial port
serPort='COM6'
#If using an additional device to do the triggering (highly recommended), try this
#This requires my caio module (see below)
from Caio.TriggerBox import TTL
stimulator=Bistim(port=serPort, trigbox=TTL())
#Else if using the serial port to trigger (note: indeterminate lag/jitter!)
stimulator=Bistim(port=serPort)
#The following functions and attributes are now available to you.
stimulator.armed #Read-Write. Set equal to True to arm. E.g., stimulator.armed = True
stimulator.trigger()
stimulator.ready #read-only. Returns whether or not the stimulator is ready. Note that Bistim does not support this feature.
stimulator.remocon #read-write. Set to True to enable. Should be enabled by default on stimulator init.
stimulator.intensity #read-write. Set equal to an int value to change stimulator intensity. e.g. stimulator.intensity = 30
#Bistim-only
stimulator.intensityb
stimulator.ISI #
stimulator.hr_mode #Whether or not bi-stim is in high-res mode. High-res set automatically if ISI has a decimal.
stimulator.master_mode #read-only. This device is controlling timing.
#Rapid2 only
stimulator.train_duration #How long the stimulus train lasts in seconds
stimulator.train_frequency #Pulse frequency, in Hz
stimulator.train_pulses #Number of pulses in the train
-
You will not receive an error if there is no magstim device connected, but the stimulator attributes armed, ready, and remocon should all return False
-
Tested with Bistim only. Not tested with Rapid2.
-
Triggering with an analog out device uses my caio module though you may devise your own.
-
Information not in the pdfs:
Host Command | |||||||||
D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 | Hex | Description |
---|---|---|---|---|---|---|---|---|---|
0 | 1 | 0 | 1 | 1 | 0 | 0 | 0 | 58 | Command |
0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 40 | Padding Byte |
0 | 1 | 1 | 0 | 0 | 1 | 1 | 1 | 67 | CRC |
Base Controller Response | |||||||||
0 | 1 | 0 | 1 | 1 | 0 | 0 | 0 | 58 | Command Acknowledge |
N | N | N | N | N | N | N | N | NN | Instrument Status |
N | N | N | N | N | N | N | N | NN | Current System Mode (see section below) |
N | N | N | N | N | N | N | N | NN | CRC |
Possible Return Values of Current System Mode:
Value (hexadecimal) | Value (string) | Description |
---|---|---|
30 | 0 | System operating as a single stimulator. |
31 | 1 | System operating as master in simultaneous firing mode. |
32 | 2 | System operating as master in normal BISTIM mode with low resolution time setting mode active. |
33 | 3 | System operating as master in BISTIM mode with independent external triggering for master and slave enabled. |
34 | 4 | System operating as master in normal BISTIM mode with high resolution time setting mode active. |
51 | Q | System operating as slave in simultaneous firing mode. |
52 | R | System operating as slave in normal BISTIM mode with low resolution time setting mode active. |
53 | S | System operating as slave in BISTIM mode with independent external triggering for master and slave enabled. |
54 | T | System operating as slave in normal BISTIM mode with high resolution time setting mode active. |