Commit 1e48dd61 authored by Martin Drechsler's avatar Martin Drechsler

add props files

parent 54ac5cf2
from __future__ import absolute_import, division, print_function
from builtins import * # @UnusedWildImport
from mcculw import ul
from mcculw.enums import BoardInfo, InfoType, ULRange, ErrorCode, ScanOptions
from mcculw.ul import ULError
from examples.props.propsbase import Props
class AnalogOutputProps(Props):
"""Provides analog output information on the hardware configured at the
board number given.
This class is used to provide hardware information for the library
examples, and may change hardware values. It is recommended that the
values provided by this class be hard-coded in production code.
"""
def __init__(self, board_num):
self._board_num = board_num
self.resolution = self._get_resolution()
self.num_chans = self._get_num_chans()
self.available_ranges = self._get_available_ranges()
self.supports_v_out = self._get_supports_v_out(
self.available_ranges)
self.supported_scan_options = self._get_supported_scan_options()
self.supports_scan = (
ScanOptions.CONTINUOUS in self.supported_scan_options)
def _get_resolution(self):
return ul.get_config(
InfoType.BOARDINFO, self._board_num, 0, BoardInfo.DACRES)
def _get_num_chans(self):
return ul.get_config(
InfoType.BOARDINFO, self._board_num, 0, BoardInfo.NUMDACHANS)
def _get_supported_scan_options(self):
try:
return ScanOptions(ul.get_config(
InfoType.BOARDINFO, self._board_num, 0,
BoardInfo.DACSCANOPTIONS))
except ULError:
return ScanOptions(0)
def _get_available_ranges(self):
result = []
# Check if the range is ignored by passing a bogus range in
try:
ul.v_out(self._board_num, 0, -5, 0)
range_ignored = True
except ULError as e:
if (e.errorcode == ErrorCode.NETDEVINUSE or
e.errorcode == ErrorCode.NETDEVINUSEBYANOTHERPROC):
raise
range_ignored = False
if range_ignored:
# Try and get the range configured in InstaCal
try:
curr_range = ULRange(ul.get_config(
InfoType.BOARDINFO, self._board_num, 0,
BoardInfo.DACRANGE))
result.append(curr_range)
except ULError as e:
if (e.errorcode == ErrorCode.NETDEVINUSE or
e.errorcode == ErrorCode.NETDEVINUSEBYANOTHERPROC):
raise
return result
for dac_range in ULRange:
try:
ul.v_out(self._board_num, 0, dac_range, 0)
result.append(dac_range)
print(dac_range)
except ULError as e:
if (e.errorcode == ErrorCode.NETDEVINUSE or
e.errorcode == ErrorCode.NETDEVINUSEBYANOTHERPROC):
raise
return result
def get_units_string(self, ao_range):
if ao_range in [
ULRange.MA4TO20,
ULRange.MA2TO10,
ULRange.MA1TO5,
ULRange.MAPT5TO2PT5]:
return "mA"
else:
return "V"
def _get_supports_v_out(self, available_ranges):
if len(available_ranges) == 0:
return False
try:
ul.v_out(self._board_num, 0, available_ranges[0], 0)
except ULError:
return False
return True
from __future__ import absolute_import, division, print_function
from builtins import * # @UnusedWildImport
from mcculw import ul
from mcculw.enums import InfoType, BoardInfo, DigitalInfo, DigitalPortType, \
DigitalIODirection, FunctionType
from examples.props.propsbase import Props
from mcculw.ul import ULError
class DigitalProps(Props):
"""Provides digital IO information on the hardware configured at the
board number given.
This class is used to provide hardware information for the library
examples, and may change hardware values. It is recommended that the
values provided by this class be hard-coded in production code.
"""
def __init__(self, board_num):
self._board_num = board_num
self.num_ports = self._get_num_digital_chans()
self.port_info = []
for port_index in range(self.num_ports):
self.port_info.append(PortInfo(board_num, port_index))
def _get_num_digital_chans(self):
try:
return ul.get_config(
InfoType.BOARDINFO, self._board_num, 0,
BoardInfo.DINUMDEVS)
except ULError:
return 0
class PortInfo(object):
def __init__(self, board_num, port_index):
self._board_num = board_num
self._port_index = port_index
self.type = self._get_digital_dev_type()
self.first_bit = self._get_first_bit(port_index, self.type)
self.num_bits = self._get_num_bits()
self.in_mask = self._get_in_mask()
self.out_mask = self._get_out_mask()
self.is_bit_configurable = self._get_is_bit_configurable(
self.type, self.first_bit, self.in_mask, self.out_mask)
self.is_port_configurable = self._get_is_port_configurable(
self.type, self.in_mask, self.out_mask)
self.supports_input = self._get_supports_input(
self.in_mask, self.is_port_configurable)
self.supports_input_scan = self._get_supports_input_scan()
self.supports_output = self._get_supports_output(
self.out_mask, self.is_port_configurable)
self.supports_output_scan = self._get_supports_output_scan()
def _get_num_bits(self):
return ul.get_config(
InfoType.DIGITALINFO, self._board_num, self._port_index,
DigitalInfo.NUMBITS)
def _get_supports_input(self, in_mask, is_port_programmable):
return in_mask > 0 or is_port_programmable
def _get_supports_input_scan(self):
try:
ul.get_status(self._board_num, FunctionType.DIFUNCTION)
except ULError:
return False
return True
def _get_supports_output_scan(self):
try:
ul.get_status(self._board_num, FunctionType.DOFUNCTION)
except ULError:
return False
return True
def _get_supports_output(self, out_mask, is_port_programmable):
return out_mask > 0 or is_port_programmable
def _get_first_bit(self, port_index, port_type):
# A few devices (USB-SSR08 for example) start at FIRSTPORTCL and
# number the bits as if FIRSTPORTA and FIRSTPORTB exist for
# compatibility with older digital peripherals
if port_index == 0 and port_type == DigitalPortType.FIRSTPORTCL:
return 16
return 0
def _get_is_bit_configurable(self, port_type, first_bit, in_mask,
out_mask):
if in_mask & out_mask > 0:
return False
# AUXPORT type ports might be configurable, check if d_config_bit
# completes without error
if port_type == DigitalPortType.AUXPORT:
try:
ul.d_config_bit(
self._board_num, port_type, first_bit,
DigitalIODirection.OUT)
ul.d_config_bit(
self._board_num, port_type, first_bit,
DigitalIODirection.IN)
except ULError:
return False
return True
return False
def _get_is_port_configurable(self, port_type, in_mask, out_mask):
if in_mask & out_mask > 0:
return False
# Check if d_config_port completes without error
try:
ul.d_config_port(self._board_num, port_type,
DigitalIODirection.OUT)
ul.d_config_port(self._board_num, port_type,
DigitalIODirection.IN)
except ULError:
return False
return True
def _get_digital_dev_type(self):
return DigitalPortType(ul.get_config(
InfoType.DIGITALINFO, self._board_num, self._port_index,
DigitalInfo.DEVTYPE))
def _get_in_mask(self):
return ul.get_config(
InfoType.DIGITALINFO, self._board_num, self._port_index,
DigitalInfo.INMASK)
def _get_out_mask(self):
return ul.get_config(
InfoType.DIGITALINFO, self._board_num, self._port_index,
DigitalInfo.OUTMASK)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment