Opticka 2.16.1
Opticka is an experiment manager for behavioral research.
Loading...
Searching...
No Matches
labJack Class Reference

LABJACK Connects and manages a LabJack U3 / U6. More...

Detailed Description

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

Inheritance diagram for labJack:

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
 

Constructor & Destructor Documentation

◆ labJack()

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.

Parameters
vararginare passed as a structure of properties which is parsed.
Returns
instance of labJack class.

Member Function Documentation

◆ checksum()

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.

Parameters
commandThe command that needs checksumming
typenormal | extended

◆ checksum16()

static function labJack::checksum16 ( in  in)
static

checksum16 Calculate checksum (lsb and msb) for extended data packet

◆ checksum8()

static function labJack::checksum8 ( in  in)
static

checksum8 Calculate checksum for data packet

◆ close()

function labJack::close ( in  obj)

Close the LabJack device void LJUSB_CloseDevice(HANDLE hDevice); //Closes the handle of a LabJack USB device.

◆ fullName()

function get labJack::fullName ( in  obj)

concatenate the name with a uuid at get.

Parameters

return name the concatenated name

◆ ledOFF()

function labJack::ledOFF ( in  obj)

Turn LED OFF.

I think this only works on the U3

◆ ledON()

function labJack::ledON ( in  obj)

Turn LED ON.

I think this only works on the U3

◆ open()

function labJack::open ( in  obj)

Open the LabJack device.

Open the LabJack device

◆ prepareStrobe()

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

Parameters
valueThe 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.
maskWhich bits to mask
sendNowif true then sends the value immediately

◆ prepareWords()

static function labJack::prepareWords ( in  value,
in  strobeState 
)
static

Prepare Strobe Word split into EIO (8bit) and CIO (3bit). 0-2047 is the max # of variables with 2^11bits.

Parameters
valueThe value to be split into EIO and CIO
Returns
eio is an 8bit word value represented the LSB
cio is a 4bit value where the 1st bit is 1 for strobe line 22 and the rest is the 3bit remainder to combine with eio to make an 11bit strobed word.

◆ rawRead()

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.

Parameters
bytein
count

◆ rawWrite()

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.

Parameters
byteThe raw hex encoded command packet to send

◆ reset()

function labJack::reset ( in  obj,
in  resetType 
)

Reset the LabJack.

Parameters
resetTypewhether to use a soft (1) or hard (2) reset type

◆ setDIO()

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]

Parameters
valueis binary identifier for 0-7 bit range
maskis the mask to apply the command
valuedirbinary identifier for input (0) or output (1) default=[255, 255, 255]
maskdiris the mask to apply the command. default=[255, 255,255]

◆ setDIODirection()

function labJack::setDIODirection ( in  obj,
in  value,
in  mask 
)

setDIODirection setDIODirection sets the direction for FIO, EIO and CIO as read or write

Parameters
valueis binary identifier for 0-7 bit range
maskis the mask to apply the command

◆ setDIOValue()

function labJack::setDIOValue ( in  obj,
in  value,
in  mask 
)

setDIOValue setDIOValue sets the value for FIO, EIO and CIO as HIGH or LOW

Parameters
valueis binary identifier for 0-7 bit range
maskis the mask to apply the command

◆ setFIO()

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

Parameters
valThe value to be set line which FIO to set

◆ strobeServer()

function labJack::strobeServer ( in  obj,
in  value 
)

◆ strobeWord()

function labJack::strobeWord ( in  obj)

Send the Strobe command.

◆ timedTTL()

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.

Parameters
line0-7=FIO, 8-15=EIO, or 16-19=CIO
timetime in ms
syncoptional logical flag whether to use blocking (true) command

◆ toggleFIO()

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

◆ validHandle()

function labJack::validHandle ( in  obj)

Is Handle Valid? bool LJUSB_IsHandleValid(HANDLE hDevice); //Is handle valid.

◆ waitLong()

function labJack::waitLong ( in  obj,
in  time 
)

WaitLong LabJack Wait in multiples of 16/32ms.

Parameters
timetime in ms, remember 16/32ms is the atomic minimum

◆ waitShort()

function labJack::waitShort ( in  obj,
in  time 
)

WaitShort LabJack Wait in multiples of 64/128microseconds.

Parameters
timetime in ms; remember 64/128microseconds is the atomic minimum

Member Data Documentation

◆ device

Property labJack::device

if more than one labJack connected, which one to open?

◆ deviceID

Property labJack::deviceID

what LabJack device to use; 3 = U3, 6 = U6

◆ header

Property labJack::header

header needed by loadlib

◆ library

Property labJack::library

the library itself

◆ name

Property labJack::name

friendly object name, setting this to 'null' will force silentMode=1

◆ openNow

Property labJack::openNow

allows the constructor to run the open method immediately (default)

◆ readResponse

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.

◆ silentMode

Property labJack::silentMode

silentMode allows one to gracefully fail methods without a labJack connected

◆ strobeTime

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

◆ timeOut

Property labJack::timeOut

how long to wait to read or write to the LabJack in milliseconds, 0 = infinity

◆ verbose

Property labJack::verbose

do we log everything to the command window?


The documentation for this class was generated from the following file: