parallel port communication: event markers

349 views
Skip to first unread message

sofia laureano

unread,
Jul 2, 2009, 7:28:10 AM7/2/09
to E-Prime
Hi there all,

I have an experiment in e-Prime and I am trying to link it to PsychLab
equipment. Basically what I need is to programme the task so that it
sends signals through the parallel port to the psychophysics data
acquisition unit.

So far, what I’ve done was to create an Inline object (called
Proposal) which I’ve inserted just before Proposal. The inline
contains the following code:

Proposal.OnsetSignalEnabled = True
Proposal.OnsetSignalData = 255
Proposal.OnsetSignalPort = &H378

Then I inserted another Inline just after Proposal, with the following
code:

Proposal.OffsetSignalEnabled = True
Proposal.OffsetSignalData = 0
Proposal.OffsetSignalPort = &H378


It’s seems to be working, i.e. events are being marked on the skin
conductance screen.
However, I would like it to be differentiating between two events
(i.e. accept/reject). Participants press a different key for each
event.

How can I get E-Prime to do this?

Thank you very much.

Best,
Sofia

Michiel Spape

unread,
Jul 2, 2009, 8:45:25 AM7/2/09
to e-p...@googlegroups.com
Hi,
Doesn't seem to have much to do with the fact that you're using the parallel port for communication, I would say. I believe the following inline should be enough to send the number 28 over the parallel port:
WritePort &H378, 28

But conceivably, you want to have some data sent at the onset of this Proposal thingamabob you have, hence '.OnsetSignalData', rather than using the above which just sends the data, 28, at the moment this line is encountered at runtime.
So, as far as I know, Proposal.OnsetSignalData = 255 sends '255' over the parallel port, and you can change that to different numbers which you'll just have to reconvert in psychlab to conditions. The rest is just very basic inline. Let's say, you have a screen, TextDisplay1 in which you ask participants to indicate 'Accept' (press A) or 'Reject' (press R). The small inline should do the trick:
If TextDisplay1.RESP = "A" then Proposal.OffsetSignalData = 28 else Proposal.OffsetSignalData = 29

That's it (as long as this proposal object comes after the inline, and the inline after the TextDisplay1). In PsychLab, you can then say that 28 indicates Accept and 29 reject.

Best,
Mich

Michiel Spapé
Research Fellow
Perception & Action group
University of Nottingham
School of Psychology
This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.

sofia laureano

unread,
Jul 2, 2009, 10:29:04 AM7/2/09
to E-Prime
Dear Mich,

Thank you very much for your reply.
The Proposal is basically a slide where I have the offer (an amount of
money) and the options whether to accept it (a) or to reject it (b).
I would like to have a mark when the slide appears (i.e. when the
participant gets to know the offer) and then two different marks, one
for accept one for reject.

Being this all in one slide, shall the Inline come before or after the
Proposal slide?

And is this what I should write in the Inline?

Proposal.OnsetSignalData = 255
Proposal.OnsetSignalPort = &H378

If Proposal.RESP = "A" then Proposal.OffsetSignalData = 28 else
Proposal.OffsetSignalData = 29


thank you!

Best,
Sofia


On Jul 2, 1:45 pm, Michiel Spape <Michiel.Sp...@nottingham.ac.uk>
wrote:

Michiel Spape

unread,
Jul 2, 2009, 10:55:16 AM7/2/09
to e-p...@googlegroups.com
Hi Sofia,
Almost, but it's a bit more difficult than I first thought. Here's the problem, which has exactly to do with your first question (before or after): the .RESP is only known AFTER the response (i.e. it is by definition "" before becoming either a or b), but you want to change properties of the slide BEFORE the slide is shown. Though I assume you can do something about this, I guess it would be much simpler just to make two Proposal slides that are basically just copies (control-drag to make a non-shadow copy).
Slide 1, let's call it Proposal1 proposes and has, for example, infinite duration or until keypress. Or whatever you currently have. Make sure it has offset sync turned off.
Slide 2, called Proposal2, is directly following Proposal1, and has neither onset, nor offset sync, and a duration of 1ms.
In between, there's a mini inline, saying:
Proposal2.OnsetSignalPort = &H378
If Proposal1.RESP = "a" then Proposal2.OnsetSignalData = 28 else Proposal2.OnsetSignalData = 29

Thus, people will think they only see one slide but will always see them both, the second one having a very short duration and doing little other than sending a signal via the parallel port.
Of course, you could also just use the one slide you currently have and add a little inline after that:
WritePort &H378, Asc(Proposal1.RESP)

That should just send a byte over the parallel port with the response converted to some byte (a = 97, for instance).

Let me know if that helps.

David McFarlane

unread,
Jul 2, 2009, 12:14:54 PM7/2/09
to e-p...@googlegroups.com

>Of course, you could also just use the one slide you currently have
>and add a little inline after that:
>WritePort &H378, Asc(Proposal1.RESP)

If you go this route (which is probably how I would do it), depending
on how the PsychLab equipment works you might also need to send a
full "pulse" and reset the output before continuing, something like

WritePort &H378, Asc(Proposal1.RESP)
Sleep 20
WritePort &H378, 0


Oh, following my fussy habits I would also replace the "magic number"
&H378 with a proper constant, e.g.,

Const LptDataPort as Integer = &H378
WritePort LptDataPort, Asc(Proposal1.RESP)
Sleep 20
WritePort LptDataPort, 0

-- David McFarlane, Professional Faultfinder

sofia laureano

unread,
Jul 3, 2009, 5:43:15 AM7/3/09
to E-Prime
Dear Michiel, Dear David,

Thank you very much for your support. I followed your suggestions (I
decided to just use one slide) and what I have now is:

1. An Inline before the Proposal (lets call it EventMarker1) with the
following:

Proposal.OnsetSignalPort = &H378
If Proposal.RESP = "a" then Proposal.OffsetSignalData = 28 else if
Proposal.RESP = "r" then Proposal.OffsetSignalData = 29 else
Proposal.OffsetSignalData = 30

(as you can see I entered another condition, since it can happen that
the participants don't respond to the Proposal on time, i.e. don't
press keys "a" or "r" during the 7sec they have to make up their
minds)

2. Proposal slide

3. Inline after the Proposal (EventMarker2):

WritePort &H378, Asc(Proposal.RESP)
Sleep 20
WritePort &H378, 0

I am not sure whether you suggested to have all the info in one lnline
after the Proposal or, as I have now, divided in two.

The problem I am encoutering now is, if I don't press any key (neither
"a" or "r"), I get a Runtime Error saying Invalid Procedure Call,
Error Number 5
The line in the script is: WritePort &H378 Asc (Proposal.Resp) . If I
press "a" or "r" the error doesn't occur.

Any ideas on why this is happening would be welcome!

thank you again,

Best,
Sofia

Michiel Spape

unread,
Jul 3, 2009, 6:51:55 AM7/3/09
to e-p...@googlegroups.com
Hi,
I agree about "David's nap" in between and setting it to 0 after that!
Still, it seems like you still don't seem to 'get' the idea about .RESP, Sofia (correct me if I'm wrong). Point is:
Before running Proposal, Proposal.RESP is nothing, just like before I click on Send here, you have received no e-mail. Thus, in the inline that comes before Proposal, Proposal.RESP is neither "a" nor "r", therefore, Proposal.OffsetSignalData will always be 30. However, it should just work (even if you delete the line), since (3) sends the response (in ascii) over the parallel port anyway.

About the error: I guess the problem is that "" does not have an ascii code assigned. Thus, it tries to convert nothing to a number, which doesn't work. Try:
If Proposal.RESP <> "" then WritePort &H378, Asc(Proposal.Resp) else WritePort &H378, myFavouriteNumberBelow256
(in which myFavouriteNumberBelow256 is your favourite number below 256, but probably above 0, and possibly not including any of the numbers already used, so you may be out of luck if your favourite number happens to be asc(a)).

Best,
Mich


Michiel Spapé
Research Fellow
Perception & Action group
University of Nottingham
School of Psychology


-----Original Message-----
From: e-p...@googlegroups.com [mailto:e-p...@googlegroups.com] On Behalf Of sofia laureano
Sent: 03 July 2009 10:43
To: E-Prime
Subject: Re: parallel port communication: event markers


sofia laureano

unread,
Jul 3, 2009, 10:20:05 AM7/3/09
to E-Prime
Dear Mich,

Thanks again for getting back to me. As you can guess, I'm a recently
E-Prime user, so there's a lot that I'm still trying to learn :)
I changed the content of the Inline and now I only have one Inline
after the Proposal with the following:

If Proposal.RESP = "a" then WritePort &H378, Asc(Proposal.Resp) else
if Proposal.RESP = "r" then WritePort &H378, Asc(Proposal.Resp) else
WritePort &H378, 255

Sleep 20
WritePort &H378, 0

Is this what you're suggesting?

Anyways, it seems to be working, 3 different events are being marked
in the PsychLab screen!

Thanks again for your support.

All the best,
Sofia


On Jul 3, 11:51 am, Michiel Spape <Michiel.Sp...@nottingham.ac.uk>
wrote:

David McFarlane

unread,
Jul 3, 2009, 11:20:02 AM7/3/09
to e-p...@googlegroups.com
Sofia,

> I changed the content of the Inline and now I only have one Inline
> after the Proposal with the following:
>
> If Proposal.RESP = "a" then WritePort &H378, Asc(Proposal.Resp) else
> if Proposal.RESP = "r" then WritePort &H378, Asc(Proposal.Resp) else
> WritePort &H378, 255
>
> Sleep 20
> WritePort &H378, 0
>
> Is this what you're suggesting?

Good job! If you have this working then you do not need to change a
thing. But I will add a short programming lesson.

Your script above has a bit of redundancy. Here is a way to write it
without the redundancy (and using constants to get rid of the "magic
numbers", which I believe improves readability, and adding a few
comments for clarity):

Const LptDataPort as Integer = &H378 ' or 888 decimal
Const NoResponseEvent as Integer = &HFF ' or 255 decimal
Const EventPulseDuration_ms as Integer = 20

' Send appropriate event pulse to PsychLab equipment...
If Proposal.RESP <> "" Then ' got a response
WritePort LptDataPort, Asc(Proposal.Resp)
Else ' no response
WritePort LptDataPort, NoResponseEvent
End If
Sleep EventPulseDuration_ms
WritePort LptDataPort, 0


BTW, you can also test for a response by using

If Proposal.RT <> 0

as well as other tests that I have documented elsewhere. It is largely
a matter of personal taste (I like the test against 0, since it seems
more efficient to test the value of an integer rather than a full string).

David McFarlane

unread,
Jul 3, 2009, 11:30:33 AM7/3/09
to e-p...@googlegroups.com
OK, I just can't help myself. Here's an even slicker way to write this
using the Iif() function (though perhaps rather less readable):

Const LptDataPort as Integer = &H378 ' or 888 decimal
Const NoResponseEvent as Integer = &HFF ' or 255 decimal
Const EventPulseDuration_ms as Integer = 20

' Send appropriate event pulse to PsychLab equipment...

WritePort LptDataPort, Iif( (Proposal.RT = 0), NoResponseEvent,
Asc(Proposal.Resp) )
Sleep EventPulseDuration_ms

David McFarlane

unread,
Jul 3, 2009, 11:32:57 AM7/3/09
to e-p...@googlegroups.com
Oh, um, we can even remove the explicit test against zero and leave that
implicit, sorry to belabor this further:

Const LptDataPort as Integer = &H378 ' or 888 decimal
Const NoResponseEvent as Integer = &HFF ' or 255 decimal
Const EventPulseDuration_ms as Integer = 20

' Send appropriate event pulse to PsychLab equipment...

WritePort LptDataPort, Iif( Proposal.RT, Asc(Proposal.Resp),
NoResponseEvent )
Sleep EventPulseDuration_ms

sofia laureano

unread,
Jul 7, 2009, 5:10:42 AM7/7/09
to E-Prime
Hi David,

Thank you very much for all your thoughts! I really appreciate it.

All the best,
Sofia
Reply all
Reply to author
Forward
0 new messages