Tutorial changing configuration (APEX)#

This tutorial provides a step-by-step guide on running the example_change_channel_settings.py located inside the examples_APEX folder.

Using TMSi APEX amplifier it’s possible to select any (sub)set of channels to be included in the signal’s acquisition reference calculation. The TMSi Python interface can be used to change this parameter as well as the channel names.

Adding the correct directory of files#

To recognize the TMSi Python interface folder, which is necessary for running the examples, your Python interpreter needs to know the corresponding path. Therefore, the first lines of code add this information. If you wish to store the recordings in a different folder than the default one, you can change the directory given in line 39.

35import sys
36from os.path import join, dirname, realpath
37Example_dir = dirname(realpath(__file__)) # directory of this file
38modules_dir = join(Example_dir, '..') # directory with all modules
39measurements_dir = join(Example_dir, '../measurements') # directory with all measurements
40configs_dir = join(Example_dir, '../TMSiSDK\\tmsi_resources') # directory with configurations

Importing the required classes and functions from TMSi SDK#

These are the libraries which are implemented by TMSi and are required for the example script to work. They are used for purposes such as handling errors, writing recording files on PC, and plotting incoming data.

43from TMSiSDK.tmsi_sdk import TMSiSDK, DeviceType, DeviceInterfaceType, DeviceState
44from TMSiSDK.tmsi_errors.error import TMSiError
45
46from TMSiGui.gui import Gui
47from TMSiPlotterHelpers.signal_plotter_helper import SignalPlotterHelper

Finding connected devices#

It’s possible to have more than one device connected. The Python interface can be used to discover each device. Therefore, it’s necessary to specify the type of connected device as well as the interface via which the device is connected to PC (line 51). For APEX it can be either usb or bluetooth. Next, a list of connected devices (device type has already been specified) can be stored inside variable discoveryList. The next line of code (line 54) is a check to ensure that at least one device has been discovered. When one or multiple devices are found, the first device is opened. The handle to this discovered device is stored in the variable dev. The dev.open() command opens a connection to APEX.

50    # Execute a device discovery. This returns a list of device-objects for every discovered device.
51    TMSiSDK().discover(DeviceType.apex, DeviceInterfaceType.usb)
52    discoveryList = TMSiSDK().get_device_list(DeviceType.apex)
53
54    if (len(discoveryList) > 0):
55        # Get the handle to the first discovered device.
56        dev = discoveryList[0]
57        
58        # Open a connection to APEX
59        dev.open()

Configuring reference channels#

Once a connection to the device is opened, it is possible to configure the reference channels. This can be done by calling the set_device_references method from dev class. There are two arguments for this method:

  • ‘list_references’, which is a binary list containing value 1 for each channel that should be included in reference calculation and value 0 for each of other channels (line 62).

  • ‘list_indices’, which is a list containing channel indices that correspond to each value given in ‘list_references’ (line 63).

61        # Set reference to first channel only 
62        dev.set_device_references(list_references = [1 if i == 0 else 0 for i in range(len(dev.get_device_channels()))],
63                                  list_indices = [i for i in range(len(dev.get_device_channels()))])

Changing channels names#

Using the method ‘set_device_channel_names’ from class ‘dev’, custom channel names can be set on the provided indices. Channels with indices 1 and 7 will get new names ‘Fpz’ and ‘F8’ respectively. In a similar way, more/less channels could be renamed to custom names.

65        # Set two custom channel names, on the specific channel indices
66        dev.set_device_channel_names(names = ['Fpz', 'F8'], indices = [1, 7])

Plotting the signals#

The plotter helper defines which plotter we use to view the signals. In this case, raw signals without any processing are desired. Therefore, the SignalPlotterHelper is initialized. This Helper needs a handle to the device, which is why the device is passed as variable. The GUI opens the defined plotter and shows the signals. For more infomration on plotters, please review Tutorial Plotters

68        # Check if there is already a plotter application in existence
69        app = QApplication.instance()
70        
71        # Initialise the plotter application if there is no other plotter application
72        if not app:
73            app = QApplication(sys.argv)
74        
75        plotter_helper = SignalPlotterHelper(device=dev)
76        # Define the GUI object and show it 
77        gui = Gui(plotter_helper = plotter_helper)
78         # Enter the event loop
79        app.exec_()        

Closing the connection#

Once the GUI is closed by the user, the event loop is stopped. Next, the connection to the device can be closed properly. APEX is now ready to be used again.

81        # Close the connection to the device
82        dev.close()