Class UsbGpioService

java.lang.Object
net.solarnetwork.node.control.numato.usbgpio.UsbGpioService
All Implemented Interfaces:
GpioService

public class UsbGpioService extends Object implements GpioService
Implementation of the GpioService.
Version:
1.0
Author:
matt
  • Field Details

    • DEFAULT_LISTEN_WAIT_MS

      public static final long DEFAULT_LISTEN_WAIT_MS
      The listenWaitMs property default value.
      See Also:
    • DEFAULT_GPIO_COUNT

      public static final int DEFAULT_GPIO_COUNT
      The gpioCount property default value.
      See Also:
  • Constructor Details

    • UsbGpioService

      public UsbGpioService(net.solarnetwork.node.io.serial.SerialConnection conn)
      Constructor.
      Parameters:
      conn - the serial connection to use
      Throws:
      IllegalArgumentException - if any argument is null
  • Method Details

    • getDeviceVersion

      public String getDeviceVersion() throws IOException
      Description copied from interface: GpioService
      Get the device version information.
      Specified by:
      getDeviceVersion in interface GpioService
      Returns:
      the device version
      Throws:
      IOException - if a communication error occurs
    • getId

      public String getId() throws IOException
      Description copied from interface: GpioService
      Get the ID of the device.
      Specified by:
      getId in interface GpioService
      Returns:
      the ID, an 8-character string
      Throws:
      IOException - if a communication error occurs
    • setId

      public void setId(String id) throws IOException
      Description copied from interface: GpioService
      Set the ID of the device.
      Specified by:
      setId in interface GpioService
      Parameters:
      id - the ID to set: an 8-character string
      Throws:
      IOException - if a communication error occurs
    • read

      public boolean read(int address) throws IOException
      Description copied from interface: GpioService
      Get the value of the GPIO address as a binary value.
      Specified by:
      read in interface GpioService
      Parameters:
      address - the address, starting from 0, of the GPIO to get
      Returns:
      true if the GPIO is on, otherwise false
      Throws:
      IOException - if a communication error occurs
    • set

      public void set(int address, boolean value) throws IOException
      Description copied from interface: GpioService
      Set the value of the GPIO address as a binary value.
      Specified by:
      set in interface GpioService
      Parameters:
      address - the address, starting from 0, of the GPIO to get
      value - true if the GPIO is on, otherwise false
      Throws:
      IOException - if a communication error occurs
    • readAnalog

      public int readAnalog(int address) throws IOException
      Description copied from interface: GpioService
      Get the analog value of the GPIO address.
      Specified by:
      readAnalog in interface GpioService
      Parameters:
      address - the address
      Returns:
      the analog value
      Throws:
      IOException - if a communication error occurs
    • readAll

      public BitSet readAll() throws IOException
      Description copied from interface: GpioService
      Read the value of all GPIO addresses.
      Specified by:
      readAll in interface GpioService
      Returns:
      the set of enabled GPIO addresses
      Throws:
      IOException - if a communication error occurs
    • writeAll

      public void writeAll(BitSet values) throws IOException
      Description copied from interface: GpioService
      Set the value of all GPIO addresses on enabled/disabled based on a BitSet.
      Specified by:
      writeAll in interface GpioService
      Parameters:
      values - the value to set, with bit positions representing GPIO addresses
      Throws:
      IOException - if a communication error occurs
    • configureWriteMask

      public void configureWriteMask(BitSet set) throws IOException
      Description copied from interface: GpioService
      Configure a bitmask to use on future GpioService.configureIoDirection(BitSet) or GpioService.writeAll(BitSet) calls.
      Specified by:
      configureWriteMask in interface GpioService
      Parameters:
      set - the GPIO addresses to enable for future operations, using bit positions
      Throws:
      IOException - if a communication error occurs
    • configureIoDirection

      public void configureIoDirection(BitSet set) throws IOException
      Description copied from interface: GpioService
      Configure the GPIO direction of all GPIO addresses.

      If a bit is enabled that means the coreponsing GPIO address should be configured as the input direction, otherwise as output.

      Specified by:
      configureIoDirection in interface GpioService
      Parameters:
      set - the GPIO addresses to configure as input, using bit positions
      Throws:
      IOException - if a communication error occurs
    • getListenWaitMs

      public long getListenWaitMs()
      Get the length of time to wait to read responses after writing a command, in milliseconds.
      Returns:
      the milliseconds to wait, or 0 to not wait at all; defaults to DEFAULT_LISTEN_WAIT_MS
    • setListenWaitMs

      public void setListenWaitMs(long listenWaitMs)
      Set the length of time to wait to read responses after writing a command, in milliseconds.
      Parameters:
      listenWaitMs - the milliseconds to set, or 0 to not wait at all
    • getGpioCount

      public int getGpioCount()
      Get the GPIO count.
      Returns:
      the count; defaults to DEFAULT_GPIO_COUNT
    • setGpioCount

      public void setGpioCount(int gpioCount)
      Set the GPIO count.
      Parameters:
      gpioCount - the gpioCount to set
      Throws:
      IllegalArgumentException - if gpioCount is less than 1