Having trouble making my VI work as a Sub VI

时间:2019-04-17 00:29:48

标签: labview

I am having trouble getting the terminals to pass any data to what they are connected to because the controls they connect to are in a while loop. My frustration level is high since I would have already had this done if I wrote it in C.

First, let me say this might get a little long so if you don't want to read it, then don't. Here goes. I have watched a couple of tutorials, read a lot, and even tried a few things out in code. I get why this can't be done directly in a while loop. Having said that, it seems that I have no choice but to use while loop(s) in my VI.

My VI is loosely based on Queued Message Handler in the Templates section of creating a new VI. I have 2 things that must take place. One - I have created a TCP client where I constantly send messages to get status from the equipment I am communicating with. This is a timed event and must be handled in a while loop so I can maintain the connection to the server. I am not doing the Open, Send, Close, Reopen, Send, Close, etc. type of message handling. Too inefficient. This is the lower half of the example template.

Second - On occasion the user will press a button on the front panel which creates a message that is sent to the equipment to make it do something. And this, it would seem, needs to be in a while loop also, hence my problem. Some/most of the controls exist with the event structure. This is the top half of the example template.

I actually have this working as a front panel, but every thing is in just one while loop and I cannot get the terminals to work. Here is where my confusion comes in, if I am passing something to the while loop, I only get its value once and if it changes, you don't get that change, and if you are passing the data out of the while loop, you only get it when the loop ends. These two things are really baffling me. How can pass data that changes while using a while loop, because I have to, but the while loop breaks using the terminals. Seems circular. The TCP communications cannot stop, and I cannot find an example of how to do this using my friend Google. Am I the only person on this planet that needs to do this? Doubt it.

Not going to show my code, as this in not a code problem. It is an understanding how LabView does things vs. how you would just write the code in C using some library. And also just being unfamiliar with all the things you can do in LabView, not to mention how things are different. I don't know what I don't know, but I can learn.

I want to be able to give the VI I have created to any user and let them use it to control my equipment. If they just want to run it as a front panel, or if they want to use it as a Sub VI that is OK too. I just need to be able to make the terminals actually pass data when used that way.

Thanks, I did order a book on LabView today, but I won't get it soon. I really need to put this problem to bed.

2 个答案:

答案 0 :(得分:1)

在没有看到代码的情况下不能提供太多帮助。但是我可以尝试让您了解发生了什么。

Dataflow是要在LabVIEW中理解的重要概念。在元素(VI,循环等)的所有输入(即端子)已被之前调用的东西接收或设置之前,它们不会启动,然后它们仅接受一次输入。如果您的终端不在循环中,则循环只能读取其起始值。 (请参见this page上的“无限循环”)。解决此问题的一种简单方法是将终端放置在循环内部而不是外部,以便在循环的每次迭代中读取该终端。

关于将值传递到循环外,有许多方法可以实现。同样,由于数据流的原因,通常在循环完成执行之前,您将无法访问循环内部内容的值。但是,有许多方法可以在不同的循环中读取这些值。局部或全局变量是最简单的方法,但是NI不建议使用它们。处理此问题的正确方法是在同步托盘上使用某些东西。有关选项的更多信息,请参见here

看到您正在将某些内容基于“排队的消息处理程序”时,队列可能是开始的好方法。 LabVIEW内置了一些代码示例,向您展示如何使用这些功能。

循环同步和异步编程是编写LabVIEW代码的基本概念。如果您不熟悉这些概念,我想说的是,向他人展示您的实际代码并让人们帮助解决这些问题将使您受益匪浅。如果您担心共享某些专有内容,请尝试制作一个简单的示例,然后发布该代码,以更好地理解这些概念。

答案 1 :(得分:0)

事件结构对evr8作出反应,并通过全局函数传递数据。

建议粘贴框图。