gov.nasa.gsfc.irc.library.ports.connections.ni.daq
Class NiDaq

java.lang.Object
  extended by gov.nasa.gsfc.irc.library.ports.connections.ni.daq.NiDaq

public class NiDaq
extends Object

NiDaq is a Java interface to a subset of the National Instruments NI-DAQ driver. NI-DAQ is a set of functions that control all of the National Instruments plug-in DAQ devices for analog I/O, digital I/O, timing I/O, SCXI signal conditioning, and RTSI multiboard synchronization. Refer to the documents: NI-DAQ User Manual and NI-DAQ Function Reference Manual available from National Instruments.

You must call one of the loadLibrary methods before using any of the NI-DAQ methods.

This code was developed for NASA, Goddard Space Flight Center, Code 580 for the Instrument Remote Control (IRC) project.

Version:
$Date: 2005/11/14 05:40:21 $
Author:
T. Ames

Field Summary
static String sNiDaqLibrary
          Name of the NI-DAG Java Native Interface library.
 
Method Summary
static long digBlockCheck(short deviceNumber, short group)
          Returns the number of items remaining to be transferred after a DIG_Block_In or DIG_Block_Out call.
static void digBlockClear(short deviceNumber, short group)
          Halts any ongoing asynchronous transfer, allowing another transfer to be initiated.
static void digBlockIn(short deviceNumber, short group, Buffer buffer, long offset, long count)
          Initiates an asynchronous data transfer from the specified group to memory.
static void digBlockIn(short deviceNumber, short group, byte[] buffer, long offset, long count)
          Initiates an asynchronous data transfer from the specified group to memory.
static void digBlockOut(short deviceNumber, short group, Buffer buffer, long offset, long count)
          Initiates an asynchronous transfer of data from memory to the specified group.
static void digBlockOut(short deviceNumber, short group, byte[] buffer, long offset, long count)
          Initiates an asynchronous transfer of data from memory to the specified group.
static void digGroupConfig(short deviceNumber, short group, short groupSize, short port, short direction)
          Configures the specified group for port assignment, direction (input or output), and size.
static void digGroupMode(short deviceNumber, short group, short protocol, short edge, short reqpol, short ackpol, short delayTime)
          Configures the specified group for handshake signal modes.
static short digInGrp(short deviceNumber, short group)
          Reads digital input data from the specified digital group.
static short digInLine(short deviceNumber, short port, short line)
          Returns the digital logic state of the specified digital line in the specified port.
static int digInPrt(short deviceNumber, short port)
          Returns digital input data from the specified digital I/O port.
static void digOutGroup(short deviceNumber, short group, short groupPattern)
          Writes digital output data to the specified digital group on the specified device.
static void digOutLine(short deviceNumber, short port, short line, short state)
          Sets or clears the specified digital output line in the specified digital port.
static void digOutPrt(short deviceNumber, short port, short pattern)
          Writes digital output data to the specified digital port.
static void digPrtConfig(short deviceNumber, short port, short mode, short dir)
          Configures the specified port for direction (input or output) and output type (standard or wired-OR).
static short initDaBoards(short deviceNumber)
          Initializes the hardware and software states of a National Instruments DAQ device to its default state, and then returns a numeric device code that corresponds to the type of device initialized.
static void loadLibrary()
          Loads the NI-DAG Java Native Interface library specified by the sNiDaqLibrary field.
static void loadLibrary(String libname)
          Loads the NI-DAG Java Native Interface library specified by the libname argument.
static void main(String[] args)
          Main method for testing.
static void setDaqDeviceInfo(short deviceNumber, int infoType, int infoValue)
          Selects parameters pertaining to the device operation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sNiDaqLibrary

public static String sNiDaqLibrary
Name of the NI-DAG Java Native Interface library. This library is loaded with the loadLibrary method. The default is "NiDaqAdapter".

Method Detail

loadLibrary

public static void loadLibrary()
Loads the NI-DAG Java Native Interface library specified by the sNiDaqLibrary field. The manner in which a library name is mapped to the actual library is system dependent.

Throws:
SecurityException - if a security manager exists and its checkLink method doesn't allow loading of the specified dynamic library
UnsatisfiedLinkError - if the library does not exist.
See Also:
loadLibrary(java.lang.String), SecurityManager.checkLink(java.lang.String)

loadLibrary

public static void loadLibrary(String libname)
                        throws UnsatisfiedLinkError
Loads the NI-DAG Java Native Interface library specified by the libname argument. The manner in which a library name is mapped to the actual library is system dependent.

Uses the System.loadLibrary(name) method call.

Parameters:
libname - the name of the library.
Throws:
SecurityException - if a security manager exists and its checkLink method doesn't allow loading of the specified dynamic library
UnsatisfiedLinkError - if the library does not exist.
See Also:
System.loadLibrary(java.lang.String), SecurityManager.checkLink(java.lang.String)

digBlockCheck

public static long digBlockCheck(short deviceNumber,
                                 short group)
                          throws NiDaqException
Returns the number of items remaining to be transferred after a DIG_Block_In or DIG_Block_Out call. Refer to the DIG_Block_Check function in the NI-DAQ Function Reference Manual.

Parameters:
deviceNumber - number assigned by configuration utility
group - the group to be configured
Returns:
number of items yet to be transferred
Throws:
NiDaqException - If a NI DAQ error occurred.

digBlockClear

public static void digBlockClear(short deviceNumber,
                                 short group)
                          throws NiDaqException
Halts any ongoing asynchronous transfer, allowing another transfer to be initiated. Refer to the DIG_Block_Clear function in the NI-DAQ Function Reference Manual.

Parameters:
deviceNumber - number assigned by configuration utility
group - the group involved in the asynchronous transfer
Throws:
NiDaqException - If a NI DAQ error occurred.

digBlockIn

public static void digBlockIn(short deviceNumber,
                              short group,
                              byte[] buffer,
                              long offset,
                              long count)
                       throws NiDaqException
Initiates an asynchronous data transfer from the specified group to memory. The parameter count is the number of items (for example, 8-bit items for a group of size 1, 16-bit items for a group of size 2, and 32-bit items for a group of size 4) to be transferred to the area of memory specified by buffer from the group indicated by group. Refer to the DIG_Block_In function in the NI-DAQ Function Reference Manual.

Parameters:
deviceNumber - number assigned by configuration utility
group - the group to be read from
buffer - conversion samples returned
offset - index at which to start storing items.
count - number of items to be transferred
Throws:
NiDaqException - If a NI DAQ error occurred.

digBlockIn

public static void digBlockIn(short deviceNumber,
                              short group,
                              Buffer buffer,
                              long offset,
                              long count)
                       throws NiDaqException
Initiates an asynchronous data transfer from the specified group to memory. The parameter count is the number of items (for example, 8-bit items for a group of size 1, 16-bit items for a group of size 2, and 32-bit items for a group of size 4) to be transferred to the area of memory specified by buffer from the group indicated by group. Refer to the DIG_Block_In function in the NI-DAQ Function Reference Manual.

Parameters:
deviceNumber - number assigned by configuration utility
group - the group to be read from
buffer - conversion samples returned
offset - index at which to start storing items.
count - number of items to be transferred
Throws:
NiDaqException - If a NI DAQ error occurred.

digBlockOut

public static void digBlockOut(short deviceNumber,
                               short group,
                               byte[] buffer,
                               long offset,
                               long count)
                        throws NiDaqException
Initiates an asynchronous transfer of data from memory to the specified group. The parameter count is the number of items (for example, 8-bit items for a group of size 1, 16-bit items for a group of size 2, and 32-bit items for a group of size 4) to be transferred from the area of memory specified by buffer to the group indicated by group. Refer to the DIG_Block_In function in the NI-DAQ Function Reference Manual.

Parameters:
deviceNumber - number assigned by configuration utility
group - the group to be written to
buffer - array containing the user’s data
offset - index where items to be transferred starts.
count - number of items to be transferred
Throws:
NiDaqException - If a NI DAQ error occurred.

digBlockOut

public static void digBlockOut(short deviceNumber,
                               short group,
                               Buffer buffer,
                               long offset,
                               long count)
                        throws NiDaqException
Initiates an asynchronous transfer of data from memory to the specified group. The parameter count is the number of items (for example, 8-bit items for a group of size 1, 16-bit items for a group of size 2, and 32-bit items for a group of size 4) to be transferred from the area of memory specified by buffer to the group indicated by group. Refer to the DIG_Block_In function in the NI-DAQ Function Reference Manual.

Parameters:
deviceNumber - number assigned by configuration utility
group - the group to be written to
buffer - array containing the user’s data
offset - index where items to be transferred starts.
count - number of items to be transferred
Throws:
NiDaqException - If a NI DAQ error occurred.

digGroupConfig

public static void digGroupConfig(short deviceNumber,
                                  short group,
                                  short groupSize,
                                  short port,
                                  short direction)
                           throws NiDaqException
Configures the specified group for port assignment, direction (input or output), and size. Refer to the DIG_Grp_Config function in the NI-DAQ Function Reference Manual.

Parameters:
deviceNumber - number assigned by configuration utility
group - the group to be configured
groupSize - size of the group
port - digital I/O port assigned to the group
direction - input or output
Throws:
NiDaqException - If a NI DAQ error occurred.

digGroupMode

public static void digGroupMode(short deviceNumber,
                                short group,
                                short protocol,
                                short edge,
                                short reqpol,
                                short ackpol,
                                short delayTime)
                         throws NiDaqException
Configures the specified group for handshake signal modes. Refer to the DIG_Grp_Mode function in the NI-DAQ Function Reference Manual.

Parameters:
deviceNumber - number assigned by configuration utility
group - the group to be configured
protocol - basic handshaking system
edge - rising-edge or falling-edge pulsed signals
reqpol - request signal is to be active high or active low
ackpol - acknowledge handshake signal is to be active high or active low
delayTime - data settling time allowed
Throws:
NiDaqException - If a NI DAQ error occurred.

digInLine

public static short digInLine(short deviceNumber,
                              short port,
                              short line)
                       throws NiDaqException
Returns the digital logic state of the specified digital line in the specified port. Refer to the DIG_In_Line function in the NI-DAQ Function Reference Manual.

Parameters:
deviceNumber - number assigned by configuration utility
port - the digital I/O port number
line - the digital line to be read
Returns:
the digital logic state low (0) or high (1).
Throws:
NiDaqException - If a NI DAQ error occurred.

digInPrt

public static int digInPrt(short deviceNumber,
                           short port)
                    throws NiDaqException
Returns digital input data from the specified digital I/O port. Refer to the DIG_In_Prt function in the NI-DAQ Function Reference Manual.

Parameters:
deviceNumber - number assigned by configuration utility
port - the digital I/O port number
Returns:
8-bit digital data read from the specified port.
Throws:
NiDaqException - If a NI DAQ error occurred.

digInGrp

public static short digInGrp(short deviceNumber,
                             short group)
                      throws NiDaqException
Reads digital input data from the specified digital group. Refer to the DIG_In_Grp function in the NI-DAQ Function Reference Manual.

Parameters:
deviceNumber - number assigned by configuration utility
group - group to read from
Returns:
digital data read from the ports.
Throws:
NiDaqException - If a NI DAQ error occurred.

digPrtConfig

public static void digPrtConfig(short deviceNumber,
                                short port,
                                short mode,
                                short dir)
                         throws NiDaqException
Configures the specified port for direction (input or output) and output type (standard or wired-OR). Refer to the DIG_Prt_Config function in the NI-DAQ Function Reference Manual.

Parameters:
deviceNumber - number assigned by configuration utility
port - digital I/O port number of the port to write to
mode - handshake mode the port uses
dir - direction, input, or output
Throws:
NiDaqException - If a NI DAQ error occurred.

digOutGroup

public static void digOutGroup(short deviceNumber,
                               short group,
                               short groupPattern)
                        throws NiDaqException
Writes digital output data to the specified digital group on the specified device. Refer to the DIG_Out_Grp function in the NI-DAQ Function Reference Manual.

Parameters:
deviceNumber - number assigned by configuration utility
group - group to write to
groupPattern - digital data to be written
Throws:
NiDaqException - If a NI DAQ error occurred.

digOutLine

public static void digOutLine(short deviceNumber,
                              short port,
                              short line,
                              short state)
                       throws NiDaqException
Sets or clears the specified digital output line in the specified digital port. Refer to the DIG_Out_Line function in the NI-DAQ Function Reference Manual.

Parameters:
deviceNumber - number assigned by configuration utility
port - digital I/O port number
line - digital output line
state - new digital logic state
Throws:
NiDaqException - If a NI DAQ error occurred.

digOutPrt

public static void digOutPrt(short deviceNumber,
                             short port,
                             short pattern)
                      throws NiDaqException
Writes digital output data to the specified digital port. Refer to the DIG_Out_Prt function in the NI-DAQ Function Reference Manual.

Parameters:
deviceNumber - number assigned by configuration utility
port - digital I/O port number of the port to write to
pattern - 8-bit digital pattern for the data written
Throws:
NiDaqException - If a NI DAQ error occurred.

initDaBoards

public static short initDaBoards(short deviceNumber)
                          throws NiDaqException
Initializes the hardware and software states of a National Instruments DAQ device to its default state, and then returns a numeric device code that corresponds to the type of device initialized. Any operation that the device is performing is halted. Refer to the Init_DA_Brds function in the NI-DAQ Function Reference Manual.

Parameters:
deviceNumber - number assigned by configuration utility
Returns:
the type of device initialized
Throws:
NiDaqException - If a NI DAQ error occurred.

setDaqDeviceInfo

public static void setDaqDeviceInfo(short deviceNumber,
                                    int infoType,
                                    int infoValue)
                             throws NiDaqException
Selects parameters pertaining to the device operation. Refer to the set_DAQ_Device_Info function in the NI-DAQ Function Reference Manual.

Parameters:
deviceNumber - number assigned by configuration utility
infoType - parameter you want to modify
infoValue - new value you want to assign to the parameter specified by infoType
Throws:
NiDaqException - If a NI DAQ error occurred.

main

public static void main(String[] args)
Main method for testing.