LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to reset sensor value without closing LabVIEW

Solved!
Go to solution

I´m creating an automated irrigation system in which I want the user to enter the value of the humidity at wich the soil has to be kept, and also the maximun and minimun humidity values that the crop can endure. When the humidity sensor reads a value above or under those numbers, LabVIEW sends an email notifying that the humidity is out of the ideal range. And when the values are above or under the specified humidity, the valve will be turned on or off. I also send the values that the sensor reads to ThingSpeak.

 

The problem is that, if for whatever reason I have to stop the program, when I start running it again the sensor values aren´t correct anymore, and I have to close labVIEW and open it again so that it functions correctly. I have been trying some functions like setting values to default, but when I use it all the values entered by the user are deleted or turn into 0 when I start running the code. Is there any way to reset only the sensor value back to 0 so that it works even if I stop and start running the code multiple times?

0 Kudos
Message 1 of 6
(1,136 Views)

Hi Natalia,

 


@NataliaB14 wrote:
Is there any way to reset only the sensor value back to 0 so that it works even if I stop and start running the code multiple times?

Which kind of sensor?

Is there a manual for that sensor?

 

On your code:

  • Don't use BytesAtPort, when you use the TermChar for serial communication!
  • You don't need to compare with "1" to create a boolean value when that "1" is created from a boolean value! (Rube-Goldberg!)
  • Implement error handling for the serial communication!
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 6
(1,105 Views)

Hi Natalia,

I tried to simplify your code a little bit as shown below.

GRCK5000_0-1681017976328.png

 

What sensors's values are you referring to? Do you mind sharing them how they should look and how they are being changed?

Message 3 of 6
(1,062 Views)
Solution
Accepted by topic author NataliaB14

@NataliaB14 wrote:

I´m creating an automated irrigation system in which I want the user to enter the value of the humidity at wich the soil has to be kept, and also the maximun and minimun humidity values that the crop can endure. When the humidity sensor reads a value above or under those numbers, LabVIEW sends an email notifying that the humidity is out of the ideal range. And when the values are above or under the specified humidity, the valve will be turned on or off. I also send the values that the sensor reads to ThingSpeak.

 

The problem is that, if for whatever reason I have to stop the program, when I start running it again the sensor values aren´t correct anymore, and I have to close labVIEW and open it again so that it functions correctly. I have been trying some functions like setting values to default, but when I use it all the values entered by the user are deleted or turn into 0 when I start running the code. Is there any way to reset only the sensor value back to 0 so that it works even if I stop and start running the code multiple times?


It really does sound like you need a FILE to store user parameters in outside of LabVIEW itself. 

 

Configuration files, *.ini, hold sections of key-value pairs in human readable text.  LabVIEW does have an API on the files pallet that can easily read and write this type of file.  There are even shipping examples that demonstrate their uses.


"Should be" isn't "Is" -Jay
Message 4 of 6
(1,053 Views)

@JÞB got there before me.  I was going to suggest the same thing, which may lead you to restructure your program a little bit.

 

When you have a routine that has "parameters" that are usually the same from run to run, but may need an occasional change, rather than have them as front panel controls, you can organize your program so that the first thing it does is to read a "Configuration File" (which could be in the format of the .ini files that Windows uses, but should be a "text" file organized so that a human can read it with an ordinary editor, if necessary, and get all the information out of it).

 

When your program starts, it "knows" where the Config.cfg (that's a name I just made up for the Configuration File) lives -- this should generally be "close" (meaning path-wise) to your running program, so you move the Program and its files together so the relative paths stay the same).  It reads the Config file, puts the parameters in indicators (not Controls).  You might have a Push Button that says "Modify Configuration", which should call up a sub-VI that reads the values you just saved, lets you change them, and then (optionally) writes them back to the Config file if you want to save them for the next time.

 

That's it!  A little more work (a few sub-VIs), but when you stop the program (or it crashes, perish forbid!), when you restart it, you'll have the "last-saved" values in the Config file, ready to go.

 

If you build your program into an Executable, there's an easy way to keep the Config file "close" to the Executable, as well.

 

Bob Schor

 

P.S. -- Oops!  Did I just cleverly answer the wrong question?  Re-reading your original Post and @GerdW response, you are asking about resetting or not resetting the sensor when LabVIEW stops.  Hmm, sounds like I have no good ideas on that, as I'm not familiar with the sensor(s) that you are using.  Many of the ones I use are fairly straight-forward -- if they are reading "Flow is 3.2 liters/minute" now, and I stop and restart the program, I'd expect them to say "Flow is 3.3 liters/minute" (or some "reasonable" response) when I restart it.  On the other hand, certain position sensors need to "calibrate themselves" (for example, to find where "0" is located) -- if that's the case, and you "calibrate" or "auto-zero" of necessity, you may need to "do it again".

 

Sorry for my confusion.

 

BS

0 Kudos
Message 5 of 6
(1,045 Views)

Thank you! I did this and now my code works well 🙂

0 Kudos
Message 6 of 6
(971 Views)