From 89dc59ed3858ad28c4f67c4cd7cf9c5712deea0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= Date: Wed, 29 Jan 2014 21:35:39 +0000 Subject: Add connect/disconnect methods to otultra2 and send \x11\r on connection. The otultraeasy requires explicit connect/disconnect so implementing this before is helpful. --- glucometer.py | 4 ++++ glucometerutils/drivers/otultra2.py | 13 ++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/glucometer.py b/glucometer.py index 1131042..e22ff23 100755 --- a/glucometer.py +++ b/glucometer.py @@ -53,6 +53,8 @@ def main(): driver = importlib.import_module('glucometerutils.drivers.' + args.driver) device = driver.Device(args.device) + device.connect() + try: if args.action == 'info': print(device.get_information_string()) @@ -95,5 +97,7 @@ def main(): print('Error while executing \'%s\': %s' % (args.action, str(err))) return 1 + device.disconnect() + if __name__ == "__main__": main() diff --git a/glucometerutils/drivers/otultra2.py b/glucometerutils/drivers/otultra2.py index dc03c97..3af78fc 100644 --- a/glucometerutils/drivers/otultra2.py +++ b/glucometerutils/drivers/otultra2.py @@ -110,16 +110,20 @@ class Device(object): parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=1, xonxoff=False, rtscts=False, dsrdtr=False, writeTimeout=None) + def connect(self): + self.serial_.write(b'\x11\r') + self.serial_.flush() + + def disconnect(self): + return + def _send_command(self, cmd): """Send command interface. Args: cmd: command and parameters to send (without newline) - - This function exists to wrap the need to send the 0x11 0x0d prefix with - each command that wakes this model up. """ - cmdstring = bytes('\x11\r' + cmd + '\r', 'ascii') + cmdstring = bytes(cmd + '\r', 'ascii') self.serial_.write(cmdstring) self.serial_.flush() @@ -155,7 +159,6 @@ class Device(object): self.get_glucose_unit())) def get_version(self): - """Returns an identifier of the firmware version of the glucometer. Returns: -- cgit v1.2.3