LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Trouble getting a subvi to update a graph in real-time on the front panel

Here is the picture. 3D graph 2 was just a regular indicator so I can observe what should happen so ignore that. 

 

And nothing else was in the selection. All I did was click on the sequence structure and click create subVI. Maybe the code is too complex for the algorithm to properly create a subVI. The code had errors after trying to create a subVI in that way, so I just gave up and used my manual version. 

 

EDIT: I looked at your example again and I realized something. If you right click on the refnum that is created in the subVI and click show control, you can see the waveform chart. If I do the same thing with my refnum, I do not see the 3d graph. Nothing really happens actually, except that the generic refnum control icon goes from having little shapes in it to turning blank. I wonder if that is related to my problem. 

0 Kudos
Message 11 of 36
(2,895 Views)

Your code suffers from severe sequecitis and localitis! Why all these stacked sequences and local variables????

 

If you try to make a subVI out of the sequence frame, it will include all code from all frames, and it would need to "fix" all local variables. That will be a horrible mess and probably will not work as you want.

 

0 Kudos
Message 12 of 36
(2,882 Views)

What's wrong with stacked sequences and local variables? They make the diagram neater. Otherwise i'd have wires out the wazoo...

0 Kudos
Message 13 of 36
(2,870 Views)

@ModusPwnens wrote:

What's wrong with stacked sequences and local variables? They make the diagram neater. Otherwise i'd have wires out the wazoo...


You really need to get familiar with the State Machine architecture before you run into a gigantic hornets nest with race conditions and unyielding sequences.  Try stopping your program due to an error in the middle of a sequence, or anywhere in the sequence.  You can't.  With sequences within sequences within sequences, your code has to go all the way to the end.  Don't use the abort button either, not very elegent, and it leaves things powered up and references open and such. 

 

Local variables are very susceptible to race conditons.  If you don't know what a race condition is, you will learn the hard way if you keep using locals.

 

Please listen to the advice being given here.  We know of the dangers of local variables and the shortcomings of sequence structure through experience.

 

Convert your code to a state machine architecture.  You will be able to eliminate locals, and you will have much better control over your execution flow.  It also gives you the advantage of being able to change your code much more easier than if you used your nested sequence structures.

 

Attached is an example of a state machine, in LV2009.  If you need a previous version, let me know.

 

 

- tbob

Inventor of the WORM Global
Message 14 of 36
(2,849 Views)

 


@ModusPwnens wrote:

What's wrong with stacked sequences and local variables? They make the diagram neater. Otherwise i'd have wires out the wazoo...


 

(In addition to what tbob said)

 

First you break all dataflow by using local variables, then you need to enforce the lost dataflow with sequence structures. Two wrongs don't make a right (but three left turns do ;)) Local variable abuse, especially with large data structures such as 2D arrays, impose a serious memory penalty, because the require additional datacopies in memory.

 

Sequencing your code like a text based program, with sequences frames as "lines" and local variables as "variables", might seem natural to somebody familiar with text based programming, but is not natural at all in LabVIEW. In addition to the extra memory overhead, you also lose all possibilities of parallel processing on multicore CPUs. Basically you spoon-feed the data one frame at a time, even if certain things could operate in parallel.

 

Remember, the wire is the variable. There is nothing wrong with wires! Abusing front panel objects (indicators/controls, often hidden from view) as cheap "variables" for intermediary storage is not correct. That is not their purpose!

 

If you store values in a shift register instead, things operate efficiently "in place" and don't involve the front panel at all.

 

Deeply stacked sequences make the code very hard to read and debug, because most of the code is hidden from view.

 

 

Anyway, as a first suggestion, did you ever try to hookup an error indicator the the property node to see if it tries to tell you something???

0 Kudos
Message 15 of 36
(2,834 Views)

Ok, so I will try and convert my code. I have read up on State Machine Architecture and understand most of it. I just have one question:

 

Should i completely avoid using sequence structures altogether? What if I have a really long sequence of code? Do i just put it in anyways? Or is there a way I can make it neater and not too much to look at without violating the idea of a State Machine Architecture?

 

Alten:

 

No, but I knew that it still plotted the data to the graph. For some reason, it just wasn't being represented on the front panel of the main VI. 

 

EDIT: Furthermore, in my code I have around a dozen buttons the user can push. If I am understanding correctly, I would have a "Wait for event" state/case that contains an event structure in a while loop that monitors for when the user pushes a button, correct? And then whenever an event is registered, you would leave the event structure and the while loop and go to the appropriate state/case, returning to the "wait for event" state/case when the user-initated one finishes? Sorry, I am just trying to understand. 

0 Kudos
Message 16 of 36
(2,831 Views)

I assume you showed the code from the subVI. Is this correct?

 

How is the reference connected in the main VI? Are there any coercion dots? What is your LabVIEW version?

 

Here's a quick demo (LabVIEW 8.6) that shows that the method works just fine. Simply select the sequence frame and create subVI, then run the main VI again. It works the same as before. 😄

 

Download All
0 Kudos
Message 17 of 36
(2,807 Views)

I connected the graph itself to the terminal on the subvi. I tried connecting a reference earlier, but when I try to now, labview yells at me and says that there isn't enough memory to do that. 

 

EDIT: Nvm, i was being dumb. Sorry, I have been working on this problem for ages. Anyways, I have a reference to my graph connected to the terminal on the subVI. And then the subvi is set up exactly like yours, yet it still doesn't work. 

 

I have attached the picture of my connection.

0 Kudos
Message 18 of 36
(2,794 Views)

@ModusPwnens wrote:

 

Should i completely avoid using sequence structures altogether? What if I have a really long sequence of code? Do i just put it in anyways? Or is there a way I can make it neater and not too much to look at without violating the idea of a State Machine Architecture?


Yes, avoid sequences altogether.  You can simply copy your code from each frame into a case of the state machine.

 


@ModusPwnens wrote:

EDIT: Furthermore, in my code I have around a dozen buttons the user can push. If I am understanding correctly, I would have a "Wait for event" state/case that contains an event structure in a while loop that monitors for when the user pushes a button, correct? And then whenever an event is registered, you would leave the event structure and the while loop and go to the appropriate state/case, returning to the "wait for event" state/case when the user-initated one finishes? Sorry, I am just trying to understand. 


Your description is correct.  Here is a small example of a state machine with an event structure.  Basically, the events case just waits for the user to push a button, then it calls the next state depending upon which button is pushed.  After the button code is done, the next state is the events state again.  The process repeats until stop is pressed.  Then the event captures the stop event and calls the exit case, where you can put cleanup code.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 19 of 36
(2,793 Views)

Ok and one more question: Is there a way I can group controls and pass them in like you did? If not, what would be an efficient way of writing to a control without having to create local variables everywhere?

0 Kudos
Message 20 of 36
(2,774 Views)