USB port TMS

708 views
Skip to first unread message

saraag

unread,
May 31, 2010, 10:25:09 AM5/31/10
to E-Prime
Hello everyone,

does anyone knows the scropt to open the USB port in order to trigger
a TMS?

please, let me know
I have to send a trigger though the USB port, because the parallel
port is used to trigger another device.

thank you very much
Sara

David McFarlane

unread,
May 31, 2010, 2:26:53 PM5/31/10
to e-p...@googlegroups.com
Sara,

Stock reminder: 1) I do not work for PST. 2) PST's trained staff
really does like to take any and all questions at
http://support.pstnet.com/e%2Dprime/support/login.asp , and they strive
to respond to all requests in 24-48 hours -- this is pretty much their
substitute for proper documentation, so make full use of it. 3) If you
do get an answer from PST Web Support, please extend the courtesy of
posting their reply back here for the sake of others.

That said, here is my take ...

Unless PST has added something new to the latest release of EP2, E-Prime
simply has no facility for sending or receiving data through a USB port,
so you are just out of luck there. But do not take my word for this,
please contact PST Web Support yourself and then report back here.

Say, why not just install another parallel port? Or, does your other
device need all 8 outputs from the parallel port? If not, why not just
build a cable to send different wires to your different devices? Just
take a look at the book "Parallel Port Complete" by Jan Axelson to get
some idea of how to make full use of the parallel port. Or, skip the
parallel port and just install a real digital I/O card (e.g., from
http://www.mccdaq.com ).

-- David McFarlane, Professional Faultfinder

David McFarlane

unread,
May 31, 2010, 6:20:18 PM5/31/10
to e-p...@googlegroups.com
Sara,

Come to think of it, there is a way to send & receive data through USB
using E-Prime, in fact I am doing that for a project now. First go to
Measurement Computing (referred to earlier) and get whatever I/O board
suits your fancy, e.g., their USB-1024 ($100). When that arrives,
install the Universal Libray software that comes with it. Then add the
appropriate Declare statements in the User Script area of your EP
program (see instructions that come with the MCC UL). Now you can use
MCC UL function calls from EP inline code to send & receive data through
the USB port.

Recognizing that the MCC UL essentially just adds a DLL to provide the
USB support, with enough ingenuity you could take this even further by
writing your own DLL to use from EP. For that, you might want to take a
look at "USB Complete" by Jan Axelson.

Mind you, I am not advising you do any of this. Just being an academic
and pointing out the full range of possibilities.

-- David McFarlane, Professional Faultfinder

Peter Quain

unread,
May 31, 2010, 6:18:24 PM5/31/10
to e-p...@googlegroups.com

what about timing issues David - anything to be aware of?

>--
>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.

Vera

unread,
Jun 1, 2010, 6:28:54 AM6/1/10
to E-Prime
Hi Sarah,

we had the same problem, and as David already proposed, we used 3 pins
of the parallel port for incoming triggers and the other five for
outgoing triggers (from E-Prime to another computer). Could you do the
same maybe?
We needed to build some kind of splitter (the cable is kind of
splitted), in order to make this work (as we had incoming and outgoing
stuff on the same port), but if you want to send out to the same
device, it would also work without splitting. You just have to define
different pins on the parallel port (which leaves you with 38 (??)
options.

Just as an example, we would send different information over different
pin combinations (thereby discerning the infos). In the example below
we use, 3 different pin combinations (8, 16 and 24 - we only have
multiplications of 8 as the first 8 bits (pins 1, 2, 4) are used for
incoming triggers).

If NewTriggerValue > 0 AND NewTriggerValue < 7 AND TargetPresAbs = 1
Then
If SetSize = 9 Then
HyperEventValue = 8
ElseIf SetSize = 16 Then
HyperEventValue = 16
ElseIf SetSize = 25 Then
HyperEventValue = 24
End If
End If

I hope this helps. I maybe don't explain it very well (I am not a
technician myself, sorry for that), but maybe it gives you some ideas.
And don't hesitate if you have any more questions.

Greetings, Vera


On Jun 1, 12:18 am, Peter Quain <pqu...@une.edu.au> wrote:
> what about timing issues David - anything to be aware of?
>
> At 08:20 AM 1/06/2010, you wrote:
>
> >Sara,
>
> >Come to think of it, there is a way to send & receive data through
> >USB using E-Prime, in fact I am doing that for a project now.  First
> >go to Measurement Computing (referred to earlier) and get whatever
> >I/O board suits your fancy, e.g., their USB-1024 ($100).  When that
> >arrives, install the Universal Libray software that comes with
> >it.  Then add the appropriate Declare statements in the User Script
> >area of your EP program (see instructions that come with the MCC
> >UL).  Now you can use MCC UL function calls from EP inline code to
> >send & receive data through the USB port.
>
> >Recognizing that the MCC UL essentially just adds a DLL to provide
> >the USB support, with enough ingenuity you could take this even
> >further by writing your own DLL to use from EP.  For that, you might
> >want to take a look at "USB Complete" by Jan Axelson.
>
> >Mind you, I am not advising you do any of this.  Just being an
> >academic and pointing out the full range of possibilities.
>
> >-- David McFarlane, Professional Faultfinder
>
> >David McFarlane wrote:
> >>Sara,
> >>Stock reminder:  1) I do not work for PST.  2) PST's trained staff
> >>really does like to take any and all questions at
> >>http://support.pstnet.com/e%2Dprime/support/login.asp, and they

Vera

unread,
Jun 1, 2010, 7:14:48 AM6/1/10
to E-Prime
Sorry, of course in the code this was missing:

writePort &H378, HyperEventValue

So the thing would be:

If NewTriggerValue > 0 AND NewTriggerValue < 7 AND TargetPresAbs = 1
Then
If SetSize = 9 Then
HyperEventValue = 8
ElseIf SetSize = 16 Then
HyperEventValue = 16
ElseIf SetSize = 25 Then
HyperEventValue = 24
End If
End If

writePort &H378, HyperEventValue

Gruss, Vera

Sara Agosta

unread,
Jun 1, 2010, 10:30:45 AM6/1/10
to e-p...@googlegroups.com
Thank you very much for your help!

s.

2010/6/1 Vera <vera...@googlemail.com>

David McFarlane

unread,
Jun 1, 2010, 3:47:20 PM6/1/10
to e-p...@googlegroups.com
Peter,

Good question, wish I knew the answer. We have been using a
different product from MCC, and using the A/D output to present
analog waveforms to subjects. Aside from any latency in starting the
waveform, the timing within the waveforms looks just fine on my
oscilloscope (waveform timing is handled internally by the MCC device
with its own clock). However, for this study we are not too
concerned about waveform onset latency, so I have not been asked to
look at that, let alone timing of straight digital I/O. We really
need someone to do that for us.

Beyond that I would just look and see what they say at the MCC site,
or contact them directly, but anyone could do that without me.

-- David McFarlane, Professional Faultfinder

Annchen Knodt

unread,
Mar 6, 2014, 11:54:32 AM3/6/14
to e-p...@googlegroups.com, mcfa...@msu.edu
Hi everyone,

I've been referring to this older post for help getting E-prime to send output signals to a USB device: MCC USB-1208FS.  Since Eprime doesn't have any native functionality for communicating with a USB I'd like to try using the DLL the comes with the device's "Universal Library" installation as David suggests below.  However, I can't find any instructions for working with Eprime anywhere in the UL documentation (and the rep I chatted with at MCC help had never heard of Eprime), so I'm hoping that someone might be able to clarify two things for me:

1) Which MCC DLL file to I link to in Eprime? (and what is the syntax of the Declare statement?)  The MCC rep said I should use cbw64.dll, but I'm not sure if he's right since he didn't really know what I was talking about
2) What inline commands then do I use in Eprime to send the signal to the USB?  We had previously used WritePort with a different device that's been replaced with this USB

Thanks!

Annchen Knodt

David McFarlane

unread,
Mar 6, 2014, 12:09:02 PM3/6/14
to e-p...@googlegroups.com
Annchen,

For the syntax & usage of the Declare statement, look at the Declare
topic in the E-Basic Help facility. You might find even better
documentation for Declare in references for Microsoft Visual Basic or
Visual Basic for Applications.

For the rest, you really do have to get that from MCC, they are
supposed to know and document which of their .dll files and functions
to use. As I recall when I used their UL (almost 4 years ago now),
it came with extensive documentation and examples. Remember that
E-Prime is just a derivative of MS VBA, so you should look at the
documentation & examples for Visual Basic. In fact, next time you
talk to MCC staff, do *not* mention E-Prime, just tell them you want
to use their board with Visual Basic, and that should help orient them better.

Best,
-----
David McFarlane
E-Prime training
online: http://psychology.msu.edu/Workshops_Courses/eprime.aspx
Twitter: @EPrimeMaster (https://twitter.com/EPrimeMaster )

/----
Stock reminder: 1) I do not work for PST. 2) PST's trained staff
take any and all questions at https://support.pstnet.com , and they
strive to respond to all requests in 24-48 hours, so make full use of
it. 3) In addition, PST offers several instructional videos on their
YouTube channel (http://www.youtube.com/user/PSTNET ). 4) If you do
get an answer from PST staff, please extend the courtesy of posting
their reply back here for the sake of others.
\----
> <http://support.pstnet.com/e%2Dprime/support/login.asp>http://support.pstnet.com/e%2Dprime/support/login.asp
> , and they strive
> > to respond to all requests in 24-48 hours -- this is pretty much their
> > substitute for proper documentation, so make full use of it. 3) If you
> > do get an answer from PST Web Support, please extend the courtesy of
> > posting their reply back here for the sake of others.
> >
> > That said, here is my take ...
> >
> > Unless PST has added something new to the latest release of EP2, E-Prime
> > simply has no facility for sending or receiving data through a USB port,
> > so you are just out of luck there. But do not take my word for this,
> > please contact PST Web Support yourself and then report back here.
> >
> > Say, why not just install another parallel port? Or, does your other
> > device need all 8 outputs from the parallel port? If not, why not just
> > build a cable to send different wires to your different devices? Just
> > take a look at the book "Parallel Port Complete" by Jan Axelson to get
> > some idea of how to make full use of the parallel port. Or, skip the
> > parallel port and just install a real digital I/O card (e.g., from
> > <http://www.mccdaq.com>http://www.mccdaq.com ).

Annchen Knodt

unread,
Mar 7, 2014, 1:59:52 PM3/7/14
to e-p...@googlegroups.com
Hi David,

Thanks for your response.  I was able to get a little further and am now fairly confident that my declare function should look like:

Declare Function WritePortUSB Lib "cbw32.dll" Alias "cbDOut" (ByVal BoardNum&, ByVal PortNum&, ByVal DataValue%) As Long
(since per MCC documentation, the cbw32.dll file contains the "cbDOut" function for sending digital signals to the device)

and my inline commands (eg to send signal 16 to the device through port 1, with board set to 0 since when I open MCC's instacal program I see that the device is labeled as Board #0) as follows:

WritePortUSB 0, 1, 16

The script will compile and run with the declare function, but once i include the WritePortUSB line of code I get a "missing parameter" error from eprime.

Any idea what I might be missing here?  I'm not sure particularly what number I should be using for PortNum, but I tried several values with the same result. 

Thanks!!

Annchen

David McFarlane

unread,
Mar 7, 2014, 3:14:06 PM3/7/14
to e-p...@googlegroups.com
Annchen,

Ah, the old "Subroutine vs. Function" distinction that is peculiar to
Visual Basic / E-Basic, and one of my pet peeves (rational languages
such as C do not make this useless distinction). Here is the deal,
which you might never see documented elsewhere:

- Subroutines *never* return a value, and their arguments must *not*
be enclosed in parentheses.

- Functions *always* return a value, and their arguments *must* be
enclosed in parentheses.

Sheesh! (In C, for example, all subroutines are functions, functions
may be defined to either return a value or not, and if a function
does return a value you need not collect it in a variable -- isn't
that a lot better?)

So try something like

Dim rtnValue as Long ' just because we need to take the returned value
rtnValue = WritePortUSB( 0, 1, 16 )

Come to think of it, the MCC UL documentation should have shown this usage.

You do not need to do anything with the return value, but VBA/E-Basic
usage *requires* that you store the function's return value to a
variable anyway. In this case, though, the function should return a
meaningful success/error code, so you might want to do something with that.

Good luck,
-----
David McFarlane
E-Prime training
online: http://psychology.msu.edu/Workshops_Courses/eprime.aspx
Twitter: @EPrimeMaster (https://twitter.com/EPrimeMaster )


><http://psychology.msu.edu/Workshops_Courses/eprime.aspx>http://psychology.msu.edu/Workshops_Courses/eprime.aspx
>
>Twitter: @EPrimeMaster
>(<https://twitter.com/EPrimeMaster>https://twitter.com/EPrimeMaster )
>
>/----
>Stock reminder: 1) I do not work for PST. 2) PST's trained staff
>take any and all questions at
><https://support.pstnet.com>https://support.pstnet.com , and they
>strive to respond to all requests in 24-48 hours, so make full use of
>it. 3) In addition, PST offers several instructional videos on their
>YouTube channel
>(<http://www.youtube.com/user/PSTNET>http://www.youtube.com/user/PSTNET
> <<http://support.pstnet.com/e%2Dprime/support/login.asp>http://support.pstnet.com/e%2Dprime/support/login.asp>http://support.pstnet.com/e%2Dprime/support/login.asp
>
> > , and they strive
> > > to respond to all requests in 24-48 hours -- this is pretty much their
> > > substitute for proper documentation, so make full use of it. 3) If you
> > > do get an answer from PST Web Support, please extend the courtesy of
> > > posting their reply back here for the sake of others.
> > >
> > > That said, here is my take ...
> > >
> > > Unless PST has added something new to the latest release of EP2, E-Prime
> > > simply has no facility for sending or receiving data through a USB port,
> > > so you are just out of luck there. But do not take my word for this,
> > > please contact PST Web Support yourself and then report back here.
> > >
> > > Say, why not just install another parallel port? Or, does your other
> > > device need all 8 outputs from the parallel port? If not, why not just
> > > build a cable to send different wires to your different devices? Just
> > > take a look at the book "Parallel Port Complete" by Jan Axelson to get
> > > some idea of how to make full use of the parallel port. Or, skip the
> > > parallel port and just install a real digital I/O card (e.g., from
> > > <<http://www.mccdaq.com>http://www.mccdaq.com>http://www.mccdaq.com ).

Annchen Knodt

unread,
Mar 7, 2014, 3:40:20 PM3/7/14
to e-p...@googlegroups.com
Thanks, I actually just caught that myself as well!  I was unknowingly copying from a call to a subroutine or something of the sort then - totally new at this.

Changing my code to the following allowed it to compile and run:

write_success = WritePortUSB(0, 888, 16)

FWIW I also realized that I might need an additional function and call to configure the device (per the user guide):
Declare Function cbDConfigPort Lib "cbw32.dll" (ByVal BoardNum&, ByVal PortNum&, ByValDirection&) As Long
...
config_success = cbDConfigPort(0, 1, 1)

Now I just have to make sure I'm getting the port number correct - any tips on how to figure out what to use for that?  I'm resorting to trial and error for now and haven't had success generating the signals yet - I'm not sure if it's this or something else that's configured incorrectly, so I'd like to have more confidence that at least some of the arguments I'm using are correct.

Thanks for all your help!

AK

David McFarlane

unread,
Mar 7, 2014, 4:14:23 PM3/7/14
to e-p...@googlegroups.com
Annchen,

OK, I dug out my old project and took a look to refresh my
memory. First, as I recall, you have to run some software that came
with the MCC board just to set it up to work with the system, and
that should have been covered in the documentation that came with the
board. If you have not yet run that setup software, and the
diagnostics to confirm that the board works with your system, then
you need to stop and do that first. As I recall, that's where the
board number gets assigned, until you do that the board is just not
available to the system. In particular, after you run the setup, run
the demo software that came with the board, as I recall that includes
both signal generator and oscillosope emulators (you will need other
equipment to measure this output or supply some varying
input). Until you get all that to work, all bets are off with
E-Prime or anything else.

Typically, again as I recall, the board number is 0 (it was in my
case), but again you need to run the MCC setup software to make that
active. You may also use the cbGetBoardName() function to discover
active board numbers, but as I keep saying, that will also fail if
you have not first run the MCC setup software. And be aware that
this board number setup has to be done individually on each machine
you use, the same USB board may be assigned a different board number
on each machine (in which case you might find the cbGetBoardName()
function handy to have your EP program automatically adapt to
different machines, but that is an advanced topic, even I skipped
that in my program and just assumed 0).

(BTW, for those tuning in, "board" here takes a special meaning
where it refers to an external USB device that performs functions
that formerly were left to adapter boards added to slots on the PC
motherboard.)

Good luck,
-- dkm
> ><<https://support.pstnet.com>https://support.pstnet.com>https://sup
> <<<http://support.pstnet.com/e%2Dprime/support/login.asp>http://support.pstnet.com/e%2Dprime/support/login.asp>http://support.pstnet.com/e%2Dprime/support/login.asp>http://support.pstnet.com/e%2Dprime/support/login.asp
>
> >
> > > , and they strive
> > > > to respond to all requests in 24-48 hours -- this is pretty much their
> > > > substitute for proper documentation, so make full use of
> it. 3) If you
> > > > do get an answer from PST Web Support, please extend the courtesy of
> > > > posting their reply back here for the sake of others.
> > > >
> > > > That said, here is my take ...
> > > >
> > > > Unless PST has added something new to the latest release of
> EP2, E-Prime
> > > > simply has no facility for sending or receiving data through
> a USB port,
> > > > so you are just out of luck there. But do not take my word for this,
> > > > please contact PST Web Support yourself and then report back here.
> > > >
> > > > Say, why not just install another parallel port? Or, does your other
> > > > device need all 8 outputs from the parallel port? If not,
> why not just
> > > > build a cable to send different wires to your different devices? Just
> > > > take a look at the book "Parallel Port Complete" by Jan Axelson to get
> > > > some idea of how to make full use of the parallel port. Or, skip the
> > > > parallel port and just install a real digital I/O card (e.g., from
> > > >
> <<<http://www.mccdaq.com>http://www.mccdaq.com>http://www.mccdaq.com>http://www.mccdaq.com
> ).
> > > >
> > > > -- David McFarlane, Professional Faultfinder
> > > >
> > > >
> > > >> does anyone knows the scropt to open the USB port in order to trigger
> > > >> a TMS?
> > > >>
> > > >> please, let me know
> > > >> I have to send a trigger though the USB port, because the parallel
> > > >> port is used to trigger another device.
> > > >>
> > > >> thank you very much
> > > >> Sara
>
>--
>You received this message because you are subscribed to the Google
>Groups "E-Prime" group.
>To unsubscribe from this group and stop receiving emails from it,
>send an email to
><mailto:e-prime+u...@googlegroups.com>e-prime+u...@googlegroups.com.
>To post to this group, send email to
><mailto:e-p...@googlegroups.com>e-p...@googlegroups.com.
>To view this discussion on the web visit
><https://groups.google.com/d/msgid/e-prime/99bace4f-6343-4d5d-a6c1-57c8be890cd7%40googlegroups.com?utm_medium=email&utm_source=footer>https://groups.google.com/d/msgid/e-prime/99bace4f-6343-4d5d-a6c1-57c8be890cd7%40googlegroups.com.
>For more options, visit
><https://groups.google.com/d/optout>https://groups.google.com/d/optout.

Annchen Knodt

unread,
Mar 13, 2014, 12:59:30 PM3/13/14
to e-p...@googlegroups.com



Thanks again for your help, David - I was able to get it working!  A big part I was missing was what to use for PortNum - the directions that came with the hardware only specified FIRSTPORTA, but I had to do a little searching before I found that the value of that constant was 10 on my device...all of the constants are listed in the file cbw.bas, which on my computer is in C:/Program Files/Measurement Computing/DAQ/VBWIN. (I found out that the board # was 0 after installation from the InstaCal program)

So, this is what I have for the working version at the top of my User script:

Dim config_success As Integer
Dim write_success As Integer

Declare Function cbDConfigPort Lib "cbw32.dll" (ByVal BoardNum&, ByVal PortNum&, ByVal Direction&) As Long
Declare Function WritePortUSB Lib "cbw32.dll" Alias "cbDOut" (ByVal BoardNum&, ByVal PortNum&, ByVal DataValue%) As Long

Then this at the beginning of the script (configuring port 10 on board 0 to DIGITALOUT = 1):
config_success = cbDConfigPort(0, 10, 1)

And this every time in the script that I wanted to send, for example the signal 4 to port 10 on board 0:
write_success = WritePortUSB(0, 10, 4)

(It was helpful to use Eprime's Debug.print when checking the write_success and config_success results)

Hope this helps somebody else who might run into the same issue!

Annchen

David McFarlane

unread,
Mar 14, 2014, 11:34:49 AM3/14/14
to e-p...@googlegroups.com
Annchen,

Cool, and thanks for following up with your report, this should come in useful!

-- David McFarlane
> <http://ychology.msu.edu/Workshops_Courses/eprime.aspx>ychology.msu.edu/Workshops_Courses/eprime.aspx>http://psychology.msu.edu/Workshops_Courses/eprime.aspx
>
> >
> > >
> > >Twitter: @EPrimeMaster
> > >(<<<https://twitter.com/EPrimeMaster>https://twitter.com/EPrimeMa
> ster>https://twitter.com/EPrimeMaste
> > r><https://twitter.com/EPrimeMaster>https://twitter.com/EPrimeMaster )
> > >
> > >/----
> > >Stock reminder: 1) I do not work for PST. 2) PST's trained staff
> > >take any and all questions at
> > ><<<https://support.pstnet.com>https://support.pstnet.com>https://
> support.pstnet.com>https://sup
> > <http://port.pstnet.com>port.pstnet.com , and they
> > >strive to respond to all requests in 24-48 hours, so make full use of
> > >it. 3) In addition, PST offers several instructional videos on their
> > >YouTube channel
> > >(<<<http://www.youtube.com/user/PSTNET>http://www.youtube.com/use
> r/PSTNET>http://www.youtube.com/user/P
> >
> STNET><http://www.youtube.com/user/PSTNET>http://www.youtube.com/user/PSTNET
> <<<<http://support.pstnet.com/e%2Dprime/support/login.asp>http://support.pstnet.com/e%2Dprime/support/login.asp>http://support.pstnet.com/e%2Dprime/support/login.asp>http://support.pstnet.com/e%2Dprime/support/login.asp>http://support.pstnet.com/e%2Dprime/support/login.asp
> <<<<http://www.mccdaq.com>http://www.mccdaq.com>http://www.mccdaq.com>http://www.mccdaq.com>http://www.mccdaq.com
Reply all
Reply to author
Forward
0 new messages