LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Getting more data than expected. How to prevent this? (See attached code and description)

Solved!
Go to solution

I developed the attached code. The main goal is to create a text file that shows what state you are in and the time. The file looks like this below.

GRCK5000_0-1718939832250.png

 

What I want:

GRCK5000_1-1718940113304.png

or something similar to this below, where there is no repetition 

GRCK5000_3-1718940651520.png

 

 

 

I tried to achieve the above by using "first call", but I kind of not like first call because that part of the code (another 1) can only execute once, but what if I would like to execute it more than once.

GRCK5000_2-1718940308656.png

 

 

 

0 Kudos
Message 1 of 9
(940 Views)

As always, we cannot debug pictures, but I suspect there are serious bugs.

 

Is this a subVI? How does it fit into the rest of the project?

0 Kudos
Message 2 of 9
(914 Views)
Solution
Accepted by GRCK5000

LabVIEW and the Laws of Data Flow to the rescue.

 

Situation -- you have a program that "does things".  At various places in this program, you want to "log some data", maybe a message that says "I'm in the Main Loop, with index value = (fill in the blank)", where by (fill in the blank) I mean you want the value of the Loop Index "i" to be written.  Let's call the place in the message for that "Main Loop" appears "What", and where "index value" appears, "How Much".  So you want a little VI that takes "What" and "How Much" as inputs, and writes it to a text file, all without interfering with the process that you are running.

 

Welcome to the Producer/Consumer Design Pattern.  (You can Google "LabVIEW Producer Consumer" and learn a lot).  The notion is your Producer is the routine that accepts "What" and "How Much", places them in a Queue or a Stream Channel Wire, and sends them off to a separate Consumer Loop, running asynchronously, basically just waiting for input from the Producer, and "doing something with it", in your case, writing a line to a Text file, for example.

 

You should be able to take it from there.  Write some code (following the articles provided by NI) and write a little Demo program to try it for yourself.  You'll learn better and faster that way.

 

Bob Schor

Message 3 of 9
(876 Views)

The Shift Register on the left side of the loop can resize.  You can drag down an extra input Shift Register to hold the previous state.  Then you can compare the previous state with the current state.  If they are different, then you write to your log.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 4 of 9
(866 Views)

These kinds of issues are VERY EASY to troubleshoot yourself.   Just turning on the Highlight Execution and watching a few iterations would show you what's wrong a lot faster than posting here.  Plus, you learn more that way.  😉

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019
0 Kudos
Message 5 of 9
(856 Views)

Hi Mr. Altenbach! I am sorry. I just attached a VI. I thought I did. 

Also, it is not a subVI.

0 Kudos
Message 6 of 9
(847 Views)

Hi GRCK,

 

your VI is programmed to log "Only one" once and "Another one" as long as you don't press the STOP button.

 

When you need only one "Another one" entry in the log file then you should stop the loop as soon as the "Another one" state has been executed!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 7 of 9
(812 Views)
Solution
Accepted by GRCK5000

You can wrap the file write around a True/False case structure. Use the VIM "Is Value Changed?" in the comparison palette. This will set a write on the first call and if the message changes.

 

snip.png

Message 8 of 9
(789 Views)

@GRCK5000 wrote:

Hi Mr. Altenbach! I am sorry. I just attached a VI. I thought I did. 

Also, it is not a subVI.


  • This is a different VI compared to the earlier picture.
  • If you would replace the while loop with a FOR loop, and wire a 2 to N, you get the desired result
  • If you want the second state to run forever, and always overwrite the same file position, you can set the file position before writing.
  • You still have horrible coding habits. If all cases of a case structure write to the file, that file IO should to be after the case structure. You cases only differ by the format, so that's all that needs to be inside. You could even write the initial data before the loop.

 

altenbach_0-1718995772195.png

 

Message 9 of 9
(777 Views)