langJapanese
HOME > RT-C Language Controller > Sample "Servo Motor Control"
> Sample for RT-C Language Controller <

 EVENT Task Operation"
Here we descrive how to run EVENT task
※ Please refer to users manual on basic programming method.
Overview of Sample
This sample runs 2 tasks such as【Main Process】which issues event and does arbitrary processes & 【Event Process】which assigns to event task.
■Main Process:
It initializes internal variables when program boots.
For example, it issues event [No.2] per 100 scans while the program is running.
■Event Process:
The event which is accored with assigned EVENT task No. runs when event is issued in the main process.
For example, it does addition of operation number while the program is running.
1. Main flow
Issue Event Process
Create module whch is always running while the program is running, and write call process to call "event issue API" in __Process()
public void __Process()
{
    ScanCount++;	// Count scan times

    if ((ScanCount % 100) == 0)
    {
        Eclr.Pcos.Resource.RaiseTaskEvent(2); // Issue event [No.2] per 100 scans
    }

}

Process by EVENT task
Create module which is assigned to EVENT task and write arbitrary process.
Assign it to arbitrary event to use.
※ Please refer to "Add Task" in the users manual on how to add / assign EVENT task.

2. Sample Program (C# Source Code)

    /// <summary>
    /// *****************************************************************************************************
    ///  Main Process Block
    /// *****************************************************************************************************
    /// </summary>
    [FUNCTION_BLOCK]
    public class _main
    {
        // *** Internal Variables ***
        public static UInt32 ScanCount;       // Count Scan times

        /// <summary>
        /// Program - Process in download
        /// </summary>
        public _main()
        {
        }

        /// <summary>
        /// Program - Process in reset
        /// </summary>
        ~_main()
        {
        }

        /// <summary>
        /// Program - Process in start
        /// </summary>
        public void __Init()
        {
            ScanCount = 0;
        }

        /// <summary>
        /// Program - Process in execute
        /// </summary>
        public void __Process()
        {
            ScanCount++;	// Count Scan times


            if ((ScanCount % 100) == 0)
            {
                Eclr.Pcos.Resource.RaiseTaskEvent(2); // Issue event [No.2] per 100 scans
            }

        }
    }
    /// <summary>
    /// *****************************************************************************************************
    ///  Event Process Block
    /// *****************************************************************************************************
    /// </summary>
    [FUNCTION_BLOCK]
    public class _event
    {
        // *** Internal Variables ***
        public static UInt32 ExeCount;      // Count Scan times

        /// <summary>
        /// Program - Process in download
        /// </summary>
        public _event()
        {
        }

        /// <summary>
        /// Program - Process in reset
        /// </summary>
        ~_event()
        {
        }

        /// <summary>
        /// Program - Process in start
        /// </summary>
        public void __Init()
        {
            ExeCount = 0;
        }

        /// <summary>
        /// Program - Process in execute
        /// </summary>
        public void __Process()
        {
            ExeCount++; // Add oeration times
        }
    }