From d21e10e5a75e1691c1bc4fd3f3f67d2f21fcbd3e Mon Sep 17 00:00:00 2001 From: Wolfgang Scherer Date: Sun, 9 Dec 2018 12:31:37 +0100 Subject: [PATCH 1/5] whitespace cleanup --- M701x.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/M701x.py b/M701x.py index 32a0f53..12b41d4 100644 --- a/M701x.py +++ b/M701x.py @@ -6,10 +6,8 @@ # # Authors: mose@fabfolk.com, juewei@fabfolk.com - import re,sys,string,serial,time - class M701x: """ Class for interfacing with Gossen Metrawatt devices over serial """ def __init__(self, serial_port): @@ -44,12 +42,10 @@ def _read(self): i+=1 return returnstr - def _write(self,str): """ adds $-delimiter, checksum and line ending to str and sends it to the serial line """ self.__serial.write(str + '$' + self._checksum(str) + '\r\n') - def _checksum(self,str): """ calculates checksum of a request/answer """ qsum_dec = ord('$') @@ -58,12 +54,10 @@ def _checksum(self,str): qsum_dec += d return "%x" % (qsum_dec & 0xff) - def _flush(self): """ discards all waiting answers in the buffer """ self.__serial.flushInput() - def request(self,command,retries=3): """ sends a command to device and parses reply """ i = 0 @@ -92,16 +86,11 @@ def request(self,command,retries=3): else: return False,'CHKSUM_ERROR' - def sync_clock(self,idn): # needs more testing and ability to sync all devices (e.g. PSI + S2N) """ synchronizes device clock with PC """ return self.request('DAT'+idn+'!'+time.strftime("%d.%m.%y;%H:%M:%S")) - - - - if __name__ == "__main__": m701 = M701x(sys.argv[1]) #m701._write("IDN?") @@ -115,4 +104,4 @@ def sync_clock(self,idn): print m701.request('WER?') # str = "\x13DATIMx=20.09.14;18:33$18\r\n\x11" - # ^what ^param ^XOFF \ No newline at end of file + # ^what ^param ^XOFF From 7a0dc416a3efc6309066de7b80dde64b88e5620a Mon Sep 17 00:00:00 2001 From: Wolfgang Scherer Date: Sun, 9 Dec 2018 12:33:51 +0100 Subject: [PATCH 2/5] :meth:`_checksum` fixed --- M701x.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/M701x.py b/M701x.py index 12b41d4..d6aee5c 100644 --- a/M701x.py +++ b/M701x.py @@ -46,13 +46,14 @@ def _write(self,str): """ adds $-delimiter, checksum and line ending to str and sends it to the serial line """ self.__serial.write(str + '$' + self._checksum(str) + '\r\n') - def _checksum(self,str): + @staticmethod + def _checksum(self, str): """ calculates checksum of a request/answer """ qsum_dec = ord('$') for i in str: d = ord(i) qsum_dec += d - return "%x" % (qsum_dec & 0xff) + return "%02x" % (qsum_dec & 0xff) def _flush(self): """ discards all waiting answers in the buffer """ From bedc8405b57bcfff04fac98a0829c65783d080db Mon Sep 17 00:00:00 2001 From: Wolfgang Scherer Date: Sun, 9 Dec 2018 12:35:03 +0100 Subject: [PATCH 3/5] turn off local echo --- M701x.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/M701x.py b/M701x.py index d6aee5c..e7a34a6 100644 --- a/M701x.py +++ b/M701x.py @@ -21,6 +21,9 @@ def __init__(self, serial_port): timeout=3, xonxoff=True ) + # turn off local echo + self.__serial.write('\x06') # ACK + # r = self.request('IDN!0') # From 5e02f35d252d5ae3d7ab36be82fce5253c80d97f Mon Sep 17 00:00:00 2001 From: Wolfgang Scherer Date: Sun, 9 Dec 2018 12:38:15 +0100 Subject: [PATCH 4/5] `idn` arg for :meth:`sync_clock` optional --- M701x.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/M701x.py b/M701x.py index e7a34a6..431c6fe 100644 --- a/M701x.py +++ b/M701x.py @@ -90,9 +90,11 @@ def request(self,command,retries=3): else: return False,'CHKSUM_ERROR' - def sync_clock(self,idn): + def sync_clock(self, idn=None): # needs more testing and ability to sync all devices (e.g. PSI + S2N) """ synchronizes device clock with PC """ + if idn is None: + idn = '' return self.request('DAT'+idn+'!'+time.strftime("%d.%m.%y;%H:%M:%S")) if __name__ == "__main__": From c63744f41918b634a5e375b0da62a57e49218eed Mon Sep 17 00:00:00 2001 From: Wolfgang Scherer Date: Sun, 9 Dec 2018 20:47:44 +0100 Subject: [PATCH 5/5] declaration of :meth:`_checksum` fixed --- M701x.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/M701x.py b/M701x.py index 431c6fe..05cca95 100644 --- a/M701x.py +++ b/M701x.py @@ -50,7 +50,7 @@ def _write(self,str): self.__serial.write(str + '$' + self._checksum(str) + '\r\n') @staticmethod - def _checksum(self, str): + def _checksum(str): """ calculates checksum of a request/answer """ qsum_dec = ord('$') for i in str: