03-06-2021 06:23 AM
In the attached vi there is a central "for" loop which reads discrete inputs and a holding register on two different servers.
If I try to increase the iteration of the for loop nothing happens.
I have a very similar program without the read discrete input read which adjusts without any problem.
Can anyone suggest why the "for" loop is not responding.
Any clues gratefully received.
I have labview 2014.
Solved! Go to Solution.
03-06-2021 08:57 AM
You have two For Loops in there.
One is small and is only converting a boolean to an integer. It will run as many times as there are elements in the boolean array. Actually, you don't need that For Loop at all because Number to Boolean to 0,1 can take arrays directly.
The other For Loop is bigger. It has a constant 3 wired to the N terminal, so it will only run 3 times. Are you changing that constant? Otherwise, I don't see anything else that affect or limit the number of times that For Loop would run.
03-06-2021 11:46 AM - edited 03-06-2021 11:50 AM
@EdHarris wrote:If I try to increase the iteration of the for loop nothing happens.
You need to be significantly more specific: What is "nothing"? I am sure "something" happens, but you are not telling us. (How do you increase the number of iterations? with >3 iteration, does it still do 3 iterations, then stall forever?) After the first small while loop, there is a 60 seconds stall. You have 3s per iteration of the small while loop and since the loop termination depends in received data, that one might actually never complete.
So, after start of the program, you would need to wait at least 63 seconds (or up to forever!!!) until your FOR loop can even start. Did you wait that long?
Your central FOR loop iterates three times with every iteration of the outermost while loop, taking at least 12 seconds to complete. (each iteration has a 4s wait).
Who wrote this code? It could certainly use a bit of a cleanup because there is some really questionable code, for example.
Your various wait are way too long for a toplevel UI loop. You really need to rewrite this in a way that the UI is isolated from the instrument interactions. Have a look at the various templates that ship with LabVIEW.
03-06-2021 03:28 PM
Hi RavensFan,
Yes it is the constant I am altering, it worked on my other program which doesnt have the discrete inputs, just by stopping the program and altering it as you would expect. I also altered the miliseconds to wait.
03-06-2021 04:47 PM
Hi altenbach,
Thanks for your comments, I made that program in 2017 as a nube to Labview and modbus and was just desperate to get it working. I had quite a bit of difficulty getting it to output the data in a convenient format which is why is so cobbled together. It has been running continuously ever since and I have only made a few improvements to add functions.
I increased the iteration constant and changed the wait milliseconds in the for loop then saved and restarted the program. The first while loop polls a PLC for a coil to go low then the program proceeds through the reads. I started it and came back the next day and found it had not read 20 times each cycle as I had set the iteration constant but the three times as it did previously. The values I had changed it to still present in the program.
03-06-2021 05:03 PM
Your two "reshape array" function will truncate the incoming data to three element. Did you adjust these values accordingly?
03-06-2021 05:13 PM
No I did not, thanks I will look at that tomorrow.
03-06-2021 07:00 PM
@EdHarris wrote:
Hi RavensFan,
Yes it is the constant I am altering, it worked on my other program which doesn't have the discrete inputs, just by stopping the program and altering it as you would expect. I also altered the miliseconds to wait.
How do you know it is only running 3 times? Something doesn't correlate between what you say and how the VI would work.
03-07-2021 08:43 AM - edited 03-07-2021 08:46 AM
Hi Altenbach,
That worked. Any other improvements you are willing to suggest?