Welcome Guest ( Login | Register )



All times are UTC - 7 hours [ DST ]



Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: How to create periodic Timers in iX Developer
PostPosted: Mon Jul 25, 2011 11:02 am 
User avatar

Joined: Fri Jul 15, 2011 3:21 pm
Posts: 214

Offline
Create a ScriptModule. Right click below the functions section and select "Add ScriptModule".

Attachment:
add_script_module.JPG
add_script_module.JPG [ 25.91 KiB | Viewed 12245 times ]


Right click on the Script Module and Rename it to "TimerScript".

Attachment:
rename_scriptmodule.JPG
rename_scriptmodule.JPG [ 10.67 KiB | Viewed 12245 times ]


The Script Module will default with the following code.

Code:
namespace Neo.ApplicationFramework.Generated
{
    using System.Windows.Forms;
    using System;
    using System.Drawing;
    using Neo.ApplicationFramework.Tools;
    using Neo.ApplicationFramework.Common.Graphics.Logic;
    using Neo.ApplicationFramework.Controls;
    using Neo.ApplicationFramework.Interfaces;   
   
    public partial class TimerScript
    {

    }
}


In the code below, I have edited the TimerScript class to create and initialize two System.Windows.Form.Timer class instances. I have also created two functions "Stop()" and "Start()" that can be used to turn the timers on or off. The timers are configured to 1000 and 250 milliseconds.

Code:
public partial class TimerScript
   {
      private static Timer timer1 = null;
      private static Timer timer2 = null;
      
      static TimerScript()
      {
         timer1 = new Timer();
         timer1.Tick += new EventHandler(TimeOut1);
         timer1.Interval = 1000;
         timer1.Enabled = true;         
         
         timer2 = new Timer();
         timer2.Tick += new EventHandler(TimeOut2);
         timer2.Interval = 250;
         timer2.Enabled = true;
      }

      public static void Stop()
      {
         try {
            timer1.Enabled = false;
            timer2.Enabled = false;
         }
         catch(Exception) {}
      }      
      
      public static void Start()
      {
         try {
            timer1.Enabled = true;
            timer2.Enabled = true;
         }
         catch(Exception) {}
      }
      
      private static void TimeOut1(Object myObject, EventArgs myEventArgs)
      {         
         Globals.Tags.Tag1.Value = Globals.Tags.Tag1.Value + 1;
      }      
      
      private static void TimeOut2(Object myObject, EventArgs myEventArgs)
      {         
         Globals.Tags.Tag2.Value = Globals.Tags.Tag2.Value + 1;
      }      
    }


You may call the "Stop()" or "Stop()" functions from actions on screens.

Attachment:
timer_script.JPG
timer_script.JPG [ 68.3 KiB | Viewed 12243 times ]


Attachments:
File comment: Sample workspace. iX Developer version 1.3.
SimpleFormTimer.zip [30.56 KiB]
Downloaded 1314 times

_________________
Best Regards,

Beijer Electronics, Inc.
Ron Lloyd | Applications Engineer
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 7 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: