LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating a Sub-VI : Serial Com

Hi Everybody,

 

So I have this program to read from a scale.

 

This is going into a much larger program, so I wanted to turn this into a sub-vi.

As a sub-vi, I want it to continuously read weight measurements, (so this program would be cycling/running every 10 ms) much like a DAQ, and I was hoping I could directly connect an output connection to a waveform graph/write to measurement file.

 

Where do I put the numeric control variable so that it will continue to read weight measurements and not just once?

Capture.PNG

Thank you for your time!

0 Kudos
Message 1 of 4
(3,379 Views)
That code is poorly written and would not work at all as a subVI. It would not return any data until it finishes and it would not finish since you cannot pass a stop condition once it starts. Separate the configuration and call that once in your main. Don't have the loop inside the subVI. Have the loop inside the main where you call a subVI that does a single read. The shift register/feedback node would be in the main.
0 Kudos
Message 2 of 4
(3,366 Views)

Please attach the actual VI instead of a hard-to-read-and-understand picture of the VI.  Not only can we see what you are doing more clearly, we can actually test your code and any changes we suggest.

 

BS

0 Kudos
Message 3 of 4
(3,362 Views)

You can put the reading into a SubVI and run it many times, but the open and close functions (like initializing the serial port) should only be used once, at the beginning and end of your program respectively.

 

If you want to update an indicator from a SubVI, you will have to pass reference to the SubVI as an input. You cannot simply drop an indicator into your SubVI. To get the reference you would right click on the actual graph that you want to update (on the front panel of the main program) and click create >> reference. (This is just one way to get it). Then you can use property nodes to udpate the graph. This will slow things down considerably and you probably won't be able to read data as quickly as you'd like. But, you probably don't need to update the graph every 10ms (as a human, it would make it hard to read), so perhaps only update it once a second with the current value, or the average of all the values that occurred since the last reading.

 

If updating the reference is too slow, you can make a queue. In your main program you would use de-queue to receive elements and update the graph (often in a loop with many UI elements in different cases of the loop). Then when you want to update the graph from your SubVI you will just enqueue another element on the queue which is very quick, and should not slow down your acquisition at all.

0 Kudos
Message 4 of 4
(3,356 Views)