Opticka 2.16.1
Opticka is an experiment manager for behavioral research.
|
LABJACK Connects and manages a LabJack U3 / U6. More...
LABJACK Connects and manages a LabJack U3 / U6.
Connects and manages a LabJack U3 / U6. To run this in OS X and Linux, you need to install libusb and the exodriver. The easiest way to do this is to use homebrew on OS X, a light-weight package manager to install universal builds of these: bash$ brew install libusb exodriver For linux, see instructions on the labjack site. With the exodriver installed, you create a new labJack object and you can then send digital I/O commands and strobed words. labJack uses a 12bit word across EIO and CIO, using CIO0 as the strobe bit so one has a resultant 11bits of values in the strobed word. For example:
lj = labJack('verbose',true) open labJack verbosely lj.toggleFIO(1) toggle FIO1 between low and high lj.timedTTL(3,200) % send a 200ms timed TTL pulse on FIO3
Copyright ©2014-2022 Ian Max Andolina — released: LGPL3, see LICENCE.md
Public Member Functions | |
function | labJack (in varargin) |
Class constructor. | |
function | open (in obj) |
Open the LabJack device. | |
function | close (in obj) |
Close the LabJack device void LJUSB_CloseDevice(HANDLE hDevice); //Closes the handle of a LabJack USB device. | |
function | validHandle (in obj) |
Is Handle Valid? bool LJUSB_IsHandleValid(HANDLE hDevice); //Is handle valid. | |
function | rawWrite (in obj, in byte) |
Write formatted command string to LabJack unsigned long LJUSB_Write(HANDLE hDevice, BYTE *pBuff, unsigned long count); // Writes to a device. Returns the number of bytes written, or -1 on error. // hDevice = The handle for your device // pBuff = The buffer to be written to the device. // count = The number of bytes to write. // This function replaces the deprecated LJUSB_BulkWrite, which required the endpoint. | |
function | rawRead (in obj, in bytein, in count) |
Read response string back from LabJack unsigned long LJUSB_Read(HANDLE hDevice, BYTE *pBuff, unsigned long count); // Reads from a device. Returns the number of bytes read, or -1 on error. // hDevice = The handle for your device // pBuff = The buffer to filled in with bytes from the device. // count = The number of bytes expected to be read. // This function replaces the deprecated LJUSB_BulkRead, which required the endpoint. | |
function | waitShort (in obj, in time) |
WaitShort LabJack Wait in multiples of 64/128microseconds. | |
function | waitLong (in obj, in time) |
WaitLong LabJack Wait in multiples of 16/32ms. | |
function | timedTTL (in obj, in line, in time) |
timedTTL Send a TTL with a defined time of pulse | |
function | setDIO (in obj, in value, in mask, in valuedir, in maskdir) |
setDIO setDIO sets the direction/value for FIO, EIO and CIO If only value supplied, set all others to [255,255,255] | |
function | setDIODirection (in obj, in value, in mask) |
setDIODirection setDIODirection sets the direction for FIO, EIO and CIO as read or write | |
function | setDIOValue (in obj, in value, in mask) |
setDIOValue setDIOValue sets the value for FIO, EIO and CIO as HIGH or LOW | |
function | prepareStrobe (in obj, in value, in mask, in sendNow) |
Prepare Strobe Word Sets the strobe value for EIO (8bits) and CIO (4bits) which are accesible via the DB15 using a single cable. This avoids using FIO, which can therefore be used for addtional control TTLs (FIO0 and FIO1 are used for START/STOP and pause/unpause of the Plexon Omniplex in Opticka for example). | |
function | strobeWord (in obj) |
Send the Strobe command. | |
function | setFIO (in obj, in val, in line) |
Set FIO to a value. | |
function | toggleFIO (in obj, in line) |
Toggle FIO value. | |
function | ledON (in obj) |
Turn LED ON. | |
function | ledOFF (in obj) |
Turn LED OFF. | |
function | reset (in obj, in resetType) |
Reset the LabJack. | |
function | checksum (in obj, in command, in type) |
checksum Calculate checksum for data packet. Note see the labjack documentation; there are 2 types of checksums, normal and extended. This method uses 2 static methods checksum8 and checksum16 for each type respectively. | |
function get | fullName (in obj) |
concatenate the name with a uuid at get. | |
function | strobeServer (in obj, in value) |
Static Public Member Functions | |
static function | checksum8 (in in) |
checksum8 Calculate checksum for data packet | |
static function | checksum16 (in in) |
checksum16 Calculate checksum (lsb and msb) for extended data packet | |
static function | prepareWords (in value, in strobeState) |
Prepare Strobe Word split into EIO (8bit) and CIO (3bit). 0-2047 is the max # of variables with 2^11bits. | |
Public Attributes | |
Property | name |
friendly object name, setting this to 'null' will force silentMode=1 | |
Property | deviceID |
what LabJack device to use; 3 = U3, 6 = U6 | |
Property | device |
if more than one labJack connected, which one to open? | |
Property | silentMode |
silentMode allows one to gracefully fail methods without a labJack connected | |
Property | header |
header needed by loadlib | |
Property | library |
the library itself | |
Property | timeOut |
Property | verbose |
do we log everything to the command window? | |
Property | openNow |
allows the constructor to run the open method immediately (default) | |
Property | readResponse |
Property | strobeTime |
function labJack::labJack | ( | in | varargin | ) |
Class constructor.
We use parseArgs to parse allowed properties on construction and also switch into silent mode and/or auto open the labjack connection.
varargin | are passed as a structure of properties which is parsed. |
function labJack::checksum | ( | in | obj, |
in | command, | ||
in | type | ||
) |
checksum Calculate checksum for data packet. Note see the labjack documentation; there are 2 types of checksums, normal and extended. This method uses 2 static methods checksum8 and checksum16 for each type respectively.
command | The command that needs checksumming |
type | normal | extended |
|
static |
checksum16 Calculate checksum (lsb and msb) for extended data packet
|
static |
checksum8 Calculate checksum for data packet
function labJack::close | ( | in | obj | ) |
Close the LabJack device void LJUSB_CloseDevice(HANDLE hDevice); //Closes the handle of a LabJack USB device.
function get labJack::fullName | ( | in | obj | ) |
concatenate the name with a uuid at get.
return name the concatenated name
function labJack::ledOFF | ( | in | obj | ) |
Turn LED OFF.
I think this only works on the U3
function labJack::ledON | ( | in | obj | ) |
Turn LED ON.
I think this only works on the U3
function labJack::open | ( | in | obj | ) |
Open the LabJack device.
Open the LabJack device
function labJack::prepareStrobe | ( | in | obj, |
in | value, | ||
in | mask, | ||
in | sendNow | ||
) |
Prepare Strobe Word Sets the strobe value for EIO (8bits) and CIO (4bits) which are accesible via the DB15 using a single cable. This avoids using FIO, which can therefore be used for addtional control TTLs (FIO0 and FIO1 are used for START/STOP and pause/unpause of the Plexon Omniplex in Opticka for example).
value | The value to be strobed, range is 0-2047 for 11bits In Opticka, 0 and 2047 are reserved. Value can be 3 byte markers for FIO (which is ignored), EIO and CIO respectively. CIO0 is used as the strobe line, which leaves EIO0-7 and CIO1-3 for value data. |
mask | Which bits to mask |
sendNow | if true then sends the value immediately |
|
static |
Prepare Strobe Word split into EIO (8bit) and CIO (3bit). 0-2047 is the max # of variables with 2^11bits.
value | The value to be split into EIO and CIO |
function labJack::rawRead | ( | in | obj, |
in | bytein, | ||
in | count | ||
) |
Read response string back from LabJack unsigned long LJUSB_Read(HANDLE hDevice, BYTE *pBuff, unsigned long count); // Reads from a device. Returns the number of bytes read, or -1 on error. // hDevice = The handle for your device // pBuff = The buffer to filled in with bytes from the device. // count = The number of bytes expected to be read. // This function replaces the deprecated LJUSB_BulkRead, which required the endpoint.
bytein | |
count |
function labJack::rawWrite | ( | in | obj, |
in | byte | ||
) |
Write formatted command string to LabJack unsigned long LJUSB_Write(HANDLE hDevice, BYTE *pBuff, unsigned long count); // Writes to a device. Returns the number of bytes written, or -1 on error. // hDevice = The handle for your device // pBuff = The buffer to be written to the device. // count = The number of bytes to write. // This function replaces the deprecated LJUSB_BulkWrite, which required the endpoint.
byte | The raw hex encoded command packet to send |
function labJack::reset | ( | in | obj, |
in | resetType | ||
) |
Reset the LabJack.
resetType | whether to use a soft (1) or hard (2) reset type |
function labJack::setDIO | ( | in | obj, |
in | value, | ||
in | mask, | ||
in | valuedir, | ||
in | maskdir | ||
) |
setDIO setDIO sets the direction/value for FIO, EIO and CIO If only value supplied, set all others to [255,255,255]
value | is binary identifier for 0-7 bit range |
mask | is the mask to apply the command |
valuedir | binary identifier for input (0) or output (1) default=[255, 255, 255] |
maskdir | is the mask to apply the command. default=[255, 255,255] |
function labJack::setDIODirection | ( | in | obj, |
in | value, | ||
in | mask | ||
) |
setDIODirection setDIODirection sets the direction for FIO, EIO and CIO as read or write
value | is binary identifier for 0-7 bit range |
mask | is the mask to apply the command |
function labJack::setDIOValue | ( | in | obj, |
in | value, | ||
in | mask | ||
) |
setDIOValue setDIOValue sets the value for FIO, EIO and CIO as HIGH or LOW
value | is binary identifier for 0-7 bit range |
mask | is the mask to apply the command |
function labJack::setFIO | ( | in | obj, |
in | val, | ||
in | line | ||
) |
Set FIO to a value.
Note this uses the pregenerated raw commands, so only works with the FIO bits seen in properties above. Us SetDIO and a mask for a robust way to control any digital I/O
val | The value to be set line which FIO to set |
function labJack::strobeServer | ( | in | obj, |
in | value | ||
) |
function labJack::strobeWord | ( | in | obj | ) |
Send the Strobe command.
function labJack::timedTTL | ( | in | obj, |
in | line, | ||
in | time | ||
) |
timedTTL Send a TTL with a defined time of pulse
Note that there is a maximum time to the TTL pulse which is ~8.16secs for the U3 and ~4.08secs for the U6; we can extend that time by adding more feedback commands in the command packet but this shouldn't be needed anyway. Any time longer than this will be truncated to the maximum allowable time.
line | 0-7=FIO, 8-15=EIO, or 16-19=CIO |
time | time in ms |
sync | optional logical flag whether to use blocking (true) command |
function labJack::toggleFIO | ( | in | obj, |
in | line | ||
) |
Toggle FIO value.
Note this uses the pregenerated raw commands, so only works with the FIO bits seen in properties above. Us SetDIO and a mask for a robust way to control any digital I/O
function labJack::validHandle | ( | in | obj | ) |
Is Handle Valid? bool LJUSB_IsHandleValid(HANDLE hDevice); //Is handle valid.
function labJack::waitLong | ( | in | obj, |
in | time | ||
) |
WaitLong LabJack Wait in multiples of 16/32ms.
time | time in ms, remember 16/32ms is the atomic minimum |
function labJack::waitShort | ( | in | obj, |
in | time | ||
) |
WaitShort LabJack Wait in multiples of 64/128microseconds.
time | time in ms; remember 64/128microseconds is the atomic minimum |
Property labJack::device |
if more than one labJack connected, which one to open?
Property labJack::deviceID |
what LabJack device to use; 3 = U3, 6 = U6
Property labJack::header |
header needed by loadlib
Property labJack::library |
the library itself
Property labJack::name |
friendly object name, setting this to 'null' will force silentMode=1
Property labJack::openNow |
allows the constructor to run the open method immediately (default)
Property labJack::readResponse |
whether we read the response (true) or not (false) to commands we send. The LabJack usually requires that we read the response and do a soft reset if no response is read, but it does allow us to not have to wait till we get a response, thus can speed methods like timedTTL up.
Property labJack::silentMode |
silentMode allows one to gracefully fail methods without a labJack connected
Property labJack::strobeTime |
strobeTime is time of strobe in unit multiples of timeShort: 16 units ~=1ms on a U6 where timeShort is 64e-6 .If you use a U3 this needs to be 8 for a 1ms pulse...
Property labJack::timeOut |
how long to wait to read or write to the LabJack in milliseconds, 0 = infinity
Property labJack::verbose |
do we log everything to the command window?