Home AMX User Forum NetLinx Studio

Controller works like crazy when i shut down the system.

This is my first attempt of writing a timeline, and i made it work with som help from this forum. But when i choose shut down the system and the timeline begins. The processor in the controller works like crazy and everything happens really slow, like bringing a up a popup?? This must have somthing to do with the timeline since that is the only new thing in this program.

by the way how do i get the code in a grey area as most people do when posting on the forum??


anyway heres the coding i'm trying.


PROGRAM_NAME='cShutdown'


DEFINE_CONSTANT

TL1 = 1

DEFINE_VARIABLE


LONG lOneSecondTick[] = { 1000 } // second tick
INTEGER nMySecondCount // manually count passes


DEFINE_EVENT



BUTTON_EVENT[dvTP,39] //IF dvTP,39 EXIT IS PUSHED, EXIT PAGE IS SHOWN AND THE COUNTDOWN TIMELINE BEGINS.
{
PUSH:
{
TIMELINE_CREATE(TL1,lOneSecondTick,1,TIMELINE_RELATIVE,TIMELINE_REPEAT)
nMySecondCount = 0
}
}


TIMELINE_EVENT[TL1]
{
IF(TIMELINE.REPETITION = 20) // 20x repeated
{
DO_PUSH(dvTP,210)
PanelPage ('Main2')
TIMELINE_KILL(TL1)
nMySecondCount = 0
}
ELSE
{
SEND_COMMAND dvTP,"'^TXT-300,0,',ITOA(20 - TIMELINE.REPETITION)"
}
}


BUTTON_EVENT[dvTP,40] //CANCEL THE TIMELINE AND RETURN TO MAIN PAGE
{
PUSH:
{
TIMELINE_KILL(TL1)
nMySecondCount = 0
}
}

BUTTON_EVENT[dvTP,210] //OFF BUTTON IS PUSHED BEFORE THE TIMELINE IS DONE. THE SYSTEM IS SHUT DOWN AND THE TIMELINE IS CANCLED.
{
PUSH:
{
TIMELINE_KILL(TL1)
nMySecondCount = 0
PanelPage ('Main2')
}
}



(****************************************************TIDSBESTEMT AUTOSHUTDOWN*********************************************************************************************************************)
(*************************************************************************************************************************************************************************************************)
DEFINE_PROGRAM

IF (TIME = '18:00:00') // TIDSBASERT AUTOSHUTDOWN
{
DO_PUSH(dvTP,39)
PanelPage ('Exit2')
SEND_COMMAND dvTP,"'WAKE'"
}

Comments

  • HedbergHedberg Posts: 671
    by the way how do i get the code in a grey area as most people do when posting on the forum??

    }

    see:http://www.amxforums.com/misc.php?do=bbcode
  • HedbergHedberg Posts: 671
    To address the main question: when I run your code on my NI700 it works fine, just like it looks like it should. The only thing about the timeline that seems odd is the TIMELINE_RELATIVE which doesn't make much sense to me with respect to a timeline which only has one time in the array. But, I can't see that it would harm anything either.

    There are probably some oddities in the code that aren't right, but I don't think they are serious as far as basic functionality. For example, in your timeline_event you kill the timeline and display page 'Main2'. You also do_push button 210 which also kills the timeline and displays the same page. I suggest that there is a redundancy.

    So, the good news is that you appear to have a working timeline that is doing mostly what you want.

    The bad news is that if your programming is causing you angst, you probably need to look elsewhere.
  • A TIMELINE_KILL() to a timeline that is not existing (e.g. after a kill) just causes a runtime error but should not sffect the system.

    There really may be some dependencies with the rest of the code. Some general hints:
    - If an Event is coming, the execution of the DEFINE_PROGRAM will be breaked. So if the DEFINE_PROGRAM is pretty large, it may not be executed completely.
    - in general with the check IF(TIME='18:00:00'), it may be happen that in this one second the IF is executed several 100 times, because a NI may run several hundred loops in a second thru DEFINE_PROGRAM, and so the instructions of the IF will be stacked.
  • Thank you both.

    I'we made the changes so i dont kill the timeline several times.

    And the IF(TIME='18:00:00'), was the one that crashed the system. But what is the proper way to get something to happend at 18.00?? I have a customer that needs a autoshutdown in over 100 rooms at that time. Good thing i havent uploaded that code yet =P
  • CT-DallasCT-Dallas Posts: 157
    With regards to the TIMELINE_KILL, you can try keyword TIMELINE_ACTIVE in a conditional.

    IF (TIMELINE_ACTIVE(TL1))
    {
    TIMELINE_KILL(TL1)
    }

    This would avoid an error if the timeline was not active and you could use the statement anywhere, as many times as you would like.

    Not that this is causing the problem, but programmatically, you could do this to avoid the conflict.
  • CT-DallasCT-Dallas Posts: 157
    on the if statement for 18:00:00 you could set a flag and add to the if statement

    IF (TIME=18:00:00 AND !nFlag)
    {
    LOCAL_VAR INTEGER _ON = 1
    fnInitiateShutDown() //trigger the function
    nFlag = _ON
    }

    IF (TIME=18:00:01 AND nFlag)
    {
    LOCAL_VAR INTEGER _OFF = 0
    nFlag = _OFF
    }

    This should work for you.

    Chris
  • Spire_JeffSpire_Jeff Posts: 1,917
    I think the reason you are running into problems is that the IF (TIME = '18:00:00') statement is running more than once. The processor executes more than 1 time per second, so this statement will evaluate as true anywhere from a couple times to a couple thousand times (depending on what is running) in the 1 second you are dealing with. The easy way to fix this is using a WAIT because the processor will only queue the wait statement once. Try something like:
    IF (TIME = '18:00:00') // TIDSBASERT AUTOSHUTDOWN
    {
    wait 15 { //wait 1.5 seconds before executing. 
      DO_PUSH(dvTP,39) 
      PanelPage ('Exit2')
      SEND_COMMAND dvTP,"'WAKE'"
    }
    }
    

    There are other ways to accomplish this, but I think this will do what you want.

    Jeff
  • I dont think i mentioned that this happens everytime i shut down the system not only at 18.00. Could this be that the system is freqently checking if time = 18.00????
  • Spire_JeffSpire_Jeff Posts: 1,917
    Can you post the code that executes when you perform a shutdown?

    Jeff
  • I shure can.

    When i write a DO-Push dvTp, 210 it will execute this set of codes.
    DEFINE_FUNCTION ShutDownProj1()
    {
        PULSE[vdvPROJECTOR,28]
        PULSE[vdvPROJECTOR,28]
        
        
        IF (vProjOn=1)
        {
    	PanelPopupOn  ('ProjectorCooling')
    	wait ProjectorCooling
    	PanelPage ('Main2')
    	vProjOn=0
        }
    	ELSE IF (vProjOn=0)
    	{
    	    vProjOn=0
    	}
    }
    
    DEFINE_FUNCTION ShutDownProj2()
    {
        PULSE[vdvPROJECTOR2,28]
        PULSE[vdvPROJECTOR2,28]
       
        
        IF (vProj2On=1)
        {
    	PanelPopupOn  ('ProjectorCooling')
    	wait ProjectorCooling
    	PanelPage ('Main2')
    	vProj2On=0
        }
    	ELSE IF (vProj2On=0)
    	{
    	    vProj2On=0
    	}
    }
    
    
  • Spire_JeffSpire_Jeff Posts: 1,917
    I don't see anything that should lock up the processor. There are a few lines that don't need to be there.
    DEFINE_FUNCTION ShutDownProj1()
    {
        PULSE[vdvPROJECTOR,28]
        PULSE[vdvPROJECTOR,28]
        
        
        IF (vProjOn=1)
        {
    	PanelPopupOn  ('ProjectorCooling')
    	wait ProjectorCooling
    	PanelPage ('Main2')
    	vProjOn=0
        }
    }
    
    DEFINE_FUNCTION ShutDownProj2()
    {
        PULSE[vdvPROJECTOR2,28]
        PULSE[vdvPROJECTOR2,28]
       
        
        IF (vProj2On=1)
        {
    	PanelPopupOn  ('ProjectorCooling')
    	wait ProjectorCooling
    	PanelPage ('Main2')
    	vProj2On=0
        }
    }
    
    

    You could enclose the conditional in a wait statement and see if that helps:
    wait 5 { //wait .5 seconds before executing. (Check twice per second)
    IF (TIME = '18:00:00') // TIDSBASERT AUTOSHUTDOWN
    {
    wait 15 { //wait 1.5 seconds before executing. 
      DO_PUSH(dvTP,39) 
      PanelPage ('Exit2')
      SEND_COMMAND dvTP,"'WAKE'"
    }
    }
    }
    


    Jeff
  • That last wait 5 made the whole thing work fine. =) Thank you very much.


    but what happens now if the controller misses the exact 18:00:00 time? Could i maybe make it check for 18.00.?? to make it look for that whole minute?
  • Spire_JeffSpire_Jeff Posts: 1,917
    The wait 5 has it checking 2 times per second. If you are paranoid, you could make it wait 2 and it would check 5 times per second.

    Jeff
Sign In or Register to comment.