I don't know if you've already solved this problem, but here's some code to read input from a Cedrus response pad (in our case, the RB-830 model). You need to install the pySerial package first (http://pyserial.sourceforge.net). Mason Smith Lab Manager Language and Cognitive Architectures Lab University of Michigan Lab phone: 734-764-6827 Cell: 734-272-4883 |
import serial import pygame pygame.init() BBOXMAPPING = {0:4,6:3,5:2,2:1,1:5,4:6,3:7,7:8} def byteToKey(byte): return (BBOXMAPPING[ord(byte)/32],(ord(byte)/16)%2) #Open a serial port at COM2 with baud rate 115200 #(or in this case, a USB port masquerading as a serial port) ser=serial.Serial(2,115200) #Record when we reset the bbox's timer clock=pygame.time.Clock() #Send a message to the bbox telling it to reset its master timer ser.write("e1") offset=pygame.time.get_ticks() #Send a message to the bbox telling it to reset its RT sub-timer ser.write("e5") #Record how long it took to send the last message error=pygame.time.get_ticks()-offset print "Error: %d\n"%error key=-1 #Loop around and collect responses until the '0' button is pressed while key != 4: ser.flushInput() print "Waiting..." #Wait for a message from the bbox saying a button got pressed s=ser.read(6) print "Message received" #Record the time, according to the CPU, since the bbox's RT timer was last reset #This should equal the time from reset to the button press (the RT), PLUS the time #it took to get the message from the bbox to the computer (typically 10-20 ms) elapsed=pygame.time.get_ticks()-offset #The first character of the message from the button box is always 'k' -- we can ignore it. #The second character of the message #indicates which button was pressed key,down=byteToKey(s[1]) #The remaining four characters, converted to base-256 digits, indicate the RT. bboxtime=(256^3)*ord(s[5])+(256^2)*ord(s[4])+256*ord(s[3])+ord(s[2]) #Compare the CPU's measurement to the bbox's measurement discrepancy=elapsed-bboxtime print "%d %d %d %d %d %d"%(key,down,bboxtime,elapsed, discrepancy, error) #Tell the bbox to reset its RT timer, and record the time we're sending the message, #and how long it takes to send the message. offset=pygame.time.get_ticks() ser.write("e5") error=pygame.time.get_ticks()-offset
On Aug 2, 2007, at 6:59 AM, Christophe Pallier wrote: Hello, |