Device-LabJack
view release on metacpan or search on metacpan
Parameter Description:
Returns: LabJack errorcodes or 0 for no error.
Inputs:
· *idnum - Local ID, serial number, or -1 for first found.
· demo - Send 0 for normal operation, >0 for demo mode. Demo mode allows this function to be called without a LabJack.
· *stateIO - Output states for IO0-IO3.
· updateIO - If >0, state values will be written. Otherwise, just a read is performed.
· ledOn - If >0, the LabJack LED is turned on.
· numChannels - Number of analog input channels to read (1,2, or 4).
· *channels - Pointer to an array of channel commands with at least numChannels elements. Each channel command is 0-7 for single-ended, or 8-11 for differential.
· *gains - Pointer to an array of gain commands with at least numChannels elements. Gain commands are 0=1, 1=2, ..., 7=20. This amplification is only available for differential channels.
· disableCal - If >0, voltages returned will be raw readings that are not corrected using calibration constants.
· *voltages - Pointer to an array where voltage readings are returned. Send a 4-element array of zeros.
Outputs:
· *idnum - Returns the local ID or -1 if no LabJack is found.
· *overVoltage - If >0, an overvoltage has been detected on one of the selected analog inputs.
=cut
void
AISample(idnum,demo,stateIO,updateIO,ledOn,channels,gains,disableCal)
int idnum
int demo
int stateIO
int updateIO
int ledOn
// int numCh
SV * channels
SV * gains
int disableCal
INIT:
int i,n,numchannels,numgains,numCh;
long errorcode;
long lchannels[14]; // ={0,1,2,3};
long lgains[14]; // ={0,0,0,0};
long ov;
float voltages[4]={0,0,0,0};
// Check that they passed an array of channels, and count the elements
if ((!SvROK(channels))
|| (SvTYPE(SvRV(channels)) != SVt_PVAV)
|| ((numchannels = av_len((AV *)SvRV(channels))) < 0))
{
XSRETURN_UNDEF;
}
// Check that they passed an array of gains, and count the elements
if ((!SvROK(gains))
|| (SvTYPE(SvRV(gains)) != SVt_PVAV)
|| ((numgains = av_len((AV *)SvRV(gains))) < 0))
{
XSRETURN_UNDEF;
}
// Make sure there's a gain for every channel
if(numgains<numchannels) {
XSRETURN_UNDEF;
}
PPCODE:
// Extract the channels we got from perl...
for (n = 0; n <= numchannels; n++) {
lchannels[n]= SvNV(*av_fetch((AV *)SvRV(channels), n, 0));
}
// Extract the gains we got from perl...
for (n = 0; n <= numgains; n++) {
lgains[n]= SvNV(*av_fetch((AV *)SvRV(gains), n, 0));
}
numCh=numchannels+1;
// Run the command
errorcode = AISample (&idnum,demo,&stateIO,updateIO,ledOn,numCh,lchannels,lgains,disableCal,&ov,voltages);
// Return the results to perl in a big array
if(errorcode) {
char errorString[51];
GetErrorString ( errorcode, errorString );
XPUSHs(sv_2mortal(newSVpv(errorString,0)));
} else {
XPUSHs(sv_2mortal(newSVnv(errorcode)));
}
XPUSHs(sv_2mortal(newSVnv(idnum)));
XPUSHs(sv_2mortal(newSVnv(ov)));
XPUSHs(sv_2mortal(newSVnv(stateIO)));
for(i=0;i<numCh;i++)XPUSHs(sv_2mortal(newSVnv(voltages[i])));
=head AOUpdate
################################################################################
INFO
Sets the voltages of the analog outputs. Also controls/reads all 20 digital
I/O and the counter. Execution time for this function is 20 milliseconds or
less.
Declaration:
long AOUpdate ( long *idnum,
long demo,
long trisD,
long trisIO,
long *stateD,
long *stateIO,
long updateDigital,
long resetCounter,
unsigned long *count,
float analogOut0,
float analogOut1)
Parameter Description:
Returns: LabJack errorcodes or 0 for no error.
Inputs:
- *idnum - Local ID, serial number, or -1 for first found.
- demo - Send 0 for normal operation, >0 for demo mode. Demo mode allows this function to be called without a LabJack.
- trisD - Directions for D0-D15. 0=Input, 1=Output.
- trisIO - Directions for IO0-IO3. 0=Input, 1=Output.
- *stateD - Output states for D0-D15.
- *stateIO - Output states for IO0-IO3.
- updateDigital - If >0, tris and state values will be written. Otherwise, just a read is performed.
- resetCounter - If >0, the counter is reset to zero after being read.
- analogOut0 - Voltage from 0.0 to 5.0 for AO0.
- analogOut1 - Voltage from 0.0 to 5.0 for AO1.
Outputs:
- *idnum - Returns the local ID or -1 if no LabJack is found.
- *stateD - States of D0-D15.
- *stateIO - States of IO0-IO3.
- *count - Current value of the 32-bit counter (CNT). This value is read before the counter is reset.
=cut
void
AOUpdate (idnum,demo,trisD,trisIO,stateD,stateIO,updateDigital,resetCounter,analogOut0,analogOut1)
int idnum
int demo
int trisD
int trisIO
int stateD
int stateIO
int updateDigital
int resetCounter
float analogOut0
float analogOut1
INIT:
unsigned count=0;
long errorcode=0;
// int lstateD=0;
// int lstateIO=0;
PPCODE:
// Run the command
// errorcode = AISample (&idnum,demo,&stateIO,updateIO,ledOn,numCh,lchannels,lgains,disableCal,&ov,voltages);
errorcode = AOUpdate (&idnum,demo,trisD,trisIO,&stateD,&stateIO,updateDigital,resetCounter,&count,analogOut0,analogOut1);
// Return the results to perl in a big array
if(errorcode) {
char errorString[51];
GetErrorString ( errorcode, errorString );
XPUSHs(sv_2mortal(newSVpv(errorString,0)));
} else {
XPUSHs(sv_2mortal(newSVnv(errorcode)));
}
XPUSHs(sv_2mortal(newSVnv(idnum)));
XPUSHs(sv_2mortal(newSVnv(stateD)));
XPUSHs(sv_2mortal(newSVnv(stateIO)));
XPUSHs(sv_2mortal(newSVnv(count)));
=head AIBurst
################################################################################
INFO
Reads a specified number of scans (up to 4096) at a specified scan rate (up to 8192 Hz) from
1,2, or 4 analog inputs. First, data is acquired and stored in the LabJack's 4096 sample RAM
buffer. Then, the data is transferred to the PC.
Declaration:
long AIBurst ( long *idnum,
long demo,
long stateIOin,
long updateIO,
long ledOn,
long numChannels,
long *channels,
long *gains,
float *scanRate,
long disableCal,
long triggerIO,
long triggerState,
long numScans,
long timeout,
float (*voltages)[4],
long *stateIOout,
long *overVoltage,
long transferMode )
- *scanRate - Returns the actual scan rate, which due to clock resolution is not always exactly the same as the desired scan rate.
- *voltages - Pointer to a 4096 by 4 array where voltage readings are returned. Unused locations are filled with 9999.0.
- *stateIOout - Pointer to a 4096 element array where IO states are returned. Unused locations are filled with 9999.0.
- *overVoltage - If >0, an overvoltage has been detected on at least one sample of one of the selected analog inputs.
=cut
void
AIBurst(idnum,demo,stateIOin,updateIO,ledOn,channels,gains,scanRate,disableCal,triggerIO,triggerState,numScans,timeout,transferMode)
long idnum
long demo
long stateIOin
long updateIO
long ledOn
// int numCh we can work this out from the size of the perl array
SV * channels
SV * gains
float scanRate
long disableCal
long triggerIO
long triggerState
long numScans
long timeout
// SV * voltages These are output vectors
// SV * stateIOout
long transferMode
INIT:
int i,n,j,numchannels,numgains,numCh; // ,numvoltages,numstateIOout
long errorcode;
long lchannels[14]; // ={0,1,2,3};
long lgains[14]; // ={0,0,0,0};
long ov;
// float voltages[4]={0,0,0,0};
float voltages[4096][4];
long stateIOout[4096];
// Check that they passed an array of channels, and count the elements
if ((!SvROK(channels))
|| (SvTYPE(SvRV(channels)) != SVt_PVAV)
|| ((numchannels = av_len((AV *)SvRV(channels))) < 0))
{
XSRETURN_UNDEF;
}
// Check that they passed an array of gains, and count the elements
if ((!SvROK(gains))
|| (SvTYPE(SvRV(gains)) != SVt_PVAV)
|| ((numgains = av_len((AV *)SvRV(gains))) < 0))
{
XSRETURN_UNDEF;
}
// Make sure there's a gain for every channel
if(numgains<numchannels) {
XSRETURN_UNDEF;
}
PPCODE:
// Extract the channels we got from perl...
for (n = 0; n <= numchannels; n++) {
lchannels[n]= SvNV(*av_fetch((AV *)SvRV(channels), n, 0));
}
// Extract the gains we got from perl...
for (n = 0; n <= numgains; n++) {
lgains[n]= SvNV(*av_fetch((AV *)SvRV(gains), n, 0));
}
numCh=numchannels+1;
// clear the output area
memset(stateIOout,0,4096*sizeof(long));
memset(voltages,0,4*4096*sizeof(float));
// Run the command
errorcode = AIBurst (&idnum,
demo,
stateIOin,
updateIO,
ledOn,
numCh,
lchannels,
lgains,
&scanRate,
disableCal,
triggerIO,
triggerState,
numScans,
timeout,
voltages,
stateIOout,
&ov,
transferMode);
// Return the results to perl in a big array
if(errorcode) {
char errorString[51];
GetErrorString ( errorcode, errorString );
XPUSHs(sv_2mortal(newSVpv(errorString,0)));
} else {
XPUSHs(sv_2mortal(newSVnv(errorcode)));
}
XPUSHs(sv_2mortal(newSVnv(idnum)));
XPUSHs(sv_2mortal(newSVnv(scanRate)));
XPUSHs(sv_2mortal(newSVnv(ov)));
for(i=0;i<numScans;i++)
for(j=0;j<numCh;j++)
XPUSHs(sv_2mortal(newSVnv(voltages[i][j])));
for(i=0;i<numScans;i++)
XPUSHs(sv_2mortal(newSVnv(stateIOout[i])));
#// ###########################################################################
#// NOTE: The rest of this file from here downwards contributed by Neil, with
#// some small adjustments by Chris (see file "Changes")
#// ###########################################################################
#// ###########################################################################
#// ###########################################################################
=head
//======================================================================
// EAnalogIn: Easy function reads the voltage from 1 analog input. Calling
// this function turns/leaves the status LED on.
//
// Returns: LabJack errorcodes or 0 for no error (I32).
// Inputs: *idnum -Local ID, Serial Number, or -1 for first
// found (I32).
// demo -Send 0 for normal operation, >0 for demo
// mode (I32). Demo mode allows this function
// to be called without a LabJack, and does
// little but simulate execution time.
// channel -Channel command is 0-7 for SE or 8-11 for Diff.
// gain -Gain command is 0=1,1=2,...,7=20. Gain only
// available for differential channels.
// Outputs: *idnum -Returns the Local ID or -1 if no LabJack is
// found (I32).
// *overVoltage -If >0, an overvoltage has been detected
// on the analog input (I32).
// *voltage -Returns the voltage reading (SGL).
//
//----------------------------------------------------------------------
=cut
#// ###########################################################################
long
EAnalogIn(idnum, demo, channel, gain)
long idnum
long demo
long channel
long gain
INIT:
long overVoltage;
float voltage;
long errcode;
PPCODE:
errcode = EAnalogIn(&idnum, demo, channel, gain, &overVoltage, &voltage);
// Return the results to perl in a big array
if(errcode) { // RETVAL
char errorString[51];
GetErrorString ( errcode, errorString );
XPUSHs(sv_2mortal(newSVpv(errorString,0)));
} else {
XPUSHs(sv_2mortal(newSVnv(errcode)));
}
XPUSHs(sv_2mortal(newSVnv(idnum))); // idnum
XPUSHs(sv_2mortal(newSVnv(overVoltage))); // overVoltage
XPUSHs(sv_2mortal(newSVnv(voltage))); // voltage
#// ###########################################################################
=head
//======================================================================
// EAnalogOut: Easy function sets the voltages of both analog outputs.
//
// Returns: LabJack errorcodes or 0 for no error (I32).
// Inputs: *idnum -Local ID, Serial Number, or -1 for first
// found (I32).
// demo -Send 0 for normal operation, >0 for demo
// mode (I32). Demo mode allows this function
// to be called without a LabJack, and does little
// but simulate execution time.
// analogOut0 -Voltage from 0 to 5 for AO0 (SGL).
// analogOut1 -Voltage from 0 to 5 for AO1 (SGL).
// Outputs: *idnum -Returns the Local ID or -1 if no LabJack is
// found (I32).
//
// Time: 20 ms
//----------------------------------------------------------------------
long _stdcall EAnalogOut(long *idnum,
long demo,
float analogOut0,
float analogOut1);
=cut
#// ###########################################################################
long
EAnalogOut(idnum, demo, analogOut0, analogOut1)
long idnum
long demo
float analogOut0
float analogOut1
INIT:
long errcode;
PPCODE:
errcode = EAnalogOut(&idnum, demo, analogOut0, analogOut1);
// Return the results to perl in a big array
if(errcode) { // RETVAL
char errorString[51];
GetErrorString ( errcode, errorString );
XPUSHs(sv_2mortal(newSVpv(errorString,0)));
} else {
XPUSHs(sv_2mortal(newSVnv(errcode)));
}
XPUSHs(sv_2mortal(newSVnv(idnum))); // idnum
#// ###########################################################################
=head
//======================================================================
// ECount: Easy function to read & reset the counter. Calling this
// function disables STB (which is the default anyway).
//
// Returns: LabJack errorcodes or 0 for no error (I32).
// Inputs: *idnum -Local ID, Serial Number, or -1 for first
// found (I32).
// demo -Send 0 for normal operation, >0 for demo
// mode (I32). Demo mode allows this function to
// be called without a LabJack, and does little but
// simulate execution time.
// resetCounter -If >0, the counter is reset to zero after
// being read (I32).
// Outputs: *idnum -Returns the Local ID or -1 if no LabJack is
// found (I32).
// *count -Current count, before reset.
// *ms -Value of Windows millisecond timer at the
// time of the counter read (within a few ms).
// Note that the millisecond timer rolls over
// about every 50 days. In general, the
// millisecond timer starts counting from zero
// whenever the computer reboots.
//
// Time: 20 ms
//----------------------------------------------------------------------
=cut
#// ###########################################################################
long
ECount(idnum, demo, resetCounter)
long idnum
long demo
long resetCounter
INIT:
long errcode;
double count;
double ms;
PPCODE:
errcode = ECount(&idnum, demo, resetCounter, &count, &ms);
// Return the results to perl in a big array
if(errcode) { // RETVAL
char errorString[51];
GetErrorString ( errcode, errorString );
XPUSHs(sv_2mortal(newSVpv(errorString,0)));
} else {
XPUSHs(sv_2mortal(newSVnv(errcode)));
}
XPUSHs(sv_2mortal(newSVnv(idnum))); // idnum
XPUSHs(sv_2mortal(newSVnv(count))); // count
XPUSHs(sv_2mortal(newSVnv(ms))); // ms
#// ###########################################################################
=head
SYNOPSIS
----------------------------------------------------------------------
EDigitalIn: Easy function reads 1 digital input. Also configures
the requested pin to input and leaves it that way.
Note that this is a simplified version of the lower
level function DigitalIO, which operates on all 20
digital lines. The DLL keeps track of the current
direction and output state of all lines, so that this
easy function can operate on a single line without
changing the others. When the DLL is first loaded,
though, it does not know the direction and state of
the lines and assumes all directions are input and
output states are low.
----------------------------------------------------------------------
# Example perl program which calls this module -
use Device::LabJack;
$idnum = -1;
my (@results) = Device::LabJack::EDigitalIn(...)
print "Firware version: " . join("\n",@results) . "\n";
----------------------------------------------------------------------
INFO
Returns: LabJack errorcodes or 0 for no error (I32).
Inputs: *idnum -Local ID, Serial Number, or -1 for first
found (I32).
demo -Send 0 for normal operation, >0 for demo
mode (I32). Demo mode allows this function to
be called without a LabJack, and does little but
simulate execution time.
channel -Line to read. 0-3 for IO or 0-15 for D.
readD -If >0, a D line is read instead of an IO line.
Outputs: *idnum -Returns the Local ID or -1 if no LabJack is
found (I32).
*state -TRUE/Set if >0. FALSE/Clear if 0.
Time: 20 ms
----------------------------------------------------------------------
=cut
#// ###########################################################################
long
EDigitalIn(idnum, channel, readD)
long idnum
long channel
long readD
INIT:
long *i, *j, *k;
long errcode;
long state;
PPCODE:
errcode = EDigitalIn(&idnum, 0, channel, readD, &state);
// Return the results to perl in a big array
if(errcode) {
char errorString[51];
GetErrorString ( errcode, errorString );
XPUSHs(sv_2mortal(newSVpv(errorString,0)));
} else {
XPUSHs(sv_2mortal(newSVnv(errcode)));
}
XPUSHs(sv_2mortal(newSVnv(idnum))); // idnum
XPUSHs(sv_2mortal(newSVnv(state))); // state
#// ###########################################################################
=head
//======================================================================
// EDigitalOut: Easy function writes 1 digital output. Also configures
// the requested pin to output and leaves it that way.
//
// Note that this is a simplified version of the lower
// level function DigitalIO, which operates on all 20
// digital lines. The DLL keeps track of the current
// direction and output state of all lines, so that this
// easy function can operate on a single line without
// changing the others. When the DLL is first loaded,
// though, it does not know the direction and state of
// the lines and assumes all directions are input and
// output states are low.
//
// Returns: LabJack errorcodes or 0 for no error (I32).
// Inputs: *idnum -Local ID, Serial Number, or -1 for first
// found (I32).
// demo -Send 0 for normal operation, >0 for demo
// mode (I32). Demo mode allows this function to
// be called without a LabJack, and does little but
// simulate execution time.
// channel -Line to write. 0-3 for IO or 0-15 for D.
// writeD -If >0, a D line is written instead of an IO line.
// state -TRUE/Set if >0. FALSE/Clear if 0.
// Outputs: *idnum -Returns the Local ID or -1 if no LabJack is
// found (I32).
//
// Time: 20 ms
//----------------------------------------------------------------------
long _stdcall EDigitalOut(long *idnum,
long demo,
long channel,
long writeD,
long state);
=head
//======================================================================
// AIStreamClear: This function stops the continuous acquisition. It
// should be called after AIStreamStart and after any
// calls to AIStreamRead.
//
// Returns: LabJack errorcodes or 0 for no error (I32).
// Inputs: localID -Send the local ID from AIStreamStart/Read (I32).
// Outputs: none
//----------------------------------------------------------------------
long _stdcall AIStreamClear(long localID);
=cut
#// ###########################################################################
#// ###########################################################################
#// BitsToVolts
=head BitsToVolts
SYNOPSIS
INFO
BitsToVolts: Converts a 12-bit (0-4095) binary value into a LabJack
voltage. Volts=((2*Bits*Vmax/4096)-Vmax)/Gain where
Vmax=10 for SE, 20 for Diff.
Declaration:
long _stdcall BitsToVolts (long chnum,
long chgain,
long bits,
float *volts);
Paramter description
Returns: LabJack errorcodes or 0 for no error (I32).
Inputs: chnum -Channel index. 0-7=SE, 8-11=Diff (I32).
chgain -Gain index. 0=1,1=2,...,7=20 (I32).
bits -Binary value from 0-4095 (I32).
Outputs: *volts -Voltage. SE=+/-10, Diff=+/-20 (SGL).
=cut
#// ###########################################################################
float
BitsToVolts(chnum, chgain, bits)
long chnum
long chgain
long bits
INIT:
long errcode;
float volts;
PPCODE:
errcode = BitsToVolts(chnum, chgain, bits, &volts);
// Return the results to perl in a big array
if(errcode) {
char errorString[51];
GetErrorString ( errcode, errorString );
XPUSHs(sv_2mortal(newSVpv(errorString,0)));
} else {
XPUSHs(sv_2mortal(newSVnv(errcode)));
}
XPUSHs(sv_2mortal(newSVnv(volts)));
#// ###########################################################################
#// VoltsToBits
=head VoltsToBits
SYNOPSIS
INFO
Declaration:
Paramter description
=cut
#// ###########################################################################
int
VoltsToBits(chnum, chgain, volts)
long chnum
long chgain
float volts
INIT:
long errcode;
long bits;
PPCODE:
errcode = VoltsToBits(chnum, chgain, volts, &bits);
// Return the results to perl in a big array
if(errcode) {
char errorString[51];
GetErrorString ( errcode, errorString );
XPUSHs(sv_2mortal(newSVpv(errorString,0)));
} else {
XPUSHs(sv_2mortal(newSVnv(errcode)));
}
XPUSHs(sv_2mortal(newSVnv(bits)));
#// ###########################################################################
#// Counter
=head Counter
SYNOPSIS
INFO
Counter: Controls and reads the counter. The counter is disabled if
the watchdog timer is enabled.
Declaration:
long _stdcall Counter(long *idnum,
long demo,
long *stateD,
long *stateIO,
long resetCounter,
long enableSTB,
unsigned long *count);
Paramter description
Returns:LabJack errorcodes or 0 for no error (I32).
Inputs: *idnum -Local ID, Serial Number, or -1 for first
found (I32).
demo -Send 0 for normal operation, >0 for demo
mode (I32). Demo mode allows this function to
be called without a LabJack, and does little but
simulate execution time.
resetCounter -If >0, the counter is reset to zero after
being read (I32).
enableSTB -If >0, STB is enabled (I32). Only works with
firmware V1.02 or later.
Outputs:*idnum -Returns the Local ID or -1 if no LabJack is
found (I32).
*stateD -States of D0-D15 (I32).
*stateIO -States of IO0-IO3 (I32).
*count -Current count, before reset (U32).
=cut
#
int
Counter(idnum, demo, stateD, stateIO, resetCounter, enableSTB, count)
long idnum
long demo
long stateD
long stateIO
long resetCounter
long enableSTB
unsigned long count
INIT:
// long *j, *k, x;
long errcode;
// int nstateD;
// unsigned long *mycount;
// Check that they passed an array of channels, and count the elements
PPCODE:
// Run the command
errcode = Counter(&idnum, demo, &stateD, &stateIO, resetCounter, enableSTB, &enableSTB);
// Return the results to perl in a big array
if(errcode) {
char errorString[51];
GetErrorString ( errcode, errorString );
XPUSHs(sv_2mortal(newSVpv(errorString,0)));
} else {
XPUSHs(sv_2mortal(newSVnv(errcode)));
}
XPUSHs(sv_2mortal(newSVnv(idnum)));
XPUSHs(sv_2mortal(newSVnv(stateD)));
XPUSHs(sv_2mortal(newSVnv(stateIO)));
XPUSHs(sv_2mortal(newSVnv(count)));
#// ###########################################################################
=head
//======================================================================
// DigitalIO: Reads and writes to the digital I/O.
//
// Returns: LabJack errorcodes or 0 for no error (I32).
// Inputs: *idnum -Local ID, Serial Number, or -1 for first
// found (I32).
// demo -Send 0 for normal operation, >0 for demo
// mode (I32). Demo mode allows this function to
// be called without a LabJack, and does little but
// simulate execution time.
// *trisD -Directions for D0-D15. 0=Input, 1=Output (I32).
// trisIO -Directions for IO0-IO3. 0=Input, 1=Output (I32).
// *stateD -Output states for D0-D15 (I32).
// *stateIO -Output states for IO0-IO3 (I32).
// updateDigital -If >0, tris and state values will be written.
// Otherwise, just a read is performed (I32).
// Outputs: *idnum -Returns the Local ID or -1 if no LabJack is
// found (I32).
// *trisD -Returns a read of the direction registers
// for D0-D15 (I32).
// *stateD -States of D0-D15 (I32).
// *stateIO -States of IO0-IO3 (I32).
// *outputD -Returns a read of the output registers
// for D0-D15 (I32).
//
// Time: 20 ms
//----------------------------------------------------------------------
long _stdcall DigitalIO(long *idnum,
long demo,
long *trisD,
long trisIO,
long *stateD,
long *stateIO,
long updateDigital,
long *outputD);
=cut
#// ###########################################################################
long
DigitalIO(idnum, demo, trisD, trisIO, stateD, stateIO, updateDigital)
long idnum
long demo
long trisD
long trisIO
long stateD
long stateIO
long updateDigital
INIT:
long *i, *j, *k, *l, *m;
long errcode;
long outputD;
i = &idnum;
j = &trisD;
k = &stateD;
l = &stateIO;
m = &outputD;
PPCODE:
errcode = DigitalIO(i, demo, j, trisIO, k, l, updateDigital, m);
// Return the results to perl in a big array
if(errcode) {
char errorString[51];
GetErrorString ( errcode, errorString );
XPUSHs(sv_2mortal(newSVpv(errorString,0)));
} else {
XPUSHs(sv_2mortal(newSVnv(errcode)));
}
XPUSHs(sv_2mortal(newSVnv(idnum)));
XPUSHs(sv_2mortal(newSVnv(trisD)));
XPUSHs(sv_2mortal(newSVnv(stateD)));
XPUSHs(sv_2mortal(newSVnv(stateIO)));
XPUSHs(sv_2mortal(newSVnv(outputD)));
#// ###########################################################################
=head
//======================================================================
//GetDriverVersion
//
// Returns: Version number of this DLL (SGL).
// Inputs: none
// Outputs: none
//----------------------------------------------------------------------
float _stdcall GetDriverVersion(void);
=cut
#// ###########################################################################
float
GetDriverVersion()
CODE:
RETVAL = GetDriverVersion();
OUTPUT:
RETVAL
#// ###########################################################################
=head
//======================================================================
//GetErrorString
//
// Returns: nothing
// Inputs: errorcode -LabJack errorcode (I32)
// *errorString -Must point to an array of at least 50
// chars (I8).
// Outputs: *errorString -A sequence a characters describing the error
// will be copied into the char (I8) array.
//----------------------------------------------------------------------
void _stdcall GetErrorString (long errorcode,
char *errorString);
=cut
#// ###########################################################################
void
GetErrorString(errn);
long errn
INIT:
char str[255];
PPCODE:
GetErrorString ( errn, str );
XPUSHs(sv_2mortal(newSVpv(str,0)));
#// ###########################################################################
=head
//======================================================================
//GetWinVersion: Uses a Windows API function to get the OS version.
//
// Returns: LabJack errorcodes or 0 for no error (I32).
// Inputs: none
//
// Outputs: (U32)
// Platform Major Minor Build
// Windows 3.1 0 - - -
// Windows 95 1 4 0 950
// Windows 95 OSR2 1 4 0 1111
// Windows 98 1 4 10 1998
// Windows 98SE 1 4 10 2222
// Windows Me 1 4 90 3000
// Windows NT 3.51 2 3 51 -
// Windows NT 4.0 2 4 0 1381
// Windows 2000 2 5 0 2195
// Whistler 2 5 1 -
//----------------------------------------------------------------------
long _stdcall GetWinVersion(unsigned long *majorVersion,
unsigned long *minorVersion,
unsigned long *buildNumber,
unsigned long *platformID,
unsigned long *servicePackMajor,
unsigned long *servicePackMinor);
=cut
#// ###########################################################################
long
GetWinVersion()
INIT:
unsigned long maj, min, build, platform, Packmaj, Packmin;
long errcode;
PPCODE:
errcode = GetWinVersion(&maj, &min, &build, &platform, &Packmaj, &Packmin);
// Return the results to perl in a big array
if(errcode) {
char errorString[51];
GetErrorString ( errcode, errorString );
XPUSHs(sv_2mortal(newSVpv(errorString,0)));
XPUSHs(sv_2mortal(newSVnv(errcode)));
} else {
XPUSHs(sv_2mortal(newSVnv(errcode)));
}
XPUSHs(sv_2mortal(newSVnv(maj)));
XPUSHs(sv_2mortal(newSVnv(min)));
XPUSHs(sv_2mortal(newSVnv(build)));
XPUSHs(sv_2mortal(newSVnv(platform)));
XPUSHs(sv_2mortal(newSVnv(Packmaj)));
XPUSHs(sv_2mortal(newSVnv(Packmin)));
#// ###########################################################################
=head
//======================================================================
// ListAll: Searches the USB for all LabJacks.
//
// Returns: LabJack errorcodes or 0 for no error (I32).
// Inputs: *productIDList -Send a 127 element array of zeros (I32).
// *serialnumList -Send a 127 element array of zeros (I32).
// *localIDList -Send a 127 element array of zeros (I32).
// *powerList -Send a 127 element array of zeros (I32).
// *calMatrix -Send a 127 by 20 element array of
// zeros (I32).
// Outputs: *productIDList -Returns the product ID for each LabJack on
// the USB (I32). Unused elements filled
// with 9999s.
// *serialnumList -Returns the serial number for each LabJack
// on the USB (I32). Unused elements filled
// with 9999s.
// *localIDList -Returns the local ID for each LabJack on
// the USB (I32). Unused elements filled
// with 9999s.
// *powerList -Returns the power allowance for each LabJack
// on the USB (I32). Unused elements filled
// with 9999s.
// *calMatrix -Returns the cal constants for each LabJack
// on the USB (I32). Unused elements filled
// with 9999s.
// *numberFound -Number of LabJacks found on the USB (I32).
// *fcddMaxSize -Max size of fcdd (I32).
// *hvcMaxSize -Max size of hvc (I32).
//----------------------------------------------------------------------
long _stdcall ListAll(long *productIDList,
long *serialnumList,
long *localIDList,
//
// Returns: LabJack errorcodes or 0 for no error (I32).
// Inputs: *idnum -Local ID, Serial Number, or -1 for first
// found (I32).
// demo -Send 0 for normal operation, >0 for demo
// mode (I32). Demo mode allows this function to
// be called without a LabJack, and does little but
// simulate execution time.
// mode -Specify SPI mode as: 0=A,1=B,2=C,3=D (I32, 0-3).
// msDelay -If >0, a 1 ms delay is added between each bit.
// husDelay -If >0, a hundred us delay is added between each bit.
// controlCS -If >0, D0-D7 is automatically controlled as CS. The
// state and direction of CS is only tested if control
// is enabled.
// csLine -D line to use as CS if enabled (I32, 0-7).
// csState -Active state for CS line. This would be 0 for the
// normal !CS, or >0 for the less common CS.
// configD -If >0, state and tris are configured for D13, D14,
// D15, and !CS.
// numWriteRead -Number of bytes to write and read (I32, 1-18).
// *data -Serial data buffer. Send an 18 element
// array of bytes. Fill unused locations with zeros (I32).
// Outputs: *idnum -Returns the Local ID or -1 if no LabJack is
// found (I32).
// *data -Serial data buffer. Returns any serial read
// data. Unused locations are filled
// with 9999s. (I32).
//
// Time: 20 ms to read & write up to 4 bytes, plus 40 ms for each
// additional 4 bytes to read or write. Extra 20 ms if configIO
// is true. Extra time if delays are enabled.
//----------------------------------------------------------------------
long _stdcall Synch( long *idnum,
long demo,
long mode,
long msDelay,
long husDelay,
long controlCS,
long csLine,
long csState,
long configD,
long numWriteRead,
long *data);
=cut
#// ###########################################################################
long
Synch(idnum, demo, mode, msDelay, husDelay, controlCS, csLine, csState, configD, numWriteRead, data)
long idnum
long demo
long mode
long msDelay
long husDelay
long controlCS
long csLine
long csState
long configD
long numWriteRead
long data
INIT:
long i, errcode;
PPCODE:
errcode = Synch(&idnum, demo, mode, msDelay, husDelay, controlCS, csLine, csState, configD, numWriteRead, &data);
// Return the results to perl in a big array
if(errcode) {
char errorString[51];
GetErrorString ( errcode, errorString );
XPUSHs(sv_2mortal(newSVpv(errorString,0)));
XPUSHs(sv_2mortal(newSVnv(errcode)));
} else {
XPUSHs(sv_2mortal(newSVnv(errcode)));
}
XPUSHs(sv_2mortal(newSVnv(idnum)));
// This still needs lots of work!
XSRETURN_PVN((long *) &data, (sizeof(long) * numWriteRead));
#// ###########################################################################
=head
//======================================================================
// Watchdog: Controls the LabJack watchdog function.
//
// Returns: LabJack errorcodes or 0 for no error (I32).
// Inputs: *idnum -Local ID, Serial Number, or -1 for first
// found (I32).
// demo -Send 0 for normal operation, >0 for demo
// mode (I32). Demo mode allows this function to
// be called without a LabJack, and does little but
// simulate execution time.
// active -Enables the LabJack watchdog function. If
// enabled, the 32-bit counter is disabled.
// timeout -Timer reset value in seconds (I32).
// reset -If >0, the LabJack will reset on timeout (I32).
// activeDn -If >0, Dn will be set to stateDn upon
// timeout (I32).
// stateDn -Timeout state of Dn, 0=low, >0=high (I32).
// Outputs: *idnum -Returns the Local ID or -1 if no LabJack is
// found (I32).
//
// Time: 20 ms
//----------------------------------------------------------------------
long _stdcall Watchdog(long *idnum,
long demo,
long active,
long timeout,
long reset,
long activeD0,
long activeD1,
long activeD8,
long stateD0,
long stateD1,
long stateD8);
=cut
#// ###########################################################################
long
Watchdog(idnum, demo, active, timeout, reset, activeD0, activeD1, activeD8, stateD0, stateD1, stateD8)
long idnum
long demo
long active
long timeout
long reset
long activeD0
long activeD1
long activeD8
long stateD0
long stateD1
long stateD8
CODE:
RETVAL = Watchdog(&idnum, demo, active, timeout, reset, activeD0, activeD1, activeD8, stateD0, stateD1, stateD8);
OUTPUT:
RETVAL
idnum
#// ###########################################################################
=head
//======================================================================
// ReadMem: Reads 4 bytes from a specified address in the LabJack's
// nonvolatile memory.
//
// Returns: LabJack errorcodes or 0 for no error (I32).
// Inputs: *idnum -Local ID, Serial Number, or -1 for first
// found (I32).
// address -Starting address of data to read
// from 0-8188 (I32).
// Outputs: *idnum -Returns the Local ID or -1 if no LabJack is
// found (I32).
// *data3 -Byte at address (I32).
// *data2 -Byte at address+1 (I32).
// *data1 -Byte at address+2 (I32).
// *data0 -Byte at address+3 (I32).
//
// Time: 20 ms
//----------------------------------------------------------------------
long _stdcall ReadMem(long *idnum,
long address,
long *data3,
long *data2,
long *data1,
long *data0);
=cut
#// ###########################################################################
long
ReadMem(idnum,address)
long idnum
long address
INIT:
long errcode;
long d0, d1, d2, d3;
PPCODE:
errcode = ReadMem(&idnum, address, &d3, &d2, &d1, &d0);
// Return the results to perl in a big array
if(errcode) {
char errorString[51];
GetErrorString ( errcode, errorString );
XPUSHs(sv_2mortal(newSVpv(errorString,0)));
XPUSHs(sv_2mortal(newSVnv(errcode)));
} else {
XPUSHs(sv_2mortal(newSVnv(errcode)));
}
XPUSHs(sv_2mortal(newSVnv(idnum)));
XPUSHs(sv_2mortal(newSVnv(d0)));
XPUSHs(sv_2mortal(newSVnv(d1)));
XPUSHs(sv_2mortal(newSVnv(d2)));
XPUSHs(sv_2mortal(newSVnv(d3)));
#// ###########################################################################
=head
//======================================================================
// WriteMem: Writes 4 bytes to the LabJack's nonvolatile memory at a
// specified address. The data is read back and verified
// after the write. Memory 0-511 is used for configuration
// and calibration data. Memory from 512-1023 is unused by the
// the LabJack and available for the user (this corresponds to
// starting addresses from 512-1020). Memory 1024-8191 is
// used as a data buffer in hardware timed AI modes.
//
// Returns: LabJack errorcodes or 0 for no error (I32).
// Inputs: *idnum -Local ID, Serial Number, or -1 for first
// found (I32).
// unlocked -If >0, addresses 0-511 are unlocked for
// writing (I32).
// address -Starting address for writing 0-8188 (I32).
// data3 -Byte for address (I32).
// data2 -Byte for address+1 (I32).
// data1 -Byte for address+2 (I32).
// data0 -Byte for address+3 (I32).
// Outputs: *idnum -Returns the Local ID or -1 if no LabJack is
// found (I32).
//
// Time: 20 ms
//----------------------------------------------------------------------
long _stdcall WriteMem(long *idnum,
long unlocked,
long address,
long data3,
long data2,
long data1,
long data0);
=cut
#// ###########################################################################
long
WriteMem(idnum,unlocked,address,data3,data2,data1,data0)
long idnum
long unlocked
long address
long data3
long data2
( run in 2.117 seconds using v1.01-cache-2.11-cpan-71847e10f99 )