Cedrus response box only works for first routine in Psychopy builder

828 views
Skip to first unread message

Maddie

unread,
Jan 21, 2014, 11:27:22 AM1/21/14
to psychop...@googlegroups.com
Hi,
 
I'm currently using Psychopy Builder 1.70 on Windows 7 and the Cedrus Response box RB-730.
 
I want to use the Cedrus box to both navigate between routines as well as record responses to stimuli. When I add a Cedrus response into the first routine the experiment runs fine. However, as soon as I add a Cedrus response into a second routine I receive this error:
 
buttonBox_2.status = NOT_STARTED
NameError: name 'buttonBox_2' is not defined
 
This is the respective code generated by the builder to which the error refers to:
 
for n in range(10): #Cedrus connection doesn't always work first time!
    try:
        devices = pyxid.get_xid_devices()
        core.wait(0.1)
        buttonBox_2 = devices[0]
        break #once we found the device we can break the loop
    except:
        pass
buttonBox_2.status = NOT_STARTED
buttonBox_2.clock = core.Clock()
 
If anyone is able to help then that would be great, thank you.

Michael MacAskill

unread,
Jan 21, 2014, 5:18:30 PM1/21/14
to psychop...@googlegroups.com
Hi Maddie,

[This seems to be the opposite problem to one that just came up on the list re interleaved staircases…]

It looks to me that Builder tries to create multiple objects representing the Cedrus box at the beginning of the experiment. The second and subsequent ones are likely failing because the box has already been "grabbed" and assigned to the component in your first routine. That code is also a bit fragile, because if the connection to Cedrus fails, subsequent lines still try to refer to it, instead of handling that failure more gracefully.

This isn't part of PsychoPy I really understand, but I suspect that you've found a bug that a(nother) developer will need to fix in the underlying Builder code. i.e. You should be able to create multiple Cedrus components in the Builder interface, but "under the hood", the code should be reusing the same Cedrus object on each routine.

Is there a workaround for this that would solve your problem immediately? I can't see one, but perhaps someone who understands how to use these devices in Coder could suggest some code you could paste into a Code component, in place of a Cedrus component on the subsequent routines.

Sorry, that isn't of much immediate help to you (and I may be quite wrong)…

Regards,

Michael

Maddie

unread,
Jan 22, 2014, 7:21:08 AM1/22/14
to psychop...@googlegroups.com
Thank you very much for your response Michael.
 
I can't see any workaround to fix my problem immediately unfortunately no. If anyone is able to offer some advice/example code to allow multiple Cedrus components then that would be greatly appreciated, thank you.
 
As a temporary fix I am currently just using one Cedrus component on my response screen so that I am still able to record some data but this is not ideal. I am also worried about the reliability of the Cedrus component when using it for repeated trials.
 
 I should clarify that I am using standalone  Psychopy 1.79.01 x 32 win in case that makes any difference.
 
 
Again, if anyone is able to offer any advice then that would be great. Many thanks.

laurabe...@googlemail.com

unread,
Jul 21, 2014, 10:03:07 AM7/21/14
to psychop...@googlegroups.com
Hi everyone,

We're using PsychoPy 1.80.03 x 64 win in Builder View and get exactly the same error message - this thread is already quite "old" (January 22nd) and we hope that maybe someone found a solution meanwhile?

To cite Maddie with the original error description:

"When I add a Cedrus response into the first routine the experiment runs fine. However, as soon as I add a Cedrus response into a second routine I receive this error:
 
buttonBox_2.status = NOT_STARTED
NameError: name 'buttonBox_2' is not defined"

Thanks for you help,

Laura&Marta

Jonathan Peirce

unread,
Jul 22, 2014, 10:55:02 AM7/22/14
to psychop...@googlegroups.com
Hi there,

Yes, the problem is that PsychoPy Builder doesn't yet know how to reuse an object that was already created. You could get around the issue by:
    - turning your experiment into a script
    - finding the each-frame code that relates to your button box
    - pasting that into a code component in your second routine in the Builder view
...or something along those lines. Basically you need to re-use the frame code without reusing the start-experiment code

cheers,
Jon
--
You received this message because you are subscribed to the Google Groups "psychopy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to psychopy-user...@googlegroups.com.
To post to this group, send email to psychop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/psychopy-users/b28d7ffb-8d8b-4553-afac-f2dcd8fd4e3f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
Jonathan Peirce
Nottingham Visual Neuroscience

http://www.peirce.org.uk

Daniel Campbell-Meiklejohn

unread,
Apr 20, 2015, 2:31:59 PM4/20/15
to psychop...@googlegroups.com
Hi

I am having a very similar problem with a new Cedrus Box. However, I am receiving the error when there is only a single routine with a response box in it.  This is unique to the Windows (7, 64 bit)  standalone version (1.82.0.1) (it works fine on Mac).
buttonBox.status = NOT_STARTED
NameError: name 'buttonBox' is not defined

What is extra puzzling to me is that when I use the command line and simply type: devices = pyxid.get_xid_devices()   it will find nothing initially, but then if I unplug and plug in again it will find the box:  devices [<ResponseDevice "Cedrus RB-730">]. However running a builder developed code from the builder or coder after this then fails to find it and give the NOT_STARTED error.

Completely stumped and hoping for some expert insight!

Cheers
Dan

Andreas Höfler

unread,
Nov 4, 2015, 6:21:09 AM11/4/15
to psychopy-users
Hello everyone with the same Cedrus Button Box Problem,

maybe it is possible to create a script that starts and ends the button box via a code snippet. I am not so familiar with the Cedrus Module in Python, but I will work on it.
Or is there a specific script already written?!

Looking forward to a solution!

Belgian Michel

unread,
Jun 12, 2016, 10:43:01 PM6/12/16
to psychopy-users
Hello Andreas,

I'm trying to help my daughter with the issue of the limitation documented in Psychopy for the Cedrus button box.
(« Note that there is a limitation currently that a button box can only be used in a single Routine. Otherwise PsychoPy tries to initialize it twice which raises an error. As a workaround, you need to insert the start-routine and each-frame code from the button box into a code component for a second routine. »)

I'am not familiar with Python.

Finally nobody explain in a "how to for dummies" how to do "a workaround" in practice...

Did you find the solution?

Michel

Ido Zilberberg

unread,
Jun 14, 2016, 3:43:56 AM6/14/16
to psychopy-users
Hi everyone

I encountered the same problem, and in order to solve it I did as Jon suggested and added some code component to the builder.

This is the code I used:

Beginning of routine
training_resp=[]
training_respRT=[]
training_resp_corr=[]
buttonBox.keys = []
buttonBox.rt = []
buttonBox.tStart = t
buttonBox.clock.reset()

Each Frame
if buttonBox.status == STARTED:
    # check for key presses
    buttonBox.poll_for_response()
    while len(buttonBox.response_queue):
        evt = buttonBox.get_next_response()
        if evt['key'] not in [2,5]:
            continue #we don't care about this key
        if evt['pressed']: #could be extended to examine releases too?
            if trainCount == 1:
                print(Training_loop.thisTrialN)
                print(evt['key'])
            training_resp.append(evt['key'])
            training_respRT.append(buttonBox.clock.getTime())
        buttonBox.poll_for_response()

    if len(training_resp) > 0:  # at least one key was pressed
        if buttonBox.keys == []:  # then this was the first keypress
            buttonBox.keys = training_resp[0]  # just the first key pressed
            buttonBox.rt = training_respRT[0]
        if Response==1 and buttonBox.keys>0:
            training_resp_corr = 1
        elif Response==0 and buttonBox.keys>0:
            training_resp_corr = 98

The red lines are demands for my experiment and you don't need to use them.

Fair warning, I now face some very weird problem which I described in other post here. 
Basically, each response is documented in one trial delay at the csv file.
If anyone will be able to find a work around that problem, please let me know.

Good Luck
Ido

Ido Zilberberg

unread,
Jun 14, 2016, 3:45:50 AM6/14/16
to psychopy-users
Oh, one more thing I forgot.

End of routine

Training_loop.addData('Training_resp',buttonBox.keys)
Training_loop.addData('Training_respRT',buttonBox.rt)

These lines are for psychopy to add the data to the csv file.

Ido

On Tuesday, January 21, 2014 at 6:27:22 PM UTC+2, Maddie wrote:
Message has been deleted

Belgian Michel

unread,
Jun 14, 2016, 8:47:17 AM6/14/16
to psychopy-users
Thanks a lot to Ido: with this code, for me, the problem is solved.
Great!
Many thanks to everyone here for generously helping to solve this annoying problem of "first routine".

Michel



noa.sl...@gmail.com

unread,
Aug 30, 2016, 7:56:57 AM8/30/16
to psychopy-users
Hi Jon,

Was this problem solved in any later version of PsychoPy?
If not - is it scheduled to be solved at some point ?

Thanks!
Noa.

Jon Peirce

unread,
Aug 30, 2016, 8:06:10 AM8/30/16
to psychop...@googlegroups.com

No, I'm afraid I haven't sorted out a solution. For now you still have to paste the code into a code component.

Jon


For more options, visit https://groups.google.com/d/optout.

-- 
Jon Peirce
http://www.peirce.org.uk
Reply all
Reply to author
Forward
0 new messages