From 69bd724d3861dfee28158e734f83463c3f620239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= Date: Sat, 15 Apr 2017 18:09:16 +0100 Subject: serial drivers: if no --device parameter is given, look for default cable. pyserial makes it very easy to look for a serial port based on VID/PID pairs, so use those when possible. Unfortunately serial drivers are also the least reliable as all of the cables but Abbott's use generic IDs. This keeps in the direction of solving Issue 9. --- glucometerutils/drivers/fsoptium.py | 9 ++++----- glucometerutils/drivers/otultra2.py | 10 +++++----- glucometerutils/drivers/otultraeasy.py | 10 +++++----- glucometerutils/drivers/sdcodefree.py | 13 +++++++------ 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/glucometerutils/drivers/fsoptium.py b/glucometerutils/drivers/fsoptium.py index 2be063e..a380c96 100644 --- a/glucometerutils/drivers/fsoptium.py +++ b/glucometerutils/drivers/fsoptium.py @@ -80,12 +80,11 @@ def _parse_clock(datestr): class Device(object): def __init__(self, device): if not device: - raise exceptions.CommandLineError( - '--device parameter is required, should point to the serial device ' - 'connected to the meter.') + logging.info('No --device parameter provided, looking for default cable.') + device = 'hwgrep://1a61:3420' - self.serial_ = serial.Serial( - port=device, baudrate=19200, bytesize=serial.EIGHTBITS, + self.serial_ = serial.serial_for_url( + device, baudrate=19200, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=1, xonxoff=True, rtscts=False, dsrdtr=False, writeTimeout=None) diff --git a/glucometerutils/drivers/otultra2.py b/glucometerutils/drivers/otultra2.py index 21d6743..28a4771 100644 --- a/glucometerutils/drivers/otultra2.py +++ b/glucometerutils/drivers/otultra2.py @@ -7,6 +7,7 @@ __copyright__ = 'Copyright © 2013-2017, Diego Elio Pettenò' __license__ = 'MIT' import datetime +import logging import re import serial @@ -125,12 +126,11 @@ def _parse_datetime(response): class Device(object): def __init__(self, device): if not device: - raise exceptions.CommandLineError( - '--device parameter is required, should point to the serial device ' - 'connected to the meter.') + logging.info('No --device parameter provided, looking for default cable.') + device = 'hwgrep://067b:2303' - self.serial_ = serial.Serial( - port=device, baudrate=9600, bytesize=serial.EIGHTBITS, + self.serial_ = serial.serial_for_url( + device, baudrate=9600, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=1, xonxoff=False, rtscts=False, dsrdtr=False, writeTimeout=None) diff --git a/glucometerutils/drivers/otultraeasy.py b/glucometerutils/drivers/otultraeasy.py index ce68625..2976b9e 100644 --- a/glucometerutils/drivers/otultraeasy.py +++ b/glucometerutils/drivers/otultraeasy.py @@ -8,6 +8,7 @@ __license__ = 'MIT' import array import datetime +import logging import re import struct import time @@ -178,12 +179,11 @@ class _Packet(object): class Device(object): def __init__(self, device): if not device: - raise exceptions.CommandLineError( - '--device parameter is required, should point to the serial device ' - 'connected to the meter.') + logging.info('No --device parameter provided, looking for default cable.') + device = 'hwgrep://067b:2303' - self.serial_ = serial.Serial( - port=device, baudrate=9600, bytesize=serial.EIGHTBITS, + self.serial_ = serial.serial_for_url( + device, baudrate=9600, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=1, xonxoff=False, rtscts=False, dsrdtr=False, writeTimeout=None) diff --git a/glucometerutils/drivers/sdcodefree.py b/glucometerutils/drivers/sdcodefree.py index 19644f6..0cd0b28 100644 --- a/glucometerutils/drivers/sdcodefree.py +++ b/glucometerutils/drivers/sdcodefree.py @@ -10,6 +10,7 @@ import array import collections import datetime import functools +import logging import operator import struct import time @@ -66,12 +67,12 @@ def xor_checksum(msg): class Device(object): def __init__(self, device): if not device: - raise exceptions.CommandLineError( - '--device parameter is required, should point to the serial ' - 'device connected to the meter.') + logging.info( + 'No --device parameter provided, looking for default cable.') + device = 'hwgrep://10c4:ea60' - self.serial_ = serial.Serial( - port=device, baudrate=38400, bytesize=serial.EIGHTBITS, + self.serial_ = serial.serial_for_url( + device, baudrate=38400, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=300, xonxoff=False, rtscts=False, dsrdtr=False, writeTimeout=None) @@ -177,7 +178,7 @@ class Device(object): # The date we return should only include up to minute, unfortunately. return datetime.datetime(date.year, date.month, date.day, - date.hour, date.minute) + date.hour, date.minute) def zero_log(self): raise NotmplementedError -- cgit v1.2.3