Skip to content

Commit

Permalink
There was a bug that make point read twice...for nothing
Browse files Browse the repository at this point in the history
Repaired bug with match fucntion delay=0 will stop it and release status

Signed-off-by: Christian Tremblay <christian.tremblay@servisys.com>
  • Loading branch information
ChristianTremblay committed Nov 5, 2015
1 parent 848cbb9 commit 610bc3e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
5 changes: 3 additions & 2 deletions BAC0/core/app/ScriptApplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
14 changes: 10 additions & 4 deletions BAC0/core/devices/Device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)

Expand Down
17 changes: 11 additions & 6 deletions BAC0/core/devices/Points.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -263,14 +263,17 @@ 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)
self._match_task.task = Match(
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')

Expand Down Expand Up @@ -307,14 +310,16 @@ 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)
except:
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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand All @@ -468,4 +473,4 @@ def __repr__(self):
return '%s : %s' % (self.properties.name, self.enumValue)

def __eq__(self,other):
return self.value == other
return self.value == self.properties.units_state.index(other) + 1
2 changes: 1 addition & 1 deletion BAC0/infos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
6 changes: 4 additions & 2 deletions BAC0/tasks/Match.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 610bc3e

Please sign in to comment.