LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

An apparent misunderstanding of data flow

So far I've taken a hacker's approach to LabVIEW and have learned most of it through trial-and-error.  I've just encountered a kind of 'Data Flow' crisis, where I once thought I could program LV in a more object-oriented function/function-call manner, and have now realized that there's another kind of logic involving data flow and multi-threaded processes.

I've been writing some process control software where I'm attempting to use a loop to cycle through various control states, and I want each one of those control states to be sent to a relay board via the serial port.

The problem I'm running in to is that the signals are not being sent, and I've narrowed it down to where it appears that the signals aren't being sent because the code used to send the commands is inside a loop.  I figure that I'm making a mistake someplace due to a data flow misunderstanding on my part.  I have included 'serialcommunication.vi' in my VI, and have placed the sub-vi inside of a loop structure.  When I am in debug mode, it appears that the proper ASCII commands are being sent to the sub-vi, but then the subsequent code within the sub-vi is not being run (at least, not when I want it to run).

I've attached the VI and sub-VI.  My problem is occuring in the "Control Cycle" section, where I have a series of Select comparison controls connected to serialcommunication.vi.  You'll see tons of redundancy, but this code is really a work-in-process and I will clean it up later.  If there is a radically different way of doing this that would be much simpler, feel free to point me in the right direction.

BTW, I am using LabVIEW 6i.  My university lab is just now upgrading to 8.20 so we will soon be up-to-date.

Message Edited by vanguns on 03-05-2007 02:26 PM

Download All
0 Kudos
Message 1 of 4
(2,597 Views)

The attachments are not there.

Never mind, they are there after you edited the post.

Message Edited by Dennis Knutson on 03-05-2007 01:28 PM

0 Kudos
Message 2 of 4
(2,596 Views)

Dataflow is the basic underlying design of LabVIEW and you violate it in just about every way. Smiley Sad Unless you are running in continuous mode (which is not the correct way to do it), none of the code that is outside the while loop is going to run more than once. For example, the status of the local variables in your emergency shutoff will be read and the case statement will executed once. It won't be run again until you restart the VI. The local variables are set inside the while loop though. The ending routine will also start up at the very beginning and not run again. As another example, once the main while loop starts, the Booleans wired to the serial case statements are no longer polled so your serial com won't work at all. As a minimum, you would have to put all of that code inside their own while loops so that they are running concurrently with the main loop.

You've got way too many local variables. Locals can be used effectively but they can also cause a race condition. Even if you create additional while loops, I suspect that you will have problems there as well.

I'm afraid that you are going to have to do a serious rewrite. If you stick with 6.0, you might want to look at something called a state machine. A state machine is simply a while loop with a case statement inside. I believe that 6.0 comes with some simple examples of this. You might also want to look at a couple different loops running in parallel and passing data between them with a queue.

0 Kudos
Message 3 of 4
(2,568 Views)
Yes, you have some serious dataflow issues here. Are you running this with the 'run continuously' button? If you are, you shouldn't be. I ask because the way your buttons are set up, most of what you have on this block diagram is not in a loop, so the boolean logic will only be checked once when the vi is run. In theory it would work by running it continuously, but that is bad practice.
 
The main thing I can see with why you're having trouble sending commands to the serial port is that you have the command wired to the VISA resource name input, and nothing wired to the command input of serialcommunication.vi. You also have all of these writes in parallel, so you have no idea what order they will execute.
 
I suggest you get your hands on some reading material about LabVIEW. Go through some tutorials to understand the basics.
0 Kudos
Message 4 of 4
(2,560 Views)