g-STIMbox is a stimulator digital I/O box with an USB interface manufactured by g.tec medical engineering GmbH. The device features 14 digital inputs and 16 digital outputs. This module encapsulates a proprietary DLL (Dynamic-link library) that operates exclusively under Microsoft Windows.
In order to install the device follow these steps:
For this Python module to work follow these steps:
For further information refer to the PDF manual shipped with the device.
This example shows both output port operation modes (manual, frequency).
The output ports can be either controlled manually (ON/OFF) or assigned a specific frequency. It’s possible to have different ports operate on different modes simultaneously (e.g. port 1 and 3 work in manual mode while 2 and 4 work in frequency mode).
Example code:
from sys import stdout
from time import sleep
from gstimbox import GStimbox
comport = 3
b = GStimbox(comport)
print "Connected to g-STIMbox (serial port %d)" % comport
print "Driver version %s, firmware version %s" % (b.getDriverVersion(), b.getHWVersion())
print "Micro-controller frequency demo running..."
stdout.flush()
port = [0, 1, 2, 3, 4, 5, 6, 7]
freq = [1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5]
mode = [1, 1, 1, 1, 1, 1, 1, 1]
b.reset()
b.setFrequency(port, freq)
b.setMode(port, mode)
sleep(10)
b.reset()
print "Manual ON/OFF demo running..."
stdout.flush()
state = [0 for i in range(16)]
for i in range(5):
for j in range(8):
state[j] = 1
b.setPortState(state)
sleep(0.1)
for j in range(8):
state[j] = 0
b.setPortState(state)
sleep(0.1)
b.reset()
print "Demo finished."
In order to handle input from the g-STIMbox input ports a callback function must be specified. The callback function receives a single argument, a list of 14 values (e.g. [0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]). Each value maps to the corresponding input port (e.g. list index 0 corresponds to input port 1). In the example input ports 2 and 4 are active while all others are not. Note that the callback function is triggered on every state change (that is on pressing and releasing of a button).
The following example prints out the complete input state vector and activates all output ports if button on input port 1 is active (pressed).
Example code:
from sys import stdout
from time import sleep
from gstimbox import GStimbox
def input_callback(input_vector):
global b
print "Input vector changed:"
print input_vector
b.setPortState([input_vector[0] for i in range(16)])
stdout.flush()
comport = 3
b = GStimbox(comport, input_callback)
print "Connected to g-STIMbox (serial port %d)" % comport
print "Driver version %s, firmware version %s" % (b.getDriverVersion(), b.getHWVersion())
b.reset()
print "Use a button connected to input port 1 to activate all output ports."
print "This program will exit after 15 seconds."
stdout.flush()
sleep(15)
b.reset()
print "Demo finished."
Create a connection to the g-STIMbox.
The serial port number defaults to 3. A callback function can be specified that handles signals from the input connectors (see Processing input).
Close device connection.
Returns API library version.
Returns firmware version.
Reset device.
Set the frequencies for output ports.
port - list of port numbers to change. Valid port numbers range from 0 to 15. (eg. [0, 6, 7])
freq - list of frequencies which are to be assigned to the ports. Allowed values range from 1 to 50. The function rounds these frequencies to one digit after the comma. The length of freq must equal the length of port list. (eg. [1, 2.7, 5.8])
Set the operation mode of output ports.
port is a list of port numbers to change (eg. [0, 2, 3]). Valid port numbers range from 0 to 15.
modes is a list of modes for the ports defined in the port variable. A mode value can be either 0 (controlled manually, see portState()) or 1 (microprocessor controlled frequency, see setFrequency()).
Set ON/OFF state for ports running in mode 0 (see setMode()).
state is a list with a length of 16. Valid values for a state is an integer of either 0 or 1.
eg. state = [0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
g-STIMbox device communication error.
moduleauthor:: Mirko Dietrich <mirko.dietrich(AT)bccn-berlin(DOT)de>