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 classJniAdeptDepp.deppNative interface wrappers to Digilent Adept DEPP API.classJniAdeptDepp.DeppExceptionA DEPP exception that encapsulates the DEPP error codes/messages.classJniAdeptDepp.djtgstatic classJniAdeptDepp.DjtgNative interface wrappers to Digilent Adept DJTG API.static classJniAdeptDepp.dmgrNative interface wrappers to Digilent Adept DMGR API.
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.awt.event.ActionListenerenumerateALDeprecated.(package private) static java.awt.event.ActionListenerimportHWALDeprecated.JniAdeptDepp.djtgjtg(package private) java.awt.event.ActionListenertimerAL
-
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 voidaddMenuItems(javax.swing.JMenu menu)A convenience function to add some standard menu items to a menu.voidclose()Closes a devicevoidconnect()Starts a timer that periodically tries to connect to a device until it succeeds.voiddisable()Disables the DEPP protocol for the devicevoiddisconnect()Stops a timer that periodically tries to connect to a devicevoidenable()Enables the DEPP protocol for the devicevoidget(byte[] addr, byte[] data)Gets multiple bytesvoidget(byte addr, byte[] buf)Gets single bytevoidget(int base, byte[] regs)Reads consecutive bytes from hardware (Depp2).voidget(int base, int addr, byte[] regs)Reads consecutive bytes from hardware (Depp2).byte[]getByteArray(int size)Deprecated.byte[]getByteArray(int size, int off)Deprecated.voidgetBytes(int base, int addr, byte[] regs)Reads consecutive bytes from legacy hardware.static java.util.prefs.PreferencesgetDevicePreferences(java.lang.Class cl, java.lang.String node)Deprecated.static voidimportHardware(java.lang.String url)Deprecated.voidlock()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.JMenumakeDeviceMenu(java.lang.String title, java.awt.event.ActionListener aL)Deprecated.booleanOK()Deprecated.voidopen()Opens a devicevoidpop(byte base, byte[] buf)Deprecated.voidpush(byte base, byte[] buf)Deprecated.voidpush(int base, int len, int addr, byte[] buf, boolean waitFlag)Deprecated.voidput(byte[] buf)Puts multiple addr,byte pairsvoidput(byte base, byte data)Puts single addr,bytevoidput(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)voidput(int base, java.nio.ByteBuffer bb)Writes byte buffer to hardware (Depp2)voidput1(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.StringselectDevice(java.lang.String filter)Deprecated.static voidshowEnumeratedDevices()Writes information about enumerated devices to System.outvoidunlock()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.DeppExceptionOpens a device
- Throws:
JniAdeptDepp.DeppException- DEPP exception
-
close
public void close()
Closes a device
- Specified by:
closein 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.DeppExceptionGets 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.DeppExceptionGets 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.DeppExceptionPuts single addr,byte
- Parameters:
base- Address to writedata- Data to write- Throws:
JniAdeptDepp.DeppException- DEPP exception
-
put
public void put(byte[] buf) throws JniAdeptDepp.DeppExceptionPuts 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 RegisterIoExceptionWrites 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.DeppExceptionDeprecated.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.DeppExceptionDeprecated.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.DeppExceptionDeprecated.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.DeppExceptionWrites 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 RegisterIoExceptionWrites 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:
putin 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 RegisterIoExceptionWrites 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:
putin 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.DeppExceptionReads 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 RegisterIoExceptionReads consecutive bytes from hardware (Depp2).
Reads regs.length bytes.
- Specified by:
getin 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 RegisterIoExceptionReads 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:
getin 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.
-
-