def convertParameter(self, mag, encoding=None ): """ convert a dimensioned parameter to the binary value expected by the hardware. The conversion is determined by the variable encoding """ try: return encode(mag, encoding) except EncodingError as e: logging.getLogger(__name__).error("Error encoding {0} with '{1}': {2}".format(mag, encoding, str(e))) return 0
def testADC(self): self.assertEqual(encode(Q(-5, 'V'), 'ADC7606_VOLTAGE_OFFSET'), 0) self.assertEqual(encode(Q(0, 'V'), 'ADC7606_VOLTAGE_OFFSET'), 0x8000) self.assertEqual(encode(Q(4.9999, 'V'), 'ADC7606_VOLTAGE_OFFSET'), 0xffff) with self.assertRaises(EncodingError): self.assertEqual(encode(Q(5, 'V'), 'ADC7606_VOLTAGE_OFFSET'), 0xffff)
def testDefaults(self): self.assertEqual(legacy_encode(Q(2000, 'Hz'), None), encode(Q(2000, 'Hz'))) self.assertEqual(legacy_encode(12345, None), encode(12345, None)) self.assertEqual(legacy_encode(12345, None), encode(12345)) self.assertEqual(encode(18374687063787175937), 18374687063787175937) self.assertEqual(encode(0xffffffffffffffff), 0xffffffffffffffff)
def testOldADC7606_VOLTAGE(self): print(hex(legacy_encode(Q(6.85, 'V'), 'ADC7606_VOLTAGE'))) print(hex(encode(Q(-3.15, 'V'), 'ADC7606_VOLTAGE')))
def testADC7606_VOLTAGE(self): for value in (Q(2.345, 'V'), Q(-2.345, 'V'), Q(0.2, 'V'), Q(-0.2, 'V'), Q(4.99, 'V'),): self.assertEqual(encode(value, 'ADC7606_VOLTAGE'), legacy_encode(value, 'ADC7606_VOLTAGE')) for value in (Q(5.01, 'V'), Q(-5.01, 'V')): with self.assertRaises(EncodingError): encode(value, 'ADC7606_VOLTAGE')
def testUnsigned64(self): self.assertEqual(encode(256, 'unsigned64'), 256) self.assertEqual(encode(72057594037927937, 'unsigned64'), 72057594037927937) self.assertEqual(encode(0xffffffffffffffff, 'unsigned64'), 0xffffffffffffffff) with self.assertRaises(EncodingError): self.assertEqual(encode(-1, 'unsigned64'), 0xffffffffffffffff)
def testFallback(self): self.assertEqual(encode(256), 256) self.assertEqual(encode(72057594037927937), 72057594037927937) self.assertEqual(encode(Q(6.076, 'kHz')), 6) self.assertEqual(encode(0xffffffffffffffff), 0xffffffffffffffff) self.assertEqual(encode(-1), 0xffffffffffffffff)
def testTime(self): self.assertEqual(encode(Q(100, 'ns')), 20) self.assertEqual(encode(Q(100, 'us')), 20000) self.assertEqual(encode(Q(200, 'us')), 40000) with self.assertRaises(EncodingError): encode(Q(-100, 'ns'))
def testDDS(self): self.assertEqual(encode(Q(500, 'MHz'), 'AD9912_FRQ'), 0x800000000000) self.assertEqual(encode(Q(500, 'MHz'), 'AD9912_FRQ'), legacy_encode(Q(500, 'MHz'), 'AD9912_FRQ'))
def testNoneEncoding(self): self.assertEqual(encode(Q(-5, 'MHz')), 18446744073709551611)
def setVoltage(self, channel, voltage, autoApply=False, applyAll=False): intVoltage = encode( voltage, self.dacInfo.encoding ) code = (2 if applyAll else 3) if autoApply else 0 self.sendCommand(channel, code, intVoltage) return intVoltage
def setVoltage(self, channel, voltage, autoApply=False, applyAll=False): intVoltage = encode(voltage, self.dacInfo.encoding) code = (2 if applyAll else 3) if autoApply else 0 self.sendCommand(channel, code, intVoltage) return intVoltage
def onDCThreshold(self, value): binvalue = encode(value, self.settings.onBoardADCEncoding ) if self.lockSettings.enableDCThreshold else 0 self.controller.setDCThreshold(binvalue) self.lockSettings.dcThreshold = value self.dataChanged.emit(self.lockSettings)
def onDCThreshold(self, value): binvalue = encode(value, self.settings.onBoardADCEncoding) if self.lockSettings.enableDCThreshold else 0 self.controller.setDCThreshold( binvalue ) self.lockSettings.dcThreshold = value self.dataChanged.emit( self.lockSettings )