API

Exceptions

class di2008.AnalogPortError

Raised when there is an analog-port related error on the DI-2008


class di2008.DigitalPortError

Raised when there is a digital port related error on the DI-2008


class di2008.PortNotValidError

Raised when there is a port access attempted where a physical port does not exist.

Device

The device is where all of the ports actually reside within.

class di2008.Di2008(serial_number: str = None, timeout=0.05, loglevel=20)

The device controller which implements its own threading.Thread class and processes incomming data based on its defined scan list. The port_name and serial_number allow the user to specify a particular device on the bus when there may be more than one device present on the bus. If both port_name and serial_number are specified, then serial_number will take precedence. If neither are specified, then the first instrument found on the bus will be automatically acquired.

Parameters:
  • port_name – the COM port (if not specified, the software will attempt to find the device)

  • serial_number – the serial number of the device to acquire

  • timeout – the period of time over which input data is pulled from the serial port and processed

  • loglevel – the logging level, i.e. logging.INFO

change_led_color(color: str)

Change the LED color.

Parameters:

color – the color as a string; valid values are in [‘black’, ‘blue’, ‘green’, ‘cyan’, ‘red’, ‘magenta’, ‘yellow’, ‘white’] and invalid values will raise a ValueError

Returns:

None

close()

Release the device and serial port.

Returns:

None

create_scan_list(scan_list: List[Port])

Builds the scan list. This must be done while the instrument is not currently scanning or results are unpredictable.

Parameters:

scan_list – a list of Port types.

Returns:

True if success, else False

read_di(channel: int)

Reads the state of any digital input/output

Parameters:

channel – the channel number as shown on the instrument

Returns:

True if the channel is high, else False

setup_dio_direction(channel: int, direction: DigitalDirection)

Setup the digital port direction for a single port.

Parameters:
  • channel – the channel number

  • direction – the DigitalDirection

Returns:

None

start()

Starts the device scanning. The scan list must already be defined using create_scan_list method.

Returns:

None

stop()

Stops the device scanning. :return:

write_do(channel: int, state: bool)

Writes to any of the digital pins in the switch state.

Parameters:
  • channel – an integer indicating the digital output

  • state – the value, True or False; True releases the internal switch, meaning that the output will float up to 5V while False will activate the internal switch, pulling the node to 0V

Returns:

None

Ports

Input ports are generally added into the scan list which the device scans in a round-robin method. All inputs are subclasses of the Port class.

class di2008.DigitalDirection(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Used to set the direction

INPUT = 0

Indicates that the port direction is to be an input

OUTPUT = 1

Indicates that the port direction is to be an output


class di2008.AnalogPort(channel: int, analog_range: (<class 'str'>, <class 'decimal.Decimal'>) = None, thermocouple_type: str = None, filter: str = 'last point', filter_decimation: int = 10, loglevel=20)

Analog input port which may be configured as a strict voltage monitor or as a thermocouple input.

Parameters:
  • channel – integer, the channel number as seen on the front of the devices, which is to say, the first channel is 1 instead of 0

  • analog_rangestr or Decimal, the expected range when configurated as an analog input; valid values are in [0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0, 10.0, 25.0, 50.0] while invalid values will raise a ValueError

  • thermocouple_type – string, a single letter denoting the thermocouple type; valid values are in [‘b’, ‘e’, ‘j’, ‘k’, ‘n’, ‘r’, ‘s’, ‘t’] and invalid values will raise a ValueError

  • filter – string, a string containing ‘last point’, ‘average’, ‘maximum’ or ‘minimum’ as defined in the device datasheet

  • filter_decimation – int, an integer containing the number of samples over which to filter as defined in the device datasheet

  • loglevel – the logging level, i.e. logging.INFO

parse(value)

The parse method is intended to be called by the Di2008 class when it receives data associated with the AnalogPort.

Parameters:

value – 16-bit integer value representing the ‘raw’ data stream

Returns:


class di2008.DigitalPort(channel: int, direction: DigitalDirection = DigitalDirection.INPUT, loglevel=20)

A digital input/output port.

Parameters:
  • channel – an integer corresponding to the digital channels as seen on the front face of the device (zero-indexed)

  • output – a boolean value, True if the channel is to be an output else false.

  • loglevel – the logging level to apply to the digital port.


class di2008.RatePort(range_hz: int = 50000, filter_samples: int = 32, loglevel=20)

Digital input port which may be configured as a frequency monitor.

Parameters:
  • range_hz – the maximum range of the input, in Hz; valid values are in [50000, 20000, 10000, 5000, 2000, 1000, 500, 200, 100, 50, 20, 10] and invalid values will raise a ValueError

  • filter_samples – filter samples as defined within the device datasheet

  • loglevel – the logging level, i.e. logging.INFO


class di2008.CountPort(loglevel=10)

todo: Implement and document CountPort