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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 return status | 149 return status |
150 | 150 |
151 | 151 |
152 def SetVoltage(self, v): | 152 def SetVoltage(self, v): |
153 """Set the output voltage, 0 to disable.""" | 153 """Set the output voltage, 0 to disable.""" |
154 if v == 0: | 154 if v == 0: |
155 self._SendStruct('BBB', 0x01, 0x01, 0x00) | 155 self._SendStruct('BBB', 0x01, 0x01, 0x00) |
156 else: | 156 else: |
157 self._SendStruct('BBB', 0x01, 0x01, int((v - 2.0) * 100)) | 157 self._SendStruct('BBB', 0x01, 0x01, int((v - 2.0) * 100)) |
158 | 158 |
| 159 def SetStartupCurrent(self, a): |
| 160 """Set the max startup output current. the unit of |a| : Amperes """ |
| 161 assert a >= 0 and a <= 8 |
159 | 162 |
160 def SetMaxCurrent(self, i): | 163 val = 1023 - int((a/8.0)*1023) |
161 """Set the max output current.""" | 164 self._SendStruct('BBB', 0x01, 0x08, val & 0xff) |
162 assert i >= 0 and i <= 8 | 165 self._SendStruct('BBB', 0x01, 0x09, val >> 8) |
163 | 166 |
164 val = 1023 - int((i/8)*1023) | 167 def SetMaxCurrent(self, a): |
| 168 """Set the max output current. the unit of |a| : Amperes """ |
| 169 assert a >= 0 and a <= 8 |
| 170 |
| 171 val = 1023 - int((a/8.0)*1023) |
165 self._SendStruct('BBB', 0x01, 0x0a, val & 0xff) | 172 self._SendStruct('BBB', 0x01, 0x0a, val & 0xff) |
166 self._SendStruct('BBB', 0x01, 0x0b, val >> 8) | 173 self._SendStruct('BBB', 0x01, 0x0b, val >> 8) |
167 | 174 |
168 def SetUsbPassthrough(self, val): | 175 def SetUsbPassthrough(self, val): |
169 """Set the USB passthrough mode: 0 = off, 1 = on, 2 = auto.""" | 176 """Set the USB passthrough mode: 0 = off, 1 = on, 2 = auto.""" |
170 self._SendStruct('BBB', 0x01, 0x10, val) | 177 self._SendStruct('BBB', 0x01, 0x10, val) |
171 | 178 |
172 | 179 |
173 def StartDataCollection(self): | 180 def StartDataCollection(self): |
174 """Tell the device to start collecting and sending measurement data.""" | 181 """Tell the device to start collecting and sending measurement data.""" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 logging.error('exception from serial port') | 286 logging.error('exception from serial port') |
280 return None | 287 return None |
281 elif len(ready_r) > 0: | 288 elif len(ready_r) > 0: |
282 flushed += 1 | 289 flushed += 1 |
283 self.ser.read(1) # This may cause underlying buffering. | 290 self.ser.read(1) # This may cause underlying buffering. |
284 self.ser.flush() # Flush the underlying buffer too. | 291 self.ser.flush() # Flush the underlying buffer too. |
285 else: | 292 else: |
286 break | 293 break |
287 if flushed > 0: | 294 if flushed > 0: |
288 logging.debug('dropped >%d bytes', flushed) | 295 logging.debug('dropped >%d bytes', flushed) |
OLD | NEW |