02-03-2016 05:28 PM
Hello,
I started learning LabView recently and I have been working on this small code. The idea is to continuously monitor power supply for voltage and current and record data into a spreadsheet only when there is a change in voltage/current reading or change in voltage by the user.
I have used an event structure to append the spreadsheet only when there is a change in value of voltage/current. But by using Highlight Execution, I have noticed that the code stops monitoring voltage/current and hence will not re-iterate till voltage is changed manually by the user. I have tried using the case structure out of the while loop but this leads to other errors.
Any information regarding this would be appreciated.
Thank you for your time.
Solved! Go to Solution.
02-03-2016 05:41 PM
02-03-2016 06:51 PM
Thank you for the response Mike.
No, I have not checked for errors. I don't think there is any error. it's just a matter of structure.
The while loop doesn't continue iterating till the event structure is initiated and executed. This wait occurs for every loop. I am assuming this is not an error and it is how the loop is expected to behave.
My issue is, how do I continuously monitor these readings while recording them onto a spreadsheet only when the values change.
Again, thank you for your time.
02-03-2016 07:03 PM
@mikeporter wrote:
Sorry, I'm on my phone and I can't look at your code.
To make things a little clearer, since you can not view the code, I have to mention that the event structure is within the while loop.
02-03-2016 07:13 PM
02-03-2016 07:53 PM
Put the writing to the file Inside of the event structure. You will also want to put in a timeout value for your event structure.
Dataflow 101: A loop cannot iterate until all code inside it is complete. That event structure is sitting there waiting for you to change the frequency or push the stop button. While waiting, nothing else in that loop can run again.
02-03-2016 08:11 PM
Welcome to LV. I'm fairly new myself, so don't quote me, Unless you hear it from someone else more knowledgeable than me.
There are a few things I notice.
Usually it's helpful to mention what version of LV you're using. Base,.. Professional, year. something about it
When I clicked and downloaded your vi, it does not contain sub-vi's that are essential for operation. The picture I'm posting is what I see when I open your vi as downloaded.
I think that a way to deal with this is to create a zip file that contains all the vi's.
The following solution is a maybe. (I'm not sure if what I'm about to describe is a result of having the Application Builder as an add-on. If everyone has this great, or maybe you have application builder.) I believe you can do this easily when your vi is made as a project. Assuming you have a newer version of LV, you can do this from the splash screen (the box that pops up when you first start LV). Click "create project". Click blank vi (or a state machine if you want a little more flexibilitiy on implementing your code. Start with just a blank vi if you're brand, brand new. Then you have just one "sheet of paper" to consider. ) After you name the project and put your code in the main vi, save it. Then while you're looking at the Items tab of the project, right click on the words "Build Specifications" > New > Zip File. Hopefully that works. I've never done it.
I'm wondering, how does your code know that current or voltage changed? How much of a change is needed to trigger saving data? I see there is a current limit, but that seems like max current the power supply will produce. I guess it's not related to detecting that much change in current to save the data. Is there a voltage limit? If so, probably should label it as such.
I'm thinking there needs to be a while loop with shift registers. Each time the loop cycles it will compare the previous reading to the current reading. Then if the difference between the previous and current readings exceeds a threshold, the current reading will go to a case structure (inside the while loop) where there is a "write to spreadsheet file", set to append.
To get a shift register, right click on the right or left wall of the while loop, select Add Shift Register. Then click the opposite wall. wire the voltage or current to the shift register on the right. make two of them. If you had many data points you would need to condense them into a single shift reg. On the outside left of the while loop, right click the shift reg input wire and create constant zeros to initialize them. The shift reg coming from the left will be the previous iteration.
Add a millisecond (ms) "wait" clock inside the while loop and put a constant on the input. This will control the delay between loop iterations. How often do you want to check for readings?
(As an aside, this is the first time I've posted to the forum responding to someone. I didn't know if I should click "Reply" to Mike, who was the last person in the thread. Or click "reply" to the orginal post. So i picked the original post, and we'll see what happens. Hopefully it will turn out all_ok.)
02-03-2016 08:38 PM
Hello and welcome to a post where you are helping someone else out.
Unfortunately, while your tips sound good, they aren't going to solve the OP's problem. As crossrulz pointed out in in his message, the problem is the loop is waiting at the event structure for an event to happen, either a value change on voltage, a value change when the stop button is press, or a timeout. And the timeout will never happen because the default value when nothing is wired is -1, which means wait forever.
It doesn't matter which of the posts you click reply on. Your message will be added to the end of the thread. If you happen to be replying to a specific message in a way that it isn't the last, or is otherwise unclear as to which message you are reffering to, it is helpful to use the quote button which puts in the text of the message you are replying to. (In that case, it is helpful to click the reply button next to that particular message.) If it is a long quote and you are really only replying on a part of it, then it is helpful to edit the quote only leaving the part of it that is relevant to your reply.
02-03-2016 09:18 PM
Thank you everyone for helping me out.
@crossrulz wrote:You will also want to put in a timeout value for your event structure.
I will check this asap, but I think this will give me the right solution. If I am not wrong in understanding this, when a timeout occurs, the event structure will be skipped and nothing will be appended to the spreadsheet and the code will go back to monitoring the power supply.
Thank you crossrulz.
02-03-2016 09:24 PM
No. The event structure won't be skipped. The Timeout case of the event structure will be executed. Whether that appends data to the spreadsheet or not all depends on how you have things coded up.
Use Highlight Execution.