LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

IF, THEN and WHILE loops

I'm really new to LabVIEW, so I'll preface this post by saying that this question has probably been asked before. I'll begin by describing what I want to do: I have a VI that controls a Lake Shore 331, which is a temperature controller, and I want to automate a data-acquiring procedure.

 

Basically, the user supplies a .txt file with a list of temperatures, say in the format "8 25 50 100..." i.e. just the values seperated by whitespace. I've figured out how to use the "read from text file" function, so I now have a string that looks like the raw input above. Now I wish to (1) split this string at the whitespace, and convert each number to a "number"; (2) for each such value, to check if it lies in a specified range, and depending on what range it's in, to pass certain values to the Lake Shore to implement for a certain amount of time.

 

I'm fairly confident that if I know what temperature range a given value is in, I could use a simple case structure to finish off the program, so it's really the first  part that I'm having trouble with. Is there an easier way to get multiple vaules from the user and covert them to decimal? This .txt file thing makes sense to me since I usually work with Python, but I'd love to hear alternatives. Then, how would one go about implementing a range-check, and then a timed loop for each of these values?

 

Any help is much appreciated; please let me know if anything's not clear.

 

Thanks!

0 Kudos
Message 1 of 12
(3,120 Views)

Re: splitting the string.

 

have a look at this post http://lavag.org/topic/10751-splitting-string-sentence/#entry63943

 

0 Kudos
Message 2 of 12
(3,110 Views)

temp range_BD.png

build an array with your ranges and temp. re arrange thru sorting, then search temp index and output with user set times

0 Kudos
Message 3 of 12
(3,092 Views)

Hi

 

just an addition to what apok has said:

 

Wire the Read Test output to "Spreadsheet String to Array" function in the string functions.

 

you can get a floating number or an integer number output as in the attached screenshot

 

Regards
Freelance_LV
TestAutomation Consultant
0 Kudos
Message 4 of 12
(3,086 Views)

Hey apok.

 

Thanks for your solution. This is almost exactly what I need.

0 Kudos
Message 5 of 12
(3,020 Views)

@vivianbritto wrote:

Now I wish to (1) split this string at the whitespace, and convert each number to a "number"; (2) for each such value, to check if it lies in a specified range, and depending on what range it's in, to pass certain values to the Lake Shore to implement for a certain amount of time.


You need to be much more specific:

 

  • Are these all integers or sometimes floating point numbers?
  • Are the values in the file always sorted as in your example or can they be in random order?
  • What determines the range?
  • Where do the "certain values" come from?
  • Do you want always want to pass a number (just different depending on range) or only sometimes (e.g. only if it is in range)?
  • Where do the "amount of times" come from? Do they also depend on the values in the file?
  • Are "certain values" and "certain times" indepdendent or are the values the times?
  • What should happen once you run out of numbers?

 

I think you should describe a full example with the most general input values and explain what output you want for that case.

0 Kudos
Message 6 of 12
(3,005 Views)

you did'nt understand my previous explanation? ok, your temperature value is put into an ascending array with your range values...that index will point to another array of user set timed values.

 

  • if temp. value is less than your range #8, then index is "0" on the ascending array, this will corespond to the user set time value index "0",which is currently set to 1
  • if temp. value is between your range #8 and #25, then index is "1" on the ascending array, this will corespond to the user set time value index "1",which is currently set to 2....and so on

these user set time value constants can be changed to whatever you want, including making it a user interface control....don't forget to kudo help and or mark as solution Smiley Wink

temp range_FP.png

Message 7 of 12
(3,002 Views)

To all, sorry for my excitement and going back and forth with my reply from earlier. Apok,I now realise that I've actually made a mistake describing what I want the VI to do.

 

altenbach, I'll answer your questions first.

  • Are these all integers or sometimes floating point numbers? Sometimes floating point.
  • Are the values in the file always sorted as in your example or can they be in random order? They'll always be in ascending order.
  • What determines the range? A range in this program is a temperature range, i.e. 0 K - 65 K, 65 K - 125 K etc. These will be determined by me.
  • Where do the "certain values" come from? The "certain values" are 4 parameters that I wish to send to Lake Shore (P, I, D, and Heater Range) depending on what range the current temp. reading (this was my first mistake in describing my problem, apok)  on the Lake Shore is. (see example below)
  • Do you want always want to pass a number (just different depending on range) or only sometimes (e.g. only if it is in range)? This was my second mistake. My Lake Shore VI is to run continuously, and as soon as its current temp. swithces to a higher range, the P, I, D and Heater Range parameters are to change. 
  • Where do the "amount of times" come from? Do they also depend on the values in the file? The "amount of times" are fixed values determined by me, specific to the different ranges (since it takes longer/shorter to heat up depending on the range).
  • Are "certain values" and "certain times" indepdendent or are the values the times? The "certain values" are the PID and Heater settings, and the "certain time" is the time I want my while loop to run.
  • What should happen once you run out of numbers? Since the Lake Shore is just the temp. controller, I want it to stabilise at the final temperature so I can take my measurement using a subVI that controls another program, and once this is done, the whole VI should terminate.

 

Here's a full example; hopefully this will make things clearer. LS stands for the Lake Shore VI.

 

  1. The user supplies the VI with the temps. that he wishes to take measurements at. The first post specified a .txt file format for this, but if entering temps. directly into an array on the front panel of the VI is easier, that works too. These temps. can sometimes be floating point numbers. Let's assume that 8 is the first value that the user enters; the full list may be something like "8 25 50 100 135 170 200 235 270 300 330". The user also specifies a tolerance setting (say, 1 K). The main VI  is then run.
  2. Forget about the ranges, since I realise now that they're messy. Let's instead talk abut critical temps. These are 65, 120, 165, 235, 325. These are fixed values.
  3. LS must now begin to excute continuously, since I constantly need the temp. readings from it (I do not know how to make a subVI execute continuously). There are two temp. readings, call them A and B.
  4. I feed the "8" into the "Setpoint" parameter of LS. Another fixed parameter is a stabilising constant (say 300 secs). I specify this and it's constant through the program.
  5. A starts off at room temp. (way above 8 K) and drops steadily. As soon as it gets to A gets to below 9 K (from 8 + 1, the tolerance setting), I start a timer which runs for 300 secs. At the end of this, I record A and B, and send a command to take a measurement (I have an easy-to-use VI that I'll call). When this VI tells me the measurement's done, we move to the next temp.
  6. I feed "25" into "Setpoint", and PID + Heater settings. All the while, I have to make sure that A is below my first critical temp. of 65 K (redundant here since the setpoint itself is below 65 K).
  7. As soon as I hit 24 K (25 - 1 this time),  the timer starts again, runs for 300 secs and I take a meausrement as above.
  8. Same drill for 50 K, since this is also below 65 K.
  9. Now for the 100 K measurement. I've fed "100" into "setpoint" and the same PID + Heater settings as before. Now though, as soon as A reads > 65, I want to input new PID + Heater settings. Then I just start the timer at 99 K, etc.
  10. This continues for all the temps, and after the final meausuerment has been taken, I want the entire program to terminate.

As you can see, the first temp (8 K in this case) is a bit of an anomaly since we're cooling down. After that though, we're constatly heating up to the next temp. in the list. I apologise for the earlier confusion.



0 Kudos
Message 8 of 12
(2,986 Views)

see if this gets you closer....

Spoiler
temp range mod.png
Message 9 of 12
(2,943 Views)

Thanks for the quick reply, apok. Could you please briefly explain what this VI does? 

0 Kudos
Message 10 of 12
(2,897 Views)