LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

SubVI call vs direct code call

Hello I'm writing a program to controll de Parallel port and I've done some subvi, when I try to call one in a loop it doesn't work but if I copy the code of the VI instead of the VI it works fine. Does anybody knows where the problem can be? I atach the code.
 
In the code there are two bit chanels with a switch each one, the switch controls the way in that these bit are set, when switch down bit is set manaully, when up a square wave is generated. The subVI in charge of generating the square wave is the one that doesn't work when is called as sub VI ( bit 0 ) but that works when its code is directly called ( bit 1 ).
 
Thanks a lot
0 Kudos
Message 1 of 5
(2,665 Views)
For your SubVI to run continuously, it should be in a while loop, whose conditional terminal should be controlled from the MainVI.
 
I cant see the code as I dont ve LV 8.x in my PC, but this should probably be the solution for these kinda problems. Smiley Wink
- Partha ( CLD until Oct 2024 🙂 )
0 Kudos
Message 2 of 5
(2,652 Views)
Well, actually, the subvi has not the loop function, but the call to the subvi is in a loop, so maybe is it same?
0 Kudos
Message 3 of 5
(2,647 Views)


@Pichiflush wrote:
Well, actually, the subvi has not the loop function, but the call to the subvi is in a loop, so maybe is it same?



YES !

I got another PC to run your code & it runs perfectly. I mean the SubVI part.

Did you forget to ON the BI0 switch ?

Maybe you can provide smal loop delays in the upper & the SubVI while loops. Else, it consumes all the CPU. This could end up problamatic...

- Partha ( CLD until Oct 2024 🙂 )
0 Kudos
Message 4 of 5
(2,637 Views)
That won't fix the fundamental problem with the code: race conditions. Multiple ones. Caused by: excessive use of local variables. You are trying to read the values of indicators before they've been updated. You need to establish an order of execution. The way it is now, it's anyone's guess when something runs.

There are also a number of other issues, and since it's clear you're a beginner, you should spend some time going through some programming fundamentals. Some pointers:
  • In your main loop you're doing this:

    which doesn't make much sense. The ON/OFF will always be on as long as i is not zero. The same thing can be accompished by this:


  • You Int2Bit can be simplified by resizing the Index Array rather than having individual Index Array functions. Also, the input datatype should be set to an I32:


  • Your Bit2Int VI is performing unnecessary actions in taking the numbers (which should be integer datatypes), converting each to a Boolean array, taking the first element, and then taking each first element into a Build Array. Just take the numbers and feed them to the Build Array directly.

  • You use of the subVIs assumes that "DB0" is updated when you call the "Square Gen" VI. This is true, but it doesn't do it the way you think it does. Inside that subVI you have a sequence frame that updates the subVI's "Signal Out Ind" with the value that you want to write. The value that the main VI gets is the value once the subVI finishes. Thus, it will never toggle. This is by design of calling a function, and is not specific to LabVIEW, as it is fundamental to programming.
Bottom line: You need to spend some time learning about local variables and the proper way to use them, as well as how subVIs work. I would suggest going through the LabVIEW tutorials as well as seeing what's available on the NI Developer Zone's Learning Center. There are also a number of books available.

Message Edited by smercurio_fc on 09-17-2007 10:03 AM

Download All
0 Kudos
Message 5 of 5
(2,624 Views)