The LabJack devices support doing serial communications using their digital lines using the standard SPI synchronous format. This is a powerful, but advanced feature of the LabJack, and the details of SPI is beyond the scope of this guide. Instead, here is some sample code that demonstrates SPI. It will use FIO0 for the clock (CLK), FIO1 for CS, FIO2 for MOSI, and FIO3 for MISO. It then sends out a string of 16 bytes and prints the received string to the command / alert window. If you short MISO to MOSI, then the 16 bytes sent out are echoed back. If MISO is tied to GND, then all zeros are received and printed. If you tie MISO to VS or leave it unconnected, then all 255's are received and printed. Here's the script. Its pretty much a direct copy of the C sample provided by LabJack:
using("device.labjack")
include("c:\program files (x86)\labjack\drivers\labjackud.h")
global ID = 0 // use first found
//First, we do a pin config reset to set the LabJack to factory defaults.
ePut(ID,LJ_ioPIN_CONFIGURATION_RESET,0,0,0)
// Configure the SPI communication:
//Enable automatic chip-select control.
AddRequest(ID, LJ_ioPUT_CONFIG, LJ_chSPI_AUTO_CS,1,0,0)
//Mode A: CPHA=1, CPOL=1.
AddRequest(ID, LJ_ioPUT_CONFIG, LJ_chSPI_MODE,0,0,0)
//125kHz clock.
AddRequest(ID, LJ_ioPUT_CONFIG, LJ_chSPI_CLOCK_FACTOR,0,0,0)
//MOSI is FIO2
AddRequest(ID, LJ_ioPUT_CONFIG, LJ_chSPI_MOSI_PIN_NUM,2,0,0)
//MISO is FIO3
AddRequest(ID, LJ_ioPUT_CONFIG, LJ_chSPI_MISO_PIN_NUM,3,0,0)
//CLK is FIO0
AddRequest(ID, LJ_ioPUT_CONFIG, LJ_chSPI_CLK_PIN_NUM,0,0,0)
//CS is FIO1
AddRequest(ID, LJ_ioPUT_CONFIG, LJ_chSPI_CS_PIN_NUM,1,0,0)
//Execute the requests on a single LabJack. The driver will use a single low-level TimerCounter command to handle all the requests above.
GoOne(ID)
// now that its setup, do the communication. Note that you can do this part in a separate sequence, and run multiple times
// without the reconfiguring the SPI with the above code.
// initialize the variables
private numSPIBytesToTransfer=4
private dataArray
dataArray[0] = 170
dataArray[1] = 138
dataArray[2] = 85
dataArray[3] = 21
//Transfer the data. The write and read is done at the same time.
eGet(ID, LJ_ioSPI_COMMUNICATION, 0, @numSPIBytesToTransfer, @dataArray)
// print the read to the command / alert window. Of course you'll probably do something a bit more exciting with the data
? dataArray
Each time you run the script the 4 bytes of dataArray will be written and then 4 bytes will be read back and printed to the command / alert window. As mentioned in the script comments, you can do the actual communication multiple times without re-running reconfiguration script at the top of this sample.