I'm using a psychopy code that was done by a previous Phd student of the lab. This code aims to display stimuli (random dot kinematogram) and use a subprocess for precise timing.
The subprocess is created with the following line :
process = subprocess.Popen(['python', 'LPTmat.py'], shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
Then when the first frame is displayed, the code writes a number to tell the subprocess to begin timing:
if first_frame == True:
process.stdin.write('%i\n'%1) #start timer and check of the PP
first_frame = False
The Subprocess then start the timer and record the button pressed (parallel port) :
while True:
input = sys.stdin.readline()
if input == '1\n':
timer.reset()
parallel_port_state = ctypes.windll.inpout32.Inp32(lptno)
while parallel_port_state == etat_repos:
parallel_port_state = ctypes.windll.inpout32.Inp32(lptno)
lecture_time = timer.getTime()
if parallel_port_state in port_gauche:
send_trigger (1)
elif parallel_port_state in port_droit:
send_trigger (2)
np.savetxt('mat.txt',mat)#a button has been pressed
The main process than detect the txt file and stop the stimulus presentation :
mtext= os.path.exists('mat.txt')
if mtext== True:#if the mat.txt file exists, a button has been pressed
myWin.flip()#black screen
process.stdin.write('%i\n'%3)
check = process.stdout.readline()#read which button has been pressed
check = int(check)
And go checking back the response time recorder by the subprocess and remove the txt file created :
process.stdin.write('%i\n'%2)
RT = process.stdout.readline()
RT = float (RT)
rep.rt = RT
os.remove('mat.txt')
The problem is that the .txt file created is not really a clean way to do the job so I was wondering if they were another way to use this subprocess and to tell the main process that a response was made ?
Cheers, Gabriel