diff options
Diffstat (limited to 'dexcom_reader/readdata.py')
-rw-r--r-- | dexcom_reader/readdata.py | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/dexcom_reader/readdata.py b/dexcom_reader/readdata.py index e589b1a..84c2356 100644 --- a/dexcom_reader/readdata.py +++ b/dexcom_reader/readdata.py | |||
@@ -11,7 +11,7 @@ import re | |||
11 | import util | 11 | import util |
12 | import xml.etree.ElementTree as ET | 12 | import xml.etree.ElementTree as ET |
13 | import platform | 13 | import platform |
14 | 14 | import termios | |
15 | 15 | ||
16 | class ReadPacket(object): | 16 | class ReadPacket(object): |
17 | def __init__(self, command, data): | 17 | def __init__(self, command, data): |
@@ -74,10 +74,20 @@ class Dexcom(object): | |||
74 | return self._port | 74 | return self._port |
75 | 75 | ||
76 | def write(self, *args, **kwargs): | 76 | def write(self, *args, **kwargs): |
77 | return self.port.write(*args, **kwargs) | 77 | try: |
78 | return self.port.write(*args, **kwargs) | ||
79 | except ValueError: | ||
80 | raise constants.SerialPortError | ||
81 | except termios.error: | ||
82 | raise constants.SerialPortError | ||
78 | 83 | ||
79 | def read(self, *args, **kwargs): | 84 | def read(self, *args, **kwargs): |
80 | return self.port.read(*args, **kwargs) | 85 | try: |
86 | return self.port.read(*args, **kwargs) | ||
87 | except ValueError: | ||
88 | raise constants.SerialPortError | ||
89 | except termios.error: | ||
90 | raise constants.SerialPortError | ||
81 | 91 | ||
82 | def readpacket(self, timeout=None): | 92 | def readpacket(self, timeout=None): |
83 | total_read = 4 | 93 | total_read = 4 |
@@ -218,11 +228,21 @@ class Dexcom(object): | |||
218 | return ET.fromstring(data) | 228 | return ET.fromstring(data) |
219 | 229 | ||
220 | def flush(self): | 230 | def flush(self): |
221 | self.port.flush() | 231 | try: |
232 | self.port.flush() | ||
233 | except ValueError: | ||
234 | raise constants.SerialPortError | ||
235 | except termios.error: | ||
236 | raise constants.SerialPortError | ||
222 | 237 | ||
223 | def clear(self): | 238 | def clear(self): |
224 | self.port.flushInput() | 239 | try: |
225 | self.port.flushOutput() | 240 | self.port.flushInput() |
241 | self.port.flushOutput() | ||
242 | except ValueError: | ||
243 | raise constants.SerialPortError | ||
244 | except termios.error: | ||
245 | raise constants.SerialPortError | ||
226 | 246 | ||
227 | def GetFirmwareHeader(self): | 247 | def GetFirmwareHeader(self): |
228 | i = self.GenericReadCommand(constants.READ_FIRMWARE_HEADER) | 248 | i = self.GenericReadCommand(constants.READ_FIRMWARE_HEADER) |