Reputation: 8327
I have a GUI in VB.Net that needs to interface with algorithms written in Python, all to run on Windows 10 Professional. The IDE is Visual Studio 2017.
How can the VB.Net GUI and Python communicate? Data needs to be communicated back and forth. The GUI will accept user commands, and then command Python to execute. Python will have events that it needs to communicate to the GUI.
To clarify the architecture, the GUI app and the Python app are two different programs running simultaneously.
The GUI has two major functions: 1) take user commands and tell Python to execute them. 2) Monitor/poll the Python app for data or events, and update (tell) the user via the GUI controls (textboxes, etc.).
Python mainly does two things: 1) runs the continuous control algorithm, subject to management by the GUI. 2) Reports data and events to the GUI.
A TCP socket is 100% reliable, but I have to write and debug a proprietary messaging scheme, which I've done a lot and it's fun, but I thought maybe I can accomplish same thing in substantially less time by some other equally reliable method... such as COM, as those below suggest.
Example scenario of asynchronous usage:
The Python app is running a robotic process. Meanwhile, user presses GUI command to see latest metrics: GUI's VB.NET calls a COM function within Python which returns an array of metrics data.
Python app running robotic process completes a step, and now needs a manual action. Python app calls COM function within VB.NET and passes an argument with requirements of manual action.
Upvotes: 2
Views: 3348
Reputation: 8327
I found answer here. This guy shows consisely how VB.NET calls IronPython scripts functions and also passes and retrieves VB data. Sweet.
I believe the value here of IronPython vs. regular Python is that IronPython is compatible with any type of .NET data that VB passes to it.
Now, I can create a GUI with the supreme quality and reliability of VB.NET that uses the supreme development efficiency/productivity of Python.
Upvotes: 1
Reputation: 2019
Here is what I would suggest you can read this it's a guide on the MSDN about communicating from C# to Pyhton
Basically calling a python script and reading output.
https://code.msdn.microsoft.com/windowsdesktop/C-and-Python-interprocess-171378ee
IronPython is an open-source implementation of the Python programming language which is tightly integrated with the .NET Framework. IronPython can use the .NET Framework and Python libraries, and other .NET languages can use Python code just as easily.
Python for .NET (pythonnet) is a package that gives Python programmers nearly seamless integration with the .NET 4.0+ Common Language Runtime (CLR) on Windows and Mono runtime on Linux and OSX.
However this one limits you to a certain version of python.
Upvotes: 4