LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

For loop of MOD bus will not change loop iteration

Solved!
Go to solution

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.

0 Kudos
Message 1 of 9
(2,168 Views)

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.

Message 2 of 9
(2,131 Views)

@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.

 

  • *No, [typecasting a U16 array to a I16 array, reversing the array, then typecasting to a SGL array] is a few steps too many.
  • Not sure why you built a 1D array into a 2D array for "array to spreadsheet string". It accepts a 1D array just fine.
  • If you would swap the inputs where you join the two U16 numbers, you would not need to "swap words" right after.
  • Why are there controls for "dimension size" when you reshape. Shouldn't these values depend on the loop iterations instead of the user?
  • Why do you insert a NOT instead of swapping the termination condition of the small inner while loop?
  • etc.etc!

 

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.

Message 3 of 9
(2,123 Views)

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.

0 Kudos
Message 4 of 9
(2,087 Views)

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.

0 Kudos
Message 5 of 9
(2,085 Views)
Solution
Accepted by topic author EdHarris

Your two "reshape array" function will truncate the incoming data to three element. Did you adjust these values accordingly?

Message 6 of 9
(2,077 Views)

No I did not, thanks I will look at that tomorrow.

0 Kudos
Message 7 of 9
(2,074 Views)

@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.

0 Kudos
Message 8 of 9
(2,067 Views)

Hi Altenbach,

That worked. Any other  improvements you are willing to suggest?

0 Kudos
Message 9 of 9
(2,020 Views)