Skip to content

cboulay/magstim_python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#Python interface for Magstim TMS devices

Installation

I assume you have Python installed and on the system path. Install pyserial. In the magstim-python folder, run python setup.py install.

Instructions

#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

Other information

  • 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.

  • Instructions to make a serial cable

  • Triggering with an analog out device uses my caio module though you may devise your own.

  • Information not in the pdfs:

Host Command
D7D6D5D4D3D2D1D0HexDescription
0101100058Command
0100000040Padding Byte
0110011167CRC
Base Controller Response
0101100058Command Acknowledge
NNNNNNNNNNInstrument Status
NNNNNNNNNNCurrent System Mode (see section below)
NNNNNNNNNNCRC

Possible Return Values of Current System Mode:

Value (hexadecimal)Value (string)Description
300System operating as a single stimulator.
311System operating as master in simultaneous firing mode.
322System operating as master in normal BISTIM mode with low resolution time setting mode active.
333System operating as master in BISTIM mode with independent external triggering for master and slave enabled.
344System operating as master in normal BISTIM mode with high resolution time setting mode active.
51QSystem operating as slave in simultaneous firing mode.
52RSystem operating as slave in normal BISTIM mode with low resolution time setting mode active.
53SSystem operating as slave in BISTIM mode with independent external triggering for master and slave enabled.
54TSystem operating as slave in normal BISTIM mode with high resolution time setting mode active.

About

Control and query your Magstim TMS device in Python.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages