06-20-2024 10:32 PM
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.
What I want:
or something similar to this below, where there is no repetition
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.
Solved! Go to Solution.
06-21-2024 12:39 AM
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?
06-21-2024 07:00 AM
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
06-21-2024 08:06 AM
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.
06-21-2024 09:12 AM
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. 😉
06-21-2024 09:47 AM - edited 06-21-2024 09:48 AM
Hi Mr. Altenbach! I am sorry. I just attached a VI. I thought I did.
Also, it is not a subVI.
06-21-2024 10:35 AM - edited 06-21-2024 10:36 AM
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!
06-21-2024 12:08 PM
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.
06-21-2024 01:49 PM
@GRCK5000 wrote:
Hi Mr. Altenbach! I am sorry. I just attached a VI. I thought I did.
Also, it is not a subVI.