예제 #1
0
 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
예제 #2
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)
예제 #3
0
 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)
예제 #4
0
 def testOldADC7606_VOLTAGE(self):
     print(hex(legacy_encode(Q(6.85, 'V'), 'ADC7606_VOLTAGE')))
     print(hex(encode(Q(-3.15, 'V'), 'ADC7606_VOLTAGE')))
예제 #5
0
 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')
예제 #6
0
 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)
예제 #7
0
 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)
예제 #8
0
 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'))
예제 #9
0
 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'))
예제 #10
0
 def testNoneEncoding(self):
     self.assertEqual(encode(Q(-5, 'MHz')), 18446744073709551611)
예제 #11
0
 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
예제 #12
0
 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
예제 #13
0
 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)
예제 #14
0
 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 )