waveform: add save_vcd

This commit is contained in:
Simon Renblad 2024-01-25 15:02:13 +08:00 committed by Sébastien Bourdeauducq
parent 06b908fd18
commit 6c9f1cbf7c
1 changed files with 23 additions and 1 deletions

View File

@ -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()