Daq Toolbox
by Denis Pelli
The Daq Toolbox provides a comprehensive set of thirty functions to control the USB-1208FS data acquisition device (formerly called "PMD-1208FS") from your MATLAB program running on a Mac OS X computer. This data acquisition device (daq), released in January 2005 by Measurement Computing, costs $150 and offers "50 kHz" input and output 12-bit sampling of analog voltages (8 in, 2 out) and 16 digital i/o lines, with signals brought out to screw terminals. ("50 kHz" is a theoretical upper limit: as of 18 April 2005 we attain 2 kHz.) It's the size of a wallet and is powered through its USB cable. The Daq Toolbox gives you complete control of it from within MATLAB, via the PsychHID extension.
Click here to download the Daq Toolbox
(version: 26 August 2005), including all the necessary files to control your USB-1208FS. This archive is complete; you don't need the rest of the Psychtoolbox. It's free. The only requirements are: a USB-1208FS and MATLAB, running on a Macintosh computer with a USB port and Mac OS X 10.3 or better. It will be included in OSX Psychtoolbox 1.06.
![]() |
Figure 1. This graph was produced by TestDaq.m, which is included in the Daq Toolbox. TestDaq exercises all the functions in the Daq Toolbox. This graph tests the analog i/o by putting out two waveforms, simultaneously, on two analog output channels and reading them back in, simultaneously, through two analog input channels. The plot is a graph of the measured input voltages over time, showing that the sine (red) and triangle (green) waves went through the output and input conversion processes without distortion. |
There is a near-perfect isolation of dependency on device and platform at the two levels of code in the Daq Toolbox. The PsychHID MEX file (written in C) is highly dependent on the platform, Mac OS X, but independent of the particular HID-compliant device. It provides generic HID commands. (HID, or Human Interface Device, is a USB class specifying a communication protocol for the device and host.) The Daq M files are specific to our HID-compliant device, the USB-1208FS, but independent of the platform (Mac OS X), and would run unchanged on any other computer for which one provided the PsychHID extension. We hope that users of the OSX Psychtoolbox will find it easy to write new MATLAB M files to support other HID-compliant devices, using the Daq Toolbox (for the USB-1208FS) as a model.
1 July 2006. Apple published a very helpful article, with code, giving a good overview of USB programming under Mac OS X. "Building customized user client drivers for USB devices." Anyone doing Mac OS USB development should also be aware of the helpful discussions on Apple's usb mailing list.
2005. The manufacturer changed the product name from "PMD-1208FS" to "USB-1208FS". It was necessary to update our MATLAB code to use the new name string to recognize the device.
30 April 2005. There is only one bug. If you use PsychHID to receive reports, then CLEAR PsychHID, and then use PsychHID again to receive reports you might crash (depending on other details that are hard to specify). Boom! MATLAB prints a huge red stack trace, showing a segmentation violation deep in the bowels of Mac OS X Core Foundation, when we call createAsyncEventSource. Apple engineer Rob Yepez, their USB-HID expert, helped me to greatly reduce the incidence of this crash, but it's not yet abolished. Note that there is no problem at all if you refrain from using CLEAR PsychHID.
26 April 2005. DaqAInScan is now working well, like the rest of the Daq Toolbox.
25 April 2005. With help from Apple engineer Rob Yepez, their USB-HID expert, we've nearly eliminated the PsychHID crash that was happening when you used PsychHID again after calling CLEAR MEX. You can follow the thread in Apple's USB forum. (21 April 2005).
I wrote this code for two reasons. The practical reason is that we needed it to measure eye movements. I have an analog eye movement monitor designed by Roger Carpenter (1988, Movements of the Eyes, Routledge Chapman & Hall, Appendix), which measures the light reflected by the limbus (the light/dark edge formed by the dark iris and the white sclera). We needed a way to digitize the analog signal from within MATLAB.
The second reason is more romantic. When I was in high school, my brother, father, and I used to read science fiction, especially A.E. Van Vogt. Van Vogt (1912 - 2000) was born in Winnipeg, Manitoba, Canada, and moved to Los Angeles in 1944. His science fiction captured something about how fascinating technology and machines can be. As my brother Rafael says, "those books created a great vision of the power of personal technology at a time when most of the sci-fi was about big equipment - like spaceships." One favorite was The Weapon Shops of Ishir (1951). "Imagine an empire of the far future, dictatorial, proud, all-conquering, yet people could defy it merely by buying a gun that the rulers don't have." These guns were technological marvels, indestructible and unbeatable. The premise of the story is that the despotic government was held in check by the citizenry's unfettered access to the weapon shops that sold these wonderful little guns that, in the story, were used solely to protect democratic freedoms. (It seems that the US constitution's right to bear arms struck a chord with Van Vogt.) Van Vogt's story captured the magic of technological invention, a perfect gadget that could empower individuals to do good.
More than fifty years after Van Vogt wrote his story, the USB bus is ushering in a new breed of computer peripherals, unlike anything seen before. From the perspective of someone doing scientific research, computer peripherals used to be either mass market devices like keyboards and basic printers, which are not very scientific, or very expensive special-purpose devices made explicitly for scientific research, which you bolted onto a 19" rack. One bought the equipment one's research demanded, but it was a significant investment, carefully justified. That is now changed. The USB bus is a hot-pluggable thin cable. It's cheap to implement, connects to all platforms, and provides power from the host computer. From the developer's perspective, a USB-based product sells to the whole computer market and doesn't need a power supply, so it needn't be pricey to be profitable. Suddenly we can now buy wallet-sized data acquisition devices (daqs) for $150 that replace rack-mounted boxes costing thousands of dollars. The new consumer-level pricing allows any scientific lab to add a daq without hesitation.
David Brainard and I developed the Psychtoolbox to provide for ourselves and our colleagues a good programming environment for vision research. I wanted to add a daq to that environment, but discovered that few of the daqs available come with Macintosh software. Furthermore, I realized that I wouldn't want to use my daq from a stand-alone application. I want to use it from within MATLAB, to coordinate everything, e.g. image synthesis and eye-position monitoring, from one program in a high-level language.
The USB protocol is committee-designed and the specification is mind-numbing to read, but it's a high-level protocol of which typically only a few commands — to send or receive a block of data — are needed to communicate with a particular device. Any manufacturer of a USB device can provide a manual specifying what commands their device accepts through USB, allowing users of any computer to write a simple driver to host their device. In my case, Measurement Computing provided the firmware manual for their USB-1208FS daq, making it possible for me to write the Daq Toolbox, which controls their daq from within MATLAB. The software is free, so anyone using Mac OS X MATLAB can add a daq by buying the USB-1208FS.
For me, these daqs share the perfection of the guns described by A.E. Van Vogt, empowering individuals to do good.
21 April 2005.
visitors
since 15 February 2005.
David
Brainard, Denis
Pelli & Allen Ingling.
psychtoolbox@yahoogroups.com
Updated