def main(): port = SpotWave.discover()[0] with SpotWave(port) as sw: # apply settings sw.set_continuous_mode(True) sw.set_cct(0) sw.set_status_interval(0) sw.set_tr_enabled(True) sw.set_tr_decimation(4) # 2 MHz / 4 = 500 kHz sw.set_ddt(100_000) # 100 ms * 500 kHz = 50.000 samples sw.set_filter(50e3, 200e3, 4) # 50-200 kHz bandpass # show settings print("Settings:") for key, value in asdict(sw.get_setup()).items(): print(f"- {key}: {value}") print() for record in sw.stream(): if isinstance(record, TRRecord): y = record.data y_max = np.max(y) # visualize max amplitude with "level meter" cols = int(80 * y_max / 0.05) # 50 mV input range print(f"{y_max:<8f} V: " + "#" * cols + "-" * (80 - cols), end="\r") elif isinstance(record, AERecord): ...
def main(basename: str, seconds_per_file: float): def get_filename(): timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") return f"{basename}_{timestamp}.wav" port = SpotWave.discover()[0] print(port) with SpotWave(port) as sw: sw.set_datetime() sw.set_continuous_mode(True) sw.set_cct(0) sw.set_status_interval(0) sw.set_tr_enabled(True) sw.set_tr_decimation(1) # 2 MHz sw.set_ddt(10_000) # 10 ms sw.set_filter(None, None) # deactivate IIR filter setup = sw.get_setup() samplerate = sw.CLOCK / setup.tr_decimation chunks_per_file = int(seconds_per_file / setup.ddt_seconds) def async_write(): chunks = chunks_per_file # create on first data while trqueue: try: tr = trqueue.get(timeout=0.1) except: continue if chunks >= chunks_per_file: logger.info(f"{chunks_per_file} chunks acquired") writer = WavWriter(get_filename(), samplerate) chunks = 0 writer.write(tr.data) chunks += 1 print("Write finished") last_t = 0 missed = 0 trqueue = queue.SimpleQueue() threading.Thread(target=async_write).start() try: for record in sw.stream( raw=True): # return ADC values with enabled raw flag if isinstance(record, TRRecord): trqueue.put(record) elif isinstance(record, AERecord): if record.trai == 0 or record.flags > 0: missed += 1 if missed > 0 and time.monotonic() - last_t > 1: logger.warning(f"Missed {missed} record(s)") missed = 0 last_t = time.monotonic() finally: trqueue = None # flag to stop
def sw(): devices = SpotWave.discover() if not devices: raise RuntimeError( "No spotWave devices found. Please connect a device to run the system tests" ) with SpotWave(devices[0]) as sw: sw.set_datetime() # set current date/time sw.clear_buffer() yield sw
def main(): port = SpotWave.discover()[0] with SpotWave(port) as sw: sw.set_continuous_mode(False) # -> hit-based sw.set_cct(0) # disable pulser sw.set_ddt(10_000) # 10.000 µs sw.set_status_interval(2) # generate status data every 2 seconds sw.set_threshold(1000) # 1000 µV = 60 dB(AE) sw.set_tr_enabled(True) # enable transient data recording sw.set_tr_pretrigger(200) # 200 pre-trigger samples sw.set_tr_postduration(0) # 0 post-duration samples sw.set_filter(100e3, 450e3, 4) # 100-450 kHz bandpass for record in merge_ae_tr_records(sw.stream()): print(record)
def main(): ports = SpotWave.discover() print(f"Discovered spotWave devices: {ports}") port = ports[0] with SpotWave(port) as sw: sw.set_datetime() sw.set_cct(0) # disable cct/pulser sw.set_continuous_mode(True) # enable continous mode sw.set_ddt(100_000) # 100 ms block size sw.set_filter(highpass=50e3, lowpass=300e3, order=4) # 50-300 kHz bandpass sw.set_status_interval(0) # disable status data sw.set_tr_enabled(False) # disable transient data for record in sw.stream(): # compute RMS from energy (in eu = 1e-14 V²s) and duration (in seconds) rms_volts = math.sqrt(record.energy / 1e14 / record.duration) print(f"RMS: {1e6 * rms_volts:0.2f} µV")
def main(): port = SpotWave.discover()[0] # prepare plot plt.ion() _, ax = plt.subplots(figsize=(10, 3), tight_layout=True) with SpotWave(port) as sw: sw.set_cct(1, sync=True) sw.set_filter(90e3, 150e3, 4) # 90-150 kHz bandpass while True: data = sw.get_data(2048) # read snapshot -> trigger pulser t = np.arange(len(data)) / sw.CLOCK # create time axis ax.clear() ax.plot(t * 1e6, data * 1e6) ax.set_xlabel("Time [µs]") ax.set_ylabel("Amplitude [µV]") plt.pause(1)