LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Labview Code Working in Highlight Execution but not in normal run

Hi,

I am using 4-Numato Ethernet Relay Board for the control of Powers supplies in my application. I have written the Labview code for testing one relay board at a time and all 4 relay boards at a time with different IP Address. Both codes are working fine. I can able to control all relays by having event control for ON/OFF. I have attached the Zip File for the code. Pls refer the image also for

 

But for my application I need automated control. I need to first turn On relay and perform some process and then turn off relays. My application is very big. To make it simple to explain my problem,i have written one code for which will Switch ON wait for 1 Sec and Switch OFF.The problem is that it is switching ON and after On second it is not switching off.

 

To Debug this i have done checked following things.

1. I am Initializing all four boards and taking TCP reference in an array and it was successful.

2. I am taking index array of references based on Board Number and giving for the ON/OFF control Vi. The selected relay is switching ON. The Problem is after one second it is not switching OFF.

3. So I put a breakpoint before sending switch OFF command and checked the inputs. No error, TCP/IP Reference is fine and vi is executing. but the relay is not switching off.

4. I repeated the test by executing with highlight execution after breakpoint. It is working fine and command is going. I thought timing problem and i increased the delay upto 10 seconds. It was not working in Normal run. But in Highlight execution it switches off instantly after break point.

 

So can you please provide me the solution why in Normal run it is having problem.

 

0 Kudos
Message 1 of 4
(2,176 Views)

I don't see anywhere in your code that you are waiting for a second then switching off the relay.  The only time the code appears to turn off the relay is if you explicitly press the ON/OFF button back to false.

 

You use a lot of local variables and that often leads to race conditions. (Why use local variables when you have the two control terminals sitting there unused?)   And code working in highlight execution and not at full speed is a pretty good indicator of a race condition.  Though in your case it didn't jump out to me right away as to which part of your code was the race condition.

 

I think one thing very odd is the use of the event structure to drive another while loop.  It's like you have a producer/consumer, but really don't.  The use of the cmd button that you manually untoggle when you could just use the ON/OFF button directly.  I think it is possible that the race condition is that you need just the right timing of having the CMD indicator's local variable be True at the same time the ON/OFF terminal is true in order to turn on the relay.  Or the CMD indicator's local variable be True at the same time the On/OFF terminal is false to turn off the relay.  A mismatch of timing could cause that set of conditions to just miss happening.

 

If you really want to turn on and off and wait, this could be simplified to a single loop, eliminate most if not all local variables, and use timing functions to track the wait within a simple state machine.  States of Initialize, ON, OFF, check time, and Cleanup are all you need.

0 Kudos
Message 2 of 4
(2,170 Views)

Thanks for reply,

 

Manual testing is working fine with buttons. My problem is with auto switch ON and OFF.

Sorry the Vi which i sent you is not original code. I taken a part of my ATE code and sent you. I forgot to add delay. It is Switching ON fine. After delay( I missed to add while sending to you) i inserted a breakpoint and executed with highlighted execution. Relay is switching OFF fine. But in normal run it is not. I thought delay was problem. But it is not effecting when increasing or decreasing the delay in normal run.

 

 

0 Kudos
Message 3 of 4
(2,150 Views)

I can only comment on the code that is presented and talk about the issues that I see could be causing a problem.

If there is a problem with the delay and turning off the relay, but it isn't in the code, then I don't know how I or anyone else can offer suggestions on code we don't see.

 

I believe my overall suggestions of using a state machine and simplifying it down to a single loop are still valid and will make it easier to get the delay part of the code and the relay turn off functioning properly when you add it back in.

0 Kudos
Message 4 of 4
(2,141 Views)