def connectToRigolScopes(self): devicelist = ds1054z.discovery.discover_devices() self.ds1000zs = [] for d in devicelist: print("Connecting to " + d["model"] + " at " + d["ip"]) dev = ds1054z.DS1054Z(d["ip"]) self.ds1000zs.append(dev) self.scopeNames[dev.idn] = "SCOPE_" + d["ip"] self.scopeIDs[d["ip"]] = dev.idn self.scopeAddress[dev.idn] = d["ip"]
def add_device(self, ip): try: self.scopes_by_ip[ip] = ds1054z.DS1054Z(ip) for f in self.scope_connect_callbacks: try: f(ip) except: handle_err() except: for g in self.error_callbacks: try: g("Failed to add device %s" % ip) except: handle_err()
samplerate = 1.0 / scope.waveform_preamble_dict['xinc'] # Trim the data to full number of periods samples_per_period = samplerate / frequency periods = int(len(ch1) / samples_per_period) samples = round(periods * samples_per_period) ch1 = ch1[:int(samples)] ch2 = ch2[:int(samples)] if periods <= 0: return 0, 0, 0 # Perform DFT at a single frequency exp = numpy.exp(math.tau * 1j * numpy.linspace(0, periods, samples, endpoint = False)) dft1 = numpy.sum(numpy.multiply(exp, ch1)) / samples dft2 = numpy.sum(numpy.multiply(exp, ch2)) / samples amplitude1 = 4 * abs(dft1) # Convert to Vpp reading amplitude2 = 4 * abs(dft2) phase = cmath.phase(dft1) - cmath.phase(dft2) deg_phase = (numpy.degrees(phase) + 180.0) % 360.0 - 180.0 return amplitude1, amplitude2, deg_phase if __name__ == '__main__': # Test this module with "python dft.py 192.168.100.10 10000" import ds1054z import sys scope = ds1054z.DS1054Z(sys.argv[1]) freq = float(sys.argv[2]) print(measure_with_dft(scope, freq))
def setUp(self): self.scope = ds1054z.DS1054Z(HOST)