NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Step only executes once in loop

Hi,

 

I seem to have encountered a weird problem.  I'm running a for each loop on elements from a csv stream, which I then split into string arrays in a statement inside the loop block.

 

This new array contains 2 elements one of which is passed to a step I defined, the other to the wait timer.  On the first iteration the data is successfully sent to my step and it triggers a relay.  However on subsequent iterations the step fails to trigger.  I have already tried changing the load option on my step to load dynamically, but this has not resulted in improved results.

 

Any idea of what is happening that is preventing the new string value from being sent to my "RunRelay" step?

0 Kudos
Message 1 of 9
(3,569 Views)

Hi,

 

I think you are not reading the good variable...

The array your are trying to iterate onver is Locals.csvFile which is a discrete single value...

Dont'you want to iterate over Localls.cvsData instead ?

CLA, CTA, LV Champion
View Cyril Gambini's profile on LinkedIn
This post is made under CC BY 4.0 DEED licensing
0 Kudos
Message 2 of 9
(3,558 Views)

Reading over the data is not an issue csvFile is a stream, element is the current element in the loop .  The variable cvsData is an array based off the current element in the loop, specifically Locals.csvData = Split( Locals.element,"," ).  I then pass the first index to my step and the second index to the wait timer. The message popup shows what is being passed to my step so I can verify it is good.

 

This all works on the first iteration, but on subsequent iterations the step RunRelay doesn't work, even though the message popup shows that I have generated the correct new value to pass to it.

0 Kudos
Message 3 of 9
(3,527 Views)

Hi, 

 

Here is the structure of the code

Locals.csvFile is a stream of csv data

Locals.element  is the current element in the loop 

Locals.csvData = Split( Locals.element,"," ) is an array created inside the loop containing two strings

 

The first string is passed to my step RunRelay, the second string is converted to an int and passed to my timer.  To verify that the first string was being generated properly I added a message popup so I could see the value that was being sent to RunRelay.

 

All of this work fine on the first iteration of the loop, after that everything except RunRelay works.  I can see that the correct string to send to it is being generated, but RunRelay is not triggering my relay like it is supposed to.  I know this all works as I wrote my own test program as a sanity check.

0 Kudos
Message 4 of 9
(3,535 Views)

Does your own test program is the same 'for each' loop but with a pop-up instead of the relay control step ?

Would you try converting your stream into an array before the 'for each' loop and looping on the array instead of the stream ?

Does it produce the same behavior?

CLA, CTA, LV Champion
View Cyril Gambini's profile on LinkedIn
This post is made under CC BY 4.0 DEED licensing
0 Kudos
Message 5 of 9
(3,530 Views)

Hi,

 

The test program I wrote had a method that read the csv and converted it to a multidimensional string array.  When running this in Visual Studio all worked as expected. However when I passed this data to Teststand I had the same problem I have described above. In order to try and get around this issue I decided to try native Teststand CSV stream as it would read each line of csv as a string.  After some modification to my .dll and sequence file I ran this version my sequence and again encountered the same results.

 

I have attached my sequence file.

 

0 Kudos
Message 6 of 9
(3,512 Views)

Hi wweaver001,

 

Normally when I've seen behavior where the code doesn't run properly after the first run, this is due to resource management issues. Are you sure the relay session is opened and closed properly, handled properly within the code module, and that the proper objects are being passed to and from the RunRelay step?

 

If you haven't already, I would try setting a breakpoint on the RunRelay step to see what the state of variables and input/output parameters are on both the first and second runs to see what is different. You may also try setting the unload options on the step to unload after step executes to see if that affects your behavior. If your code module is running properly the first time, there is more than likely a difference in parameters passed into the code module or a difference in how the code module is loaded and unloaded from memory, so properly debugging and capturing this data can help us figure out what might be happening.

 

It sounds like the userData has been thoroughly tested, but I haven't seen much mention of the Existing Object. Could you check that parameter to see if there are any noticeable changes between first and second runs? I'm guessing that your CreateRelay step is what obtains the object reference for TestStand, so if that's the case, I would compare the output parameter object reference on that step with the input parameter object reference on the RunRelay step each time.

 

It's also possible that your code isn't passing up exceptions or errors back to TestStand, so you might also check to make sure that you've properly handled errors in your code module and that TestStand isn't configured to ignore runtime errors.

 

Hopefully this helps, but let us know what you find!

 

Edited: I noticed the for loop around the RunRelay step and realized that you were talking about multiple iterations of the loop and not multiple runs of the code, so I've edited my reply to make more sense with that in mind.

Andy F.
Applications Engineering
National Instruments
0 Kudos
Message 7 of 9
(3,494 Views)

Hi,

 

I put a breakpoint on the RunRelay step as you suggested and saw no change during each iteration of the loop. Next I put all of my steps in the loop so that the relay would be created, set, and destroyed each time.  Again same result, the first loop works just fine and subsequent iterations fail.

0 Kudos
Message 8 of 9
(3,450 Views)

Hi,

 

I was able to figure out how to get it to run properly.  I had to add a sleep timer to my RunRelay method and pass the sleep timer value to both RunRelay and to the wait timer in Teststand.

0 Kudos
Message 9 of 9
(3,406 Views)