LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Several Loops - One case does not allow me to stop.

Solved!
Go to solution

Here's how it works (or how it should work)

  1. Initial while loop just checks if we are connected to the proper wifi, then enters the conditional loop if we are connected properly.
    1. If we are not connected properly, it just checks again
  2. Inside the Case Structure 
    1. While loop 1 checks the buttons over and over while there are no events
    2. While loop 2 opens a UDP port and waits for the command. If we have a change, (1/4 buttons) then the event is triggered
  3. Inside the Event structure
    1. There are 4 commands that I prepared the event structure to hold - 'connect', 'disconnect', 'record', 'end recording'
    2. When it connects / disconnects / ends recording, the event is a simple line which has a UDP write and then closes the port, and opens it again to send the next command.
  4. The "record" event.
    1. The "record" event is the most complicated one, and the one shown in the image below.
      1. It begins by sending out a command to the UDP port, initializing the device recording (works fine)
      2. Then it enters a while loop where it reads the received UDP packet, and if there are no errors in the UDP connection, it decodes the information (using a Matlab code) (WORKS FINE)
      3. If there is a timeout error (56) it just waits some more (WORKS FINE)
      4. When the user hits the 'y' button, the recording should end, and then the UDP socket is released. (NOT WORKING)
  • Things I have tried
    • I have tried placing arbitrary buttons inside every loop to see if I could press any of them while in the middle of the "record" while loop. I was unable to click any of the buttons at any time. 
    • Switching the mechanics of the button to any and all options (latch / switch / on press/release/etc). No change
    • Using the 'highlight' feature, I was able to see that the while loop does indeed take a new value from the 'y' switch during every iteration, but it does not allow me to change the value at any time. Even spamming the button while highlighting, or otherwise.

I am desperately seeking any solution which doesn't eliminate my UDP functionality. Any help is appreciated. I also added my VI if you need it.

 

 

udp_connection_VI-1.jpg

0 Kudos
Message 1 of 6
(2,791 Views)
Solution
Accepted by topic author rodrigonramon

You should not have interactive loops inside event cases. Events are (by default) configured to "lock the front panel until the event completes" but your event cannot complete until a button is pressed or an error occurs. You cannot press a button if the panel is locked: Deadlock! What's the purpose of the greedy loop in the upper left?

 

LabTOON06132008

 

Why are there so many loops within loops within loops? Think state machine instead.

 

An event structure should never be inside a case structure.

 

Most of your loops cannot be stopped. 

 

There are probably better ways to parse a string than using a matlab script.

 

You really should take a few more tutorials and re-think the entire code architecture from scratch.

 

Also please attach the actual VI instead of a picture to get more specific advice. We cannot see what's in the other cases. We cannot see how the events are configured. We cannot tell the mechanical action of the buttons, etc.

0 Kudos
Message 2 of 6
(2,786 Views)

There are two infinite while loops in that case.  Why would it ever stop?

0 Kudos
Message 3 of 6
(2,759 Views)

The infinite while loops were done on purpose because I don't have a need to exit those loops at this point. 

This is the structure - 

  • While loop - Checks for wifi status, enters case structure when the wifi status is correct
    • Case Structure - initializes a while loop to check the buttons (until we force exit the program), and a while loop for everything else
      • While loop to check for buttons (indefinitely)
      • While loop to to send UDP commands (indefinitely)
        • Event loop to check for button command
          • Inside the event loop, there are 4 possible events:
            • Connect, disconnect, record, and end recording.
            • The 'connect', 'disconnect', and 'end recording' events do not contain loops - just simple UDP commands which exit the event loop immediately.
          • Only in the "record" event, there is a while loop to continually receive new UDP data until the user wishes to end the recording. This is the loop that freezes the front panel and does not allow me to press the "end recording" button, nor the "y" button which is the "stop" button inside the final 'record' while loop.

I'm no professional labview programmer, so if anyone thinks I can do this in a simpler way which wouldn't disrupt my UDP command structure, please let me know.

0 Kudos
Message 4 of 6
(2,740 Views)

I appreciate your feedback. I'll start to rethink my architecture given that I have only a few months of experience with Labview.

 

In any case, removing the "lock until event finishes" checkbox in the event handler details did the trick. now I can record without issue, and then exit the loop by hitting 'y'

0 Kudos
Message 5 of 6
(2,738 Views)

@rodrigonramon wrote:

 

      • While loop to check for buttons (indefinitely)

This is a complete misunderstanding. These buttons are not even connected to anything and you "read" the button state with event structures. These terminals could be anywhere. Only If they are latch action (and I guess they are), they belong inside their respective event case so they reset once the event fires and the terminal is read by the code. You should be aware that your current small loop runs as fast as the CPU allows and will saturate one CPU core 100%.

 

LabVIEW ships with some good templates. I am sure one is suitable for your problem.

0 Kudos
Message 6 of 6
(2,734 Views)