LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why does while loop pause during operation

Hi everyone,

 

I have written the attached code which will eventually be a part of a bigger program. The program is intended to log some test value, in this case just the date and time  to a csv file  when a button is pressed (log in WHITE, loop1).  Loop2 is intended to read a test value from a line in the first csv file and then add an extra test value to the end of that line when the serial number matches and then saves that line to a new csv file. This all works well but loop2 seems to pause a few times before continuing when either of the log button is pressed. I tried putting the code in 1 while loop with no success. Can anybody see what I am doing wrong?

0 Kudos
Message 1 of 6
(2,742 Views)

The Write To Spreadsheet File.vi is not reentrant.  This means that only one call to it can run at a time.  So if you are logging data in loop 1, loop 2 must wait until the first call to the Write To Spreadsheet File is complete before it can use the function.


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 2 of 6
(2,722 Views)

Suggestion: Do not use the Read from Spreadsheet VI inside a while loop at that rate. When you open the VI you may see the file is opened and closed everythime when you excute the VI, which is not a good practice. Instead try to use the the open file and then Read from Text file and Write to Text file primitives to perform read/write operation.

 

Good luck!

-----

The best solution is the one you find it by yourself
Message 3 of 6
(2,708 Views)

@Maiz wrote:

Can anybody see what I am doing wrong?


In addition to waht has been said already, your code is extremely convoluted.

 

  • How often does the "read" file change? Do you really need to read the entire file with thousands of rows every ms just to look at one row?. If the file never changes, you could read it once before the loop.
  • The way do do array opearions is mind boggling. You take one row, Index out the first element twice in parallel (once is enough!), then you index out the first element, built it into an array of one element, and compare that array with a scalar. Would't comparing the orignal element with the scalar be equivalent?
  • Index array is resizable, you only need one instance.
  • Getting five elements in a row just to build them back into a 1D array seems rather pointless. If the array has only five elements, there is nothing to do, and if it has more elements, you cold use "array subset", and if it has fewer elements, use "reshape array" to size 5.
  • The correct format for reading strings is %s (not %.10f).
  • Since you want both loops to run at the same speed, why don't you put it all in one loop? (this even eliminates the local variable) Then you could use a parallel loop for the file saving, using queues in order not to slow down the main loop. In the parallel loop, open the files before the loop, use lowlevel writes inside the loop, and close the files once the program stops.

Can you explain your setup and what the program is supposed to do? I am sure it could be done with 20% of the current code.

0 Kudos
Message 4 of 6
(2,664 Views)

Hello altenbach,

 

This is my very first attempt at writting a real program. It took me ages to work out how to read a row from a csv file and then add a value to the end of that row. I was quite proud of this until now 😞 . As you can guess I am very new to this and the main problem I have with Labview is finding the right functional block to use. 

 

The main purpose of the program will be to log a number of motor stator weights before and after varnish. When the stator is weighed after varnish the program will need to find the log data that was recorded against a serial number before varnish and then add the varnished weight to the end of that line.

 

I will take on what you said and have a go at simplifying the code. Are you able to help me with some sample code?

 

Best regards,

 

Maiz

0 Kudos
Message 5 of 6
(2,616 Views)

Maiz wrote:

I will take on what you said and have a go at simplifying the code. Are you able to help me with some sample code?


Sure. See how far you get and post back if you gets stuck.

 

You simply need to gain a little bit more experience (we've all been there ;)), that that's most easily achieved by actual programming. Also look at the design templates and example programs that ship with LabVIEW.

 

0 Kudos
Message 6 of 6
(2,588 Views)