From e64e364039c7feb3f803fb809e5c9c6d226135c9 Mon Sep 17 00:00:00 2001 From: Matt Grau <graum@phys.ethz.ch> Date: Tue, 13 Jul 2021 13:13:51 +0200 Subject: [PATCH] create mock device class --- .gitignore | 3 +++ README.md | 9 ++++++++- device/__init__.py | 1 + device/device.py | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 device/__init__.py create mode 100644 device/device.py diff --git a/.gitignore b/.gitignore index 7f56f29..7bfd7fb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ # ignore any virtual environment *venv + +# ignore pycache +*__pycache__ \ No newline at end of file diff --git a/README.md b/README.md index 5f1c9c6..306a155 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # README -# First create a python virtual environment +## First create a python virtual environment ```bash python3 -m venv demo_venv @@ -17,4 +17,11 @@ which pip $ ~/tiqi-js-tutorial/demo_venv/bin/pip which python $ ~/tiqi-js-tutorial/demo_venv/bin/python +``` + +## Create mock device class + +```bash +mkdir device +touch device/__init__.py ``` \ No newline at end of file diff --git a/device/__init__.py b/device/__init__.py new file mode 100644 index 0000000..3f39f41 --- /dev/null +++ b/device/__init__.py @@ -0,0 +1 @@ +from .device import Device diff --git a/device/device.py b/device/device.py new file mode 100644 index 0000000..ec557c4 --- /dev/null +++ b/device/device.py @@ -0,0 +1,32 @@ +class Device: + __voltage = 0.0 + __current = 0.0 + + def __init__(self): + # code to connect to device + self.__voltage = 1.0 + self.__current = 0.0 + + def _get_voltage(self): + # read voltage from device + voltage = self.__voltage + return voltage + + def _set_voltage(self, new_voltage): + # write voltage to device + self.__voltage = new_voltage + + def _get_current(self): + # read current from device + current = self.__curent + return current + + def _set_current(self, new_current): + # write current to device + self.__curent = new_current + + def _calculate_resistance(self): + current = self._get_current() + voltage = self._get_voltage() + resistance = voltage / current + return resistance -- GitLab