LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Event Structure Problems

Solved!
Go to solution

Hello all,

 

Im using the following code trying to obtain voltages and then use the peak voltage to trigger an event. My event structure doesn't seem to be working properly and I'm not sure what I need to do.

 

Take a look, and any help would be great!

0 Kudos
Message 1 of 25
(4,022 Views)

Hi fresh,

 

My event structure doesn't seem to be working properly

Why do you think so?

It works exactly the way you programmed it to work!

 

You created a valuechange event for "peak voltage". the problem is: there is NO event source as

- the event structure reacts on UI actions of the user

- "peak voltage" is an indicator, so the user cannnot create valuechange events on it

 

Please study the example VIs coming with LabVIEW. They show how to use the event structure!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 25
(4,012 Views)

First, just saying that it "...doesn't seem to be working properly..." is not very helpful. Please be as specific as possible about the ways in which it does not work as you expect.

 

Next. Value change events only apply to user generated changes, as when a user clicks on a boolean button.

 

It is generally not good practice to put code which may take a long time to execute (such as dialog boxes) inside event cases because it can lock up the program.

 

You should have an event case for Stop Button 2: Value changed so you do not need to wait up to 20 seconds to stop the loop.

 

The left loop should probably have a Wait or delay unless the missing subVI performs that function.

 

The DAQ task should be closed after the loop exits.

 

Lynn

0 Kudos
Message 3 of 25
(4,004 Views)

As mentioned, you are not using the event structure properly.  But WHY are you using it at all?  If you want to increment a value when a boolean changes put the increment code in a case structure and wire it to the boolean.  Done.

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019 - Unfortunately now moving back to C#, .NET, Python due to forced change to subscription model by NI. 8^{
0 Kudos
Message 4 of 25
(3,994 Views)

The value is changing though without the user needing to do anything. I don't get why it wouldn't work. Is there another event trigger I should be using for the peak voltage then?

 

Sorry this VI is kind of a mess, I through it together pretty quickly to illustrate a problem I was having.

0 Kudos
Message 5 of 25
(3,993 Views)

try looking here at a couple of examples(value signaling or dynamic event)...

0 Kudos
Message 6 of 25
(3,980 Views)

@winterfresh11 wrote:

The value is changing though without the user needing to do anything. I don't get why it wouldn't work.


Think about what you said.  The Event Structure is something that responds to user events.

 

If the user isn't doing anything, why would it respond?

If it shouldn't respond, you want to look at using an algorithm that SHOULD respond.  You're using a more complicated architecture than you need to be using in order to incorrectly use the Event Structure.  Stop that.

0 Kudos
Message 7 of 25
(3,942 Views)
Solution
Accepted by winterfresh11

hey,

 

there are a couple of things wrong with your layout, other than the Event Structure isn't being called. What you have here doesn't do a lot and that is the beauty of LabVIEW: you can do the same thing in many different ways.

 

Following the Event Structure design you are intending to go with I have attached a redesign of your code, including comments. I believe this should work for you now. I have followed the common State Machine approach, which quite nicely, uses the Event Structure - when in a 'stable' or non-working state.

 

The main aspect you need to consider is how the Event Structure is called. It needs an interrupt in order to identify a state that it needs to address. In this case here, to increment a counter each time the peak voltage is detected.

 

The Enumerated data type (the value that holds the state of the State Diagram) can be added to or changed. Normally you should 'Customize...' the data type (right click) and create a Type Def variable (ensures all changes are provided throughout the code, where it is used).

 

There is more you can do with this structure, it is quite useful and powerful. There are quite a few examples online or within the LabVIEW help function to give you more. In regards to the DAQmx, there is a State Machine project already set up for you - with all type-defs and some events already created for you. After you've mastered this you should go along and check that out more.

 

All the best. David.

Message 8 of 25
(3,926 Views)

@winterfresh11 wrote:

The value is changing though without the user needing to do anything. I don't get why it wouldn't work. Is there another event trigger I should be using for the peak voltage then?

 

Sorry this VI is kind of a mess, I through it together pretty quickly to illustrate a problem I was having.


I haven't looked at David's state machine yet but regardless of whether it works for you you're missing an important concept here...  There is no event trigger you should use because there are no events occuring in your code.  You have chosen the wrong tool (event structure) and you should delete it and use the correct tool (case structure).  The case structure is useful when you want to react to a variable (like a boolean indicator that monitors peak voltage for instance Smiley Wink).  You wire the boolean to the case structure selector input and drop the code you want to execute into the proper case.  In your situation you would simply put the increment code into the TRUE state and nothing in the FALSE state.  

 

You CAN force the event structure to do what you want with Value Signaling or Register Events but the Case structure is DESIGNED to do what you want.  Unless you have a good reason that you haven't mentioned for needing to use it try the case structure instead.  I'm away from my LabVIEW PC right now but I'll create a simple example tomorrow to show you how easy this is to do...

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019 - Unfortunately now moving back to C#, .NET, Python due to forced change to subscription model by NI. 8^{
0 Kudos
Message 9 of 25
(3,880 Views)

See im kind of experimenting here with an event structure, clearly doing it wrong though, I've never used one before, and I'm really only doing so becase I was having trouble getting the results I wanted with a case structure. When the volatge is at its peak, I want to trigger some code, when it's not I want it to wait and do nothing. When it hits peak again, I want to trigger the code again. I was having trouble passing this true statement from the while loop that it's in (so it can continuoulsy collect data) to a for loop ( a for loop because I want to control using the iteration how many times the code in the for loop is triggered). Ideally I would like this to be in a stacked sequence structure, so when the for loop is done iterating it goes to another sequence to do something else based upone the the peak voltage being true.

0 Kudos
Message 10 of 25
(3,834 Views)