Product specifications
NRAO Linux Python Library
24
def _generate_checksum(self, bytes):
return chr(sum([ord(b) for b in bytes]) % 256)
def _verify_checksum(self, bytes, checksum):
return (self._generate_checksum(bytes) == checksum)
def _pack_freq_registers(self, ncount, frac, mod, dbf, old_bytes):
dbf_table = {1: 0, 2: 1, 4: 2, 8: 3, 16: 4}
reg0, reg1, reg2, reg3, reg4, reg5 = struct.unpack('>IIIIII', old_bytes)
reg0 &= 0x80000007
reg0 |= ((ncount & 0xffff) << 15) | ((frac & 0x0fff) << 3)
reg1 &= 0xffff8007
reg1 |= (mod & 0x0fff) << 3
reg4 &= 0xff8fffff
reg4 |= (dbf_table.get(dbf, 0)) << 20
return struct.pack('>IIIIII', reg0, reg1, reg2, reg3, reg4, reg5)
def _unpack_freq_registers(self, bytes):
dbf_rev_table = {0: 1, 1: 2, 2: 4, 3: 8, 4: 16}
reg0, reg1, reg2, reg3, reg4, reg5 = struct.unpack('>IIIIII', bytes)
ncount = (reg0 >> 15) & 0xffff
frac = (reg0 >> 3) & 0x0fff
mod = (reg1 >> 3) & 0x0fff
dbf = dbf_rev_table.get((reg4 >> 20) & 0x07, 1)
return ncount, frac, mod, dbf
def get_frequency(self, synth):
"""
Returns the current output frequency for the selected synthesizer.
@param synth : synthesizer this command affects (0 for 1, 8 for 2).
@type synth : int
@return: the frequency in MHz (float)
"""
self.conn.open()
bytes = struct.pack('>B', 0x80 | synth)
self.conn.write(bytes)
bytes = self.conn.read(24)
checksum = self.conn.read(1)
self.conn.close()
#self._verify_checksum(bytes, checksum)
ncount, frac, mod, dbf = self._unpack_freq_registers(bytes)
EPDF = self._getEPDF(synth)
return (ncount + float(frac) / mod) * EPDF / dbf
def set_frequency(self, synth, freq, chan_spacing = 10.):
"""
Sets the synthesizer to the desired frequency
Sets to the closest possible frequency, depending on the channel spacing.
Range is determined by the minimum and maximum VCO frequency.
@param synth : synthesizer this command affects (0 for 1, 8 for 2).
@type synth : int
@param freq : output frequency
@type freq : float
@param chan_spacing : output frequency increment
@type chan_spacing : float
@return: True if success (bool)
"""
min, max = self.get_vco_range(synth)
dbf = 1
while (freq * dbf) <= min and dbf <= 16:
dbf *= 2