Skip to content

Commit c533885

Browse files
committed
Allow connecting to scopes via command line args. Fixes #525.
1 parent 16daf17 commit c533885

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

src/ngscopeclient/main.cpp

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,38 @@ int main(int argc, char* argv[])
182182
if(!sessionToOpen.empty())
183183
g_mainWindow->SetStartupSession(sessionToOpen);
184184

185+
//Render the main window once, so it can initialize a new empty session before we connect any instruments
186+
glfwPollEvents();
187+
g_mainWindow->Render();
188+
185189
//Initialize the session with the requested arguments
186-
//TODO: support connecting to things other than scopes
187-
//(this will make more sense when we unify our driver model)
188-
/*
189-
vector<string> instrumentConnectionStrings;
190-
*/
190+
for(auto s : instrumentConnectionStrings)
191+
{
192+
LogTrace("Setup: connecting to %s\n", s.c_str());
193+
LogIndenter li;
194+
195+
char name[128];
196+
char driver[128];
197+
char transport[128];
198+
char args[256];
199+
sscanf(s.c_str(), "%127[^:]:%127[^:]:%127[^:]:%255s", name, driver, transport, args);
200+
201+
//Try to connect
202+
auto ptransport = SCPITransport::CreateTransport(transport, args);
203+
if(ptransport == nullptr)
204+
{
205+
LogError("Failed to create transport of type \"%s\"\n", transport);
206+
return 1;
207+
}
208+
if(!ptransport->IsConnected())
209+
{
210+
delete ptransport;
211+
LogError("Failed to connect to \"%s\"\n", args);
212+
return 1;
213+
}
214+
215+
session.CreateAndAddInstrument(driver, ptransport, name);
216+
}
191217

192218
//Main event loop
193219
while(!glfwWindowShouldClose(g_mainWindow->GetWindow()))

0 commit comments

Comments
 (0)