‎09-18-2019 08:49 AM
Is there a way to do this. I just have one event case (case B) that needs information generated by another event case (case A), and was wondering if there was a way that I could trigger event A when event B is clicked if event A hasn't occurred. If it has occurred trigger event B with the information of event A.....
As I type this out, it seems like I should just be learning how to use ques.... as that seems to be exactly what I'm describing, but am unsure.
P.S. My workplace doesn't allow me to post work VI's.... but I really don't think a VI is required for this.... more of a general knowledge query
Solved! Go to Solution.
‎09-18-2019 09:38 AM - edited ‎09-18-2019 09:41 AM
You could just have a single event case for A or B and place parts of code in case structures to bypass it if not needed.
Typically we can give more specific advice if we can look at some code. What do the event cases do and how do they get triggered usually? There are many, many different ways to solve a problem, maybe there is a much simpler solution.
‎09-18-2019 09:46 AM
Well, yes, but it will probably cause some pain later on.
You can e.g. check if Event A has recently been fired (you'll need to keep track of this) and if not, trigger both A and B (and skip the rest of the event), though this is problematic as the event execution order isn't deterministic.
It'd be safer to trigger A with a parameter that makes it trigger B. This in itself has the problem of leading to a self feeding loop and design as you can get event that queues up events forever, and what happens if something else triggers events in between?
Another option is to add a user event (or two) that does the B or A+B part, though this leads to some code duplication, since you'll have Event A and user event A. This can be handled by having A simply call user event A. Now you've basically implemented a queued machine in events. 🙂
If this is the only case among many events it can be a decent solution, else add a consumer queue (see the producer/consumer example), it's probably the easiest and best solution.
/Y
‎09-18-2019 09:56 AM
My event case A fits my data (using the 2d fit you provided a few weeks ago) and adjusts it as needs, then checks correlation....
My event case B will use the fitted data from event case A, and output it as a binary file.... I basically don't want my program to Fit or Output unless I tell it so (click button)... and I don't want B to be able to occur without A.
I just got the email with Yamaeda's suggestions... and it might be best to simply do two event cases, as the fit is a quick event case and it won't change the result of the data. Event case 1) just A, event case 2) A + B.
I will mark this as solved, but will continue to monitor it for other suggestions. I agree with what alten said about many solutions, so i'm really just trying to build a little arsenal for myself of methods to try for different problems.
Really appreciate all the help this forum gives, definitely one of the healthier forums lol
‎09-18-2019 09:59 AM
@Jewsus wrote:
As I type this out, it seems like I should just be learning how to use ques.... as that seems to be exactly what I'm describing, but am unsure.
Do a search for Queued Message Handler. It would probably be the cleaner route to go, depending on any other requirements you might have.
‎09-18-2019 10:40 AM
@Jewsus wrote:
I just got the email with Yamaeda's suggestions... and it might be best to simply do two event cases, as the fit is a quick event case and it won't change the result of the data. Event case 1) just A, event case 2) A + B.
No, don't duplicate massive sections of code (e.g. fitting). Also, if the fitting takes more than a fraction of a second, it does not belong inside an event case. You can keep "state" (e.g. a boolean for "fit done/not done") in a shift register or you could just hide the [save] button and make it only visible if a successful fit has occurred.