Class JniAdeptDepp

java.lang.Object
cbsw.adept.JniAdeptDepp
All Implemented Interfaces:
RegisterIo

public class JniAdeptDepp extends 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.

  • Field Details

  • Constructor Details

    • JniAdeptDepp

      public JniAdeptDepp(String dev)

      Constructor

      Parameters:
      dev - Connection name of device
    • JniAdeptDepp

      public JniAdeptDepp(String dev, ActionListener al)

      Constructor

      Parameters:
      dev - Connection name of device
      al - ActionListener to replace default timer (can be null)
  • Method Details

    • addMenuItems

      public static void addMenuItems(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 interface RegisterIo
    • 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 address
      buf - 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 read
      data - 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 write
      data - 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 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 address
      addr - Register offset
      val - 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 address
      len - Transaction length
      addr - Register start offset
      buf - Values to write
      waitFlag - 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 address
      buf - 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 address
      buf - 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 address
      addr - Register start offset
      regs - 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 interface RegisterIo
      Parameters:
      base - DEPP base address
      addr - Register start offset
      regs - Write transaction buffer, payload starting at byte 4
      Throws:
      RegisterIoException - Register I/O exception
    • put

      public void put(int base, 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 interface RegisterIo
      Parameters:
      base - DEPP base address
      bb - 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 address
      addr - Register start offset
      regs - 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 interface RegisterIo
      Parameters:
      base - DEPP base address
      addr - Register start offset
      regs - 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 interface RegisterIo
      Parameters:
      base - DEPP base address
      regs - 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(String url)
      Deprecated.

      Imports list of known hardware from web (legacy code)

      Parameters:
      url - The URL of the XML data
    • makeDeviceMenu

      @Deprecated public static JMenu makeDeviceMenu(String title, ActionListener aL)
      Deprecated.
    • selectDevice

      @Deprecated public static String selectDevice(String filter)
      Deprecated.
    • selectConnectedDevice

      public static 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 JComboBox<String> makeDeviceComboBox(String selectedName, ActionListener aL, String filter)
      Deprecated.
    • getDevicePreferences

      @Deprecated public static Preferences getDevicePreferences(Class cl, String node)
      Deprecated.