From fb45ef1ca1588c7b4df097d57b457bf7924a21f7 Mon Sep 17 00:00:00 2001 From: Blaise Thompson Date: Thu, 31 Aug 2023 16:58:58 -0500 Subject: [PATCH 1/2] actually invert --- yaqd_mcc/_mcc_ulw_sensor.py | 61 ++++++++++++++++++++++++++++++++++++ yaqd_mcc/mcc-ulw-sensor.toml | 30 ++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 yaqd_mcc/_mcc_ulw_sensor.py create mode 100644 yaqd_mcc/mcc-ulw-sensor.toml diff --git a/yaqd_mcc/_mcc_ulw_sensor.py b/yaqd_mcc/_mcc_ulw_sensor.py new file mode 100644 index 0000000..bacb97f --- /dev/null +++ b/yaqd_mcc/_mcc_ulw_sensor.py @@ -0,0 +1,61 @@ +__all__ = ["Mcc118"] + +import asyncio +from typing import Dict, Any, List +from dataclasses import dataclass + +from yaqd_core import HasMeasureTrigger, IsSensor, IsDaemon + + +@dataclass +class Channel: + name: str + enabled: bool + invert: bool + index: int + + +class MccUlwSensor(HasMeasureTrigger, IsSensor, IsDaemon): + _kind = "mcc-ulw-sensor" + + def __init__(self, name, config, config_filepath): + super().__init__(name, config, config_filepath) + self._channels = list() + for k, d in self._config["channels"].items(): + channel = Channel(**d, name=k) + self._channels.append(channel) + self._channel_names = [c.name for c in self._channels] + self._channel_units = {k: "V" for k in self._channel_names} + from mcculw import ul # type: ignore + + ul.ignore_instacal() + devices = ul.get_daq_device_inventory(InterfaceType.ANY) + if self._config["serial"]: + for device in devices: + if device.unique_id == self._config["serial"]: + ul.create_daq_device(0, device) + break + raise Exception("no device with that serial found") + else: + ul.create_daq_device(0, devices[0]) + from mcculw.device_info import DaqDeviceInfo # type: ignore + + info = DaqDeviceInfo(board_num) + self._ai_info = info.get_ai_info() + + async def _measure(self): + from mcculw import ul # type: ignore + + out = dict() + for c in self._channels: + ai_range = self._ai_info.supported_ranges[c.index] + if ai_info.resolution <= 16: + value = ul.a_in(0, c.index, ai_range) + voltage = ul.to_eng_units(0, ai_range, value) + else: + value = ul.a_in_32(0, c.index, ai_range) + voltage = ul.to_eng_units_32(0, ai_range, value) + if c.invert: + voltage *= -1 + out[c.name] = voltage + return out diff --git a/yaqd_mcc/mcc-ulw-sensor.toml b/yaqd_mcc/mcc-ulw-sensor.toml new file mode 100644 index 0000000..5510733 --- /dev/null +++ b/yaqd_mcc/mcc-ulw-sensor.toml @@ -0,0 +1,30 @@ +protocol = "mcc-ulw-sensor" +doc = "" +traits = ["has-measure-trigger", "is-sensor", "is-daemon"] +hardware = ["mccdaq:mcc-usb-205"] + +[links] +source = "https://github.com/yaq-project/yaqd-mcc" +bugtracker = "https://github.com/yaq-project/yaqd-mcc/-/issues" + +[installation] +PyPI = "https://pypi.org/project/yaqd-mcc" + +[[types]] +type = "record" +name = "channel" +fields = [{"name"="enabled", "type"="boolean", "default"=true}, + {"name"="invert", "type"="boolean", "default"=false}, + {"name"="index", "type"="int", "doc"="Physical index of channel."}, +] + + +[config] + +[config.channels] +type = "map" +values = "channel" + +[state] + +[messages] From c260a9b126bb518891013f1e58952a0fb47be35a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 31 Aug 2023 22:01:42 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- yaqd_mcc/mcc-ulw-sensor.avpr | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/yaqd_mcc/mcc-ulw-sensor.avpr b/yaqd_mcc/mcc-ulw-sensor.avpr index e8f5db3..a534693 100644 --- a/yaqd_mcc/mcc-ulw-sensor.avpr +++ b/yaqd_mcc/mcc-ulw-sensor.avpr @@ -1,5 +1,9 @@ { "config": { + "channels": { + "type": "map", + "values": "channel" + }, "enable": { "default": true, "doc": "Disable this daemon. The kind entry-point will not attempt to start this daemon.",