|
11 | 11 | from collections import OrderedDict |
12 | 12 | from math import log |
13 | 13 | import string |
14 | | -import abc |
15 | 14 |
|
16 | 15 | from basil.HL.HardwareLayer import HardwareLayer |
17 | 16 |
|
@@ -115,15 +114,13 @@ def _read_eeprom(self, address, size): |
115 | 114 | return data |
116 | 115 |
|
117 | 116 | def _write_eeprom(self, address, data): |
118 | | - raise NotImplementedError() |
| 117 | + raise NotImplementedError("_write_eeprom() not implemented") |
119 | 118 |
|
120 | 119 |
|
121 | 120 | class Fei4Dcs(object): |
122 | 121 | '''FEI4AdapterCard interface |
123 | 122 | ''' |
124 | 123 |
|
125 | | - __metaclass__ = abc.ABCMeta |
126 | | - |
127 | 124 | # EEPROM |
128 | 125 | HEADER_ADDR = 0 |
129 | 126 | HEADER_FORMAT = '>H' # Version of EEPROM data |
@@ -210,17 +207,14 @@ def get_id(self): |
210 | 207 | ret = self._read_eeprom(self.ID_ADDR, size=calcsize(self.ID_FORMAT)) |
211 | 208 | return unpack_from(self.ID_FORMAT, ret)[0] |
212 | 209 |
|
213 | | - @abc.abstractmethod |
214 | 210 | def _get_adc_value(self, channel): |
215 | | - pass |
| 211 | + raise NotImplementedError("_get_adc_value() not implemented") |
216 | 212 |
|
217 | | - @abc.abstractmethod |
218 | 213 | def _set_dac_value(self, channel, value): |
219 | | - pass |
| 214 | + raise NotImplementedError("_set_dac_value() not implemented") |
220 | 215 |
|
221 | | - @abc.abstractmethod |
222 | 216 | def _read_eeprom(self, address, size): |
223 | | - pass |
| 217 | + raise NotImplementedError("_read_eeprom() not implemented") |
224 | 218 |
|
225 | 219 |
|
226 | 220 | class FEI4AdapterCard(AdcMax1239, DacMax520, Eeprom24Lc128, Fei4Dcs): |
@@ -329,20 +323,20 @@ def init(self): |
329 | 323 | # read calibration |
330 | 324 | if not self._init['no_calibration']: |
331 | 325 | self.read_eeprom_calibration() |
332 | | - logger.info('Found adapter card: {}'.format('%s with ID %s' % ('Single Chip Adapter Card', self.get_id()))) |
| 326 | + logger.info('Found adapter card: {}'.format('%s with ID %s' % ('FEI4 Single Chip Adapter Card', self.get_id()))) |
333 | 327 | else: |
334 | | - logger.info('FEI4AdapterCard: Using default calibration.') |
| 328 | + logger.info('FEI4 Single Chip Adapter Card: skip reading calibration parameters from EEPROM') |
335 | 329 |
|
336 | 330 | def read_eeprom_calibration(self, temperature=False): # use default values for temperature, EEPROM values are usually not calibrated and random |
337 | 331 | '''Reading EEPROM calibration for power regulators and temperature |
338 | 332 | ''' |
339 | 333 | header = self.get_format() |
340 | 334 | if header == self.HEADER_V1: |
341 | 335 | data = self._read_eeprom(self.CAL_DATA_ADDR, size=calcsize(self.CAL_DATA_V1_FORMAT)) |
342 | | - for idx, channel in enumerate(self._ch_cal.iterkeys()): |
| 336 | + for idx, channel in enumerate(self._ch_cal.keys()): |
343 | 337 | ch_data = data[idx * calcsize(self.CAL_DATA_CH_V1_FORMAT):(idx + 1) * calcsize(self.CAL_DATA_CH_V1_FORMAT)] |
344 | 338 | values = unpack_from(self.CAL_DATA_CH_V1_FORMAT, ch_data) |
345 | | - self._ch_cal[channel]['name'] = "".join([c for c in values[0] if (c in string.printable)]) # values[0].strip() |
| 339 | + self._ch_cal[channel]['name'] = "".join([c for c in values[0].decode('utf-8', errors='ignore') if (c in string.printable)]) # values[0].strip() |
346 | 340 | self._ch_cal[channel]['default'] = values[1] |
347 | 341 | self._ch_cal[channel]['ADCI']['gain'] = values[2] |
348 | 342 | self._ch_cal[channel]['ADCI']['offset'] = values[3] |
@@ -389,7 +383,7 @@ def get_temperature(self, channel, sensor='VNTC'): |
389 | 383 | kwargs = self._ch_map[channel][sensor] |
390 | 384 | temp_raw = self._get_adc_value(**kwargs) |
391 | 385 |
|
392 | | - v_adc = ((temp_raw - self._ch_cal.items()[0][1]['ADCV']['offset']) / self._ch_cal.items()[0][1]['ADCV']['gain']) # voltage, VDDA1 |
| 386 | + v_adc = ((temp_raw - list(self._ch_cal.items())[0][1]['ADCV']['offset']) / list(self._ch_cal.items())[0][1]['ADCV']['gain']) # voltage, VDDA1 |
393 | 387 | k = self._ch_cal[channel][sensor]['R4'] / (self._ch_cal[channel][sensor]['R2'] + self._ch_cal[channel][sensor]['R4']) # reference voltage divider |
394 | 388 | r_ntc = self._ch_cal[channel][sensor]['R1'] * (k - v_adc / self._ch_cal[channel][sensor]['VREF']) / (1 - k + v_adc / self._ch_cal[channel][sensor]['VREF']) # NTC resistance |
395 | 389 |
|
|
0 commit comments