我们正在开发一个项目,需要我们与一组特定的硬件进行交互;一组可以使用 C# 轻松控制,另一组则使用 Python 进行本地编程。该项目的一部分涉及让运行在 Python 上的硬件与运行在 C# 上的硬件进行通信,不幸的是,由于时间限制,我们无法创建一组 C# 或 Python 软件来控制另一组硬件。
在 Python 上运行的硬件集完全基于事件,因为我们可以对硬件满足某些条件时调用的函数进行编程。我们的想法是修改控制另一组硬件以托管 Python 应用程序的 C# 应用程序(使用诸如 Application.Run()
之类的东西),然后对 Python 函数进行编程以将相关数据传播到 C# 应用程序当事件来自硬件时。
我们正在考虑使用套接字连接来处理两者之间的通信,因为 C# 和 Python 都相当容易以这种方式工作(或者我们的 Python 人员声称)。我们对此最大的担忧是,这两个程序将托管在同一台计算机上是否会出现任何问题。如果这不是问题,我们可能最终会使用共享库,例如 0MQ
我们还对以下领域进行了一些研究:
基本上,我们想知道这些方法(或任何其他方法)中的哪种方法最容易用这些语言实现,以及哪种方法可以提供我们表现最好。我们只关心数据的速度和准确性(即,如果使用网络数据包,则丢弃最少的数据包)。安全性不是问题。
理想情况下,应该有一个从 Python 应用程序到 C# 应用程序的数据流,以及两个从 C# 应用程序到 Python 应用程序的数据流。主机将运行 Windows 7。我可以根据需要提供其他信息。
We're working on a project that requires us to interface with a specific set of hardware; one set can be controlled very easily using C#, the other of which is natively programmed using Python. Part of the project involves getting the hardware running on Python to communicate with the hardware running through C#, and unfortunately, due to time constraints, we aren't able to create a set of C# or Python software to control the other set of hardware.
The set of hardware running on Python is completely event based, in that we can program functions that are called when certain conditions are met by the hardware. Our thought was to modify the C# application controlling the other set of hardware to host the Python application (using something like Application.Run()
), then program the Python functions to propagate relevant data to the C# application as the events come in from the hardware.
We're considering using a socket connection to handle communication between the two, as both C# and Python are fairly simple to get working that way (or so our Python guy claims). The biggest concern with this that we have is if there will be any issues with the fact that both programs will be hosted on the same machine. If this won't be an issue, we would probably end up using a shared library such as 0MQ
We've also done some research into the following areas:
- Pipes / Named Pipes
- Message Queues
- Shared Memory
Basically we want to know which method of these (or any others) will be the easiest to implement with these languages, and which will give us the best performance. We are concerned only with speed and accuracy of the data (ie, if using network packets, one that will drop the least). Security is not a concern.
Ideally, there should be one data stream going from the Python application to the C# application, and two data streams going from the the C# application to the Python application. The host machine will be running Windows 7. I can give additional information as needed.
发布评论
评论(1)
一种选择是尝试 IronPython。由于 IronPython 是一种 .NET 语言,因此与 C# 代码的通信应该很容易。
似乎值得研究一下让现有的 Python 代码在 IronPython 上运行有多困难。
One option is to try IronPython. Since IronPython is a .NET language, communicating with C# code should be easy.
It seems worth looking into how hard it would be to get your existing Python code running on IronPython.