beginners-question parallel port

1,651 views
Skip to first unread message

mrtj

unread,
Oct 21, 2011, 3:57:09 PM10/21/11
to E-Prime
I have a beginners-question regarding my E-prime programming.
I want to send event-related triggers to BioPac and after doing some
research I figured that an Inline with the following should do the
trick:

Stimulus.OnsetSignalEnabled = True
Stimulus.OnsetSignalPort = &H378
Stimulus.OnsetSignalData = 1

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

However, it seems to me that I should define/open/set-to-zero the Port
at the beginning of my experiment first. Am I correct to assume, and
if do... how can I do this.

I hope you can help me out. Many thanks!
Maartje



Paul Groot

unread,
Oct 21, 2011, 6:04:23 PM10/21/11
to e-p...@googlegroups.com
Hi Maartje,

It is not required to open a classic LPT port. EPrime directly writes
to the output registers of the IO-port. However, it is a good think to
initialize the state of the output pins at the start of your
experiment with a single line of inline script:

WritePort &H378, 0


(although you could also use 3 lines of code to configure the
onsetsignal method on the first object using code 0 to achieve the
same thing)

best,
Paul


2011/10/21 mrtj <maartje...@gmail.com>:

> --
> You received this message because you are subscribed to the Google Groups "E-Prime" group.
> To post to this group, send email to e-p...@googlegroups.com.
> To unsubscribe from this group, send email to e-prime+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/e-prime?hl=en.
>
>

mcfa...@msu.edu

unread,
Oct 22, 2011, 12:45:11 PM10/22/11
to e-p...@googlegroups.com
Maartje ,

And if you want to look like a real programmer instead of a novice,
you will replace the "magic numbers" with named constants, thus,

Const OutPort as Integer = &h0378
Const BioPacTrigger as Integer = &h01

WritePort OutPort, 0

Stimulus.OnsetSignalEnabled = True
Stimulus.OnsetSignalPort = OutPort
Stimulus.OnsetSignalData = BioPacTrigger

Stimulus.OffsetSignalEnabled = True
Stimulus.OffsetSignalPort = OutPort
Stimulus.OffsetSignalData = 0

-- David McFarlane, Professional Faultfinder


Quoting Paul Groot:
> Hi Maartje,
>
> It is not required to open a classic LPT port. EPrime directly writes
> to the output registers of the IO-port. However, it is a good think to
> initialize the state of the output pins at the start of your
> experiment with a single line of inline script:
>
> WritePort &H378, 0
>
>
> (although you could also use 3 lines of code to configure the
> onsetsignal method on the first object using code 0 to achieve the
> same thing)
>
> best,
> Paul
>
>

> 2011/10/21 mrtj:

mrtj

unread,
Nov 4, 2011, 12:20:29 PM11/4/11
to E-Prime

Thanks Paul, and thanks David. Your (David's) suggestion indeed looks
more fancy :-)

I have an additional question: I want e-prime to send a trigger to
BioPac for some but not all trials within a procedure: Based on the
attribute Shock (1 or 0) in the List I want Eprime to send a signal if
Shock = 1 and no signal if Shock = 0. I tried my very best with what
little I know of E-prime, and I ended up with the following
(nonfunctioning) Inline:

if c.GetAttrib("Shock") = 1 then
ITI.OnsetSignalEnabled = True
ITI.OnsetSignalPort = &H378
ITI.OnsetSignalData = &H80
else
end if

What happens with this inline is that a shock is given with the start
of every ITI, instead of when Shock=1. What am I doing wrong?
Many thanks once again!
Maartje

On Oct 22, 5:45 pm, mcfar...@msu.edu wrote:
> Maartje ,
>
> And if you want to look like a real programmer instead of a novice,
> you will replace the "magic numbers" with named constants, thus,
>
> Const  OutPort as Integer = &h0378
> Const  BioPacTrigger as Integer = &h01
>
> WritePort OutPort, 0
>
> Stimulus.OnsetSignalEnabled = True
> Stimulus.OnsetSignalPort = OutPort
> Stimulus.OnsetSignalData = BioPacTrigger
>
> Stimulus.OffsetSignalEnabled = True
> Stimulus.OffsetSignalPort = OutPort
> Stimulus.OffsetSignalData = 0
>
> -- David McFarlane, Professional Faultfinder
>
> Quoting Paul Groot:
>
>
>
>
>
>
>
> > Hi Maartje,
>
> > It is not required to open a classic LPTport. EPrime directly writes
> > to the output registers of the IO-port. However, it is a good think to
> > initialize the state of the output pins at the start of your
> > experiment with a single line of inline script:
>
> > WritePort &H378, 0
>
> > (although you could also use 3 lines of code to configure the
> > onsetsignal method on the first object using code 0 to achieve the
> > same thing)
>
> > best,
> > Paul
>
> > 2011/10/21 mrtj:
> >> I have abeginners-questionregarding my E-prime programming.

David McFarlane

unread,
Nov 4, 2011, 2:45:04 PM11/4/11
to e-p...@googlegroups.com
Maartje,

OK, first, putting on my full pedant's hat. Next, I refuse to do
this without proper named constants, so I will add those back in (and
*please* do not strip them out for your next question, or I will
refuse to answer). I will also add some conventional capitalization
and more parentheses, but I will not hold you to those :). (I will
give you credit for using proper hexadecimal notation from the outset.)

Now, I presume that you put this inline in your trial Procedure, else
it would not work at all. Then, to begin with, you left the code out
of your Else clause. The full inline code should read instead

Const OutPort as Integer = &h0378

Const ShockSignal as Integer = &h80

If (c.GetAttrib("Shock") = 1) Then
ITI.OnsetSignalPort = OutPort
ITI.OnsetSignalData = ShockSignal
ITI.OnsetSignalEnabled = True
Else
ITI.OnsetSignalEnabled = False
End If

At that point you are done, but I cannot let matters rest
there. Note that the only thing that changes from trial to trial is
OnsetSignalEnabled; OnsetSignalPort and OnsetSignalData never
change. So why repeat those operations on every trial? Out in
SessionProc, before running your trial List, add an inline to do the following

Const OutPort as Integer = &h0378

Const ShockSignal as Integer = &h80

ITI.OnsetSignalPort = OutPort
ITI.OnsetSignalData = ShockSignal

Then, the inline in your trial Procedure reduces to simply

If (c.GetAttrib("Shock") = 1) Then
ITI.OnsetSignalEnabled = True
Else
ITI.OnsetSignalEnabled = False
End If

(Or, if you like the more compact Iif statement (see that topic in
the E-Basic Help facility), the inline in your trial Procedure could
read simply

ITI.OnsetSignalEnabled = Iif( (c.GetAttrib("Shock") = 1), _
True, False )

which I personally find easier to follow, but I am odd.)

Next, if you want to prepare the way for other inlines in your
program that may need those constants, you will move them out of
SessionProc and into the global User script area (see Chapter 4 of
the User's Guide that came with E-Prime).

But wait, there's more! You could do this with only *one* line of
code in your trial Procedure and *no* If-Then. Here's how.

First set everything up with some inline code out in the SessionProc, thus,

Const OutPort as Integer = &h0378

ITI.OnsetSignalEnabled = True
ITI.OnsetSignalPort = OutPort

(Again, you might instead move that constant out into the global User
script area.)

Note that we do *not* set OnsetSignalData out here, and in this
scenario we leave OnsetSignalEnabled for all the trials.

Next we make a different use of the Shock attribute in your trial
List. Instead of entering an arbitrary flag value that indirectly
indicates whether or not to shock, simply enter an actual value to
output to the BioPac with the ITI. In particular, if the output sits
at 0 in between shocks, then outputting an extra 0 does nothing. So,
simply set Shock to "&h80" for trials that get shock, and "0" for
trials that do not get a shock.

Now, down in your trial Procedure, you have one line of inline code
before your ITI, thus,

ITI.OnsetSignalData = c.GetAttrib("Shock")

And that's all! Now, for shock trials, ITI outputs &h80, and for
non-shock trials it outputs 0, but because the output is already 0
nothing changes at the output so no shock. Simple, eh?

Something left out of this discussion is the need to *reset* the
output (e.g., set output to 0) some time before outputting a new
signal, possibly by means of OffsetSignal, or WritePort. But since
you do already get a shock on every trial with your existing code, I
presume that you have that part worked out.


BTW, I just wrote a video lesson on using E-Prime for fMRI, EEG, and
psychophysiology, for an online course that we hope to offer by the
start of the new year.

-- David McFarlane, Professional Faultfinder

mrtj

unread,
Nov 6, 2011, 4:01:32 PM11/6/11
to E-Prime
Thank you so much! I can't wait to actually test this on my computer
(instead of my home-office laptop, which doesn't have a parallel
port...). Your explanation surely helps me get a (for now still small)
grasp on E-prime programming. I can do the usual drag and drop, but
other than that.... Well, at least I now know how to send triggers
through a parallel port :)

Apologies for not yet having incorporated your earlier suggestions in
my follow-up question.
groeten,
Maartje

mrtj

unread,
Nov 7, 2011, 6:10:29 PM11/7/11
to E-Prime
Hi David,

I did not manage to set up the Inline in the SessionProc and make it
work on a trial level. Guess this means I have to put it in the
script, but that did not work either. Putting an InLine at lower
levels (where needed) did however do the trick. So for now I work
with:

Const OutPort as Integer = &h0378
Const ShockSignal as Integer = &h80

ITI.OnsetSignalPort = OutPort
ITI.OnsetSignalData = ShockSignal

Then, the inline in your trial Procedure reduces to simply

If (c.GetAttrib("Shock") = 1) Then
ITI.OnsetSignalEnabled = True
Else
ITI.OnsetSignalEnabled = False
End If

(btw: I have several markers, for shock, noise burst and stimulus
presentation)

I hope to find out how to define at higher level as well, in time. But
that is not my question: I was able to do some final testing and work
through the whole experiment today. As I have set up the experiment
right now, a Stimulus is displayed for 5 sec with No clearing after,
Then a SoundOut is displayed for 3 sec (the sound file starts with a
40msec noiseburst and continues with silence). After the SoundOut,
there is a (semi-random) variable ITI of 15 to 25 sec. To the
participant it looks as if the Stimulus is displayed for 8s, and a
soundburst is given at 5s into stimulus presentation.
Depending on the Stimulus (picture) being presented, a shock will or
will not be administered.
The common way to send markers is by using Onset, so that is what I
did. I used the Onset of the ITI to send a marker to (mark and)
generate a shock. That works fine. The shock duration is set via the
hardware of the shockstimulator (duration is 200ms).
Now something funny happends when c.GetAttrib("Shock") = 1. The shock
is administered as it should, at the onset of the ITI. It is again
given some hundreds of ms later. And it is also given at the Offset of
the ITI.

I gather that the shock at Offset possibly has to do with the
shockstimulator being sensitive to both increase and decrease in
current/voltage/whatever the marker generates. I hope that I can
overcome this by setting the marker for only a brief period of time. I
was thinking along the lines of an Inline right after the SoundOut:
WritePort &H378, 80
sleep 5
writePort &H378, 0
(or could I do with WritePort OutPort, ShockSignal instead of &H378,
80?)

I am not yet sure whether it will work (working from a laptop right
now instead of my PC). But this trick won't solve the issue of the
second (unwanted) shock that is given. Do you have any suggestions? I
am puzzeled.

groeten,
Maartje

Btw: the shockstimulator is a device that has been build by our
faculty technicians. So I have no device name for you here.

mrtj

unread,
Nov 9, 2011, 11:30:05 AM11/9/11
to E-Prime
I think I fixed the problem. We are doing some pilotting now, to be
sure!
groeten,
Maartje
> ...
>
> read more »- Hide quoted text -
>
> - Show quoted text -

David McFarlane

unread,
Nov 10, 2011, 10:51:55 AM11/10/11
to e-p...@googlegroups.com
Maartje,

That's great, and thanks for writing back. So
what did you figure out, what was the problem? I
would like the opportunity to learn something from this.

Thanks,
-- David McFarlane

Sibel

unread,
Nov 19, 2011, 7:41:29 AM11/19/11
to E-Prime
Hi Everybody,
Actually, Dear Maartje,
I also wonder the solution you found, would you mind sharing
it,please?

thank you, best,
Sibel

> ...
>
> tamamını oku »- Alıntıyı gizle -
>
> - Alıntıyı göster -

Reply all
Reply to author
Forward
0 new messages