# Velleman K8090 8-channel relay board

class pymeasure.instruments.velleman.VellemanK8090(adapter, name='Velleman K8090', timeout=100, **kwargs)

  Bases: `Instrument`

  For usage with the K8090 relay board, by Velleman.

  View the “K8090/VM8090 PROTOCOL MANUAL” for the serial command instructions.

  The communication is done by serial USB. The IO settings are fixed:

  Baud rate | 19200
  Data bits | 8
  Parity | None
  Stop bits | 1
  Flow control | None

  A short timeout is recommended, since the device is not consistent in giving status messages and serial timeouts will occur also in normal operation.

  Use the class like:

      from pymeasure.instruments.velleman import VellemanK8090, VellemanK8090Switches as Switches

      instrument = VellemanK8090("ASRL1::INSTR")

      # Get status update from device
      last_on, curr_on, time_on = instrument.status

      # Toggle a selection of channels on
      instrument.switch_on = Switches.CH3 | Switches.CH4 | Switches.CH5

  check_set_errors()

    Check for errors after having set a property and log them.

    Called if `check_set_errors=True` is set for that property.

    The K8090 replies with a status after a switch command, but only after any switch actually changed. In order to guarantee the buffer is empty, we attempt to read it fully here. No actual error checking is done here!

    Returns:

      List of error entries.

  id = None
  read(**kwargs)

    The read command specifically for the protocol of the K8090.

    This overrides the method from the `instrument` class.

    See `write()`, replies from the machine use the same format.

    A read will return a list of CMD, MASK, PARAM1 and PARAM2.

  property status

    Get current relay status. The reply has a different command byte than the request.

    Three items (`VellemanK8090Switches` flags) are returned:

    - Previous state: the state of each relay before this event

    - Current state: the state of each relay now

    - Timer state: the state of each relay timer

  property switch_off

    Set channels to off state. See `switch_on` for more details.

  property switch_on

    Set channels to on state. Other channels are unaffected. Pass either a list or set of channel numbers (starting at 1), or pass a bitmask.

    After switching this waits for a reply from the device. This is only send when a relay actually toggles, otherwise expect a blocking time equal to the communication timeout If speed is important, avoid calling switch_ unnecessarily.

  property version

    Get firmware version, as (year - 2000, week). E.g. `(10, 1)`

  write(command, **kwargs)

    The write command specifically for the protocol of the K8090.

    This overrides the method from the `Instrument` class.

    Each packet to the device is 7 bytes:

    STX (0x04) - CMD - MASK - PARAM1 - PARAM2 - CHK - ETX (0x0F)

    Where CHK is checksum of the package.

    Parameters:

      command (str) – String like “CMD[, MASK, PARAM1, PARAM2]” - only CMD is mandatory

class pymeasure.instruments.velleman.VellemanK8090Switches(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

  Bases: `IntFlag`

  Use to identify switch channels.