From f02d742f17eb6bc018b5464d71474a3e63bb90e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= Date: Sat, 7 Dec 2013 23:50:21 +0000 Subject: Add a new command to dump the identification of the glucometer. This allows to get the serial number, as well as other details about the glucometer once it's installed. --- glucometer.py | 12 ++++++++---- glucometerutils/drivers/otultra2.py | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/glucometer.py b/glucometer.py index baa21ca..d9fbf68 100755 --- a/glucometer.py +++ b/glucometer.py @@ -27,6 +27,11 @@ def main(): '--device', action='store', required=True, help='Select the path to the glucometer device.') + subparsers.add_parser( + 'info', help='Display information about the meter.') + subparsers.add_parser( + 'zero', help='Zero out the data log of the meter.') + parser_dump = subparsers.add_parser( 'dump', help='Dump the readings stored in the device.') parser_dump.add_argument( @@ -39,15 +44,14 @@ 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) device = driver.Device(args.device) - if args.action == 'dump': + if args.action == 'info': + print(device.get_information_string()) + elif args.action == 'dump': for reading in device.get_readings(): print('%s,%.2f,%s' % (reading.timestamp, reading.get_value_as(args.unit), reading.comment)) diff --git a/glucometerutils/drivers/otultra2.py b/glucometerutils/drivers/otultra2.py index d4db307..4f275ba 100644 --- a/glucometerutils/drivers/otultra2.py +++ b/glucometerutils/drivers/otultra2.py @@ -82,7 +82,25 @@ class Device(object): line = self.serial_.readline().decode('ascii') return self._validate_and_strip_checksum(line) + def get_information_string(self): + """Returns a single string with all the identification information. + + Returns: + A string including the serial number, software version, date and time and + default unit. + """ + return ('OneTouch Ultra 2 glucometer\n' + 'Serial number: %s\n' + 'Software version: %s\n' + 'Time: %s\n' + 'Default unit: %s' % ( + self.get_serial_number(), + self.get_version(), + self.get_datetime(), + self.get_glucose_unit())) + def get_version(self): + """Returns an identifier of the firmware version of the glucometer. Returns: -- cgit v1.2.3