From 610bc3e3ed988c0e9a494fdff2b1ba41df906ebe Mon Sep 17 00:00:00 2001 From: Christian Tremblay Date: Thu, 5 Nov 2015 15:48:47 -0500 Subject: [PATCH] There was a bug that make point read twice...for nothing Repaired bug with match fucntion delay=0 will stop it and release status Signed-off-by: Christian Tremblay --- BAC0/core/app/ScriptApplication.py | 5 +++-- BAC0/core/devices/Device.py | 14 ++++++++++---- BAC0/core/devices/Points.py | 17 +++++++++++------ BAC0/infos.py | 2 +- BAC0/tasks/Match.py | 6 ++++-- 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/BAC0/core/app/ScriptApplication.py b/BAC0/core/app/ScriptApplication.py index 6994110a..a47ca2bc 100644 --- a/BAC0/core/app/ScriptApplication.py +++ b/BAC0/core/app/ScriptApplication.py @@ -37,7 +37,7 @@ from threading import Event from queue import Queue -from ..io.IOExceptions import WriteAccessDenied +from ..io.IOExceptions import WriteAccessDenied, NoResponseFromController # some debugging _DEBUG = 0 @@ -174,13 +174,14 @@ def confirmation(self, apdu): evt = Event() self.ResponseQueue.put((None, evt)) evt.wait() - raise WriteAccessDenied + raise WriteAccessDenied('Cannot write to point') elif isinstance(apdu, AbortPDU): print('Abort PDU') evt = Event() self.ResponseQueue.put((None, evt)) evt.wait() + raise NoResponseFromController('Abort PDU received') if isinstance(apdu, SimpleAckPDU): evt = Event() diff --git a/BAC0/core/devices/Device.py b/BAC0/core/devices/Device.py index 27af015c..4b805c59 100644 --- a/BAC0/core/devices/Device.py +++ b/BAC0/core/devices/Device.py @@ -7,6 +7,7 @@ #from ..functions.discoverPoints import discoverPoints from .Points import NumericPoint, BooleanPoint, EnumPoint +from ..io.IOExceptions import NoResponseFromController, WriteAccessDenied try: import pandas as pd @@ -222,7 +223,7 @@ def __getitem__(self,key): :returns: (Point) the point (can be Numeric, Boolean or Enum) """ # Read point value and store it - self._findPoint(key).value + #self._findPoint(key).value # return the point itself return self._findPoint(key) @@ -285,9 +286,13 @@ def _discoverPoints(self): If pandas can't be found, df will be a simple array """ - pss = self.network.read( - '%s device %s protocolServicesSupported' % - (self.addr, self.deviceID)) + try: + pss = self.network.read( + '%s device %s protocolServicesSupported' % + (self.addr, self.deviceID)) + except NoResponseFromController as error: + print('Controller not found, aborting. (%s)' % error) + return ('Not Found', '', [], [], []) deviceName = self.network.read( '%s device %s objectName' % (self.addr, self.deviceID)) @@ -375,6 +380,7 @@ def _findPoint(self, name): """ for point in self.points: if point.properties.name == name: + point.value return point raise ValueError("%s doesn't exist in controller" % name) diff --git a/BAC0/core/devices/Points.py b/BAC0/core/devices/Points.py index 150da8ed..e0eabf0c 100644 --- a/BAC0/core/devices/Points.py +++ b/BAC0/core/devices/Points.py @@ -143,7 +143,7 @@ def write(self, value, *, prop='presentValue', priority=''): (self.properties.device.addr, self.properties.type, str( self.properties.address), prop, str(value), str(priority))) except Exception: - raise NoResponseFromController + raise NoResponseFromController() # Read after the write so history gets updated. self.value @@ -263,7 +263,7 @@ def match(self, point, *, delay=5): command=point, status=self, delay=delay) self._match_task.task.start() self._match_task.running = True - elif self._match_task.running: + elif self._match_task.running and delay > 0: self._match_task.task.stop() self._match_task.running = False time.sleep(1) @@ -271,6 +271,9 @@ def match(self, point, *, delay=5): command=point, status=self, delay=delay) self._match_task.task.start() self._match_task.running = True + elif self._match_task.running and delay == 0: + self._match_task.task.stop() + self._match_task.running = False else: raise RuntimeError('Stop task before redefining it') @@ -307,6 +310,8 @@ def _set(self, value): self._setitem(value) else: try: + if isinstance(value,Point): + value = value.history[-1] val = float(value) if isinstance(val, float): self._setitem(value) @@ -314,7 +319,7 @@ def _set(self, value): raise ValueError('Value must be numeric') def __repr__(self): - return '%s : %.2f %s' % (self.properties.name, self.value, self.properties.units_state) + return '%s : %.2f %s' % (self.properties.name, self.history[-1], self.properties.units_state) def __add__(self,other): return self.value + other @@ -381,7 +386,7 @@ def boolValue(self): """ returns : (boolean) Value """ - if self.value == 'active': + if self.history[-1] == 'active': self._key = 1 self._boolKey = True else: @@ -446,7 +451,7 @@ def enumValue(self): """ returns: (str) Enum state value """ - return self.properties.units_state[int(self.value) - 1] + return self.properties.units_state[int(self.history[-1]) - 1] @property def units(self): @@ -468,4 +473,4 @@ def __repr__(self): return '%s : %s' % (self.properties.name, self.enumValue) def __eq__(self,other): - return self.value == other \ No newline at end of file + return self.value == self.properties.units_state.index(other) + 1 \ No newline at end of file diff --git a/BAC0/infos.py b/BAC0/infos.py index 045ce069..df6a7862 100644 --- a/BAC0/infos.py +++ b/BAC0/infos.py @@ -12,5 +12,5 @@ __email__ = 'christian.tremblay@servisys.com' __url__ = 'https://github.com/ChristianTremblay/BAC0' __download_url__ = 'https://github.com/ChristianTremblay/BAC0/archive/master.zip' -__version__ = '0.98.3.1' +__version__ = '0.98.3.2' __license__ = 'LGPLv3' \ No newline at end of file diff --git a/BAC0/tasks/Match.py b/BAC0/tasks/Match.py index 85a4317f..fcf4e3d4 100644 --- a/BAC0/tasks/Match.py +++ b/BAC0/tasks/Match.py @@ -25,5 +25,7 @@ def __init__(self, command = None, status = None, delay=5): def task(self): self.status._setitem(self.command.value) - def beforeStop(self): - self.status = 'auto' + def stop(self): + self.status._setitem('auto') + self.exitFlag = True +