From 6c9f1cbf7c9ef058152bf6656a9bd5c5e33165ba Mon Sep 17 00:00:00 2001 From: Simon Renblad Date: Thu, 25 Jan 2024 15:02:13 +0800 Subject: [PATCH] waveform: add save_vcd --- artiq/dashboard/waveform.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/artiq/dashboard/waveform.py b/artiq/dashboard/waveform.py index d8d150311..0d0c8ca37 100644 --- a/artiq/dashboard/waveform.py +++ b/artiq/dashboard/waveform.py @@ -11,7 +11,7 @@ from sipyco.pc_rpc import AsyncioClient from artiq.tools import exc_to_warning from artiq.coredevice import comm_analyzer from artiq.coredevice.comm_analyzer import WaveformType -from artiq.gui.tools import LayoutWidget, get_open_file_name +from artiq.gui.tools import LayoutWidget, get_open_file_name, get_save_file_name from artiq.gui.models import DictSyncTreeSepModel, LocalModelManager @@ -267,6 +267,7 @@ class WaveformDock(QtWidgets.QDockWidget): self._file_menu = QtWidgets.QMenu() self._add_async_action("Open trace...", self.load_trace) self._add_async_action("Save trace...", self.save_trace) + self._add_async_action("Save trace as VCD...", self.save_vcd) self._menu_btn.setMenu(self._file_menu) def _add_async_action(self, label, coro): @@ -338,6 +339,27 @@ class WaveformDock(QtWidgets.QDockWidget): except: logger.error("Failed to save analyzer trace", exc_info=True) + async def save_vcd(self): + if self._dump is None: + logger.error("No analyzer trace stored in dashboard, " + "try loading from file or fetching from device") + return + try: + filename = await get_save_file_name( + self, + "Save VCD", + self._current_dir, + "All files (*.*)") + except asyncio.CancelledError: + return + self._current_dir = os.path.dirname(filename) + try: + decoded_dump = comm_analyzer.decode_dump(self._dump) + with open(filename, 'w') as f: + comm_analyzer.decoded_dump_to_vcd(f, self._ddb, decoded_dump) + except: + logger.error("Failed to save trace as VCD", exc_info=True) + def _process_ddb(self): channel_list = comm_analyzer.get_channel_list(self._ddb) self._channel_model.clear()