Closed BardiyaAk closed 3 years ago
Autoscoper code for TCP/IP connection: https://github.com/BrownBiomechanics/autoscoper/tree/master/autoscoper/src/net The code that opens a connection between Matlab and Autoscoper: https://github.com/BrownBiomechanics/autoscoper/blob/master/matlab/openConnection.m
Here is an example of code to start a process:
def onFinished(exitCode, exitStatus):
print("exitCode [%d] exitStatus [%s]" % (
exitCode,
{qt.QProcess.NormalExit: "NormalExit", qt.QProcess.CrashExit: "CrashExit"}[exitStatus]))
process = qt.QProcess()
process.connect("finished(int, QProcess::ExitStatus)", onFinished)
process.start("/usr/bin/xcalc", ["-rpn"])
process.waitForStarted()
On Linux, this snippet can be copied in the Slicer Python interactor and it will start the xcalc
executable asynchronously passing the -rpn
argument.
It also illustrates how to connect signal to the QProcess
object to be notified of state changed.
Thanks. I got the QProcess running. There is a minor issue though. I want to have the "command prompt" open with Autoscoper. I couldn't make it work using "cmd.exe /K" in process.start:
I'm working on a TCP/IP connection, but I can't send the full message from Python to Autoscoper. I have my code in "Playground/TCP_IP_test.py". I can send the case number, but I can't send the path to Autoscoper.
running
cmd.exe
In this case, you would have to do something like this:
process.start("cmd.exe", ["/K", "aut_path"])
That said, what is the motivation to use cmd.exe
? I anticipate this could make cross-platform use of the extension more complicated.
re: name of variables
I suggest to be more explicit when naming variables: aut_path
-> autoscoper_executable_path
re: connection
Instead of using socket
, I suggest to use the class QTcpSocket
, this would to nicely integrate with the server implemented here
For an example of client, you could look at https://doc.qt.io/qt-5/qtnetwork-fortuneclient-example.html
running
cmd.exe
In this case, you would have to do something like this:
process.start("cmd.exe", ["/K", "aut_path"])
That said, what is the motivation to use
cmd.exe
? I anticipate this could make cross-platform use of the extension more complicated.
Thanks, but it's still not keeping the command prompt open. Autoscoper doesn't have any console/display window at the moment, so I usually "std::cout/std::cerr" the optimization outputs or filepaths in the command prompt.
Thanks, but it's still not keeping the command prompt open
When you run the application by double-clicking on it from the file explorer, is there a console displayed ?
If not, it may be worth evaluating if the flag /SUBSYSTEM:CONSOLE
is properly associated with the linker.
It my also be worth updating how add_executable
is called here and passing WIN32
to build the application with a console.
This approach would allow to remove this hard-coded linker flag here
For reference, here is how it is done in Slicer:
The logic has been updated in https://github.com/BrownBiomechanics/SlicerAutoscoperM/pull/2
Before integrating, I still need to address the transfer of double :heavy_check_mark:
@BardiyaAk Would be great if you could test the pull request.
Copying the following is expected to work (just make sure the paths are correct):
from AutoscoperConnect import AutoscoperConnectLogic
logic = AutoscoperConnectLogic()
logic.startAutoscoper(r"C:\Dev\autoscoper-git\build\install\bin\Release\autoscoper.exe")
logic.loadTrial(r"C:\Dev\autoscoper-git\build\install\bin\Release\sample_data\wrist.cfg")
Note that output of the autoscoper process is now expected to be reported in the Slicer log.
If you would like to compile the mock server, sources are available in the AutoscoperMockServer
directory also available in the pull request.
Slicer and Autoscoper need to be able to "talk" to each other, because want 3DSlicer be able to run functions in Autoscoper, and read data from it. Autoscoper uses a static IP of "127.0.0.1" and "30007" port number for its Matlab connections.