I'm working on integrating an experiment in psychopy with the eyelink eyetracking system. The way to do this seems to be through pylink. Unfortunately I'm really unfamiliar with pylink and I was hoping there was a sample of an experiment that combines the two. I haven't been able to find one. If anyone would be able to share an example or point me towards a more accessible manual than the pylink api that sr-research provides I'd be really grateful.
Thanks!
I am glad you found your solution. I have not used iohub, but we do use psychopy and an eyelink and therefore some of the following code may be of use to others who wish to invoke more direct communication. Note that our computers use Archlinux. If none of the following makes any sense to you, don't worry about it, but maybe it will help others who are stumbling along the same path we are.
Communication between experimental machine and eye tracker machine
First, you have to establish communication with the eyelink. If your experimental machine is turned on and plugged into a live Eyelink computer then on linux you have to first set your ethernet card up, and then set the default address that Eyelink uses (this also works for the Eyelink 1000 - they kept the same address). Note your ethernet will probably have a different name than enp4s0. Try simply with ip link and look for something similar. NB: these commands are being typed into a terminal.
#To set up connection with Eyelink II computer:
#ip link set enp4s0 up
#ip addr add 100.1.1.2/24 dev enp4s0
Eyetracker functions
We have found it convenient to write some functions for talking to the Eyelink computer. For example:
Initialize Eyetracker
sp refers to the tuple of screenx, screeny sizes.
def eyeTrkInit (sp):
el = pl.EyeLink()
el.sendCommand("screen_pixel_coords = 0 0 %d %d" %sp)
el.sendMessage("DISPLAY_COORDS 0 0 %d %d" %sp)
el.sendCommand("select_parser_configuration 0")
el.sendCommand("scene_camera_gazemap = NO")
el.sendCommand("pupil_size_diameter = %s"%("YES"))
return(el)
NB: the pl function comes from import pylink as pl. Also, note that there is another python library called pylink that you can find on line. It is probably not the one you want. Go through the Eyelink forum and get pylink from there. It is old, but it still works.
Calibrate Eyetracker
el is the name of the eyetracker object initialized above. sp screen size, and cd is color depth, e.g. 32.
def eyeTrkCalib (el,sp,cd):
pl.openGraphics(sp,cd)
pl.setCalibrationColors((255,255,255),(0,0,0))
pl.setTargetSize(int(sp[0]/70), int(sp[1]/300))
pl.setCalibrationSounds("","","")
pl.setDriftCorrectSounds("","off","off")
el.doTrackerSetup()
pl.closeGraphics()
#el.setOfflineMode()
Open datafile
You can talk to the eye tracker and do things like opening a file
def eyeTrkOpenEDF (dfn,el):
el.openDataFile(dfn + '.EDF')
Drift correction
Or drift correct
def driftCor(el,sp,cd):
blockLabel=psychopy.visual.TextStim(expWin,text="Press the space bar to begin drift correction",pos=[0,0], color="white", bold=True,alignHoriz="center",height=0.5)
notdone=True
while notdone:
blockLabel.draw()
expWin.flip()
if keyState[key.SPACE] == True:
eyeTrkCalib(el,sp,cd)
expWin.winHandle.activate()
keyState[key.SPACE] = False
notdone=False
Sending and getting messages.
There are a number of built-in variables you can set, or you can add your own. Here is an example of sending a message from your python program to the eyelink
eyelink.sendMessage("TRIALID "+str(trialnum))
eyelink.startRecording(1,1,1,1)
eyelink.sendMessage("FIX1")
tFix1On=expClock.getTime()
Gaze contingent programming
Here is a portion of some code that uses the eyelink's most recent sample in the logic of the experimental program.
while notdone:
if recalib==True:
dict['recalib']=True
eyelink.sendMessage("RECALIB END")
eyelink.startRecording(1,1,1,1)
recalib=False
eventType=eyelink.getNextData()
if eventType==pl.STARTFIX or eventType==pl.FIXUPDATE or eventType==pl.ENDFIX:
sample=eyelink.getNewestSample()
if sample != None:
if sample.isRightSample():
gazePos = sample.getRightEye().getGaze()
if sample.isLeftSample():
gazePos = sample.getLeftEye().getGaze()
gazePosCorFix = [gazePos[0]-scrx/2,-(gazePos[1]-scry/2)]
posPix = posToPix(fixation)
eucDistFix = sqrt((gazePosCorFix[0]-posPix[0])**2+(gazePosCorFix[1]-posPix[1])**2)
if eucDistFix < tolFix:
core.wait(timeFix1)
notdone=False
eyelink.resetData()
break
Happy Hacking.
rather than PyLink, you might want to look into using the ioHub system within PsychoPy. This is a more general-purpose eye tracking system that also allows for saving data in a common format (integrated with PsychoPy events), and provides tools for data analysis and visualisation.
ioHUb is built to be agnostic to the particular eye tracker you are using. You just need to create a configuration file specific to your EyeLink system, and thereafter use the generic functions ioHiv provides for calibration, accessing gaze data in real-time, and so on.
There are some teaching resources accessible here: http://www.psychopy.org/resources/ECEM_Python_materials.zip
For future readers, I wanted to share my library for combining pylink and psychopy. I've recently updated it to work with python 3. It provides simple to use, high level functions.
https://github.com/colinquirk/templateexperiments/tree/master/eyelinker
You could also work at a lower level with the PsychoPyCustomDisplay class (see the pylink docs for more info about EyeLinkCustomDisplay).
For an example of it in use, see:
https://github.com/colinquirk/ChangeDetectionEyeTracking
(At the time of writing, this experiment code is not yet python 3 ready, but it should still be a useful example.)
The repo also includes other modules for creating experiments and recording EEG data, but they are not necessary if you are just interested in the eyelinker code.
I can't really find anything on how to print through EPL with Visual Basic. Can anyone help me write some simple text to the printer? I found the Zebra EPL manual so I think I can go from there, I just don't know how to get it started.
The way I do it is using the FSO to do a filecopy from of the label text file to the UNC path of the printer. (i.e. FSO.copyfile filepath, UNCpath).
Create a string with the EPL raw file (text) in it. Save it to a temp file then do the copyfile I mentioned above.
What I have found is that the best way to learn what the EPL is doing is to take an existing string and just play with the settings. Here is a sample FedEx label in EPL for you to start with. Remember - its just text.
(between the 2 'N's)
N
OD10
q812
Q1624,24
D15
ZB
LO0,459,800,4
LO0,713,800,4
LO0,1048,800,4
A35,321,0,2,1,1,N,"From:"
A35,340,0,2,1,1,N,"SHIPPING DEPT"
A35,360,0,2,1,1,N,"Company INC."
A35,380,0,2,1,1,N,"1820 SMARKET BLVD"
A35,401,0,2,1,1,N,""
A35,441,0,2,1,1,N,"(800) 999-9997"
A490,381,0,2,1,1,N,"CAD: 12345/FXRS1060"
A43,500,0,4,1,1,N,"TEST"
A43,535,0,4,1,1,N,"123-45TH"
A43,570,0,4,1,1,N,""
A35,421,0,2,1,1,N,"CHANHASSEN, MN 55317"
A490,340,0,2,1,1,N,"Ship Date: 24NOV10"
A490,360,0,2,1,1,N,"ActWgt: 12.0 LB"
A43,465,0,4,1,1,N,"TEST"
A615,465,0,2,1,1,N,"(320) 555-1212"
A43,608,0,3,1,2,N,"ST CLOUD, MN 56301"
A530,608,0,2,2,2,N,"(US)"
LO670,550,105,10
LO670,560,10,112
LO765,560,10,112
LO670,672,105,10
LO476,315,4,145
A650,485,0,3,2,2,N,"FedEx"
A690,568,0,5,2,2,N,"G"
B80,1083,0,1E,4,2,290,N,"9612304400426670000014"
A135,1397,0,4,1,1,N,"(9612302) 4000266 70000014"
A783,700,3,1,1,1,N,"J10100912242124"
A10,470,0,3,1,1,N,"TO"
A25,1420,0,3,1,1,N,"GND"
A25,1445,0,3,1,1,N,"Prepaid"
A300,1425,0,3,1,1,N,"Hazmat"
A300,1447,0,3,1,1,N,"DIRECT SIGN"
b50,740,P,800,800,s5,f0,x2,y10,r80,o0,l12,"[)>010256301840302400426670000014FDEB40042663281/112.0LBN123-45THST CLOUDMNTEST0610ZGD00411ZTEST12Z320555121223ZN22ZN20Z0.0009KTEST99ZGHAZ028004249300 26Z822a"
A645,1400,0,5,1,1,R,"HAZ"
A580,1457,0,2,1,1,N,"Emergency Contact#"
A580,1477,0,2,1,1,N,"8004249300"
A16,670,0,1,1,1,N,"Ref: TEST"
A16,685,0,1,1,1,N,"INV: "
A16,700,0,1,1,1,N,"PO: TEST"
A406,700,0,1,1,1,N,"Dept: "
P1
N
As you can see the Coordinates are the first 2 sets per line.
A indicates text I believe.
b indicates barcode.
I dont know all the parameters off the top of my head, but you mentioned you had a manual so it should list those details for you.
Hope this helps.
Here's a great blog post by Nicholas Piasecki how to send EPL code to the printer:
Sending Raw EPL2 Directly to a Zebra LP2844 via C#
I was using Zebra printers before (so I already knew EPL), but when I had to print from .NET the first time, I managed to get it to work just with the information from this blog post.
Note that the example code is in C#, but you can translate that to VB.NET.
(the post also mentions an external class named RawPrinterHelper which you can download from Microsoft - if you don't want to translate this to VB, just put it into a separate C# assembly and reference that in your VB project)
If you need to print images too, here's another blog post by the same guy about this:
Using the EPL2 GW command to send an image to a Zebra thermal printer