コード例 #1
0
ファイル: mine.py プロジェクト: GrahamW/Hantek6022API
class ScopeInterface(QObject):
    new_data = pyqtSignal(list)

    def __init__(self, parent=None):
        super(ScopeInterface, self).__init__(parent)
        self.inprogress = False

    def initialize(self):
        self.sample_rate_index = 8
        self.voltage_range = 0x01
        self.data_points = 3 * 1024

        self.trigger_level = 150
        self.trigger_type = +1

        self.scope = Oscilloscope()
        self.scope.setup()
        self.scope.open_handle()
        if (not self.scope.is_device_firmware_present):
            self.scope.flash_firmware()
        self.scope.set_interface(1)
        # choose ISO
        self.scope.set_num_channels(1)
        self.scope.set_sample_rate(self.sample_rate_index)
        self.scope.set_ch1_voltage_range(self.voltage_range)
        time.sleep(0.1)
        return None

    def capture(self):
        if not self.inprogress:
            self.inprogress = True
            self.scope.start_capture()
            shutdown_event = self.scope.read_async(self.data_callback,
                                                   self.data_points,
                                                   outstanding_transfers=25)
            print("Clearing FIFO and starting data transfer...")

    def data_callback(self, ch1_data, _):
        d = list(ch1_data)
        i = 0
        #print("got new data ", time.time(), " : ", len(d))
        if self.trigger_type > 0:
            while (i < len(d) - 1) and not (d[i + 1] > self.trigger_level
                                            and d[i] < self.trigger_level):
                i += 1
        #print("Trigger at ", i)
        if (i != len(d) - 1):
            self.new_data.emit(d[i:])

    def stop(self):
        self.scope.stop_capture()
        print("Stopping new transfers.")
        shutdown_event.set()
        print("Snooze 1")
        time.sleep(1)
        print("Closing handle")
        self.scope.close_handle()
        print("Handle closed.")
        self.inprogress = False
コード例 #2
0
ファイル: mine.py プロジェクト: GrahamW/Hantek6022API
class ScopeInterface(QObject):
    new_data = pyqtSignal(list)
    def __init__(self, parent=None):
        super(ScopeInterface, self).__init__(parent)
        self.inprogress = False

    def initialize(self):
        self.sample_rate_index = 8
        self.voltage_range = 0x01
        self.data_points = 3 * 1024

        self.trigger_level = 150
        self.trigger_type = +1

        self.scope = Oscilloscope()
        self.scope.setup()
        self.scope.open_handle()
        if (not self.scope.is_device_firmware_present):
            self.scope.flash_firmware()
        self.scope.set_interface(1); # choose ISO
        self.scope.set_num_channels(1)
        self.scope.set_sample_rate(self.sample_rate_index)
        self.scope.set_ch1_voltage_range(self.voltage_range)
        time.sleep(0.1)
        return None

    def capture(self):
        if not self.inprogress:
            self.inprogress = True
            self.scope.start_capture()
            shutdown_event = self.scope.read_async(self.data_callback, self.data_points, outstanding_transfers=25)
            print("Clearing FIFO and starting data transfer...")

    def data_callback(self, ch1_data, _):
        d = list(ch1_data)
        i = 0
        #print("got new data ", time.time(), " : ", len(d))
        if self.trigger_type > 0:
            while (i < len(d) - 1) and not (d[i+1] > self.trigger_level and d[i] < self.trigger_level):
                i += 1
        #print("Trigger at ", i)
        if (i != len(d) - 1):
            self.new_data.emit(d[i:])


    def stop(self):
        self.scope.stop_capture()
        print("Stopping new transfers.")
        shutdown_event.set()
        print("Snooze 1")
        time.sleep(1)
        print("Closing handle")
        self.scope.close_handle()
        print("Handle closed.")
        self.inprogress = False
コード例 #3
0
data = []
data_extend = data.append


def extend_callback(ch1_data, _):
    global data_extend
    data_extend(ch1_data)


start_time = time.time()
print("Clearing FIFO and starting data transfer...")
shutdown_event = scope.read_async(extend_callback,
                                  blocksize,
                                  outstanding_transfers=10,
                                  raw=True)
scope.start_capture()
while time.time() - start_time < numseconds:
    scope.poll()
print("Stopping new transfers.")
#scope.stop_capture()
shutdown_event.set()
time.sleep(1)
scope.stop_capture()
scope.close_handle()

total = sum(len(block) for block in data)

filename = "test.wav"
print("Writing out data from scope to {}".format(filename))
with open(filename, "wb") as wf:
    wf.write(b"RIFF")
コード例 #4
0
scope.set_sample_rate(sample_rate_index)
scope.set_ch1_voltage_range(voltage_range)
time.sleep(1)

data = deque(maxlen=2*1024*1024)
data_extend = data.extend


def extend_callback(ch1_data, _):
    global data_extend
    data_extend(ch1_data)

start_time = time.time()
print("Clearing FIFO and starting data transfer...")
i = 0
scope.start_capture()
shutdown_event = scope.read_async(extend_callback, data_points, outstanding_transfers=10, raw=True)
while time.time() - start_time < 1:
    scope.poll()
scope.stop_capture()
print("Stopping new transfers.")
shutdown_event.set()
print("Snooze 1")
time.sleep(1)
print("Closing handle")
scope.close_handle()
print("Handle closed.")
print("Points in buffer:", len(data))
scaled_data = scope.scale_read_data(data, voltage_range)
with open('/tmp/continuous_read.out','wt') as ouf:
    ouf.write(str(scaled_data[:65536])[1:-1].replace(', ',chr(10)))