OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Interface for a USB-connected Monsoon power meter. | 5 """Interface for a USB-connected Monsoon power meter. |
6 | 6 |
7 http://msoon.com/LabEquipment/PowerMonitor/ | 7 http://msoon.com/LabEquipment/PowerMonitor/ |
8 Currently Unix-only. Relies on fcntl, /dev, and /tmp. | 8 Currently Unix-only. Relies on fcntl, /dev, and /tmp. |
9 """ | 9 """ |
10 | 10 |
(...skipping 26 matching lines...) Expand all Loading... |
37 """ | 37 """ |
38 | 38 |
39 def __init__(self, device=None, serialno=None, wait=True): | 39 def __init__(self, device=None, serialno=None, wait=True): |
40 """Establish a connection to a Monsoon. | 40 """Establish a connection to a Monsoon. |
41 | 41 |
42 By default, opens the first available port, waiting if none are ready. | 42 By default, opens the first available port, waiting if none are ready. |
43 A particular port can be specified with 'device', or a particular Monsoon | 43 A particular port can be specified with 'device', or a particular Monsoon |
44 can be specified with 'serialno' (using the number printed on its back). | 44 can be specified with 'serialno' (using the number printed on its back). |
45 With wait=False, IOError is thrown if a device is not immediately available. | 45 With wait=False, IOError is thrown if a device is not immediately available. |
46 """ | 46 """ |
| 47 assert float(serial.VERSION) >= 2.7, \ |
| 48 'Monsoon requires pyserial v2.7 or later. You have %s' % serial.VERSION |
47 | 49 |
48 self._coarse_ref = self._fine_ref = self._coarse_zero = self._fine_zero = 0 | 50 self._coarse_ref = self._fine_ref = self._coarse_zero = self._fine_zero = 0 |
49 self._coarse_scale = self._fine_scale = 0 | 51 self._coarse_scale = self._fine_scale = 0 |
50 self._last_seq = 0 | 52 self._last_seq = 0 |
51 self._voltage_multiplier = None | 53 self._voltage_multiplier = None |
52 | 54 |
53 if device: | 55 if device: |
54 self.ser = serial.Serial(device, timeout=1) | 56 self.ser = serial.Serial(device, timeout=1) |
55 return | 57 return |
56 | 58 |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 logging.error('exception from serial port') | 278 logging.error('exception from serial port') |
277 return None | 279 return None |
278 elif len(ready_r) > 0: | 280 elif len(ready_r) > 0: |
279 flushed += 1 | 281 flushed += 1 |
280 self.ser.read(1) # This may cause underlying buffering. | 282 self.ser.read(1) # This may cause underlying buffering. |
281 self.ser.flush() # Flush the underlying buffer too. | 283 self.ser.flush() # Flush the underlying buffer too. |
282 else: | 284 else: |
283 break | 285 break |
284 if flushed > 0: | 286 if flushed > 0: |
285 logging.debug('dropped >%d bytes', flushed) | 287 logging.debug('dropped >%d bytes', flushed) |
OLD | NEW |