[open] Sending triggers for EEG through serial port
Hi,
I have been trying to set up my OpenSesame experiment to run from my laptop, with an EEG system. I want to send triggers to the EEG machine via a (USB converted) serial port, and had previously been using an inline script for sending through a parallel port (copied from the forum). So far, I had some help to make the changes for sending via the serial port, but am still having some issues. Firstly, I do not know how to open and close the serial port appropriately. I have included some inline script at the beginning of the experiment, as follows:
import serial
global ser
ser = serial.Serial('COM1', 19200)
try:
from ctypes import windll
global io
io = windll.dlportio # requires dlportio.dll !!!
except:
print 'The parallel port couldnt be opened'
Then, for sending triggers, I have included this inline script just after stimulus presentation:
global io
global ser
trigger = self.get("triggerstart")
try:
io.DlPortWritePortUchar(port, trigger)
except:
print 'Failed to send trigger!'
ser.write(trigger)
self.sleep(80)
ser.write(0)
I am presenting a series of images in short succession (hopefully for 80ms each), and have therefore used "sleep" here. The triggers are defined in the loop, in the variable "triggerstart". Right now, the inline script does seem to be sending the triggers, but a problem is that it seems to be sending ASCII codes, instead of the integers that I have defined in "triggerstart". There also seems to be some additional trigger codes coming on the EEG recording that I cannot see where, and if (unintentionally), I defined them, or where they are coming from.
Is there something I am doing wrong in the inline script?
How I should open and close the port properly?
How I can change the trigger codes to be the integers I defined, instead of the ASCII codes that I am currently getting?
Many thanks!
Elliot.
Comments
here is the script again, for easier reading:
1st part, at beginning of experiment:
2nd part, after stimulus presentation:
Following code is working for me:
hope it helps
Great! Thanks a lot sviter