summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Baumann <derflob@derflob.de>2018-01-18 23:38:52 +0100
committerFlorian Baumann <derflob@derflob.de>2018-01-18 23:38:52 +0100
commit7274a6311b6fcad8a3f14b1436d6cb995e88bb0f (patch)
treeb4afacfde8c8c6bc61a20975dd2ce4d0a3b01fff
downloadQJ3005P-master.tar.gz
QJ3005P-master.tar.bz2
QJ3005P libraryHEADmaster
-rw-r--r--QJ3005P/QJ3005P.py84
-rw-r--r--QJ3005P/__init__.py1
2 files changed, 85 insertions, 0 deletions
diff --git a/QJ3005P/QJ3005P.py b/QJ3005P/QJ3005P.py
new file mode 100644
index 0000000..94b5a44
--- /dev/null
+++ b/QJ3005P/QJ3005P.py
@@ -0,0 +1,84 @@
+import logging
+from serial import Serial
+
+class QJ3005P():
+ def __init__(self, port='/dev/ttyUSB0', baudrate=9600):
+ self._port = port
+ self._baudrate = baudrate
+ self._serial = Serial(port=port, baudrate=baudrate, timeout=0.1)
+
+ def _status(self):
+ self._serial.write(rb'STATUS?\r\n')
+ status = self._serial.read(4)
+
+ return (status[0] == 49, status[1] == 49, status[2] == 49)
+
+ @property
+ def enabled(self):
+ return self._status()[1]
+
+ @enabled.setter
+ def enabled(self, enable=True):
+ if (enable):
+ self._serial.write(rb'OUTPUT1\r\n')
+ else:
+ self._serial.write(rb'OUTPUT0\r\n')
+
+ @property
+ def vset(self):
+ self._serial.write(rb'VSET1?\r\n')
+ v = self._serial.read(6)
+ logging.debug(v)
+ return float(v)
+
+ @vset.setter
+ def vset(self, v):
+ self._serial.write(rb'VSET1:' + '{:05.2f}'.format(v).encode('ascii') + rb'\r\n')
+
+
+ @property
+ def iset(self):
+ self._serial.write(rb'ISET1?\r\n')
+ i = self._serial.read(6)
+ logging.debug(i)
+ return float(i)
+
+ @iset.setter
+ def iset(self, v):
+ self._serial.write(rb'ISET1:' + '{:05.3f}'.format(v).encode('ascii') + rb'\r\n')
+
+ @property
+ def vout(self):
+ self._serial.write(rb'VOUT1?\r\n')
+ v = self._serial.read(6)
+ logging.debug(v)
+ return float(v)
+
+ @property
+ def iout(self):
+ self._serial.write(rb'IOUT1?\r\n')
+ i = self._serial.read(6)
+ logging.debug(i)
+ return float(i)
+
+ @property
+ def wout(self):
+ return self.vout * self.iout
+
+ @property
+ def cv(self):
+ return self._status()[0]
+
+ @property
+ def cc(self):
+ return not self._status()[0]
+
+ @property
+ def ocp(self):
+ return self._status()[2]
+
+ @property
+ def idn(self):
+ self._serial.write(rb'*IDN?\r\n')
+ return self._serial.read(20).decode('ascii')
+
diff --git a/QJ3005P/__init__.py b/QJ3005P/__init__.py
new file mode 100644
index 0000000..365068b
--- /dev/null
+++ b/QJ3005P/__init__.py
@@ -0,0 +1 @@
+from .QJ3005P import QJ3005P