From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

executing code in a while loop with an event structure in it

Hello -
 
 
How can I execute both the continuous commands in a while loop and have an event structure execute something if a button is pressed, whithout the event struc holding everythign up?
 
 
 
I have one main while loop that contains an event structure, and two VISA write commands that retrieve data from some sensors.
The event structure is for when the operator presses buttons on the front panel.....a motor command or some motor reading will execute a hex command and display it. However, there are two sensors (a hall effect and a motor temp sensor) that need to be continuously read so I placed that inside the while loop, hoping it would always update. I can see that the event structure holds up the whole program until a button for an event is pressed, so the two sensors that need constant updating aren't being read. I tried adding a timeout event and wired 100 milliseconds to it, but that just makes the motor command(like continuous forward) act funny by turning in spurts, like stopping and starting again.
 
 
Thanks! i also attached the vi - it has the event structure and the two different sensor's code above that
0 Kudos
Message 1 of 12
(3,741 Views)
Add an empty timeout case to the event structure and wire a small value to the timeout terminal.
 
(your code has quite a few serious problems, for example you should make sure tha the VISA reference is wired across ALL event cases.).
0 Kudos
Message 2 of 12
(3,737 Views)


@altenbach wrote:
Add an empty timeout case to the event structure and wire a small value to the timeout terminal.
 
(your code has quite a few serious problems, for example you should make sure tha the VISA reference is wired across ALL event cases.).



but like i said i tried the timeout event and it made my vi even worse...when i pressed a button to move the motor "forward continuous" the timeout made the motor stop and start every 100 milliseconds (or whatever constant i wired into the event). its like it sends an interrupt or something. is there any other way i could program the vi to make both things work? thanks!
0 Kudos
Message 3 of 12
(3,729 Views)
Well I think one way you can work around is by putting the event structure in a loop of it's own. I mean have two parrallel loops running.





---------------------------------------------------------
NI labview 8 tutorials available at www.fafiles.com
---------------------------------------------------------
National Instruments LabVIEW beginner video tutorials available at www.fafiles.com. Get Wired Up!!!
0 Kudos
Message 4 of 12
(3,726 Views)


@NewMachine wrote:
but like i said i tried the timeout event and it made my vi even worse...when i pressed a button to move the motor "forward continuous" the timeout made the motor stop and start every 100 milliseconds (or whatever constant i wired into the event). its like it sends an interrupt or something. is there any other way i could program the vi to make both things work? thanks!


I assume you have tried a 0ms timeout?
0 Kudos
Message 5 of 12
(3,718 Views)
yes i did try a zeo constant - the motor still jumps as it goes around. its like it sends an interrupt as the motor command to go forward continuously is being executed. however, i can press other buttons and that doesn't ever interrupt the motor.

@altenbach wrote:


@NewMachine wrote:
but like i said i tried the timeout event and it made my vi even worse...when i pressed a button to move the motor "forward continuous" the timeout made the motor stop and start every 100 milliseconds (or whatever constant i wired into the event). its like it sends an interrupt or something. is there any other way i could program the vi to make both things work? thanks!


I assume you have tried a 0ms timeout?


0 Kudos
Message 6 of 12
(3,699 Views)
hello - i also tried parallel while loops but one loop still waits at the event structure for anything else to happen.

@felan wrote:
Well I think one way you can work around is by putting the event structure in a loop of it's own. I mean have two parrallel loops running.





---------------------------------------------------------
NI labview 8 tutorials available at www.fafiles.com
---------------------------------------------------------



0 Kudos
Message 7 of 12
(3,698 Views)

Hello,

If you're communicating with your motor using VISA, you're likely using a serial port or GPIB, so your motors behavior and responsiveness is going to depend on the speed of those buses.  As far as not having the event structure hold up other code, multiple loops is the way to go.  If you need to have your continous (no event structure) loop communication or trigger events in the event handling loop, you can use User Events.

I hope this helps!

Best Regards,

JLS

Best,
JLS
Sixclear
0 Kudos
Message 8 of 12
(3,671 Views)

I am having the same issue. I was following the instructions in the LabView tutorial. In the tutorial it says to put Event structures inside While loops. I did that, but the moment i put it in the while loop, the whole while loop only executes when the Event executes - I am trying to capture data only when a button is pressed, but I need the data to continuously be graphed in the while loop, and only capture it when the button is pressed. What really happens is contrary to instructed and what is expected to happen.

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

This thread is very old. Please create a new thread and post your vi.

It's difficult to troubleshoot code on the basis of a description only.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 10 of 12
(3,033 Views)