Skip to content

Commit

Permalink
Session: fixed bug where trying to load a session online did not corr…
Browse files Browse the repository at this point in the history
…ectly degrade if the instrument socket connection fails
  • Loading branch information
azonenberg committed Nov 19, 2023
1 parent 96f814e commit 41e0583
Showing 1 changed file with 87 additions and 8 deletions.
95 changes: 87 additions & 8 deletions src/ngscopeclient/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ bool Session::PreLoadOscilloscope(int version, const YAML::Node& node, bool onli
//Create the scope
auto transport = CreateTransportForNode(node);

if(transport)
if(transport && transport->IsConnected())
{
scope = Oscilloscope::CreateOscilloscope(driver, transport);
if(!VerifyInstrument(node, scope))
Expand All @@ -923,6 +923,15 @@ bool Session::PreLoadOscilloscope(int version, const YAML::Node& node, bool onli
scope = nullptr;
}
}
else
{
delete transport;

m_mainWindow->ShowErrorPopup(
"Unable to reconnect",
string("Failed to reconnect to oscilloscope at ") + node["args"].as<string>() + ".\n\n"
"Loading this instrument in offline mode.");
}
}
}

Expand Down Expand Up @@ -979,7 +988,7 @@ bool Session::PreLoadLoad(int version, const YAML::Node& node, bool online)
//Create the PSU
auto transport = CreateTransportForNode(node);

if(transport)
if(transport && transport->IsConnected())
{
load = SCPILoad::CreateLoad(driver, transport);
if(!VerifyInstrument(node, load))
Expand All @@ -988,6 +997,16 @@ bool Session::PreLoadLoad(int version, const YAML::Node& node, bool online)
load = nullptr;
}
}

else
{
delete transport;

m_mainWindow->ShowErrorPopup(
"Unable to reconnect",
string("Failed to reconnect to load at ") + node["args"].as<string>() + ".\n\n"
"Loading this instrument in offline mode.");
}
}
}

Expand Down Expand Up @@ -1044,7 +1063,7 @@ bool Session::PreLoadMisc(int version, const YAML::Node& node, bool online)
//Create the PSU
auto transport = CreateTransportForNode(node);

if(transport)
if(transport && transport->IsConnected())
{
misc = SCPIMiscInstrument::CreateInstrument(driver, transport);
if(!VerifyInstrument(node, misc))
Expand All @@ -1053,6 +1072,16 @@ bool Session::PreLoadMisc(int version, const YAML::Node& node, bool online)
misc = nullptr;
}
}

else
{
delete transport;

m_mainWindow->ShowErrorPopup(
"Unable to reconnect",
string("Failed to reconnect to miscellaneous instrument at ") + node["args"].as<string>() + ".\n\n"
"Loading this instrument in offline mode.");
}
}
}

Expand Down Expand Up @@ -1109,7 +1138,7 @@ bool Session::PreLoadBERT(int version, const YAML::Node& node, bool online)
//Create the BERT
auto transport = CreateTransportForNode(node);

if(transport)
if(transport && transport->IsConnected())
{
bert = SCPIBERT::CreateBERT(driver, transport);
if(!VerifyInstrument(node, bert))
Expand All @@ -1118,6 +1147,16 @@ bool Session::PreLoadBERT(int version, const YAML::Node& node, bool online)
bert = nullptr;
}
}

else
{
delete transport;

m_mainWindow->ShowErrorPopup(
"Unable to reconnect",
string("Failed to reconnect to BERT at ") + node["args"].as<string>() + ".\n\n"
"Loading this instrument in offline mode.");
}
}
}

Expand Down Expand Up @@ -1174,7 +1213,7 @@ bool Session::PreLoadMultimeter(int version, const YAML::Node& node, bool online
//Create the PSU
auto transport = CreateTransportForNode(node);

if(transport)
if(transport && transport->IsConnected())
{
meter = SCPIMultimeter::CreateMultimeter(driver, transport);
if(!VerifyInstrument(node, meter))
Expand All @@ -1183,6 +1222,16 @@ bool Session::PreLoadMultimeter(int version, const YAML::Node& node, bool online
meter = nullptr;
}
}

else
{
delete transport;

m_mainWindow->ShowErrorPopup(
"Unable to reconnect",
string("Failed to reconnect to multimeter at ") + node["args"].as<string>() + ".\n\n"
"Loading this instrument in offline mode.");
}
}
}

Expand Down Expand Up @@ -1239,7 +1288,7 @@ bool Session::PreLoadPowerSupply(int version, const YAML::Node& node, bool onlin
//Create the PSU
auto transport = CreateTransportForNode(node);

if(transport)
if(transport && transport->IsConnected())
{
psu = SCPIPowerSupply::CreatePowerSupply(driver, transport);
if(!VerifyInstrument(node, psu))
Expand All @@ -1248,6 +1297,16 @@ bool Session::PreLoadPowerSupply(int version, const YAML::Node& node, bool onlin
psu = nullptr;
}
}

else
{
delete transport;

m_mainWindow->ShowErrorPopup(
"Unable to reconnect",
string("Failed to reconnect to power supply at ") + node["args"].as<string>() + ".\n\n"
"Loading this instrument in offline mode.");
}
}
}

Expand Down Expand Up @@ -1304,7 +1363,7 @@ bool Session::PreLoadRFSignalGenerator(int version, const YAML::Node& node, bool
//Create the PSU
auto transport = CreateTransportForNode(node);

if(transport)
if(transport && transport->IsConnected())
{
gen = SCPIRFSignalGenerator::CreateRFSignalGenerator(driver, transport);
if(!VerifyInstrument(node, gen))
Expand All @@ -1313,6 +1372,16 @@ bool Session::PreLoadRFSignalGenerator(int version, const YAML::Node& node, bool
gen = nullptr;
}
}

else
{
delete transport;

m_mainWindow->ShowErrorPopup(
"Unable to reconnect",
string("Failed to reconnect to RF signal generator at ") + node["args"].as<string>() + ".\n\n"
"Loading this instrument in offline mode.");
}
}
}

Expand Down Expand Up @@ -1369,7 +1438,7 @@ bool Session::PreLoadFunctionGenerator(int version, const YAML::Node& node, bool
//Create the PSU
auto transport = CreateTransportForNode(node);

if(transport)
if(transport && transport->IsConnected())
{
gen = SCPIFunctionGenerator::CreateFunctionGenerator(driver, transport);
if(!VerifyInstrument(node, gen))
Expand All @@ -1378,6 +1447,16 @@ bool Session::PreLoadFunctionGenerator(int version, const YAML::Node& node, bool
gen = nullptr;
}
}

else
{
delete transport;

m_mainWindow->ShowErrorPopup(
"Unable to reconnect",
string("Failed to reconnect to function generator at ") + node["args"].as<string>() + ".\n\n"
"Loading this instrument in offline mode.");
}
}
}

Expand Down

0 comments on commit 41e0583

Please sign in to comment.