Package cbsw.adept

Class 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.

    • 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)
      Constructor
      JniAdeptDepp​(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 device
      void connect()
      Starts a timer that periodically tries to connect to a device until it succeeds.
      void disable()
      Disables the DEPP protocol for the device
      void disconnect()
      Stops a timer that periodically tries to connect to a device
      void enable()
      Enables the DEPP protocol for the device
      void get​(byte[] addr, byte[] data)
      Gets multiple bytes
      void get​(byte addr, byte[] buf)
      Gets single byte
      void 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 device
      void 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 pairs
      void put​(byte base, byte data)
      Puts single addr,byte
      void put​(int base, int addr, byte[] regs)
      Writes array of bytes to hardware (Depp2)
      <T extends java.lang.Byte,​Integer,​Short,​Long>
      void
      put​(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 device
      static java.lang.String selectDevice​(java.lang.String filter)
      Deprecated.
      static void showEnumeratedDevices()
      Writes information about enumerated devices to System.out
      void unlock()
      Releases access to DEPP interface.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • 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 device
        al - 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.

      • 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

      • 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 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
      • 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,
                        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 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​(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.