if statement not working


Recommended Posts

I have an if statement in a sequence, here is an example

if ((channel1[0] != 9) && (Channel2[0] != 9))

   DoSomething()

endif

I have at least one of the channels set to 9 and it is still getting to DoSomething().

What am I missing?

Is there some compiled cache somewhere that needs to be cleared and recompiled?

Link to comment
Share on other sites

There isn't a cache, but if you edit a sequence that is running, you have to stop the sequence and restart it to pick up the changes.  If that isn't it, I'd have to see the rest of the code to know what is happening.  You might have a symbol name conflict (i.e. a private or global variable with the same name as one of your channels.)

Link to comment
Share on other sites

I closed DAQFactory and reopened it.

All my channel names start with Chn, so I have no variables with the same name. My sequence code is below:

"ChnSystemEstop" is a channel that gets set or cleared when an emergency estop button is pressed on the system. The estop button is physically connected to a controller board that communicates with DAFactory over a serial connection. The controller board is polled for messages, which then sends a reply.

systemEStopSignalled is a global variable which is used to stop the clear estop sequence being called unless an estop has been sent already.

SystemEstopCmd is a sequence which sends an emergency stop request message to all parts of the system.

SystemEstopClearCmd is a sequence which sends an emergency stop cleared message to all parts of the system.

The four channels: ChnCell1Status[0], ChnCell2Status[0], ChnCell3Status[0], ChnFinalInspectionStationStatus contain the status value of the 4 parts of the system, the value 9 on the cells indicates that that particular cell is estopped, and the value 8 on the final inspection station indicates an estop, so we cannot send the estop message.

I had all 4 of these channels in the watch window, so that I could see their latest value. ChnCell3Status[0] was at the value 9, yet it still went into the body of the if statement, which clearly asks for not equal to 9.

This did not happen all the time but it did happen a lot at random.

Hope that makes sense

Could it be that I was writing a channel in another sequence while I was reading it here?

Thanks

//************************************************

while(1)
   
   if (ChnSystemEstop[0] > 0)
      
      if (systemEStopSignalled == 0)
         systemEStopSignalled = 1
         beginseq(SystemEstopCmd)
         while(Sequence.SystemEstopCmd.Running)
         endwhile
      endif
      
   else
   
      // Try hardcoded numbers as we keep getting through
      if (systemEstopSignalled == 1)
         if ((ChnCell1Status[0] != 9) && \
            (ChnCell2Status[0] != 9) && \
            (ChnCell3Status[0] != 9) && \
            (ChnFinalInspectionStationStatus[0] != 8))
            
            systemEStopSignalled = 0
            beginseq(SystemEstopClearCmd)
            while(sequence.SystemEstopClearCmd.Running)
            endwhile
         endif
      endif
   endif
   
   delay(0.01)
   
endwhile

return (NULL)

//************************************************

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.