"""Manual native smoke test: synthetic 3-phase PWM, embedded DSView screenshot. Run with a Python containing PySide6. No acquisition hardware is accessed. """ import argparse import json import math import os from pathlib import Path import subprocess import time import zipfile def fixture(path): count, rate, period = 60032, 1000000, 500 decoders = [dict(id='pwm_waveform', version=2, label='PWM sine A / B / C', view_index=3, channel=[{'a': 0}, {'b': 1}, {'c': 2}], options=dict(active_a='high', active_b='high', active_c='high', carrier_hz=0, smoothing_ms=0.0), **{'stacked decoders': [], 'show': {'pwm_waveform': True, **{'pwm_waveform: '+ch+' duty / frequency': False for ch in 'ABC'}}})] session = dict(Device='virtual-session', DeviceMode=0, Version=3, Title='DSView v1.3.2', decoder=decoders, channel=[dict(index=i, enabled=True, name='D'+str(i), colour='default', strigger=0, type=10000, view_index=i) for i in range(3)], **{'Sample count': str(count), 'Sample rate': str(rate), 'Max Height': '1X'}) header = ('[version]\nversion = 3\n[header]\ndriver = virtual-session\n' 'device mode = 0\ncapturefile = data\n' f'total samples = {count}\ntotal probes = 3\ntotal blocks = 1\n' f'samplerate = {rate} Hz\ntrigger time = 0\ntrigger pos = 0\n' 'probe0 = D0\nprobe1 = D1\nprobe2 = D2\n') with zipfile.ZipFile(path, 'w', zipfile.ZIP_DEFLATED) as archive: archive.writestr('header', header) archive.writestr('session', json.dumps(session)) archive.writestr('decoders', json.dumps(decoders)) for ch in range(3): bits = bytearray(count // 8) for i in range(count): width = round(250 + 200 * math.sin(2 * math.pi * (i // period) / 40 + ch * 2 * math.pi / 3)) if i % period < width: bits[i // 8] |= 1 << (i % 8) archive.writestr(f'L-{ch}/0', bits) def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--runtime', type=Path, required=True) parser.add_argument('--output', type=Path, required=True) args = parser.parse_args() from PySide6.QtWidgets import QApplication, QWidget runtime, output = args.runtime.resolve(), args.output.resolve() output.mkdir(parents=True, exist_ok=True) capture = output / 'pwm-three-phase.dsl' screenshot = output / 'pwm-native.png' fixture(capture) app = QApplication([]) window = QWidget() window.resize(1400, 850) window.setWindowTitle('PWM native rendering test') window.show() env = {k: v for k, v in os.environ.items() if not k.startswith(('PYTHON', 'QT_', 'QML'))} env['PATH'] = str(runtime) + os.pathsep + str(Path(os.environ['SystemRoot']) / 'System32') env['DSVIEW_HOST_SCREENSHOT'] = str(screenshot) began = time.time() with (output / 'pwm-native.log').open('w', encoding='utf-8') as log: process = subprocess.Popen([str(runtime / 'DSView.exe'), '--embed-parent', str(int(window.winId())), str(capture)], cwd=runtime, env=env, stdin=subprocess.PIPE, stdout=log, stderr=log, creationflags=subprocess.CREATE_NO_WINDOW) try: deadline = time.monotonic() + 8 while time.monotonic() < deadline and process.poll() is None: app.processEvents() time.sleep(.02) if process.poll() is None: process.stdin.write(b'CLOSE\n') process.stdin.flush() deadline = time.monotonic() + 5 while time.monotonic() < deadline and process.poll() is None: app.processEvents() time.sleep(.02) assert process.poll() == 0, 'DSView did not close cleanly; inspect pwm-native.log' assert screenshot.exists() and screenshot.stat().st_mtime >= began, 'No fresh render artifact' finally: if process.poll() is None: process.terminate() process.wait(timeout=5) window.close() print('Inspect three phase-shifted sine curves:', screenshot) if __name__ == '__main__': main()