[ADD]Added Upstream Patch for hw_scale module

This commit is contained in:
Riddhi Kansara 2018-07-19 17:13:31 +05:30
parent 1260eab566
commit 1a1e197981

View File

@ -28,7 +28,7 @@ except ImportError:
def _toledo8217StatusParse(status): def _toledo8217StatusParse(status):
""" Parse a scale's status, returning a `(weight, weight_info)` pair. """ """ Parse a scale's status, returning a `(weight, weight_info)` pair. """
weight, weight_info = None, None weight, weight_info = None, None
stat = ord(status[status.index('?') + 1]) stat = status[status.index(b'?') + 1]
if stat == 0: if stat == 0:
weight_info = 'ok' weight_info = 'ok'
else: else:
@ -68,17 +68,17 @@ Toledo8217Protocol = ScaleProtocol(
parity=serial.PARITY_EVEN, parity=serial.PARITY_EVEN,
timeout=1, timeout=1,
writeTimeout=1, writeTimeout=1,
weightRegexp="\x02\\s*([0-9.]+)N?\\r", weightRegexp=b"\x02\\s*([0-9.]+)N?\\r",
statusRegexp="\x02\\s*(\\?.)\\r", statusRegexp=b"\x02\\s*(\\?.)\\r",
statusParse=_toledo8217StatusParse, statusParse=_toledo8217StatusParse,
commandDelay=0.2, commandDelay=0.2,
weightDelay=0.5, weightDelay=0.5,
newWeightDelay=0.2, newWeightDelay=0.2,
commandTerminator='', commandTerminator=b'',
weightCommand='W', weightCommand=b'W',
zeroCommand='Z', zeroCommand=b'Z',
tareCommand='T', tareCommand=b'T',
clearCommand='C', clearCommand=b'C',
emptyAnswerValid=False, emptyAnswerValid=False,
autoResetWeight=False, autoResetWeight=False,
) )
@ -98,15 +98,15 @@ ADAMEquipmentProtocol = ScaleProtocol(
weightRegexp=r"\s*([0-9.]+)kg", # LABEL format 3 + KG in the scale settings, but Label 1/2 should work weightRegexp=r"\s*([0-9.]+)kg", # LABEL format 3 + KG in the scale settings, but Label 1/2 should work
statusRegexp=None, statusRegexp=None,
statusParse=None, statusParse=None,
commandTerminator="\r\n", commandTerminator=b"\r\n",
commandDelay=0.2, commandDelay=0.2,
weightDelay=0.5, weightDelay=0.5,
newWeightDelay=5, # AZExtra beeps every time you ask for a weight that was previously returned! newWeightDelay=5, # AZExtra beeps every time you ask for a weight that was previously returned!
# Adding an extra delay gives the operator a chance to remove the products # Adding an extra delay gives the operator a chance to remove the products
# before the scale starts beeping. Could not find a way to disable the beeps. # before the scale starts beeping. Could not find a way to disable the beeps.
weightCommand='P', weightCommand=b'P',
zeroCommand='Z', zeroCommand=b'Z',
tareCommand='T', tareCommand=b'T',
clearCommand=None, # No clear command -> Tare again clearCommand=None, # No clear command -> Tare again
emptyAnswerValid=True, # AZExtra does not answer unless a new non-zero weight has been detected emptyAnswerValid=True, # AZExtra does not answer unless a new non-zero weight has been detected
autoResetWeight=True, # AZExtra will not return 0 after removing products autoResetWeight=True, # AZExtra will not return 0 after removing products
@ -165,8 +165,8 @@ class Scale(Thread):
if not char: if not char:
break break
else: else:
answer.append(char) answer.append(bytes(char))
return ''.join(answer) return b''.join(answer)
def _parse_weight_answer(self, protocol, answer): def _parse_weight_answer(self, protocol, answer):
""" Parse a scale's answer to a weighing request, returning """ Parse a scale's answer to a weighing request, returning