I am trying to launch a PlusServer instance from the python interactor. Specifically, I need to be able to start/stop the server, and each time I start, I would like to specify the config file. The reason for this is because we will be updating parameters in the config file and then restarting PlusServer with new, calibrated parameters, and this will eventually need to be done in a scripted module.
I have had success interacting with the PlusServerLauncher from the Plus Remote GUI in slicer, but it would be great if I could do something like:
Then start an OpenIGTLinkConnector to stream data into slicer. When I want to change the config file, I would do something like:
remote.StopServer() # When I want to stop streaming data
remote.SetConfigFile(âSomeUpdatedConfigFileâ)
remote.StartServer()
I have tried to search for a good way to do the above from the python interactor, but I have had no luck. Let me know if you have any insights on this.
What version of Slicer are you using?
If you are using Slicer >= 4.10.1 with an updated version of SlicerOpenIGTLink, then there are a couple of ways to do it:
For anyone else who needs the info, after starting PlusServerLauncher, the full way I got this working was by:
fn = "C:/Full/Path/To/ConfigFile.xml"
with open(fn, 'r') as file:
configText = file.read()
configNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLTextNode')
configNode.SetText(configText) # Sets the text to the XML file contents
launcherNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLPlusServerLauncherNode")
serverNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLPlusServerNode")
launcherNode.AddAndObserveServerNode(serverNode)
serverNode.SetAndObserveConfigNode(configNode)
serverNode.StartServer()
# Do whatever with data streamed into Slicer...
pass
# Also, you can change the configFile if/when desired
serverNode.StopServer()
configNode.SetText(SomeNewXmlText)
serverNode.StartServer()