From 09de774dcc1a5abc1c8f3a00fdb039aa3c522f52 Mon Sep 17 00:00:00 2001 From: Manel Caro Date: Wed, 4 Mar 2020 17:46:36 +0100 Subject: SOPA Initial Commit --- test-cli/test/tests/qamp.py | 47 +++++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 29 deletions(-) (limited to 'test-cli/test/tests/qamp.py') diff --git a/test-cli/test/tests/qamp.py b/test-cli/test/tests/qamp.py index 9fcd6d2..3e38ce9 100644 --- a/test-cli/test/tests/qamp.py +++ b/test-cli/test/tests/qamp.py @@ -5,10 +5,17 @@ import time class Qamp(unittest.TestCase): - def __init__(self, testname, testfunc, undercurrent=0.1, overcurrent=2): + #varlist: undercurrent, overcurrent + def __init__(self, testname, testfunc, varlist): self._current = 0.0 - self._undercurrent=undercurrent - self._overcurrent = overcurrent + if "undercurrent" in varlist: + self._undercurrent = varlist["undercurrent"] + else: + raise Exception('undercurrent param inside Qamp must be defined') + if "overcurrent" in varlist: + self._overcurrent = varlist["overcurrent"] + else: + raise Exception('overcurrent param inside Qamp must be defined') self._vshuntfactor=16384.0 self._ser = serial.Serial() self._ser.port = '/dev/ttyUSB0' @@ -33,24 +40,12 @@ class Qamp(unittest.TestCase): except: self.fail("failed: IMPOSSIBLE OPEN USB-SERIAL PORT ( {} )".format(self._ser.port)) error=1 - return -1 if error==0: # Clean input and output buffer of serial port self._ser.flushInput() self._ser.flushOutput() # Send command to read Voltage at Shunt resistor # Prepare cmd - cmd = ('at\n\r') - i=0 - while (i < len(cmd)): - i = i + self._ser.write(cmd[i].encode('ascii')) - time.sleep(0.05) - self._ser.read(1) - res0 = [] - while (self._ser.inWaiting() > 0): # if incoming bytes are waiting to be read from the serial input buffer - res0.append(self._ser.read(1).decode('ascii')) # read the bytes and convert from binary array to ASCII - print(res0) - #CHECK COM FIRST cmd = ('at+in?\n\r') i = 0 @@ -67,21 +62,15 @@ class Qamp(unittest.TestCase): string = ''.join(res) string = string.replace('\n', '') - try: - self._current = float(int(string, 0)) / self._vshuntfactor - except: - self.fail("failed: CAN'T READ CONSUMPTION (CURRENT=0?)") - error=1 - return -1 - if error==0: - print(self._current) + self._current = float(int(string, 0)) / self._vshuntfactor + print(self._current) # In order to give a valid result it is importarnt to define an under current value - if (self._current > float(self._overcurrent)): - self.fail("failed: OVERCURRENT DETECTED ( {} )".format(self._current)) - return -1 + if (self._current > float(self._overcurrent)): + self.fail("failed: OVERCURRENT DETECTED ( {} )".format(self._current)) + + if (self._current < float(self._undercurrent)): + self.fail("failed: UNDERCURRENT DETECTED ( {} )".format(self._current)) + - if (self._current < float(self._undercurrent)): - self.fail("failed: UNDERCURRENT DETECTED ( {} )".format(self._current)) - return -1 -- cgit v1.1 From 9f07a57d89a927aa9b172c1bf20c7ab563658c73 Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Fri, 6 Mar 2020 12:46:27 +0100 Subject: Fixed multiple errors. --- test-cli/test/tests/qamp.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'test-cli/test/tests/qamp.py') diff --git a/test-cli/test/tests/qamp.py b/test-cli/test/tests/qamp.py index 3e38ce9..cf18fc5 100644 --- a/test-cli/test/tests/qamp.py +++ b/test-cli/test/tests/qamp.py @@ -3,10 +3,13 @@ import unittest import serial import time + class Qamp(unittest.TestCase): + params = None - #varlist: undercurrent, overcurrent + # varlist: undercurrent, overcurrent def __init__(self, testname, testfunc, varlist): + self.params = varlist self._current = 0.0 if "undercurrent" in varlist: self._undercurrent = varlist["undercurrent"] @@ -16,7 +19,7 @@ class Qamp(unittest.TestCase): self._overcurrent = varlist["overcurrent"] else: raise Exception('overcurrent param inside Qamp must be defined') - self._vshuntfactor=16384.0 + self._vshuntfactor = 16384.0 self._ser = serial.Serial() self._ser.port = '/dev/ttyUSB0' self._ser.baudrate = 115200 @@ -34,19 +37,19 @@ class Qamp(unittest.TestCase): def execute(self): # Open Serial port ttyUSB0 - error=0 + error = 0 try: self._ser.open() except: self.fail("failed: IMPOSSIBLE OPEN USB-SERIAL PORT ( {} )".format(self._ser.port)) - error=1 - if error==0: + error = 1 + if error == 0: # Clean input and output buffer of serial port self._ser.flushInput() self._ser.flushOutput() # Send command to read Voltage at Shunt resistor # Prepare cmd - cmd = ('at+in?\n\r') + cmd = 'at+in?\n\r' i = 0 # Write, 1 by 1 byte at a time to avoid hanging of serial receiver code of listener, emphasis being made at sleep of 50 ms. @@ -57,7 +60,7 @@ class Qamp(unittest.TestCase): # Read, 1 by 1 byte res = [] - while (self._ser.inWaiting() > 0): # if incoming bytes are waiting to be read from the serial input buffer + while self._ser.inWaiting() > 0: # if incoming bytes are waiting to be read from the serial input buffer res.append(self._ser.read(1).decode('ascii')) # read the bytes and convert from binary array to ASCII string = ''.join(res) @@ -65,12 +68,8 @@ class Qamp(unittest.TestCase): self._current = float(int(string, 0)) / self._vshuntfactor print(self._current) # In order to give a valid result it is importarnt to define an under current value - if (self._current > float(self._overcurrent)): + if self._current > float(self._overcurrent): self.fail("failed: OVERCURRENT DETECTED ( {} )".format(self._current)) - if (self._current < float(self._undercurrent)): + if self._current < float(self._undercurrent): self.fail("failed: UNDERCURRENT DETECTED ( {} )".format(self._current)) - - - - -- cgit v1.1 From a03055f657d2e970e45e7ea2a3e66857f821eabd Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Mon, 9 Mar 2020 09:03:28 +0100 Subject: Solved problems with consumption test. Fixed error when getting mac address. --- test-cli/test/tests/qamp.py | 1 + 1 file changed, 1 insertion(+) (limited to 'test-cli/test/tests/qamp.py') diff --git a/test-cli/test/tests/qamp.py b/test-cli/test/tests/qamp.py index cf18fc5..56511c8 100644 --- a/test-cli/test/tests/qamp.py +++ b/test-cli/test/tests/qamp.py @@ -36,6 +36,7 @@ class Qamp(unittest.TestCase): self._ser.close() def execute(self): + # Open Serial port ttyUSB0 error = 0 try: -- cgit v1.1 From db3b1e45c47a1ef23c1ad67114a09cbec0976681 Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Thu, 25 Jun 2020 11:45:31 +0200 Subject: Solved bugs. Adapted to DB changes. --- test-cli/test/tests/qamp.py | 76 --------------------------------------------- 1 file changed, 76 deletions(-) delete mode 100644 test-cli/test/tests/qamp.py (limited to 'test-cli/test/tests/qamp.py') diff --git a/test-cli/test/tests/qamp.py b/test-cli/test/tests/qamp.py deleted file mode 100644 index 56511c8..0000000 --- a/test-cli/test/tests/qamp.py +++ /dev/null @@ -1,76 +0,0 @@ -from test.helpers.syscmd import SysCommand -import unittest -import serial -import time - - -class Qamp(unittest.TestCase): - params = None - - # varlist: undercurrent, overcurrent - def __init__(self, testname, testfunc, varlist): - self.params = varlist - self._current = 0.0 - if "undercurrent" in varlist: - self._undercurrent = varlist["undercurrent"] - else: - raise Exception('undercurrent param inside Qamp must be defined') - if "overcurrent" in varlist: - self._overcurrent = varlist["overcurrent"] - else: - raise Exception('overcurrent param inside Qamp must be defined') - self._vshuntfactor = 16384.0 - self._ser = serial.Serial() - self._ser.port = '/dev/ttyUSB0' - self._ser.baudrate = 115200 - self._ser.parity = serial.PARITY_NONE - self._ser.timeout = 0 - self._ser.writeTimout = 0 - self._ser.xonxoff = False - self._ser.rtscts = False - self._ser.dsrdtr = False - super(Qamp, self).__init__(testfunc) - self._testMethodDoc = testname - - def __del__(self): - self._ser.close() - - def execute(self): - - # Open Serial port ttyUSB0 - error = 0 - try: - self._ser.open() - except: - self.fail("failed: IMPOSSIBLE OPEN USB-SERIAL PORT ( {} )".format(self._ser.port)) - error = 1 - if error == 0: - # Clean input and output buffer of serial port - self._ser.flushInput() - self._ser.flushOutput() - # Send command to read Voltage at Shunt resistor - # Prepare cmd - cmd = 'at+in?\n\r' - i = 0 - - # Write, 1 by 1 byte at a time to avoid hanging of serial receiver code of listener, emphasis being made at sleep of 50 ms. - while (i < len(cmd)): - i = i + self._ser.write(cmd[i].encode('ascii')) - time.sleep(0.05) - self._ser.read(1) - - # Read, 1 by 1 byte - res = [] - while self._ser.inWaiting() > 0: # if incoming bytes are waiting to be read from the serial input buffer - res.append(self._ser.read(1).decode('ascii')) # read the bytes and convert from binary array to ASCII - - string = ''.join(res) - string = string.replace('\n', '') - self._current = float(int(string, 0)) / self._vshuntfactor - print(self._current) - # In order to give a valid result it is importarnt to define an under current value - if self._current > float(self._overcurrent): - self.fail("failed: OVERCURRENT DETECTED ( {} )".format(self._current)) - - if self._current < float(self._undercurrent): - self.fail("failed: UNDERCURRENT DETECTED ( {} )".format(self._current)) -- cgit v1.1