分享C和LabVIEW的变量? [英] Share a variable between C and Labview?

查看:373
本文介绍了分享C和LabVIEW的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是允许C code到定期访问从一个单独的LabVIEW程序生成一个整数的瞬时值的最佳方法?

What is the best way to permit C code to regularly access the instantaneous value of an integer generated from a separate Labview program?

我有时间要求严格的C code,它控制着科学实验和记录数据每20ms一次。我也有经营不同的仪器,并输出一个整数值不断100ms的一些LabVIEW的code。我希望我的C code到能够记录从LabVIEW值。什么是做到这一点的最好方法是什么?

I have time-critical C code that controls a scientific experiment and records data once every 20ms. I also have some labview code that operates a different instrument and outputs an integer value ever 100ms. I want my C code to be able to record the value from labview. What is the best way to do this?

一个想法是让写的Labview在一个循环中以文件的整数,并有C $ C $℃的循环读取文件的价值。 (我可以在必要时第二个线程添加到我的C code)。LabVIEW还可以链接到C DLL的。所以,我也许可以用C来写一个DLL,不知怎的,促进了两个程序之间共享。那是可取?我会怎么做呢?

One idea is to have Labview write the integer to file in a loop, and have the C code read the value of the file in a loop. (I could add a second thread to my C code if necessary.) Labview can also link to C dll's. So I might be able to write a DLL in C that somehow facilitates sharing between the two programs. Is that advisable? How would I do that?

推荐答案

我跟进@斯泰恩的理想之一:

I followed up on one of @stijn's ideals:

拥有的C程序和另一个DLL有着共同的记忆。 LV将加载该DLL并调用它的方法将值写入共享内存,那么C应用程序可以轮询后阅读它的标志(这需要一个锁!)。

have the C app and another dll share common memory. LV will load that dll and call a method on it to write a value to the shared memory, then the C app can read it after polling a flag (which needs a lock!).

我写的进程间图书馆,可在这里: http://github.com/samuellab/InterProcess

I wrote the InterProcess library, available here: http://github.com/samuellab/InterProcess

进程间是建立使用共享内存窗口紧凑的通用库的CreateFileMapping() MapViewOfFile()。它允许用户无缝地存储任何类型的值(INT,CHAR,你的结构..等等)在命名字段任意数量。它还实现了互斥对象,以避免冲突和竞争条件,它抽象了所有这一切都在一个清洁,简单的界面。经测试在Windows XP上。应该与任何现代的Windows上工作。

InterProcess is a compact general library that sets up windows shared memory using CreateFileMapping() and MapViewOfFile(). It allows the user to seamlessly store values of any type (int, char, your struct.. whatever) in an arbitrary number of named fields. It also implements Mutex objects to avoid collisions and race conditions, and it abstracts away all of this in a clean and simple interface. Tested on Windows XP. Should work with any modern Windows.

对于我现有的C code和LabVIEW之间的接口,我写了坐在进程间的顶部,仅公开特定功能的小包装DLL我的C code或LabVIEW中需要访问。这样一来,所有的共享内存是完全抽象化了。

For interfacing between my existing C code and labview, I wrote a small wrapper DLL that sits on top of InterProcess and exposes only the specific functions that my C code or labview need to access. In this way, all of the shared memory is completely abstracted away.

希望别人会觉得这code有用。

Hopefully someone else will find this code useful.

这篇关于分享C和LabVIEW的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆