LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Loops not working properly

Solved!
Go to solution

Hello,

 

I'm working on a labview testing program. I've been trying to implement a loop that will essentially take a measurement ten times then stop. I then intend on reading all this data into an array for data trending. My problem is that my loops are not working as intended, basically it just runs thru one measurement and then stops. I'm thinking it may be a problem with my initial while loop. I've attached my vi. Most of my front panel indicators are not connected because I'm trying to solve this loop problem first and foremost.

 

Any help you can give is appreciated,

 

Konrad

Download All
0 Kudos
Message 1 of 14
(5,125 Views)

Why are you using a stacked sequence structure?  It looks like all frames of that code would execute properly in sequence if you used the error wire.

Why are you using a While Loop instead of a For Loop?  If you know it is going to run 10 times, then a 10 iteration For Loop reduces the amount of code.

 

How do you know that loop is running for only one iteration?  Did you put any probes into it such as on the wire coming from the i terminal?  I don't see any reason why that loop wouldn't run 10 times.  What is the setup for the serial port?  Does it use termination characters? 

0 Kudos
Message 2 of 14
(5,120 Views)

It appears that the first two frames of your stacked sequence structure are initialisation, which is done only once?

 

Also its better practice not to use the sequence structure and use error clusters to enforce the dataflow you require.

 

See attached modified vi - I have taken out your initialisation code from the loop and changed your read loop to a for loop set to iterate 10 times.  I haven't tested it, but should be a starter for you

 

--dave

Message 3 of 14
(5,110 Views)

It seemed like the stacked structure loop would be the easiest way to organize the steps in my testing procedure. Why would connecting the error wire help making the loop work? I thought that was just for debugging basically. The only reason I'm using a While loop instead of a for Loop is because eventually I want to add in the possibility of redoing a test point if the data is bad after the measurement. It seemed like using a For loop would make this harder to implement later. I know the loop is running because I have my test computer in the lab connected to an HP 4155c and I'm visually watching the steps being acted out on the test equiment itself. I'm using a GPIB interface with the 4155 and I don't currently have a termination character programmed in, could that be the problem?

 

Thanks for the help so far,

 

Konrad

0 Kudos
Message 4 of 14
(5,109 Views)

Dave,

 

Thanks for taking a look at my code, I tried something similar to this when my initial code did not work. I just tried running the modified code and it's essentially doing the same thing and only running one scan, no errors or anything. I'm wondering if I need to close the session with the test equipment after every measurement?

 

Konrad

0 Kudos
Message 5 of 14
(5,106 Views)

Stacked sequences are the worst because of the way it hides code.  You can't see the sequence since only one fram is visible at a time.

 

Error wires are used for proper error handling.  Do you want later steps in the sequence to still run even if the first step (such as initialization) fails?

 

Error wires aren't a debugging tool.  They are a mechanism for properly handling errors and order of execution within your code.

 

If you want to add to your code to redo tests, then the proper architecture is a state machine architecture.  It is a case structure within a while loop, that allows you to determine what the next state to execute is (such as redo a test) depending on decisions made during execution (such as the failure of the previous test.)

 

You say the you know the loop is running, but I thought you originally said that only the first loop iteration was running.  Please give a clear picture as to what is actually happening, how it is wrong, and what you are expecting to happen.

Message 6 of 14
(5,097 Views)

Ah I see, that makes sense. So the error wire would basically just stop the program should one of the procedures fail? I know the loop is running because after running the program, I see the GPIB take control of the HP 4155 I'm using, it then loads the MES file as per the program and then runs thru a scan of the spectrum. It then stops after one scan. Basically I want it to run this scan 10 different times in a row. Once I get that part of my code to work, then I can focus on the state machine architecture to get the user response part done. Could it be that the instrument doesn't have enough time between commands to process? For example it's running the first measurement still and the other 9 commands come in and it simply ignores them since it's still running the previous command?

 

Konrad

0 Kudos
Message 7 of 14
(5,090 Views)

Also I'm using labview 12 if that helps at all

0 Kudos
Message 8 of 14
(5,089 Views)
Solution
Accepted by topic author niedk

Konrad,

 

I do not know your instrument but GPIB instruments, especially older ones, often require noticeable amounts of time to process some commands.  Check the manual.  Sometimes information about how long it takes for commands to be processed may be difficult to find.  It may be in an appendix or a footnote to some part of the manual which is not the obvious place to look.

 

Lynn

Message 9 of 14
(5,079 Views)

Lynn,

 

Yep that was part of the problem. Simplifying the code from the other posters helped too. I added an 8000 ms wait to the loop and it's working as intended now. Thanks for the help everyone.

 

Konrad

0 Kudos
Message 10 of 14
(5,074 Views)