From d00330fdf0cd12e71aaff53783c6f1b302840dc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= Date: Sat, 7 Dec 2013 23:25:12 +0000 Subject: otultra2: implement a zero log command to clear a device's memory. --- glucometer.py | 9 +++++++++ glucometerutils/drivers/otultra2.py | 12 +++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/glucometer.py b/glucometer.py index 1cd0303..baa21ca 100755 --- a/glucometer.py +++ b/glucometer.py @@ -39,6 +39,9 @@ def main(): '--set', action='store', nargs='?', const='now', default=None, help='Set the date rather than just reading it from the device.') + reset = subparsers.add_parser( + 'zero', help='Zero out the data log of the meter.') + args = parser.parse_args() driver = importlib.import_module('glucometerutils.drivers.' + args.driver) @@ -58,6 +61,12 @@ def main(): print('%s: not a valid date' % args.set, file=sys.stderr) else: print(device.get_datetime()) + elif args.action == 'zero': + try: + device.zero_log() + print('Device data log zeroed.') + except Exception as e: + print('Error while zeroing device log: %s' % e) else: return 1 diff --git a/glucometerutils/drivers/otultra2.py b/glucometerutils/drivers/otultra2.py index 1a29d36..d4db307 100644 --- a/glucometerutils/drivers/otultra2.py +++ b/glucometerutils/drivers/otultra2.py @@ -176,7 +176,18 @@ class Device(object): return self._parse_datetime(response[2:]) + def zero_log(self): + """Zeros out the data log of the device. + + This function will clear the memory of the device deleting all the readings + in an irrecoverable way. + """ + response = self._send_oneliner_command('DMZ') + if response != 'Z': + raise exceptions.InvalidResponse(response) + def _parse_glucose_unit(self, unit): + """Parses the value of a OneTouch Ultra Glucose unit definition. Args: @@ -265,7 +276,6 @@ class Device(object): yield common.Reading(date, int(line_data['value']), common.UNIT_MGDL, comment=comment) - # The following two hashes are taken directly from LifeScan's documentation _MEAL_CODES = { 'N': '', -- cgit v1.2.3