diff --git a/Software/PC_Application/LibreVNA-GUI/appwindow.cpp b/Software/PC_Application/LibreVNA-GUI/appwindow.cpp index 487fcf7..79301a6 100644 --- a/Software/PC_Application/LibreVNA-GUI/appwindow.cpp +++ b/Software/PC_Application/LibreVNA-GUI/appwindow.cpp @@ -143,11 +143,6 @@ AppWindow::AppWindow(QWidget *parent) central = new QStackedWidget; setCentralWidget(central); - auto vnaIndex = modeHandler->createMode("Vector Network Analyzer", Mode::Type::VNA); - modeHandler->createMode("Signal Generator", Mode::Type::SG); - modeHandler->createMode("Spectrum Analyzer", Mode::Type::SA); - modeHandler->setCurrentIndex(vnaIndex); - auto setModeStatusbar = [=](const QString &msg) { lModeInfo.setText(msg); }; @@ -170,10 +165,9 @@ AppWindow::AppWindow(QWidget *parent) SetupSCPI(); + SetInitialState(); + auto& pref = Preferences::getInstance(); - if(pref.Startup.UseSetupFile) { - LoadSetup(pref.Startup.SetupFile); - } // List available devices UpdateDeviceList(); if(pref.Startup.ConnectToFirstDevice && deviceList.size() > 0) { @@ -315,6 +309,21 @@ void AppWindow::closeEvent(QCloseEvent *event) QMainWindow::closeEvent(event); } +void AppWindow::SetInitialState() +{ + modeHandler->closeModes(); + + auto& pref = Preferences::getInstance(); + if(pref.Startup.UseSetupFile) { + LoadSetup(pref.Startup.SetupFile); + } else { + auto vnaIndex = modeHandler->createMode("Vector Network Analyzer", Mode::Type::VNA); + modeHandler->createMode("Signal Generator", Mode::Type::SG); + modeHandler->createMode("Spectrum Analyzer", Mode::Type::SA); + modeHandler->setCurrentIndex(vnaIndex); + } +} + bool AppWindow::ConnectToDevice(QString serial, DeviceDriver *driver) { if(serial.isEmpty()) { @@ -477,6 +486,10 @@ void AppWindow::SetupSCPI() scpi.add(new SCPICommand("*IDN", nullptr, [=](QStringList){ return "LibreVNA,LibreVNA-GUI,dummy_serial,"+appVersion; })); + scpi.add(new SCPICommand("*RST", [=](QStringList){ + SetInitialState(); + return SCPI::getResultName(SCPI::Result::Empty); + }, nullptr)); scpi.add(new SCPICommand("*OPC", nullptr, [=](QStringList){ return "1"; })); diff --git a/Software/PC_Application/LibreVNA-GUI/appwindow.h b/Software/PC_Application/LibreVNA-GUI/appwindow.h index e47376e..175dd1b 100644 --- a/Software/PC_Application/LibreVNA-GUI/appwindow.h +++ b/Software/PC_Application/LibreVNA-GUI/appwindow.h @@ -58,6 +58,7 @@ public slots: protected: void closeEvent(QCloseEvent *event) override; private slots: + void SetInitialState(); bool ConnectToDevice(QString serial = QString(), DeviceDriver *driver = nullptr); void DisconnectDevice(); int UpdateDeviceList(); diff --git a/Software/PC_Application/LibreVNA-GUI/scpi.cpp b/Software/PC_Application/LibreVNA-GUI/scpi.cpp index 4684033..6b5a89b 100644 --- a/Software/PC_Application/LibreVNA-GUI/scpi.cpp +++ b/Software/PC_Application/LibreVNA-GUI/scpi.cpp @@ -5,7 +5,6 @@ SCPI::SCPI() : SCPINode("") { - lastNode = this; add(new SCPICommand("*LST", nullptr, [=](QStringList){ QString list; createCommandList("", list); @@ -97,16 +96,19 @@ QString SCPI::getResultName(SCPI::Result r) void SCPI::input(QString line) { auto cmds = line.split(";"); + SCPINode *lastNode = this; for(auto cmd : cmds) { - if(cmd[0] == ':' || cmd[0] == '*') { - // reset to root node - lastNode = this; + if(cmd.size() > 0) { + if(cmd[0] == ':' || cmd[0] == '*') { + // reset to root node + lastNode = this; + } + if(cmd[0] == ':') { + cmd.remove(0, 1); + } + auto response = lastNode->parse(cmd, lastNode); + emit output(response); } - if(cmd[0] == ':') { - cmd.remove(0, 1); - } - auto response = lastNode->parse(cmd, lastNode); - emit output(response); } } diff --git a/Software/PC_Application/LibreVNA-GUI/scpi.h b/Software/PC_Application/LibreVNA-GUI/scpi.h index f56f92e..10634cf 100644 --- a/Software/PC_Application/LibreVNA-GUI/scpi.h +++ b/Software/PC_Application/LibreVNA-GUI/scpi.h @@ -81,9 +81,6 @@ public slots: void input(QString line); signals: void output(QString line); - -private: - SCPINode *lastNode; }; #endif // SCPI_H