About Cedrus Response Box

Hi, Some time ago I had some issues when building an experiment on Psychopy (v2021.1.4 running on Windows 10) that use two Cedrus Response Box (in my case, two RB-740). Looking on the forum it seems that cedrus devices tend to give some problems, so I document here what happened and possible solutions. Hopefully it will be useful for future users, or eventually solved in upcoming updates.

The problem is that some parameters required in Builder for the buttonBox Component (‘Device number’ and ‘Allowed keys’) are not properly translated to code when compiling. Consequently, all the following raise an error when attempting to run the experiment:

  1. Regarding the ‘Device number’ parameter, an int value is expected as input, but when compiled, this translates to a float value. Here is the self- generated code:
   import pyxid2 as pyxid
except ImportError:
   import pyxid
cedrusBox_0.0 = None # Here Device number 0 outputs 0.0
for n in range(10):  # doesn't always work first time!
        devices = pyxid.get_xid_devices()
        cedrusBox_0.0 = devices[0.0] # Here Device number 0 also outputs a float as an index
        cedrusBox_0.0.clock = core.Clock()
        break  # found the device so can break the loop
    except Exception:
if not cedrusBox_0.0:
    logging.error('could not find a Cedrus device.')

The same error repeats for the code generated for the second cedrus Device, where Device number = 1 translates to a index of 1.0.

Further, when assigning these devices to a Component inside a Routine, this problem repeats once again.

buttonBox1L = cedrusBox_0.0
buttonBox1R = cedrusBox_1.0

These errors can be fixed by modifying the self-generated code. However, if the experiment needs to be tweaked using Builder, the error will persist and the code will have to be modified again after compiling, which can become very tedious during experiment testing and debugging.

The solution I tried to get my experiment working (not recommended, though) was to modify the ‘__ init __.py’ script from the cedrusBox package, which controls the actual compiling for the buttonBox Component. Although not very elegant, I managed to inser a str.replace() function to remove the floating part of the deviceNumber variable that the script handles.

  1. With respect to ‘Allowed keys’, a list of allowed keys is expected, as with other response devices within PsychoPy. However, when compiled, the list of allowed keys lacks the brackets. Here is part of the code generated to terminate a Routine when a button is pressed:
while len(buttonBox1L.response_queue):
    evt = buttonBox1L.get_next_response()
    if evt['key'] not in 6,7: # Here the brackets are missing, i.e. [6,7]
     if evt['pressed']:

This can be easily solved by the including the brackets on the buttonBox Component properties. Here is an example:

  1. Finally, regarding the frequently reported ‘Could not find a Cedrus device’ error, I have found that a simple reboot makes Psychopy detect the devices once again, at least for the first time.