Classes and functions for using trigger boxes.

Trigger boxes are used to send electrical signals to external devices. They are typically used to synchronize the presentation of stimuli with the recording of physiological data. This module provides a common interface for accessing trigger boxes from within PsychoPy.

This module serves as the entry point for plugin classes implementing third-party trigger box interfaces. All installed interfaces are discoverable by calling the getAllTriggerBoxes() function. To have your trigger box interface discovered by PsychoPy, you need to create a Python module that defines a class inheriting from BaseTriggerBox and set its entry point to psychopy.hardware.triggerbox in your plugin setup script or configuration file.

Overview

BaseTriggerBox(*args, **kwargs)

Base class for trigger box interfaces.

BaseTriggerBox.deviceName

Get the name of the trigger box.

BaseTriggerBox.deviceVendor

Get the name of the manufacturer.

BaseTriggerBox.getCapabilities(**kwargs)

Get the capabilities of the trigger box.

BaseTriggerBox.open(**kwargs)

Open a connection to the trigger box.

BaseTriggerBox.close(**kwargs)

Close the trigger box.

BaseTriggerBox.isOpen

Check if the trigger box connection is open.

BaseTriggerBox.setData(data, **kwargs)

Set the data to be sent.

BaseTriggerBox.getData(**kwargs)

Get the data to be sent.

BaseTriggerBox.setPin(pin, value, **kwargs)

Set the value of a pin.

BaseTriggerBox.getPin(pin, **kwargs)

Read the value of a pin.

getAllTriggerBoxes()

Get all trigger box interface classes.

Details

class psychopy.hardware.triggerbox.BaseTriggerBox(*args, **kwargs)[source]

Base class for trigger box interfaces.

This class defines the minimal interface for trigger box implementations. All trigger box implementations should inherit from this class and override its methods.

Initialize the trigger box interface.

close(**kwargs)[source]

Close the trigger box.

property deviceName

Get the name of the trigger box.

Returns:

Name of the trigger box.

Return type:

str

property deviceVendor

Get the name of the manufacturer.

Returns:

Name of the manufacturer.

Return type:

str

static getAvailableDevices()

Get all available devices of this type.

Returns:

List of dictionaries containing the parameters needed to initialise each device.

Return type:

list[dict]

getCapabilities(**kwargs)[source]

Get the capabilities of the trigger box.

The returned dictionary contains information about the capabilities of the trigger box. The strutcture of the dictionary may vary between trigger box implementations, so it is recommended to check if a key exists before accessing it.

Returns:

Capabilities of the trigger box. The names of the capabilities are the keys of the dictionary. The values are information realted to the specified capability.

Return type:

dict

Examples

Check what the required baudrate of the device is:

useBaudrate = getCapabilities()[‘baudrate’]

getData(**kwargs)[source]

Get the data to be sent.

Returns:

Data to be sent.

Return type:

int

getDeviceProfile()

Generate a dictionary describing this device by finding the profile from getAvailableDevices which represents the same physical device as this object.

Returns:

Dictionary representing this device

Return type:

dict

getJSON(asString=True)

Convert the output of getDeviceProfile to a JSON string.

Parameters:

asString (bool) – If True, then the output will be converted to a string, otherwise will simply be a JSON-friendly dict.

Returns:

JSON string (or JSON friendly dict) of getDeviceProfile.

Return type:

str or dict

getPin(pin, **kwargs)[source]

Read the value of a pin.

Parameters:

pin (int) – Pin number.

Returns:

Value of the pin.

Return type:

int

property isOpen

Check if the trigger box connection is open.

Returns:

True if the trigger box is open, False otherwise.

Return type:

bool

isSameDevice(other)

Determine whether this object represents the same physical device as a given other object.

Parameters:

other (BaseDevice, dict) – Other device object to compare against, or a dict of params.

Returns:

True if the two objects represent the same physical device

Return type:

bool

open(**kwargs)[source]

Open a connection to the trigger box.

setData(data, **kwargs)[source]

Set the data to be sent.

Parameters:

data (int) – Data to be sent.

setPin(pin, value, **kwargs)[source]

Set the value of a pin.

Parameters:
  • pin (int) – Pin number.

  • value (int) – Value to be set.

psychopy.hardware.triggerbox.getAllTriggerBoxes()[source]

Get all trigger box interface classes.

Returns:

Mapping of trigger box classes.

Return type:

dict


Back to top