08-26-2020 10:22 AM
No. This is exactly opposite of what I said. Move your wait out of the loop that's sending the commands and into the loop that is receiving the commands. Also, the examples that you posted make absolutely no sense. The loop that you're calling MAIN WHILE LOOP will not begin until your other loop has completed. Why are you adding all the complexity to this? Send the command directly to your bottom loop - no need for the middle loop.
Please do look at the training resources available at the top of this forum.
hold on... if I put my wait command into the consumer/main loop, it will stall the whole loop until the wait function is complete. This is not what I'm asking for. I'm asking to stall the reading of the next command only, until the wait function is complete. In the interim, while the wait function is executing, the rest of the main while loop needs to complete its execution. Perhaps my wait function needs adjustment instead?
Right now my main loop is set up the way you have indicated, which is what led me to this problem to begin with. What I'm trying to do is simply allow my main loop to continue as it is while only that portion of it which reads the commands, pauses.
08-26-2020 10:57 AM
@jedi.engineer wrote:
No. This is exactly opposite of what I said. Move your wait out of the loop that's sending the commands and into the loop that is receiving the commands. Also, the examples that you posted make absolutely no sense. The loop that you're calling MAIN WHILE LOOP will not begin until your other loop has completed. Why are you adding all the complexity to this? Send the command directly to your bottom loop - no need for the middle loop.
Please do look at the training resources available at the top of this forum.
hold on... if I put my wait command into the consumer/main loop, it will stall the whole loop until the wait function is complete. This is not what I'm asking for. I'm asking to stall the reading of the next command only, until the wait function is complete. In the interim, while the wait function is executing, the rest of the main while loop needs to complete its execution. Perhaps my wait function needs adjustment instead?
Right now my main loop is set up the way you have indicated, which is what led me to this problem to begin with. What I'm trying to do is simply allow my main loop to continue as it is while only that portion of it which reads the commands, pauses.
You need to separate the Consumer loop that receives commands from the rest of the "Main" loop. If the Commands must be used in your "Main" loop then use an interim loop and a second queue. Make sure that you set a small timeout on your Dequeue in the "Main" loop and properly handle the timeout.
08-26-2020 11:06 AM - edited 08-26-2020 11:15 AM
You need to separate the Consumer loop that receives commands from the rest of the "Main" loop. If the Commands must be used in your "Main" loop then use an interim loop and a second queue. Make sure that you set a small timeout on your Dequeue in the "Main" loop and properly handle the timeout.
The commands toggle case structures that control other parts of my main loop. So if I separate it out, I need to inject them into my main loop somehow. I can maybe do this with a local/global variable or property nodes, but otherwise, I'm unsure how to separate without re-writing my entire program. That's why I asked about pausing the execution of a command without stalling my main loop.
Will a property node work across two parallel loops? Right now, my cases set property nodes within the same loop, so as not to need to run multiple wires all over the place and get caught up in a spaghetti mess...
08-26-2020 11:42 AM - edited 08-26-2020 11:43 AM
@johntrich1971 wrote:
@jedi.engineer wrote:
No. This is exactly opposite of what I said. Move your wait out of the loop that's sending the commands and into the loop that is receiving the commands. Also, the examples that you posted make absolutely no sense. The loop that you're calling MAIN WHILE LOOP will not begin until your other loop has completed. Why are you adding all the complexity to this? Send the command directly to your bottom loop - no need for the middle loop.
Please do look at the training resources available at the top of this forum.
hold on... if I put my wait command into the consumer/main loop, it will stall the whole loop until the wait function is complete. This is not what I'm asking for. I'm asking to stall the reading of the next command only, until the wait function is complete. In the interim, while the wait function is executing, the rest of the main while loop needs to complete its execution. Perhaps my wait function needs adjustment instead?
Right now my main loop is set up the way you have indicated, which is what led me to this problem to begin with. What I'm trying to do is simply allow my main loop to continue as it is while only that portion of it which reads the commands, pauses.
You need to separate the Consumer loop that receives commands from the rest of the "Main" loop. If the Commands must be used in your "Main" loop then use an interim loop and a second queue. Make sure that you set a small timeout on your Dequeue in the "Main" loop and properly handle the timeout.
The commands toggle case structures that control other parts of my main loop. So if I separate it out, I need to inject them into my main loop somehow. I can maybe do this with a local/global variable or property nodes, but otherwise, I'm unsure how to separate without re-writing my entire program. That's why I asked about pausing the execution of a command without stalling my main loop.
Will a property node work across two parallel loops? Right now, my cases set property nodes within the same loop, so as not to need to run multiple wires all over the place and get caught up in a spaghetti mess...
note: For some reason, this comment keeps getting deleted. I will keep posting it until NI tells me why or the thread is locked.
08-26-2020 11:58 AM
@johntrich1971 wrote:
@jedi.engineer wrote:
No. This is exactly opposite of what I said. Move your wait out of the loop that's sending the commands and into the loop that is receiving the commands. Also, the examples that you posted make absolutely no sense. The loop that you're calling MAIN WHILE LOOP will not begin until your other loop has completed. Why are you adding all the complexity to this? Send the command directly to your bottom loop - no need for the middle loop.
Please do look at the training resources available at the top of this forum.
hold on... if I put my wait command into the consumer/main loop, it will stall the whole loop until the wait function is complete. This is not what I'm asking for. I'm asking to stall the reading of the next command only, until the wait function is complete. In the interim, while the wait function is executing, the rest of the main while loop needs to complete its execution. Perhaps my wait function needs adjustment instead?
Right now my main loop is set up the way you have indicated, which is what led me to this problem to begin with. What I'm trying to do is simply allow my main loop to continue as it is while only that portion of it which reads the commands, pauses.
You need to separate the Consumer loop that receives commands from the rest of the "Main" loop. If the Commands must be used in your "Main" loop then use an interim loop and a second queue. Make sure that you set a small timeout on your Dequeue in the "Main" loop and properly handle the timeout.
For some reason my comments keep getting marked as spam... moderator notified, hopefully this one won't because I'd like a reply.
The commands toggle case structures that control other parts of my main loop. So if I separate it out, I need to inject them into my main loop somehow. I can maybe do this with a local/global variable or property nodes, but otherwise, I'm unsure how to separate without re-writing my entire program. That's why I asked about pausing the execution of a command without stalling my main loop.
Will a property node work across two parallel loops? Right now, my cases set property nodes within the same loop, so as not to need to run multiple wires all over the place and get caught up in a spaghetti mess...
08-26-2020 12:33 PM
@jedi.engineer wrote:
@johntrich1971 wrote:
@jedi.engineer wrote:
No. This is exactly opposite of what I said. Move your wait out of the loop that's sending the commands and into the loop that is receiving the commands. Also, the examples that you posted make absolutely no sense. The loop that you're calling MAIN WHILE LOOP will not begin until your other loop has completed. Why are you adding all the complexity to this? Send the command directly to your bottom loop - no need for the middle loop.
Please do look at the training resources available at the top of this forum.
hold on... if I put my wait command into the consumer/main loop, it will stall the whole loop until the wait function is complete. This is not what I'm asking for. I'm asking to stall the reading of the next command only, until the wait function is complete. In the interim, while the wait function is executing, the rest of the main while loop needs to complete its execution. Perhaps my wait function needs adjustment instead?
Right now my main loop is set up the way you have indicated, which is what led me to this problem to begin with. What I'm trying to do is simply allow my main loop to continue as it is while only that portion of it which reads the commands, pauses.
You need to separate the Consumer loop that receives commands from the rest of the "Main" loop. If the Commands must be used in your "Main" loop then use an interim loop and a second queue. Make sure that you set a small timeout on your Dequeue in the "Main" loop and properly handle the timeout.
For some reason my comments keep getting marked as spam... moderator notified, hopefully this one won't because I'd like a reply.
The commands toggle case structures that control other parts of my main loop. So if I separate it out, I need to inject them into my main loop somehow. I can maybe do this with a local/global variable or property nodes, but otherwise, I'm unsure how to separate without re-writing my entire program. That's why I asked about pausing the execution of a command without stalling my main loop.
Will a property node work across two parallel loops? Right now, my cases set property nodes within the same loop, so as not to need to run multiple wires all over the place and get caught up in a spaghetti mess...
First, I would try to reformat the code to get rid of the property nodes. There is rarely, if ever, a need for that. Using property nodes (local variables would be preferable if you're going that route) breaks dataflow and can lead to race conditions (you do not know when the property node or local variable is read from the control/indicator). This cannot be reliably viewed using highlight execution.There are a number of ways to reduce the spaghetti. Using subvis is a start. Also, you can bundle the data and have the bundle go in and out of any structures/subvis. It is always better to use wires.
In the event that you choose to continue with our property nodes or local variables each of these will work anywhere in the program.
Another option is to use an intermediate loop that reads the commands from the queue. If the command is not wait then it will forward the command to another queue. Otherwise it will wait and then get the next queue.
08-26-2020 01:21 PM
@johntrich1971 wrote:
First, I would try to reformat the code to get rid of the property nodes. There is rarely, if ever, a need for that. Using property nodes (local variables would be preferable if you're going that route) breaks dataflow and can lead to race conditions (you do not know when the property node or local variable is read from the control/indicator). This cannot be reliably viewed using highlight execution.There are a number of ways to reduce the spaghetti. Using subvis is a start. Also, you can bundle the data and have the bundle go in and out of any structures/subvis. It is always better to use wires.
In the event that you choose to continue with our property nodes or local variables each of these will work anywhere in the program.
Another option is to use an intermediate loop that reads the commands from the queue. If the command is not wait then it will forward the command to another queue. Otherwise it will wait and then get the next queue.
I used property nodes to pass numeric values across the program rather than run wires. Thankfully, I've got it set so as to avoid read-before-write situations. I've used subVIs wherever possible, but this program is still rather large, and I'm not afforded the time to condense it any further. Maybe the simpler approach is as you have said, an intermediate loop to dequeue, assess, wait, and re-enqueue. I'm getting a queue error, but is this basically what you're referring to? This uses the same sample script I previously used.
08-26-2020 01:27 PM
Yes, this is the basic idea. Does your "MAIN WHILE LOOP" actually need to receive a WAIT command? If not then you can just not enqueue anything in that case. Since you don't have a timeout on the dequeue it will wait for the next command.
08-26-2020 01:35 PM
@jedi.engineer wrote:
I think we might have gotten off track a little from the original topic, when we went down the road of the producer-consumer structure, which can be a help, I think. What I'm trying to do is this:
- open a text file that contains scripted commands, as in the example I gave.
- process commands in my "main" or "consumer" loop.
- When a "WAIT" command comes through, commands to the "main" or "Consumer" loop are paused until that "WAIT" command finishes, without pausing my main loop.
How would you pause a loop..... without pausing a loop?
I'm guessing you meant without pausing your producer loop?
As others have said it's hard to give suggestions without seeing how the whole program is put together. It seems your question really can only be answered by looking at the architecture of the rest of the program. I edited your uploaded example VI with some notes on what I think you want, or at least an example of what might work. Mainly I got rid of the second loop and put the event structure in a while loop (this is pretty standard structure for handling UI events). The producer loop (the top UI loop) can respond to other events and keep running in parallel while the consumer loop can do longer processes.
One note I made is that if possible I would just pass the file path to the consumer loop and have it perform the read and parsing functionality you currently have in the event structure.
08-26-2020 01:40 PM
@johntrich1971 wrote:
Yes, this is the basic idea. Does your "MAIN WHILE LOOP" actually need to receive a WAIT command? If not then you can just not enqueue anything in that case. Since you don't have a timeout on the dequeue it will wait for the next command.
I pass the "WAIT" command because it lights an indicator and triggers another event. The only issue I have with this setup is the dequeue on the main loop. It throws an error and I'm not entirely sure why.