Author Topic: Setting Variables  (Read 10480 times)

tobor0216

  • Newbie
  • Posts: 24
  • I'm a llama!
    • View Profile
Setting Variables
« on: January 16, 2010, 06:06:13 AM »
I have a time of day based custom function running. I can turn on and off out puts based on time of day and day of week. I am trying to be bale to override the time of setting by seeing if a input is set. When I compile the program , I get a error stating the name is incorrect.

Code is below.

@10   If RLY[1]=1 goto @90
@20   Else
@30   If Date[4]>=1 and Date[4]<=5 and TIME[1]>7 and TIME[1]<16
@40   CLRIO PWR_TV
@50   CLRIO PWR_COMP
@60   CLRIO SPARE_1
@70   CLRIO SPARE_2
@80   Else
@90   Setio PWR_TV
@100  Setio PWR_COMP
@110  ENDIF


garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:Setting Variables
« Reply #1 on: January 16, 2010, 08:16:26 PM »
Your programming example has several problems:
  • In your first line, RLY[1] should have been RELAY[1]
  • You have two "IF" statements, but only 1 "ENDIF"
  • You don't need line numbers (@10, @20, ...) on any line except the target of the GOTO statment.
  • You don't need the GOTO statement at all.
  • I suggest that you use the TESTIO(x) function to test the state of an input rather than the RELAY[1] mechanism because it is easier to read and to maintain.
The following code is a bit more straight forward and may be easier to debug/maintain:

IF TestIO(Input_X) OR ((DATE[4]<1 OR DATE[4}>5) AND (TIME[1]<=7 OR TIME[1]>=16))
   SetIO PWR_TV
   SetIO PWR_COMP
ELSE
   ClrIO PWR_TV
   ClrIO PWR_COMP
EDNDIF