beginners-question parallel port

David McFarlane mcfarla9 at msu.edu
Fri Nov 4 18:45:04 UTC 2011


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


At 11/4/2011 12:20 PM Friday, you wrote:

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

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



More information about the Eprime mailing list