Cedrus (response boxes)

The pyxid package, written by Cedrus, is included in the Standalone PsychoPy distributions. See https://github.com/cedrus-opensource/pyxid for further info.

Example usage:

    import pyxid2 as pyxid

# get a list of all attached XID devices
devices = pyxid.get_xid_devices()

dev = devices[0] # get the first device to use
if dev.is_response_device():

    while True:
        if dev.response_queue_size() > 0:
            response = dev.get_next_response()
            # do something with the response

Useful functions


returns device at a given index.

Raises ValueError if the device at the passed in index doesn’t exist.


Returns a list of all Xid devices connected to your computer.

Device classes

class pyxid2.XidDevice(xid_connection)[source]

Class for interfacing with a Cedrus XID device.

At the beginning of an experiment, the developer should call:


Whenever a stimulus is presented, the developer should call:


_send_command(command, expected_bytes)[source]

Send an XID command to the device

activate_line(lines=None, bitmask=None, leave_remaining_lines=False)[source]

Triggers an output line.

There are up to 16 output lines on XID devices that can be raised in any combination. To raise lines 1 and 7, for example, you pass in the list: activate_line(lines=[1, 7]).

To raise a single line, pass in just an integer, or a list with a single element to the lines keyword argument:




The lines argument must either be an Integer, list of Integers, or None.

If you’d rather specify a bitmask for setting the lines, you can use the bitmask keyword argument. Bitmask must be a Integer value between 0 and 255 where 0 specifies no lines, and 255 is all lines. For a mapping between lines and their bit values, see the _lines class variable.

To use this, call the function as so to activate lines 1 and 6:


leave_remaining_lines tells the function to only operate on the lines specified. For example, if lines 1 and 8 are active, and you make the following function call:

activate_line(lines=4, leave_remaining_lines=True)

This will result in lines 1, 4 and 8 being active.

If you call activate_line(lines=4) with leave_remaining_lines=False (the default), if lines 1 and 8 were previously active, only line 4 will be active after the call.

clear_line(lines=None, bitmask=None, leave_remaining_lines=False)[source]

The inverse of activate_line. If a line is active, it deactivates it.

This has the same parameters as activate_line()


Clears the response queue


Pops the response at the beginning of the response queue and returns it.

This function returns a dict object with the following keys:

pressed: A boolean value of whether the event was a keypress

or key release.

key: The key on the device that was pressed. This is a

0 based index.

port: Device port the response came from. Typically this

is 0 on RB-series devices, and 2 on SV-1 voice key devices.

time: For the time being, this just returns 0. There is

currently an issue with clock drift in the Cedrus XID devices. Once we have this issue resolved, time will report the value of the RT timer in miliseconds.


Do we have responses in the queue


Initializes the device with the proper keymaps and name


Polls the device for user input

If there is a keymapping for the device, the key map is applied to the key reported from the device. This only applies to port 0 (typically the physical buttons) responses. Rest are unchanged.

If a response is waiting to be processed, the response is appended to the internal response_queue


gets the value from the device’s base timer


Resets the base timer


Resets the Reaction Time timer.


Number of responses in the response queue


Sets the pulse duration for events in miliseconds when activate_line is called

Back to top