Class JniAdeptDepp
- java.lang.Object
-
- cbsw.adept.JniAdeptDepp
-
- All Implemented Interfaces:
RegisterIo
public class JniAdeptDepp extends java.lang.Object implements RegisterIo
This class encapsulates and extends the Digilent Adept2 APIs through Jni calls.
Most target hardware now uses the Depp2 protocol in which the transaction buffer contains 4 header bytes. The first two bytes contain the payload length (that is, excluding the header bytes) and the second two bytes contain the register start offset. The byte order for the header bytes is little-endian.
Note that the hardware treats the MSB of the register start offset as a flag to activate the DEPP wait feature. Therefore the highest allowed offset is 0x7fff. The wait feature allows a subsequent transaction to be started immediately after the previous call returns and it will block until the previous transaction completes. This avoids the need for polling in many situations if the feature has been implemented in the hardware.
Most of the methods described here that read or write the hardware implement a locking mechanism to grant exclusive access to the hardware device. This only applies for calls from within the same program.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JniAdeptDepp.depp
Native interface wrappers to Digilent Adept DEPP API.class
JniAdeptDepp.DeppException
A DEPP exception that encapsulates the DEPP error codes/messages.class
JniAdeptDepp.djtg
static class
JniAdeptDepp.Djtg
Native interface wrappers to Digilent Adept DJTG API.static class
JniAdeptDepp.dmgr
Native interface wrappers to Digilent Adept DMGR API.
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.awt.event.ActionListener
enumerateAL
Deprecated.(package private) static java.awt.event.ActionListener
importHWAL
Deprecated.JniAdeptDepp.djtg
jtg
(package private) java.awt.event.ActionListener
timerAL
-
Constructor Summary
Constructors Constructor Description JniAdeptDepp(java.lang.String dev)
ConstructorJniAdeptDepp(java.lang.String dev, java.awt.event.ActionListener al)
Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
addMenuItems(javax.swing.JMenu menu)
A convenience function to add some standard menu items to a menu.void
close()
Closes a devicevoid
connect()
Starts a timer that periodically tries to connect to a device until it succeeds.void
disable()
Disables the DEPP protocol for the devicevoid
disconnect()
Stops a timer that periodically tries to connect to a devicevoid
enable()
Enables the DEPP protocol for the devicevoid
get(byte[] addr, byte[] data)
Gets multiple bytesvoid
get(byte addr, byte[] buf)
Gets single bytevoid
get(int base, byte[] regs)
Reads consecutive bytes from hardware (Depp2).void
get(int base, int addr, byte[] regs)
Reads consecutive bytes from hardware (Depp2).byte[]
getByteArray(int size)
Deprecated.byte[]
getByteArray(int size, int off)
Deprecated.void
getBytes(int base, int addr, byte[] regs)
Reads consecutive bytes from legacy hardware.static java.util.prefs.Preferences
getDevicePreferences(java.lang.Class cl, java.lang.String node)
Deprecated.static void
importHardware(java.lang.String url)
Deprecated.void
lock()
Grants exclusive access to DEPP interface.static javax.swing.JComboBox<java.lang.String>
makeDeviceComboBox(java.lang.String selectedName, java.awt.event.ActionListener aL, java.lang.String filter)
Deprecated.static javax.swing.JMenu
makeDeviceMenu(java.lang.String title, java.awt.event.ActionListener aL)
Deprecated.boolean
OK()
Deprecated.void
open()
Opens a devicevoid
pop(byte base, byte[] buf)
Deprecated.void
push(byte base, byte[] buf)
Deprecated.void
push(int base, int len, int addr, byte[] buf, boolean waitFlag)
Deprecated.void
put(byte[] buf)
Puts multiple addr,byte pairsvoid
put(byte base, byte data)
Puts single addr,bytevoid
put(int base, int addr, byte[] regs)
Writes array of bytes to hardware (Depp2)<T extends java.lang.Byte,Integer,Short,Long>
voidput(int base, int addr, T val)
Writes a value to hardware in little-endian order (Depp2)void
put(int base, java.nio.ByteBuffer bb)
Writes byte buffer to hardware (Depp2)void
put1(int base, int addr, byte[] regs)
Writes array of bytes to legacy hardware.static java.lang.String[]
selectConnectedDevice()
Creates a dialog to allow the user to select a connected devicestatic java.lang.String
selectDevice(java.lang.String filter)
Deprecated.static void
showEnumeratedDevices()
Writes information about enumerated devices to System.outvoid
unlock()
Releases access to DEPP interface.
-
-
-
Field Detail
-
jtg
public JniAdeptDepp.djtg jtg
-
importHWAL
@Deprecated static java.awt.event.ActionListener importHWAL
Deprecated.Import database of known hardware from web database.
- See Also:
selectConnectedDevice()
-
enumerateAL
@Deprecated static java.awt.event.ActionListener enumerateAL
Deprecated.
-
timerAL
java.awt.event.ActionListener timerAL
-
-
Constructor Detail
-
JniAdeptDepp
public JniAdeptDepp(java.lang.String dev)
Constructor
- Parameters:
dev
- Connection name of device
-
JniAdeptDepp
public JniAdeptDepp(java.lang.String dev, java.awt.event.ActionListener al)
Constructor
- Parameters:
dev
- Connection name of deviceal
- ActionListener to replace default timer (can be null)
-
-
Method Detail
-
addMenuItems
public static void addMenuItems(javax.swing.JMenu menu)
A convenience function to add some standard menu items to a menu.
- Parameters:
menu
- The menu to which the items are added.
-
lock
public void lock()
Grants exclusive access to DEPP interface.
Blocks until interface is available.
-
unlock
public void unlock()
Releases access to DEPP interface.
-
OK
@Deprecated public boolean OK()
Deprecated.
-
showEnumeratedDevices
public static void showEnumeratedDevices()
Writes information about enumerated devices to System.out
-
connect
public void connect()
Starts a timer that periodically tries to connect to a device until it succeeds.
-
disconnect
public void disconnect()
Stops a timer that periodically tries to connect to a device
After stopping the timer, closes the device.
-
open
public void open() throws JniAdeptDepp.DeppException
Opens a device
- Throws:
JniAdeptDepp.DeppException
- DEPP exception
-
close
public void close()
Closes a device
- Specified by:
close
in interfaceRegisterIo
-
enable
public void enable()
Enables the DEPP protocol for the device
-
disable
public void disable()
Disables the DEPP protocol for the device
-
get
public void get(byte addr, byte[] buf) throws JniAdeptDepp.DeppException
Gets single byte
- Parameters:
addr
- The register addressbuf
- Array to receive the data- Throws:
JniAdeptDepp.DeppException
- DEPP exception
-
get
public void get(byte[] addr, byte[] data) throws JniAdeptDepp.DeppException
Gets multiple bytes
- Parameters:
addr
- Array of addresses to readdata
- Array to receive the data- Throws:
JniAdeptDepp.DeppException
- DEPP exception
-
put
public void put(byte base, byte data) throws JniAdeptDepp.DeppException
Puts single addr,byte
- Parameters:
base
- Address to writedata
- Data to write- Throws:
JniAdeptDepp.DeppException
- DEPP exception
-
put
public void put(byte[] buf) throws JniAdeptDepp.DeppException
Puts multiple addr,byte pairs
- Parameters:
buf
- Array of address/data pairs to write- Throws:
JniAdeptDepp.DeppException
- DEPP exception
-
put
public <T extends java.lang.Byte,Integer,Short,Long> void put(int base, int addr, T val) throws RegisterIoException
Writes a value to hardware in little-endian order (Depp2)
Consider using
put(int,java.nio.ByteBuffer)
instead.Integer, Short, Long and Byte values are allowed, others result in RuntimeException.
- Type Parameters:
T
- Type of value to write- Parameters:
base
- DEPP base addressaddr
- Register offsetval
- Value to write- Throws:
RegisterIoException
- RegisterIo exception
-
push
@Deprecated public void push(int base, int len, int addr, byte[] buf, boolean waitFlag) throws JniAdeptDepp.DeppException
Deprecated.Writes array of bytes to hardware (Depp2)
Use
put(int,java.nio.ByteBuffer)
instead.- Parameters:
base
- DEPP base addresslen
- Transaction lengthaddr
- Register start offsetbuf
- Values to writewaitFlag
- If true, activates the DEPP wait in hardware- Throws:
JniAdeptDepp.DeppException
- DEPP exception
-
push
@Deprecated public void push(byte base, byte[] buf) throws JniAdeptDepp.DeppException
Deprecated.Writes array of bytes to hardware
Use
put(int,java.nio.ByteBuffer)
instead.- Parameters:
base
- DEPP base addressbuf
- Values to write- Throws:
JniAdeptDepp.DeppException
- DEPP exception
-
pop
@Deprecated public void pop(byte base, byte[] buf) throws JniAdeptDepp.DeppException
Deprecated.Reads array of bytes from hardware
Use
get(int,byte[])
instead.- Parameters:
base
- DEPP base addressbuf
- Values to write- Throws:
JniAdeptDepp.DeppException
- DEPP exception
-
put1
public void put1(int base, int addr, byte[] regs) throws JniAdeptDepp.DeppException
Writes array of bytes to legacy hardware.
Avoid using this for new applications. May be required for some legacy hardware.
- Parameters:
base
- DEPP base addressaddr
- Register start offsetregs
- Values to write- Throws:
JniAdeptDepp.DeppException
- DEPP exception
-
put
public void put(int base, int addr, byte[] regs) throws RegisterIoException
Writes array of bytes to hardware (Depp2)
In contrast to
put(int,java.nio.ByteBuffer)
this method initialises the first four header bytes. The first two bytes are filled with the data payload length (regs.length-4) and the second two bytes are filled with the register start offset (addr). Any values in these locations in the array passed to this method will therefore be overwritten.- Specified by:
put
in interfaceRegisterIo
- Parameters:
base
- DEPP base addressaddr
- Register start offsetregs
- Write transaction buffer, payload starting at byte 4- Throws:
RegisterIoException
- Register I/O exception
-
put
public void put(int base, java.nio.ByteBuffer bb) throws RegisterIoException
Writes byte buffer to hardware (Depp2)
The buffer should contain the payload length (2 bytes, little-endian, excludes the 4 header bytes) followed by the register start offset (2 bytes, little-endian) followed by the data.
- Specified by:
put
in interfaceRegisterIo
- Parameters:
base
- DEPP base addressbb
- Write transaction buffer- Throws:
RegisterIoException
- Register I/O exception
-
getBytes
public void getBytes(int base, int addr, byte[] regs) throws JniAdeptDepp.DeppException
Reads consecutive bytes from legacy hardware.
Reads regs.length bytes.
- Parameters:
base
- DEPP base addressaddr
- Register start offsetregs
- Array to receive data- Throws:
JniAdeptDepp.DeppException
- DEPP exception
-
get
public void get(int base, int addr, byte[] regs) throws RegisterIoException
Reads consecutive bytes from hardware (Depp2).
Reads regs.length bytes.
- Specified by:
get
in interfaceRegisterIo
- Parameters:
base
- DEPP base addressaddr
- Register start offsetregs
- Array to receive data- Throws:
RegisterIoException
- Register I/O exception
-
get
public void get(int base, byte[] regs) throws RegisterIoException
Reads consecutive bytes from hardware (Depp2).
Reads regs.length bytes.
This version of get is intended to be called after the header has been sent.
- Specified by:
get
in interfaceRegisterIo
- Parameters:
base
- DEPP base addressregs
- Array to receive data- Throws:
RegisterIoException
- Register I/O exception
-
getByteArray
@Deprecated public byte[] getByteArray(int size)
Deprecated.
-
getByteArray
@Deprecated public byte[] getByteArray(int size, int off)
Deprecated.
-
importHardware
@Deprecated public static void importHardware(java.lang.String url)
Deprecated.Imports list of known hardware from web (legacy code)
- Parameters:
url
- The URL of the XML data
-
makeDeviceMenu
@Deprecated public static javax.swing.JMenu makeDeviceMenu(java.lang.String title, java.awt.event.ActionListener aL)
Deprecated.
-
selectDevice
@Deprecated public static java.lang.String selectDevice(java.lang.String filter)
Deprecated.
-
selectConnectedDevice
public static java.lang.String[] selectConnectedDevice()
Creates a dialog to allow the user to select a connected device
- Returns:
- Data describing selected device (or null if nothing selected)
-
makeDeviceComboBox
@Deprecated public static javax.swing.JComboBox<java.lang.String> makeDeviceComboBox(java.lang.String selectedName, java.awt.event.ActionListener aL, java.lang.String filter)
Deprecated.
-
getDevicePreferences
@Deprecated public static java.util.prefs.Preferences getDevicePreferences(java.lang.Class cl, java.lang.String node)
Deprecated.
-
-