Lines Matching refs:self
66 def __init__(self, device=None, serialno=None, wait=1): argument
75 self._coarse_ref = self._fine_ref = self._coarse_zero = self._fine_zero = 0
76 self._coarse_scale = self._fine_scale = 0
77 self._last_seq = 0
78 self.start_voltage = 0
81 self.ser = serial.Serial(device, timeout=1)
88 self._tempfile = open(tmpname, "w")
94 fcntl.lockf(self._tempfile, fcntl.LOCK_EX | fcntl.LOCK_NB)
100 self.ser = serial.Serial("/dev/%s" % dev, timeout=1)
101 self.StopDataCollection() # just in case
102 self._FlushInput() # discard stale input
103 status = self.GetStatus()
114 self.start_voltage = status["voltage1"]
117 self._tempfile = None
123 def GetStatus(self): argument
144 self._SendStruct("BBB", 0x01, 0x00, 0x00)
146 bytes = self._ReadPacket()
171 def RampVoltage(self, start, end): argument
175 self.SetVoltage(v)
178 self.SetVoltage(end)
180 def SetVoltage(self, v): argument
183 self._SendStruct("BBB", 0x01, 0x01, 0x00)
185 self._SendStruct("BBB", 0x01, 0x01, int((v - 2.0) * 100))
188 def SetMaxCurrent(self, i): argument
193 self._SendStruct("BBB", 0x01, 0x0a, val & 0xff)
194 self._SendStruct("BBB", 0x01, 0x0b, val >> 8)
196 def SetUsbPassthrough(self, val): argument
198 self._SendStruct("BBB", 0x01, 0x10, val)
201 def StartDataCollection(self): argument
203 self._SendStruct("BBB", 0x01, 0x1b, 0x01) # Mystery command
204 self._SendStruct("BBBBBBB", 0x02, 0xff, 0xff, 0xff, 0xff, 0x03, 0xe8)
207 def StopDataCollection(self): argument
209 self._SendStruct("BB", 0x03, 0x00) # stop
212 def CollectData(self): argument
215 bytes = self._ReadPacket()
226 if self._last_seq and seq & 0xF != (self._last_seq + 1) & 0xF:
228 self._last_seq = seq
231 if not self._coarse_scale or not self._fine_scale:
238 out.append(((main & ~1) - self._coarse_zero) * self._coarse_scale)
240 out.append((main - self._fine_zero) * self._fine_scale)
244 self._fine_zero = data[0][0]
245 self._coarse_zero = data[1][0]
250 self._fine_ref = data[0][0]
251 self._coarse_ref = data[1][0]
259 if self._coarse_ref != self._coarse_zero:
260 self._coarse_scale = 2.88 / (self._coarse_ref - self._coarse_zero)
261 if self._fine_ref != self._fine_zero:
262 self._fine_scale = 0.0332 / (self._fine_ref - self._fine_zero)
265 def _SendStruct(self, fmt, *args): argument
271 self.ser.write(out)
274 def _ReadPacket(self): argument
276 len_char = self.ser.read(1)
285 result = self.ser.read(data_len)
294 def _FlushInput(self): argument
296 self.ser.flush()
299 ready_r, ready_w, ready_x = select.select([self.ser], [], [self.ser], 0)
305 self.ser.read(1) # This may cause underlying buffering.
306 self.ser.flush() # Flush the underlying buffer too.