LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Index array elements (from excel file) every 10 minutes

I want to read values from an excel file at 10 minute/10 second time interval.

Untitled.png

 

Currently I am trying to do it this way:

 

The main while loop has wait in ms of 2000. If I want to read the data every 10 minute then I divide counter (i) by time interval (10*60)/2 and round it down to small interger, so that it reads the same value until the next time step. This works, but when I inclue it in my main VI which has DAQs and control strategy, the time at which the values are read are typically slower compared to when run independently.

 

Is it possible to index the elements with a timer or something else?

0 Kudos
Message 1 of 5
(1,168 Views)

The behavior you are experiencing is expected.

 

You are using WAIT function which briefly just wait 2s after completion of your code (to be honest, it all depends how you have it implemented in your code).

 

So if you run only reading part, it runs quite fast, so read + 2s takes 2,4s (this value is made up).

If you run reading part + daq, it runs slower, so read + daq + 2s takes 3s (again, some made up value).

 

So the interval between reads for both solutions will be different.

If you would like to control it more precisely, you need to implement a timer, that will check elapsed time with every iteration of your while loop.



0 Kudos
Message 2 of 5
(1,137 Views)

Looking at your code, I can only say "Why?".  Several comments:

  • Please do not call a "Comma-separated Values" (.csv) file an "Excel" file.  Don't let Microsoft "fool" you because Windows gives it an icon that strongly resembles the Icon for true Excel (.xls, .xlsx) Files.  A Comma-separated Values file is an ordinary Text file that uses a designated character (by convention, a Comma, hence the name, but LabVIEW uses a <tab>, go figure) to separate "values on a line" (a.k.a. a "Column" in a 2D Array format) and Line Delimiters to separate "Rows".
  • You appear to be reading a (constant?) file and saving values in Global Variables.  Why not skip the Reading (or do it once) and return the values as a Cluster, everything at once?  No need for Globals.
  • Have you thought carefully about what you want to do?  You seem to be hung up on "how" to do it, but it is not clear (to me) what is being done (except resetting constants).  Note you don't need to explain to me what/why you are doing what you are doing, but if it is this unclear to someone looking at your code, that means it will be hard to maintain, and suggests a "rethink".

Bob Schor

0 Kudos
Message 3 of 5
(1,134 Views)

@Bob_Schor wrote:

Looking at your code, I can only say "Why?".  Several comments:

  • Please do not call a "Comma-separated Values" (.csv) file an "Excel" file.  Don't let Microsoft "fool" you because Windows gives it an icon that strongly resembles the Icon for true Excel (.xls, .xlsx) Files.  A Comma-separated Values file is an ordinary Text file that uses a designated character (by convention, a Comma, hence the name, but LabVIEW uses a <tab>, go figure) to separate "values on a line" (a.k.a. a "Column" in a 2D Array format) and Line Delimiters to separate "Rows".
  • You appear to be reading a (constant?) file and saving values in Global Variables.  Why not skip the Reading (or do it once) and return the values as a Cluster, everything at once?  No need for Globals.
  • Have you thought carefully about what you want to do?  You seem to be hung up on "how" to do it, but it is not clear (to me) what is being done (except resetting constants).  Note you don't need to explain to me what/why you are doing what you are doing, but if it is this unclear to someone looking at your code, that means it will be hard to maintain, and suggests a "rethink".

Bob Schor


I am storing in global variables so that I can use them as a setpoint input to the PID blocks (real values are read from the DAQs). These setpoints changing every 10 minutes or 10 seconds depending on which circuit we are trying to control. That's why I thought reading the values to global variables (instead of reading everything at once) and passing them to the PID block would work. 

0 Kudos
Message 4 of 5
(1,114 Views)

Thank you for attaching your code -- that tells me that you are using LabVIEW 2017, which includes a powerful feature for communicating between multiple loops running in parallel, namely the Asynchronous Channel Wires.

 

In your case, you have a loop running every 10 minutes or 10 seconds that sets some criteria (which I symbolize here as a Cluster, as it can contain multiple elements of multiple types, numeric, boolean, string, etc.) that need to be used by another loop until it is time to change again.

 

One of the Channel Wire types is called a "Tag", which "remembers" (and delivers whenever it is called) the "latest value" passed to it.  Here's a picture illustrating this:

Using Tags for Loop Updates pix.png

(I tried to create a Snippet, but it failed to show the Tag Channel Wire containing the Criteria Cluster on the left to the "Latest Criteria" on the right, so I just did a Screen Capture ...)

 

The things that look like "Pipes" and that sit "on top of" the edge of Structures such as While Loops are Channel Wires -- they are "metaphors" for "instantaneous transfer of content" that ignore LabVIEW's Prime Principle, the Principle of Data Flow.  In this sense, they resemble Global Variables (which you used), but they show (very explicitely) where the data originate and where they are used.  Note that I used another Tag Channel to connect one Stop button to both Parallel Loops -- whatever value is carried on the Stop Control in the left loop will be reflected (simultaneously) as the output of the Tag Channel Reader in the right loop.

 

I don't know how you decide to change the loop of the left-hand "Criteria-generating" loop, but it doesn't matter -- when the Criteria change in the Left Loop, it will be "used" in the Right Loop.  And the "Instantaneous Data Flow" (a term I just made up) will be obviously visible -- just follow the distinctive "Pipes".

 

Bob Schor

 

 

Message 5 of 5
(1,084 Views)