LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

why does simple case structure code hang ?

Solved!
Go to solution

hello 

in this code case structure have two case in one of them there is a one event structure .

with one button i just conrtol the state mechine .

 

after playing with This button labview hangs .

some times after one ot two time some times after more than 10 ....

 

0 Kudos
Message 1 of 9
(4,541 Views)

Well I couldn't reproduce what you describe. After a hundred of value changes LabVIEW still runs fine.

But I'm not sure what you are trying to achieve here ? Why not use only an event structure to set the new time value each time you press the button ? Anyway it's not a good habit to use event structures in a case structure. You're are most likely to make LabVIEW hangs than making it run through the whole program.

CLAMaxime -- Kudos are a great way to say thank you
0 Kudos
Message 2 of 9
(4,520 Views)

When you say LabVIEW hangs does it closes or the Front panel just freezes?

-----

The best solution is the one you find it by yourself
0 Kudos
Message 3 of 9
(4,506 Views)

"Well I couldn't reproduce what you describe. After a hundred of value changes LabVIEW still runs fine."

 

but i myself cheching it many times and here highlight state when hang happen:

Capture.PNG

 

"But I'm not sure what you are trying to achieve here ? Why not use only an event structure to set the new time value each time you press the button ?"

 

This just sample code that i'm trying to develope .

for example in case 1 answer to user event and in case 2 reading Process value and controlling outputs(actuators).

"Anyway it's not a good habit to use event structures in a case structure."

why ?

"You're are most likely to make LabVIEW hangs than making it run through the whole program."

why you say this ?

 

 

0 Kudos
Message 4 of 9
(4,500 Views)

"When you say LabVIEW hangs does it closes or the Front panel just freezes?"

 

i can stop with abort button .

0 Kudos
Message 5 of 9
(4,489 Views)
Solution
Accepted by topic author mori64

It hangs because you can get yourself into a situation the event structure is not being accessed (so the events are not handled) but an event it pending.

 

You have 'Lock Panel' selected in the value change event case which, just as it says, locks the front panel until the event is handled.

 

Occasionally you get a race condition where

- you click to turn off the button

- a value change event gets placed on the event queue

- you set your state variable to 1 (disable event handling)

 

the event structure never runs, so the event does not get handled, and the front panel remains locked.

 

You should never have an event loop set up to handle events that cannot run to handle those events!

 

I cannot tell what you are actually trying to achieve with this code - it is a very strange way of going about things. I think you need to plan out your states a bit more and work out what you are trying to do, and perhaps look at some of the examples of state machines and the producer consumer architecture if you want to  handle events and have a state machine running.

Message 6 of 9
(4,466 Views)

thanks  stuart

now i understand the meaning of this option :

 

 

Capture.PNG

 

0 Kudos
Message 7 of 9
(4,452 Views)

By the way, even though it might fix your immediate problem, the answer is not to just uncheck that box.

 

You get the problem because you are trying to handle changes to the state of the button in two different places in two different ways at the same time. In one state you are polling it, in the other state you use an event. Why both? There are times when you might need to poll the state of a control that is handled by an event, but they are rare and you certainly shouldn't be using them to disable the event itself!

 

You would do much better to take the event structure out of the case statement.

 

Take a look at the Producer/Consumer Design Pattern (Events) from the LabVIEW  File->New... menu

 

PCE.png

0 Kudos
Message 8 of 9
(4,395 Views)

apart from that button that change sate

is it wrong way :

state 0:  initial ...

state 1: have an event structure to respose to the user 

state 2 :get log ,process datat and so on 

back to state 1

 

as i undrestood i got a problem if state 2 take long and during this time and event happen ?

0 Kudos
Message 9 of 9
(4,358 Views)