LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

user-generated event doesn't register

Solved!
Go to solution

I'm having some trouble with a user-generated event, and hope someone else has seen the same thing. I'm running LV 9 SP1, with a pretty standard producer-consumer structure. The producer is event-driven and sends commands to the queue-driven consumer via queues, and the consumer passes information back up to the producer via user-generated events. In most cases this works perfectly, but in one situation the user-generated event is not registered by the producer's event structure.

 

The problem arises when the producer enqueues a command for the consumer that calls for immediately generating an event. When this happens the event is usually not acted upon by the producer -- maybe 1 in 100 times the event is seen by the producer. My guess is that the user event is generated before the producer has finished executing the event structure case that registered the consumer queue command, and (for some reason) this means it will never respond to the event. This would suggest that LV event structures will not respond to events created while they are executing. Is this the case?

 

I have gotten around the problem by adding a 10ms before generating the user event (to allow the event case to finish executing), but would really rather fix the underlying problem if possible. Any suggestions?

 

Thanks,

Bayen

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

Can you post your code?

Tim
GHSP
0 Kudos
Message 2 of 12
(3,836 Views)

Do you have this event registered to other loops?

Tim
GHSP
0 Kudos
Message 3 of 12
(3,835 Views)

Do you have this event registered to other loops?

Tim
GHSP
0 Kudos
Message 4 of 12
(3,834 Views)

Difficult to say without code, but it sounds like you create the callback event inside the producers event frame and enqueue it to the consumer that will generate the event and register for this newly created event (inside the producer). It might help that you register for the event before you enqueue it (use the error wires to enfore this sequencial action). But I think it would be much better to Create and register once (and forever) outside the producer loop.

 

Felix

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

I can't post the code as-is, but will pull the relevant sections out and post if necessary. To answer questions so far:

 

 

  1. This event is only registered to the producer event structure. No other event structures should be picking it up, but I do have other events registered to several event structures and these work fine.
  2. My apologies if this is unclear, but the user event is NOT created/registered/generated within the producer's event structure. The user event is created and registered before either loop begin executing (previous state in state machine). During execution, the event structure (producer) enqueues a command for the consumer, and the consumer then pulls some data from a buffer and generates an event to be pass these data back to the producer's event structure.

 

0 Kudos
Message 6 of 12
(3,810 Views)
Solution
Accepted by topic author bayenCPG

So you do not have the output from the register event that contains this event connected to any other loop other than the producer loop is this correct?

 

My first guess is that you fire the event and there is a race condidtion on the event and one loop is getting there faster than the other.

Tim
GHSP
0 Kudos
Message 7 of 12
(3,803 Views)

Maybe instead of the code, just post a screenshot. You can blacken confidential information with a paint program.

 

So here some more guesses what could be your problem:

* Any event registration node in any of the states that changes the event registration refnum.

* A branch of the event reg refnum (to another event structure)

* An error in at the generate event function

* Your queue consumer loop isn't running at all

 

I guess you have a serious Heisen-Bug. The 10 ms wait works, so you won't see the buggy behaviour in highlight execution mode.

A Heisen-Bug is caused by a race-condition (with the addition that it doesn't occure when you enable debugging, it's not observable 😉 ), so check if you have any race-condition-enabling code (like locals and globals). Also any timeing-related code is suspious (like time-out values for DAQ, even default ones).

 

Felix

0 Kudos
Message 8 of 12
(3,788 Views)

I wasn't aware events could have race conditions, but this appears to have been the case. I have three event structures and two dynamic events registered, and each event structure had the same event registration refnum wired into it. The problem event structure was the only one programmed to respond to the event I'm having the issue with, and when I added empty cases to the other event structures this issue disappeared. Thanks for your help!

 

I've attached a dummy VI that demonstrates this problem. As uploaded, it should work properly: every time you click "add" an element should be added to the array. If you delete the case "<Ev.prod>: User Event" in the "secondary event loop" it will exhibit the problem I was having before: sometimes when "add" is clicked, no element is added to "array."

0 Kudos
Message 9 of 12
(3,783 Views)

If you register an event to a structure the structure will receive that event even if it does nothing with it. So with that in mind if the loop that does nothing gets the event then nothing happens because the event has been removed from the event queue when the loop that need the event is ready to process the event.

 

If you need multiple loop to process or do something for the same event then each one will have to have a new registration. You can not use the same output on all structures.

 

 

as you found out.

Tim
GHSP
0 Kudos
Message 10 of 12
(3,776 Views)