使用 ActiveX 在 C# 和 Labview 之间传递参数

发布于 2024-12-16 19:58:45 字数 1153 浏览 2 评论 0原文

我有两个问题:

我想知道我可以使用activeX从C#或python将什么样的变量类型传递到labview中。 我猜它们可能是数字类型、字符串等。但是路径或错误簇呢?

同样在labview中,我通常将labview对象传递到我的子vi中。用另一种语言怎么可能做到这一点?

假设我有一个自定义的数据库对象,我通常在labview中传递它。我可以从C#调用一些工厂方法vi,并在运行vi后从前面板获取控制权吗?将其转换为 C# 中的通用对象,然后调用另一个 vi,并传入该对象?

喜欢。

// Get a vi reference, and run my databaseFactory vi.
string databaseFactoryPath = ...;  
VirtualInstrument viTest = labVIEWApp.GetVIReference(databaseFactoryPath "", false, 0);
databaseFactoryVi.Run(true);

// Get the database labview object from the frontpanel control called "database out"
object databaseObject = (object)viTest.GetControlValue("database out");

// Obtain a reference to a database method called load.vi
string databaseLoadPath = ...;
VirtualInstrument databaseload = labVIEWApp.GetVIReference(databaseLoadPath "", false, 0);

string parameterName = "database in";
databaseLoad.Call( parameterName, databaseObject );  

...

这不起作用,因为在 viTest.GetControlValue("database out") 处抛出异常: “参数不正确。(HRESULT 异常:0x80070057 (E_INVALIDARG))”

有人知道是否可以做这样的事情吗? (我试图摆脱labview编程,但我不想让我的所有代码在此过程中变得无用。)

谢谢, 实验室狂人

I've two questions:

I would like to know what sort of variable types can I pass into labview from C# or python, using activeX.
I guess they would be things like, number types, strings, etc. But what about paths, or error clusters?

Also in labview I normally pass in labview objects into my subvi's. How would it be possible to do this from another language?

Lets say I have a self defined database object that I normally pass around in labview. Can I call some factory method vi from C#, and get the control from the front panel after running the vi. Cast that as a generic object in C#, and then call another vi, and pass in the object?

Like.

// Get a vi reference, and run my databaseFactory vi.
string databaseFactoryPath = ...;  
VirtualInstrument viTest = labVIEWApp.GetVIReference(databaseFactoryPath "", false, 0);
databaseFactoryVi.Run(true);

// Get the database labview object from the frontpanel control called "database out"
object databaseObject = (object)viTest.GetControlValue("database out");

// Obtain a reference to a database method called load.vi
string databaseLoadPath = ...;
VirtualInstrument databaseload = labVIEWApp.GetVIReference(databaseLoadPath "", false, 0);

string parameterName = "database in";
databaseLoad.Call( parameterName, databaseObject );  

...

This doesn't work because an exception is thrown at viTest.GetControlValue("database out"):
"The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))"

Anyone know if it is possible to do such things?
(I'm trying to get out of labview programming, but I don't want to render all my code as useless in the process.)

Thanks,
labjunky

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

無心 2024-12-23 19:58:45

LabVIEW 可以选择自行生成 .NET 程序集,该程序集包装了您的 VI,并且可以从 .NET 应用程序中调用。我认为,这是 G 开发人员在尝试在 .NET 应用程序中使用 G 代码时经常忽略的选项之一。这是 LV 项目中的 BuildSpecification 中的“.NET Interop Assembly”选项。

您可以从项目中选择您想要公开的 VI,以便在 .NET 应用程序中调用(我认为,它也可以为 LVOOP vis 生成);生成 .NET 包装器程序集;然后使用此包装器程序集与 .NET 应用程序中的 LabVIEW 代码进行交互。

当然,如果类型是基本的,那么在选择VI时,它会自动配置函数签名。我不确定引用/句柄是否可以在.NET/LabVIEW 边界之间无缝传递。但是,我确信您在 LabVIEW 端编写整数/字符串到 LVObject 映射,然后使用通用类型跨越边界引用它们,比在一个文件中重写所有代码更快。 .NET 语言。

LabVIEW has an option to generate a .NET assembly itself that wraps your VIs and is callable from your .NET application. I think, this is one of the options that's often neglected by G developers when trying to use G code in .NET apps.This is the ".NET Interop Assembly" option in your BuildSpecification in the LV Project.

You can select the VIs from your project that you want to be exposed for calling in your .NET application (I think, it can generate for LVOOP vis also); generate the .NET wrapper assembly; and then use this wrapper assembly to interface with the LabVIEW code from your .NET app.

Of course, if the types are basic, then while selecting the VIs, it automatically configures the function signature. I'm not sure, if the references/handles can be passed around seamlessly between the .NET/LabVIEW boundary. But, I'm sure its faster for you to write a integer/string-to-LVObject-map in LabVIEW side, and then use the common type to refer to them across the boundaries, than to re-write all the code in a .NET language.

忆伤 2024-12-23 19:58:45

您有很多问题需要回答...我将为所有这些问题提供一些一般性答案。

从 LabVIEW 2010 开始,LabVIEW 支持 .NET 4.0。早于该版本的版本通常支持 .NET 3.5。您可以通过构造函数节点、属性节点和调用节点在 LabVIEW 中调用 .NET 代码并使用 .NET 对象。搜索 .NET 的调色板,您会发现一些很好的支持。

LabVIEW 对传递数据的支持有些有限。传递 LabVIEW 对象(类)非常困难(如果不是不可能的话。我在 LabVIEW 团队工作,但我不确定……主要是因为我从未尝试过)。您可以将大多数其他类型展平为字符串(更好地描述为我们将其视为字符串的 u8 数组),并将结果字符串传递给 .NET 或本机 DLL。您可以阅读扁平化数据格式这里。

您绝对应该查看Measurement Studio。他们有一些很棒的工具可以在.NET 中创建类似 LabVIEW 的控件。您可能还对 LabWindows 感兴趣(我会链接它,但 SO 不会让我链接,因为我是一个相对较新的用户)。我知道我只是想销售更多 NI 产品,但老实说,这些可能是您想要做的事情的可行解决方案。

没有公开的方法可以从 .NET 代码调用 VI(我上次检查过。自从我从事Measurement Studio 工作以来已经有 3 年了,它是最有可能帮助您从 .NET 调用 VI 的产品)。

You've got a lot of questions to answer...I'll go for a few general answers to all of them.

LabVIEW supports .NET 4.0 as of LabVIEW 2010. Versions older than that generally support .NET 3.5. You can call .NET code and use .NET objects from within LabVIEW using Constructor nodes, Property Nodes, and Invoke Nodes. Search the palettes for .NET and you'll find some good support.

LabVIEW's support for passing data out is somewhat limited. Passing LabVIEW objects (classes) out is hard (if not impossible. I work on the LabVIEW team and I'm not sure...mostly because I've never tried it). You can flatten most other types to strings (better described as an array of u8s that we treat as a string) and pass the resulting string to .NET or a native DLL. You can read about the flattened data format here.

You should definitely check out Measurement Studio. They have some awesome tools for creating LabVIEW-like controls in .NET. You might also be interested in LabWindows (I'd link it, but SO won't let me since I'm a relatively new user). I know it looks like I'm just trying to sell more NI products, but honestly these may be viable solutions for what you're trying to do.

There's no public way to call a VI from .NET code (last time I checked. It's been 3 years since I worked on Measurement Studio, the most likely product to help you call VIs from .NET).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文