From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Code Running in Debug Mode, but not in Standard Mode

Solved!
Go to solution

Hi Everyone,

 

A few months ago I wrote some code that records the current over time.  It measures the current every 1s, and it gives the user the option to specify how often the data should be coded.  It can be either linearly (for example, every minute), or logarithmically (small increments in the bigger leading up to a larger value and the user can specify the maximum sample intervals).  I also created a queue that will record the "last minutes".  For example, if the user wants to see what happened in the last minute, he will have every second recorded and that data will be appended the end of the file.

 

However, it was a messy piece of code (although working), and I wanted to clean it up so that it would be easier to add to in the future.  I started to learn about state machines.  I am building it slowly.  First the user pushes play, and then fill in where to save, maximum recording intervals, other variables etc. and click load.  After, the user can push play to start the program.  At the moment, it is not connected to any equipment, just wanted to get the time recording intervals working.

 

At the moment, if it is run in debug mode, everything runs fine, but if it is not in debug mode, it stops after a few intervals.  I think that is most likely a race condition.  I do have some local variables, and I read that they should only be used if there are being used in two places within the same VI. But I don't think I am using them in the subVIs.

 

Can anyone give me some advice please?  It looks like it is not updating to the next recording interval.  I have attached my code.

0 Kudos
Message 1 of 14
(4,378 Views)

@_natalie_ wrote:

Hi Everyone,

 [...]  I have attached my code.


The lvproj does NOT contain the sources of the project. It is a "management file" which is XML based....

 

It sounds like a race condition so question is: Where do you run parallel things? Focus your search to these VIs/structures.

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 2 of 14
(4,367 Views)

Oh, I am sorry.  Not sure how to attach projects then.

 

Here are the VIs though.

Download All
0 Kudos
Message 3 of 14
(4,361 Views)

Looking into your main vi i honestly have NO idea what you are up to.

It is a Producer/Consumer (Event Based), not a Statemachine architecture.

The meaning and usage of your two queues in the consumer (Time and Date) is really inscrutable to me. What are they purpose? What do you intend to do here?

 

Coming back to your original question:

Is the VI stuck or is it "stopped"? Meaning: When you press the stop button, does the application stop or does it continue to run like a zombie?

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 4 of 14
(4,346 Views)

 

Hi Norbert,

 

Eventually I will use this code to record current over time.  I want the user to be able to specify if they want to record the measurements linearly or logarithmically.  If the measurement runs for a really long time, I don't want to record every second for weeks.  Eventually if the time between recordings becomes very long, we might not see what happened between the last recording and the next if the device breaks.  Those queues are there to record the last few minutes.  If the user wants to record the last two minutes leading up to when the component breaks, then the measurement will be placed into the queue every second (for a total of 120 samples since it is measuring every second).  The whole purpose of this is to reduce the data log once the measurement is long.

 

The VI is stuck.  If I push stop, it runs like a zombie.  The VI "Record INT" which can be found in "Start" will determine how long to wait until the next measurement is recorded.  After a few intervals, it gets stuck.  I have setup a few indicators.  On the Main Panel, there is an indicator that says "Recording Interval" and one "X-Y".  After the third interval, the "X-Y" indicator stays at 0.  This "X-Y" indicator tells me how long it has waited from the last recording until now.  If it equal to or larger than the "Recording Interval" it will append the data to a csv file.

 

I just want to see the code append the time to the csv for the time being.  Like I said, I am just learning these things and I want to see this work first before I move on.

 

Sorry for the confusion.

0 Kudos
Message 5 of 14
(4,327 Views)

Natalie,

 

i wouldn't store the values as a scalar directly in a queue.

Depending on where you require the data, you can use a circular buffer which essentially is an array you use with replace array subset and stored read/write "handles" (aka indices). You can put that data into an FGV.

 

You didn't attach the Record INT.vi to this post yet, so pls do so.

 

Did you have the chance to attend LV Core 2 and Core 3 training at NI?

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 6 of 14
(4,285 Views)

Hi Norbert,

 

I did attach in another post, but here it is again anyway (recordingInterval.VI).  No, I haven't had the chance to attend any LV courses.  

 

I will look at change how I handle those queues differently.  

 

Thanks for looking at my code again.

0 Kudos
Message 7 of 14
(4,253 Views)

Hi Natalie,

 

Looking on the VIs that you attached and the answers from Norbert, he is right. What you are using in your Main VI is a producer/consumer architecture, the issue why is “running like a zombie” is because you have your stop button only in your first while loop and inside your event case, all the others while loops their stop condition depends directly if the condition of the while loop is met and because you have a producer consumer architecture after the first while loop start sending data all the others will initialize and they won’t stop until the condition for stopping is met.

 

I am adding some links with documentation/tutorials to avoid race conditions, how to build producer consumer architecture and a link to a forum with an example to implement producer consumer design.

 

Hopefully this (and Norbert’s help) will help you building your application

 

http://www.ni.com/white-paper/7585/en/ Tutorial to avoid race conditions

http://www.ni.com/white-paper/7517/en/ Example/avoiding race conditions

http://www.winemantech.com/blog/avoiding-race-conditions-with-labview-programming/ Race Conditions

http://www.ni.com/white-paper/3023/en/ Producer/consumer Design

http://forums.ni.com/t5/LabVIEW/Producer-Consumer-Architecture/td-p/494883 Producer/consumer implementation example.

 

Regards 

Michael

0 Kudos
Message 8 of 14
(4,220 Views)

Thank you for your help!

 

I will definitely go through these tutorials and figure out where I am going wrong.

 

 

0 Kudos
Message 9 of 14
(4,204 Views)

I see that my one of the reasons my code wasn't working was due to the queues.  I needed to add a small timeout to the enqueue.  However, I don't really understand why, or why it would be better to use a circular buffer than a queue.

0 Kudos
Message 10 of 14
(4,129 Views)