﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using CLoggerCs;

namespace CollectionConditions
{
    public partial class CollectionConditions : Form
    {
        //----------------------------------------
        // Create instance CLogger class
        //----------------------------------------
        CLogger logger = new CLogger();
        //----------------------------------------
        // Declaration of global variables
        //----------------------------------------
        public short g_appid = 0;                   // ID for application access
        public GCHandle gCh;                        // GCHandle for callback routine
        public PLOGGEREVENTCALLBACK pdelegate_func; // Delegate for event notification
        public IntPtr pfunc;                        // IntPtr for callback routine

        public CollectionConditions()
        {
            InitializeComponent();
        }

        //================================================================================
        // Initial settings
        //================================================================================
        unsafe private void Form1_Load(object sender, EventArgs e)
        {
            //----------------------------------------
            // Update the initial display of device name
            //----------------------------------------
            textBox_DeviceName.Text = "AIO000";
            //----------------------------------------
            // Create the combobox for screen size
            //----------------------------------------
            comboBox_OpenMode.Items.Add("Minimize");
            comboBox_OpenMode.Items.Add("Normal");
            comboBox_OpenMode.Items.Add("Maximize");
            //----------------------------------------
            // Change the selection of screen size combobox to Minimize
            //----------------------------------------
            comboBox_OpenMode.SelectedIndex = 0;
            //----------------------------------------
            // Update the initial display of memory size
            //----------------------------------------
            textBox_MemorySize.Text = "10";
            //----------------------------------------
            // Create the combobox for file type
            //----------------------------------------
            comboBox_AutosaveType.Items.Add("None");
            comboBox_AutosaveType.Items.Add("clb");
            comboBox_AutosaveType.Items.Add("csv");
            //----------------------------------------
            // Change the selection of file type combobox to None
            //----------------------------------------
            comboBox_AutosaveType.SelectedIndex = 0;
            //----------------------------------------
            // Initialize the delegate for event notification
            //----------------------------------------
            pdelegate_func = new PLOGGEREVENTCALLBACK(CallBackProc);
            //----------------------------------------
            // Set the delegate to never be released
            //----------------------------------------
            if (gCh.IsAllocated == false)
            {
                gCh = GCHandle.Alloc(pdelegate_func);
            }
            return;
        }

        //================================================================================
        // It is the process when the LoggerOpenApplication button is clicked
        // Launch the app and enable access
        //================================================================================
        private void button_LoggerOpenApplication_Click(object sender, EventArgs e)
        {
            string  device_name;     // Device name
            ushort  openmode;        // Screen size
            int     ret;             // For return code
            string  error_string;    // Error code string

            //----------------------------------------
            // Get the device name from textbox
            //----------------------------------------
            device_name = textBox_DeviceName.Text;
            //----------------------------------------
            // Get the screen size from combobox
            //----------------------------------------
            openmode = (ushort)comboBox_OpenMode.SelectedIndex;
            //----------------------------------------
            // Initialize the application
            //----------------------------------------
            ret = logger.OpenApplication(device_name, out g_appid, openmode);
            //----------------------------------------
            // Get the error string
            //----------------------------------------
            logger.GetErrorString(ret, out error_string);
            //----------------------------------------
            // Display the error code and the message
            //----------------------------------------
            textBox_returnnum.Text = string.Format("LoggerOpenApplication = {0} : {1} ", ret, error_string);
            return;
        }

        //================================================================================
        // It is the process when the LoggerSetDeviceName button is clicked
        // Set the device name
        //================================================================================
        private void button_LoggerSetDeviceName_Click(object sender, EventArgs e)
        {
            string  device_name;     // Device name
            int     ret;             // For return code
            string  error_string;    // Error code string

            //----------------------------------------
            // Get the device name from textbox
            //----------------------------------------
            device_name = textBox_DeviceName.Text;
            //----------------------------------------
            // Set the device name
            //----------------------------------------
            ret = logger.SetDeviceName(g_appid, device_name);
            //----------------------------------------
            // Get the error string
            //----------------------------------------
            logger.GetErrorString(ret, out error_string);
            //----------------------------------------
            // Display the error code and the message
            //----------------------------------------
            textBox_returnnum.Text = string.Format("LoggerSetDeviceName = {0} : {1} ", ret, error_string);
            return;
        }

        //================================================================================
        // It is the process when the LoggerGetDeviceName button is clicked
        // Get the device name
        //================================================================================
        private void button_LoggerGetDeviceName_Click(object sender, EventArgs e)
        {
            string  device_name;     // Device name
            int     ret;             // For return code
            string  error_string;    // Error code string

            //----------------------------------------
            // Get the device name
            //----------------------------------------
            ret = logger.GetDeviceName(g_appid, out device_name);
            //----------------------------------------
            // Get the error string
            //----------------------------------------
            logger.GetErrorString(ret, out error_string);
            //----------------------------------------
            // Display the error code and the message
            //----------------------------------------
            textBox_returnnum.Text = string.Format("LoggerGetDeviceName = {0} : {1} ", ret, error_string);
            //----------------------------------------
            // If the device name acquisition function is completed successfully
            //----------------------------------------
            if (ret == 0)
            {
                //----------------------------------------
                // Update the device name in the textbox
                //----------------------------------------
                textBox_DeviceName.Text = device_name;
            }
            return;
        }

        //================================================================================
        // It is the process when the Channel Settings... button is clicked
        // Display the channel setting dialog
        //================================================================================
        private void button_ChannelSetting_Click(object sender, EventArgs e)
        {
            ChannelSetting  channeldlg      = new ChannelSetting();         // Channel setting dialog
            ushort          sequence_num    = channeldlg.m_sequence_num;    // Number of sequences
            ushort          InputType       = 0;                            // Input method
            ushort          AiChannels      = 0;                            // Number of channels
            ushort[]        ChannelNo       = new ushort[256];              // Channel number
            byte[]          ChName          = new byte[256*256];            // Channel name
            ushort[]        Range           = new ushort[256];              // Range
            ushort[]        ScaleEnable     = new ushort[sequence_num];     // Scale conversion enable/disable
            float[]         MinData         = new float[sequence_num];      // Minimum data
            float[]         MaxData         = new float[sequence_num];      // Maximum data
            float[]         MinScale        = new float[sequence_num];      // Minimum scale
            float[]         MaxScale        = new float[sequence_num];      // Maximum scale
            ushort          i;                                              // Loop count
            int             ret;                                            // For return code
            string          error_string;                                   // Error code string

            //----------------------------------------
            // Set the initial value
            //----------------------------------------
            InputType = (ushort)CLoggerConst.LOGGER_PARAM_SINGLEENDED;
            AiChannels = sequence_num;
            for (i = 0; i < sequence_num; i++)
            {
                ChannelNo[i] = 0;
                ChName[i*256] = 0;
                Range[i] = 0;
                ScaleEnable[i] = (ushort)CLoggerConst.LOGGER_PARAM_DISABLE;
                MinData[i] = -10.0f;
                MaxData[i] = 10.0f;
                MinScale[i] = -10.0f;
                MaxScale[i] = 10.0f;
            }
            //----------------------------------------
            // Get the channel settings
            //----------------------------------------
            ret = logger.GetChannelSetting(g_appid, out InputType, ref AiChannels, ChannelNo, ChName, Range);
            if (ret != 0)
            {
                //----------------------------------------
                // Get the error string
                //----------------------------------------
                logger.GetErrorString(ret, out error_string);
                //----------------------------------------
                // Display the error code and the message
                //----------------------------------------
                textBox_returnnum.Text = string.Format("LoggerGetChannelSetting = {0} : {1} ", ret, error_string);
                channeldlg.Dispose();
                return;
            }
            //----------------------------------------
            // Get the scale conversion settings
            //----------------------------------------
            for (i = 0; i < sequence_num; i++)
            {
                if (AiChannels < i + 1)
                {
                    break;
                }
                ret = logger.GetScaleConversion(g_appid, i, out ScaleEnable[i], out MinData[i], out MaxData[i], out MinScale[i], out MaxScale[i]);
                if(ret != 0)
                {
                    break;
                }
            }
            if (ret != 0)
            {
                //----------------------------------------
                // Get the error string
                //----------------------------------------
                logger.GetErrorString(ret, out error_string);
                //----------------------------------------
                // Display the error code and the message
                //----------------------------------------
                textBox_returnnum.Text = string.Format("LoggerGetScaleConversion = {0} : {1} ", ret, error_string);
                channeldlg.Dispose();
                return;
            }
            //----------------------------------------
            // Set the date to channel setting dialog
            //----------------------------------------
            channeldlg.channel_data_set(InputType, AiChannels, ChannelNo, ChName, Range, ScaleEnable, MinData, MaxData, MinScale, MaxScale);
            //----------------------------------------
            // If OK is pressed, the process is performed
            //----------------------------------------
            if (channeldlg.ShowDialog() == DialogResult.OK)
            {
                //----------------------------------------
                // Get the date from channel setting dialog
                //----------------------------------------
                channeldlg.channel_data_get(ref InputType, ref AiChannels, ref ChannelNo, ref ChName, ref Range, ref ScaleEnable, ref MinData, ref MaxData, ref MinScale, ref MaxScale);
                //----------------------------------------
                // Set the channel
                //----------------------------------------
                ret = logger.SetChannelSetting(g_appid, InputType, AiChannels, ChannelNo, ChName, Range);
                if(ret != 0)
                {
                    //----------------------------------------
                    // Get the error string
                    //----------------------------------------
                    logger.GetErrorString(ret, out error_string);
                    //----------------------------------------
                    // Display the error code and the message
                    //----------------------------------------
                    textBox_returnnum.Text = string.Format("LoggerSetChannelSetting = {0} : {1} ", ret, error_string);
                    channeldlg.Dispose();
                    return;
                }
                //----------------------------------------
                // Set the scale conversion
                //----------------------------------------
                for (i = 0; i < AiChannels; i++)
                {
                    ret = logger.SetScaleConversion(g_appid, i, ScaleEnable[i], MinData[i], MaxData[i], MinScale[i], MaxScale[i]);
                    if(ret != 0)
                    {
                        break;
                    }
                }
                if (ret != 0)
                {
                    //----------------------------------------
                    // Get the error string
                    //----------------------------------------
                    logger.GetErrorString(ret, out error_string);
                    //----------------------------------------
                    // Display the error code and the message
                    //----------------------------------------
                    textBox_returnnum.Text = string.Format("LoggerSetScaleConversion = {0} : {1} ", ret, error_string);
                    channeldlg.Dispose();
                    return;
                }
                //----------------------------------------
                // Display the message that channel setting is completed
                //----------------------------------------
                textBox_returnnum.Text = "Channel Settings : Successful completion";
            }
            channeldlg.Dispose();
        }

        //================================================================================
        // It is the process when the Clock Settings... button is clicked
        // Display the clock setting dialog
        //================================================================================
        private void button_ClockSetting_Click(object sender, EventArgs e)
        {
            ClockSetting clockdlg = new ClockSetting();     // Clock setting dialog
            ushort  clock_type;                             // Clock type
            ushort  sampling_clock_unit;                    // Sampling clock unit
            double  sampling_clock;                         // Sampling clock
            double  external_clock;                         // External clock
            uint    sampling_times;                         // Sampling times condition
            float   scan_clock;                             // Scan clock
            uint    repeat_times;                           // Repeat times condition
            ushort  start_trigger_type;                     // Start condition
            ushort  stop_trigger_type;                      // Stop condition
            uint    delay_time;                             // Delay sampling condition
            ushort  start_level_trigger_edge;               // Start trigger  Level comparison  Comparison direction
            ushort  start_level_sequence_no;                // Start trigger  Level comparison  Sequence number
            float   start_level_border_value;               // Start trigger  Level comparison  Comparison value
            ushort  start_range_sequence_no;                // Start trigger  In range/out range comparison  Sequence number
            float   start_range_upper_border_value;         // Start trigger  In range/out range comparison  Upper limit value
            float   start_range_lower_border_value;         // Start trigger  In range/out range comparison  Lower limit value
            uint    start_range_state_times;                // Start trigger  In range/out range comparison  State times
            uint    start_time_time;                        // Start condition - Time/Moment - Time
            uint    start_time_hour;                        // Start condition - Time/Moment - Moment(H)
            uint    start_time_minute;                      // Start condition - Time/Moment - Moment(M)
            uint    start_time_second;                      // Start condition - Time/Moment - Moment(S)
            ushort  stop_level_trigger_edge;                // Stop trigger  Level comparison  Comparison direction
            ushort  stop_level_sequence_no;                 // Stop trigger  Level comparison  Sequence number
            float   stop_level_border_value;                // Stop trigger  Level comparison  Comparison value
            ushort  stop_range_sequence_no;                 // Stop trigger  In range/out range comparison  Sequence number
            float   stop_range_upper_border_value;          // Stop trigger  In range/out range comparison  Upper limit value
            float   stop_range_lower_border_value;          // Stop trigger  In range/out range comparison  Lower limit value
            uint    stop_range_state_times;                 // Stop trigger  In range/out range comparison  State times
            uint    stop_time_time;                         // Stop condition - Time/Moment - Time
            uint    stop_time_hour;                         // Stop condition - Time/Moment - Moment(H)
            uint    stop_time_minute;                       // Stop condition - Time/Moment - Moment(M)
            uint    stop_time_second;                       // Stop condition - Time/Moment - Moment(S)
            double  value_temp;                             // For temporary storage of setting value
            ushort  value_time_type;                        // For temporary storage of setting value
            uint    value_time1;                            // For temporary storage of setting value
            uint    value_time2;                            // For temporary storage of setting value
            uint    value_time3;                            // For temporary storage of setting value
            int     ret;                                    // For return code
            string  error_string;                           // Error code string

            //----------------------------------------
            // Set the initial value
            //----------------------------------------
            sampling_clock_unit = (ushort)CLoggerConst.LOGGER_PARAM_FREQUNIT_USEC;
            sampling_clock = 0.0;
            external_clock = 0.0;
            //----------------------------------------
            // Get the sampling clock condition
            //----------------------------------------
            value_temp = 0.0;
            ret = logger.GetSamplingClock(g_appid, out clock_type, sampling_clock_unit, out value_temp);
            if (ret != 0)
            {
                //----------------------------------------
                // Get the error string
                //----------------------------------------
                logger.GetErrorString(ret, out error_string);
                //----------------------------------------
                // Display the error code and the message
                //----------------------------------------
                textBox_returnnum.Text = string.Format("LoggerGetSamplingClock = {0} : {1} ", ret, error_string);
                clockdlg.Dispose();
                return;
            }
            //----------------------------------------
            // Set the acquired value to the sampling clock in the case of internal clock setting
            //----------------------------------------
            if (clock_type == (ushort)CLoggerConst.LOGGER_PARAM_CLOCK_INTERNAL)
            {
                sampling_clock = value_temp;

            //----------------------------------------
            // Set the acquired value to the external clock in the case of external clock setting
            //----------------------------------------
            }
            else
            {
                external_clock = value_temp;
            }
            //----------------------------------------
            // Get the sampling times, conversion speed and repeat times
            //----------------------------------------
            ret = logger.GetSamplingSetting(g_appid, out sampling_times, out scan_clock, out repeat_times, out start_trigger_type, out stop_trigger_type, out delay_time);
            if (ret != 0)
            {
                //----------------------------------------
                // Get the error string
                //----------------------------------------
                logger.GetErrorString(ret, out error_string);
                //----------------------------------------
                // Display the error code and the message
                //----------------------------------------
                textBox_returnnum.Text = string.Format("LoggerGetSamplingSetting = {0} : {1} ", ret, error_string);
                clockdlg.Dispose();
                return;
            }
            //----------------------------------------
            // Get the start trigger analog level
            //----------------------------------------
            ret = logger.GetAnalogLevelTrigger(g_appid, (ushort)CLoggerConst.LOGGER_PARAM_STARTTRIGGER, out start_level_trigger_edge, out start_level_sequence_no, out start_level_border_value);
            if (ret != 0)
            {
                //----------------------------------------
                // Get the error string
                //----------------------------------------
                logger.GetErrorString(ret, out error_string);
                //----------------------------------------
                // Display the error code and the message
                //----------------------------------------
                textBox_returnnum.Text = string.Format("LoggerGetAnalogLevelTrigger = {0} : {1} ", ret, error_string);
                clockdlg.Dispose();
                return;
            }
            //----------------------------------------
            // Get the start trigger analog in range/out range
            //----------------------------------------
            ret = logger.GetAnalogRangeTrigger(g_appid, (ushort)CLoggerConst.LOGGER_PARAM_STARTTRIGGER, out start_range_sequence_no, out start_range_upper_border_value, out start_range_lower_border_value, out start_range_state_times);
            if (ret != 0)
            {
                //----------------------------------------
                // Get the error string
                //----------------------------------------
                logger.GetErrorString(ret, out error_string);
                //----------------------------------------
                // Display the error code and the message
                //----------------------------------------
                textBox_returnnum.Text = string.Format("LoggerGetAnalogRangeTrigger = {0} : {1} ", ret, error_string);
                clockdlg.Dispose();
                return;
            }
            //----------------------------------------
            // Get start trigger Time/Moment
            //----------------------------------------
            ret = logger.GetTimeTrigger(g_appid, (ushort)CLoggerConst.LOGGER_PARAM_STARTTRIGGER, out value_time_type, out value_time1, out value_time2, out value_time3);
            if (ret != 0)
            {
                //----------------------------------------
                // Get error string
                //----------------------------------------
                logger.GetErrorString(ret, out error_string);
                //----------------------------------------
                // Display error code and message
                //----------------------------------------
                textBox_returnnum.Text = string.Format("LoggerGetTimeTrigger = {0} : {1} ", ret, error_string);
                clockdlg.Dispose();
                return;
            }
            //----------------------------------------
            // For Time, assign the acquired value to the time
            //----------------------------------------
            if (value_time_type == (ushort)CLoggerConst.LOGGER_PARAM_TIMETYPE_ELAPSED)
            {
                start_time_time = value_time1;
                start_time_hour = 0;
                start_time_minute = 0;
                start_time_second = 0;
            }
            //----------------------------------------
            // For Moment, assign the acquired value to the moment
            //----------------------------------------
            else
            {
                start_time_time = 60;
                start_time_hour = value_time1;
                start_time_minute = value_time2;
                start_time_second = value_time3;
            }
            //----------------------------------------
            // Get the stop trigger analog level
            //----------------------------------------
            ret = logger.GetAnalogLevelTrigger(g_appid, (ushort)CLoggerConst.LOGGER_PARAM_STOPTRIGGER, out stop_level_trigger_edge, out stop_level_sequence_no, out stop_level_border_value);
            if (ret != 0)
            {
                //----------------------------------------
                // Get the error string
                //----------------------------------------
                logger.GetErrorString(ret, out error_string);
                //----------------------------------------
                // Display the error code and the message
                //----------------------------------------
                textBox_returnnum.Text = string.Format("LoggerGetAnalogLevelTrigger = {0} : {1} ", ret, error_string);
                clockdlg.Dispose();
                return;
            }
            //----------------------------------------
            // Get the stop trigger analog in range/out range
            //----------------------------------------
            ret = logger.GetAnalogRangeTrigger(g_appid, (ushort)CLoggerConst.LOGGER_PARAM_STOPTRIGGER, out stop_range_sequence_no, out stop_range_upper_border_value, out stop_range_lower_border_value, out stop_range_state_times);
            if (ret != 0)
            {
                //----------------------------------------
                // Get the error string
                //----------------------------------------
                logger.GetErrorString(ret, out error_string);
                //----------------------------------------
                // Display the error code and the message
                //----------------------------------------
                textBox_returnnum.Text = string.Format("LoggerGetAnalogRangeTrigger = {0} : {1} ", ret, error_string);
                clockdlg.Dispose();
                return;
            }
            //----------------------------------------
            // Get stop trigger Time/Moment
            //----------------------------------------
            ret = logger.GetTimeTrigger(g_appid, (ushort)CLoggerConst.LOGGER_PARAM_STOPTRIGGER, out value_time_type, out value_time1, out value_time2, out value_time3);
            if (ret != 0)
            {
                //----------------------------------------
                // Get error string
                //----------------------------------------
                logger.GetErrorString(ret, out error_string);
                //----------------------------------------
                // Display error code and message
                //----------------------------------------
                textBox_returnnum.Text = string.Format("LoggerGetTimeTrigger = {0} : {1} ", ret, error_string);
                clockdlg.Dispose();
                return;
            }
            //----------------------------------------
            // For Time, assign the acquired value to the time
            //----------------------------------------
            if (value_time_type == (ushort)CLoggerConst.LOGGER_PARAM_TIMETYPE_ELAPSED)
            {
                stop_time_time = value_time1;
                stop_time_hour = 0;
                stop_time_minute = 0;
                stop_time_second = 0;
            }
            //----------------------------------------
            // For Moment, assign the acquired value to the moment
            //----------------------------------------
            else
            {
                stop_time_time = 60;
                stop_time_hour = value_time1;
                stop_time_minute = value_time2;
                stop_time_second = value_time3;
            }
            //----------------------------------------
            // Set the date to clock setting dialog
            //----------------------------------------
            clockdlg.clock_data_set(clock_type,
                                        sampling_clock_unit,
                                        sampling_clock,
                                        external_clock,
                                        sampling_times,
                                        scan_clock,
                                        repeat_times,
                                        start_trigger_type,
                                        stop_trigger_type,
                                        delay_time,
                                        start_level_trigger_edge,
                                        start_level_sequence_no,
                                        start_level_border_value,
                                        start_range_sequence_no,
                                        start_range_upper_border_value,
                                        start_range_lower_border_value,
                                        start_range_state_times,
                                        start_time_time,
                                        start_time_hour,
                                        start_time_minute,
                                        start_time_second,
                                        stop_level_trigger_edge,
                                        stop_level_sequence_no,
                                        stop_level_border_value,
                                        stop_range_sequence_no,
                                        stop_range_upper_border_value,
                                        stop_range_lower_border_value,
                                        stop_range_state_times,
                                        stop_time_time,
                                        stop_time_hour,
                                        stop_time_minute,
                                        stop_time_second);

            //----------------------------------------
            // If OK is pressed, the process is performed
            //----------------------------------------
            if (clockdlg.ShowDialog() == DialogResult.OK)
            {
                //----------------------------------------
                // Get the date from clock setting dialog
                //----------------------------------------
                clockdlg.clock_data_get(ref clock_type,
                                            ref sampling_clock_unit,
                                            ref sampling_clock,
                                            ref external_clock,
                                            ref sampling_times,
                                            ref scan_clock,
                                            ref repeat_times,
                                            ref start_trigger_type,
                                            ref stop_trigger_type,
                                            ref delay_time,
                                            ref start_level_trigger_edge,
                                            ref start_level_sequence_no,
                                            ref start_level_border_value,
                                            ref start_range_sequence_no,
                                            ref start_range_upper_border_value,
                                            ref start_range_lower_border_value,
                                            ref start_range_state_times,
                                            ref start_time_time,
                                            ref start_time_hour,
                                            ref start_time_minute,
                                            ref start_time_second,
                                            ref stop_level_trigger_edge,
                                            ref stop_level_sequence_no,
                                            ref stop_level_border_value,
                                            ref stop_range_sequence_no,
                                            ref stop_range_upper_border_value,
                                            ref stop_range_lower_border_value,
                                            ref stop_range_state_times,
                                            ref stop_time_time,
                                            ref stop_time_hour,
                                            ref stop_time_minute,
                                            ref stop_time_second);
                //----------------------------------------
                // Specify the sampling clock period (frequency) for internal clock
                //----------------------------------------
                if (clock_type == (ushort)CLoggerConst.LOGGER_PARAM_CLOCK_INTERNAL)
                {
                    value_temp = sampling_clock;
                }
                //----------------------------------------
                // Specify the external clock update interval for external clock
                //----------------------------------------
                else
                {
                    value_temp = external_clock;
                }
                //----------------------------------------
                // Set the sampling clock condition
                //----------------------------------------
                ret = logger.SetSamplingClock(g_appid, clock_type, sampling_clock_unit, value_temp);
                if (ret != 0)
                {
                    //----------------------------------------
                    // Get the error string
                    //----------------------------------------
                    logger.GetErrorString(ret, out error_string);
                    //----------------------------------------
                    // Display the error code and the message
                    //----------------------------------------
                    textBox_returnnum.Text = string.Format("LoggerSetSamplingClock = {0} : {1} ", ret, error_string);
                    clockdlg.Dispose();
                    return;
                }
                //----------------------------------------
                // Set the sampling times, conversion speed and repeat times
                //----------------------------------------
                ret = logger.SetSamplingSetting(g_appid, sampling_times, scan_clock, repeat_times, start_trigger_type, stop_trigger_type, delay_time);
                if (ret != 0)
                {
                    //----------------------------------------
                    // Get the error string
                    //----------------------------------------
                    logger.GetErrorString(ret, out error_string);
                    //----------------------------------------
                    // Display the error code and the message
                    //----------------------------------------
                    textBox_returnnum.Text = string.Format("LoggerSetSamplingSetting = {0} : {1} ", ret, error_string);
                    clockdlg.Dispose();
                    return;
                }
                if (start_trigger_type == (ushort)CLoggerConst.LOGGER_PARAM_TRIGGER_LEVEL)
                {
                    //----------------------------------------
                    // Set the start trigger analog level
                    //----------------------------------------
                    ret = logger.SetAnalogLevelTrigger(g_appid, (ushort)CLoggerConst.LOGGER_PARAM_STARTTRIGGER, start_level_trigger_edge, start_level_sequence_no, start_level_border_value);
                    if (ret != 0)
                    {
                        //----------------------------------------
                        // Get the error string
                        //----------------------------------------
                        logger.GetErrorString(ret, out error_string);
                        //----------------------------------------
                        // Display the error code and the message
                        //----------------------------------------
                        textBox_returnnum.Text = string.Format("LoggerSetAnalogLevelTrigger = {0} : {1} ", ret, error_string);
                        clockdlg.Dispose();
                        return;
                    }
                }
                if ((start_trigger_type == (ushort)CLoggerConst.LOGGER_PARAM_TRIGGER_INRANGE) || (start_trigger_type == (ushort)CLoggerConst.LOGGER_PARAM_TRIGGER_OUTRANGE))
                {
                    //----------------------------------------
                    // Set the start trigger analog in range/out range
                    //----------------------------------------
                    ret = logger.SetAnalogRangeTrigger(g_appid, (ushort)CLoggerConst.LOGGER_PARAM_STARTTRIGGER, start_range_sequence_no, start_range_upper_border_value, start_range_lower_border_value, start_range_state_times);
                    if (ret != 0)
                    {
                        //----------------------------------------
                        // Get the error string
                        //----------------------------------------
                        logger.GetErrorString(ret, out error_string);
                        //----------------------------------------
                        // Display the error code and the message
                        //----------------------------------------
                        textBox_returnnum.Text = string.Format("LoggerSetAnalogRangeTrigger = {0} : {1} ", ret, error_string);
                        clockdlg.Dispose();
                        return;
                    }
                }
                if (start_trigger_type == (ushort)CLoggerConst.LOGGER_PARAM_TRIGGER_ELAPSED_TIME)
                {
                    //----------------------------------------
                    // Set start trigger Time
                    //----------------------------------------
                    ret = logger.SetTimeTrigger(g_appid, (ushort)CLoggerConst.LOGGER_PARAM_STARTTRIGGER, (ushort)CLoggerConst.LOGGER_PARAM_TIMETYPE_ELAPSED, start_time_time, 0, 0);
                    if (ret != 0)
                    {
                        //----------------------------------------
                        // Get error string
                        //----------------------------------------
                        logger.GetErrorString(ret, out error_string);
                        //----------------------------------------
                        // Display error code and message
                        //----------------------------------------
                        textBox_returnnum.Text = string.Format("LoggerSetTimeTrigger = {0} : {1} ", ret, error_string);
                        clockdlg.Dispose();
                        return;
                    }
                }
                if (start_trigger_type == (ushort)CLoggerConst.LOGGER_PARAM_TRIGGER_CURRENT_TIME)
                {
                    //----------------------------------------
                    // Set start trigger Moment
                    //----------------------------------------
                    ret = logger.SetTimeTrigger(g_appid, (ushort)CLoggerConst.LOGGER_PARAM_STARTTRIGGER, (ushort)CLoggerConst.LOGGER_PARAM_TIMETYPE_CURRENT, start_time_hour, start_time_minute, start_time_second);
                    if (ret != 0)
                    {
                        //----------------------------------------
                        // Get error string
                        //----------------------------------------
                        logger.GetErrorString(ret, out error_string);
                        //----------------------------------------
                        // Display error code and message
                        //----------------------------------------
                        textBox_returnnum.Text = string.Format("LoggerSetTimeTrigger = {0} : {1} ", ret, error_string);
                        clockdlg.Dispose();
                        return;
                    }
                }
                if (stop_trigger_type == (ushort)CLoggerConst.LOGGER_PARAM_TRIGGER_LEVEL)
                {
                    //----------------------------------------
                    // Set the stop trigger analog level
                    //----------------------------------------
                    ret = logger.SetAnalogLevelTrigger(g_appid, (ushort)CLoggerConst.LOGGER_PARAM_STOPTRIGGER, stop_level_trigger_edge, stop_level_sequence_no, stop_level_border_value);
                    if (ret != 0)
                    {
                        //----------------------------------------
                        // Get the error string
                        //----------------------------------------
                        logger.GetErrorString(ret, out error_string);
                        //----------------------------------------
                        // Display the error code and the message
                        //----------------------------------------
                        textBox_returnnum.Text = string.Format("LoggerSetAnalogLevelTrigger = {0} : {1} ", ret, error_string);
                        clockdlg.Dispose();
                        return;
                    }
                }
                if ((stop_trigger_type == (ushort)CLoggerConst.LOGGER_PARAM_TRIGGER_INRANGE) || (stop_trigger_type == (ushort)CLoggerConst.LOGGER_PARAM_TRIGGER_OUTRANGE))
                {
                    //----------------------------------------
                    // Set the stop trigger analog in range/out range
                    //----------------------------------------
                    ret = logger.SetAnalogRangeTrigger(g_appid, (ushort)CLoggerConst.LOGGER_PARAM_STOPTRIGGER, stop_range_sequence_no, stop_range_upper_border_value, stop_range_lower_border_value, stop_range_state_times);
                    if (ret != 0)
                    {
                        //----------------------------------------
                        // Get the error string
                        //----------------------------------------
                        logger.GetErrorString(ret, out error_string);
                        //----------------------------------------
                        // Display the error code and the message
                        //----------------------------------------
                        textBox_returnnum.Text = string.Format("LoggerSetAnalogRangeTrigger = {0} : {1} ", ret, error_string);
                        clockdlg.Dispose();
                        return;
                    }
                }
                if (stop_trigger_type == (ushort)CLoggerConst.LOGGER_PARAM_TRIGGER_ELAPSED_TIME)
                {
                    //----------------------------------------
                    // Set stop trigger Time
                    //----------------------------------------
                    ret = logger.SetTimeTrigger(g_appid, (ushort)CLoggerConst.LOGGER_PARAM_STOPTRIGGER, (ushort)CLoggerConst.LOGGER_PARAM_TIMETYPE_ELAPSED, stop_time_time, 0, 0);
                    if (ret != 0)
                    {
                        //----------------------------------------
                        // Get error string
                        //----------------------------------------
                        logger.GetErrorString(ret, out error_string);
                        //----------------------------------------
                        // Display error code and message
                        //----------------------------------------
                        textBox_returnnum.Text = string.Format("LoggerSetTimeTrigger = {0} : {1} ", ret, error_string);
                        clockdlg.Dispose();
                        return;
                    }
                }
                if (stop_trigger_type == (ushort)CLoggerConst.LOGGER_PARAM_TRIGGER_CURRENT_TIME)
                {
                    //----------------------------------------
                    // Set stop trigger Moment
                    //----------------------------------------
                    ret = logger.SetTimeTrigger(g_appid, (ushort)CLoggerConst.LOGGER_PARAM_STOPTRIGGER, (ushort)CLoggerConst.LOGGER_PARAM_TIMETYPE_CURRENT, stop_time_hour, stop_time_minute, stop_time_second);
                    if (ret != 0)
                    {
                        //----------------------------------------
                        // Get error string
                        //----------------------------------------
                        logger.GetErrorString(ret, out error_string);
                        //----------------------------------------
                        // Display error code and message
                        //----------------------------------------
                        textBox_returnnum.Text = string.Format("LoggerSetTimeTrigger = {0} : {1} ", ret, error_string);
                        clockdlg.Dispose();
                        return;
                    }
                }
                //----------------------------------------
                // Display the message that clock setting is completed
                //----------------------------------------
                textBox_returnnum.Text = "Clock Settings : Successful completion";
            }
            clockdlg.Dispose();
        }

        //================================================================================
        // It is the process when the LoggerSetMemoryOption button is clicked
        // Set the memory option
        //================================================================================
        private void button_LoggerSetMemoryOption_Click(object sender, EventArgs e)
        {
            int     ret;            // For return code
            string  error_string;   // Error code string
            ushort  memorysize;     // Memory size

            //----------------------------------------
            // Get the memory size from textbox
            //----------------------------------------
            if(ushort.TryParse(textBox_MemorySize.Text, out memorysize) == true)
            {
                //----------------------------------------
                // Set the memory option
                //----------------------------------------
                ret = logger.SetMemoryOption(g_appid, memorysize);
                //----------------------------------------
                // Get the error string
                //----------------------------------------
                logger.GetErrorString(ret, out error_string);
                //----------------------------------------
                // Display the error code and the message
                //----------------------------------------
                textBox_returnnum.Text = string.Format("LoggerSetMemoryOption = {0} : {1} ", ret, error_string);
            }
            else
            {
                textBox_returnnum.Text = "Memory size acquisition error";
            }
            return;

        }

        //================================================================================
        // It is the process when the LoggerSetAutoSave button is clicked
        // Set the autosave
        //================================================================================
        private void button_LoggerSetAutoSave_Click(object sender, EventArgs e)
        {
            string filepath;        // File path
            int    ret;             // For return code
            string error_string;    // Error code string
            ushort auto_save_type;  // Autosave type

            //----------------------------------------
            // Get the save file path from textbox
            //----------------------------------------
            filepath = textBox_AutoSaveFile.Text;
            //----------------------------------------
            // Get the autosave type from combobox
            //----------------------------------------
            auto_save_type = (ushort)comboBox_AutosaveType.SelectedIndex;
            //----------------------------------------
            // Set the autosave
            //----------------------------------------
            ret = logger.SetAutoSave(g_appid, 0, auto_save_type, filepath);
            //----------------------------------------
            // Get the error string
            //----------------------------------------
            logger.GetErrorString(ret, out error_string);
            //----------------------------------------
            // Display the error code and the message
            //----------------------------------------
            textBox_returnnum.Text = string.Format("LoggerSetAutoSave = {0} : {1} ", ret, error_string);
            return;
        }

        //================================================================================
        // It is the process when the LoggerExportSettingFile button is clicked
        // Export the setting file
        //================================================================================
        private void button_LoggerExportSettingFile_Click(object sender, EventArgs e)
        {
            string  filepath;        // File path
            int     ret;             // For return code
            string  error_string;    // Error code string

            //----------------------------------------
            // Get the setting file path from textbox
            //----------------------------------------
            filepath = textBox_SettingFile.Text;
            //----------------------------------------
            // Export the setting file
            //----------------------------------------
            ret = logger.ExportSettingFile(g_appid, filepath);
            //----------------------------------------
            // Get the error string
            //----------------------------------------
            logger.GetErrorString(ret, out error_string);
            //----------------------------------------
            // Display the error code and the message
            //----------------------------------------
            textBox_returnnum.Text = string.Format("LoggerExportSettingFile = {0} : {1} ", ret, error_string);
            return;
        }

        //================================================================================
        // It is the process when the LoggerImportSettingFile button is clicked
        // Import the setting file
        //================================================================================
        private void button_LoggerImportSettingFile_Click(object sender, EventArgs e)
        {
            string  filepath;           // File path
            int     ret;                // For return code
            string  error_string;       // Error code string
            uint    status;             // Status              

            //----------------------------------------
            // Get the setting file path from textbox
            //----------------------------------------
            filepath = textBox_SettingFile.Text;
            //----------------------------------------
            // Import the setting file
            //----------------------------------------
            ret = logger.ImportSettingFile(g_appid, filepath, out status);
            //----------------------------------------
            // Get the error string
            //----------------------------------------
            logger.GetErrorString(ret, out error_string);
            //----------------------------------------
            // Display the error code and the message
            //----------------------------------------
            textBox_returnnum.Text = string.Format("LoggerImportSettingFile = {0} : {1} \r\nstatus=0x{2:X16}", ret, error_string, status);
            return;
        }

        //================================================================================
        // It is the process when the Logging Start button is clicked
        // Start the application input and output
        //================================================================================
        unsafe private void button_StartOperation_Click(object sender, EventArgs e)
        {
            string  error_string;       // Error code string
            int     ret;                // For return code
            uint    status;             // Status   
            uint    Event;              // Event setting

            //----------------------------------------
            // Close the file
            //----------------------------------------
            ret = logger.GraphWindowOperation(g_appid, (ushort)CLoggerConst.LOGGER_PARAM_GRAPH_CLOSE, (ushort)CLoggerConst.LOGGER_PARAM_FILE, 0);
            if (ret != 0)
            {
                //----------------------------------------
                // Get the error string
                //----------------------------------------
                logger.GetErrorString(ret, out error_string);
                //----------------------------------------
                // Display the error code and the message
                //----------------------------------------
                textBox_returnnum.Text = string.Format("LoggerGraphWindowOperation = {0} : {1} ", ret, error_string);
                return;
            }
            //----------------------------------------
            // Specify the buffer mode (basic mode)
            //----------------------------------------
            ret = logger.SetAcquiredMode(g_appid, (ushort)CLoggerConst.LOGGER_PARAM_MODE_BASIC);
            if (ret != 0)
            {
                //----------------------------------------
                // Get the error string
                //----------------------------------------
                logger.GetErrorString(ret, out error_string);
                //----------------------------------------
                // Display the error code and the message
                //----------------------------------------
                textBox_returnnum.Text = string.Format("LoggerSetAcquiredMode = {0} : {1} ", ret, error_string);
                return;
            }
            //----------------------------------------
            // Get the fixed pointer of the delegate for event notification
            //----------------------------------------
            pfunc = Marshal.GetFunctionPointerForDelegate(pdelegate_func);
            //----------------------------------------
            // Set the event
            //----------------------------------------
            Event =     (uint)CLoggerConst.LOGGER_PARAM_EVENT_DATANUM |
                        (uint)CLoggerConst.LOGGER_PARAM_EVENT_RPTEND |
                        (uint)CLoggerConst.LOGGER_PARAM_EVENT_END |
                        (uint)CLoggerConst.LOGGER_PARAM_EVENT_OFERR |
                        (uint)CLoggerConst.LOGGER_PARAM_EVENT_SCERR;
            ret = logger.SetNotifyEvent(g_appid, pfunc, Event, null);
            if (ret != 0)
            {
                //----------------------------------------
                // Get the error string
                //----------------------------------------
                logger.GetErrorString(ret, out error_string);
                //----------------------------------------
                // Display the error code and the message
                //----------------------------------------
                textBox_returnnum.Text = string.Format("LoggerSetNotifyEvent = {0} : {1} ", ret, error_string);
                return;
            }
            //----------------------------------------
            // Start the application input and output
            //----------------------------------------
            ret = logger.StartOperation(g_appid, out status);
            if(ret != 0)
            {
                //----------------------------------------
                // Get the error string
                //----------------------------------------
                logger.GetErrorString(ret, out error_string);
                //----------------------------------------
                // Display the error code and the message
                //----------------------------------------
                textBox_returnnum.Text = string.Format("LoggerStartOperation = {0} : {1} \r\nstatus = {2}", ret, error_string, status);
                return;
            }
            //----------------------------------------
            // Start the timer
            //----------------------------------------
            timer_SamplingCount.Enabled = true;
            return;
        }

        //================================================================================
        // It is the process when the LoggerGetApplicationStatus button is clicked
        // Get the device status
        //================================================================================
        private void button_LoggerGetApplicationStatus_Click(object sender, EventArgs e)
        {
            string  error_string;       // Error code string
            int     ret;                // For return code
            uint    status;             // Status
            string  status_string;      // Status string

            //----------------------------------------
            // Get the device status
            //----------------------------------------
            ret = logger.GetApplicationStatus(g_appid, out status);
            //----------------------------------------
            // Get the error string
            //----------------------------------------
            logger.GetErrorString(ret, out error_string);
            //----------------------------------------
            // Display the error code and the message
            //----------------------------------------
            textBox_returnnum.Text = string.Format("LoggerGetApplicationStatus = {0} : {1} ", ret, error_string);
            //----------------------------------------
            // If the status acquisition function is completed successfully
            //----------------------------------------
            if (ret == 0)
            {
                //--------------------
                // Get the status string
                //--------------------
                switch (status)
                {
                    case (uint)CLoggerConst.LOGGER_STATUS_STOP:
                        status_string = "Stop";
                        break;
                    case (uint)CLoggerConst.LOGGER_STATUS_START_TRG:
                        status_string = "Wait the start trigger";
                        break;
                    case (uint)CLoggerConst.LOGGER_STATUS_BUSY:
                        status_string = "Operating";
                        break;
                    default:
                        status_string = "Unknown status";
                        break;
                }
                //--------------------
                // Display the status
                //--------------------
                textBox_Status.Text = String.Format("{0} ({1})", status, status_string);
            }
            return;
        }

        //================================================================================
        // It is the process when the Logging Stop button is clicked
        // Stop the application input and output
        //================================================================================
        unsafe private void button_StopOperation_Click(object sender, EventArgs e)
        {
            int    ret;                     // For return code
            string error_string;            // Error code string
            uint   total_sampling_count;    // Total sampling count

            //----------------------------------------
            // Stop the timer
            //----------------------------------------
            timer_SamplingCount.Enabled = false;
            //----------------------------------------
            // Stop the application input and output
            //----------------------------------------
            ret = logger.StopOperation(g_appid);
            if (ret != 0)
            {
                //----------------------------------------
                // Get the error string
                //----------------------------------------
                logger.GetErrorString(ret, out error_string);
                //----------------------------------------
                // Display the error code and the message
                //----------------------------------------
                textBox_returnnum.Text = string.Format("LoggerStopOperation = {0} : {1} ", ret, error_string);
                return;
            }
            //----------------------------------------
            // Get the total sampling count
            //----------------------------------------
            total_sampling_count = 0;
            ret = logger.GetTotalSamplingCount(g_appid, out total_sampling_count);
            if (ret != 0)
            {
                //----------------------------------------
                // Get the error string
                //----------------------------------------
                logger.GetErrorString(ret, out error_string);
                //----------------------------------------
                // Display the error code and the message
                //----------------------------------------
                textBox_returnnum.Text = string.Format("LoggerGetTotalSamplingCount = {0} : {1} ", ret, error_string);
            }
            //----------------------------------------
            // Display the total sampling count
            //----------------------------------------
            textBox_SamplingCount.Text = string.Format("{0}", total_sampling_count);
            return;
        }

        //================================================================================
        // It is the process when the ... button is clicked (Data file)
        // Display the file selection dialog
        //================================================================================
        private void button_AutoSaveFile_Click(object sender, EventArgs e)
        {
            //----------------------------------------
            // If the path exists, set the current path to the initial path of dialog
            //----------------------------------------
            if (textBox_AutoSaveFile.Text.Length > 0)
            {
                folderBrowserDialog1.SelectedPath = textBox_AutoSaveFile.Text;
            }
            //----------------------------------------
            // If the path does not exist, set the MyDocuments path to the initial path of dialog
            //----------------------------------------
            else
            {
                folderBrowserDialog1.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            }
            //----------------------------------------
            // Display the selected path
            //----------------------------------------
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox_AutoSaveFile.Text = folderBrowserDialog1.SelectedPath;
            }
            return;
        }

        //================================================================================
        // It is the process when the ... button is clicked (Logging condition file)
        // Display the file selection dialog
        //================================================================================
        private void button_SettingFile_Click(object sender, EventArgs e)
        {
            //----------------------------------------
            // Don't check if file name exists
            //----------------------------------------
            openFileDialog1.CheckFileExists = false;
            //----------------------------------------
            // If the path exists, set the current path to the initial path of dialog
            //----------------------------------------
            if (textBox_SettingFile.Text.Length > 0)
            {
                openFileDialog1.InitialDirectory = textBox_SettingFile.Text;
                openFileDialog1.FileName = openFileDialog1.SafeFileName;
            }
            //----------------------------------------
            // If the path does not exist, set the MyDocuments path to the initial path of dialog
            //----------------------------------------
            else
            {
                openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                openFileDialog1.FileName = "";
            }
            //----------------------------------------
            // Display the selected path
            //----------------------------------------
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox_SettingFile.Text = System.IO.Path.GetFullPath(openFileDialog1.FileName);
            }
            return;
        }

        //================================================================================
        // It is the process when the C-LOGGER Exit button is clicked
        // Stop the application and disable access
        //================================================================================
        private void button_LoggerCloseApplication_Click(object sender, EventArgs e)
        {
            uint    status = 0;     // Status
            int     ret;            // For return code
            string  error_string;   // Error code string
            string  status_string;  // Status string

            //----------------------------------------
            // Close the file(Considering that C-LOGGER may have exited, do not check the result)
            //----------------------------------------
            ret = logger.GraphWindowOperation(g_appid, (ushort)CLoggerConst.LOGGER_PARAM_GRAPH_CLOSE, (ushort)CLoggerConst.LOGGER_PARAM_FILE, 0);
            //----------------------------------------
            // Stop the application and disable access
            //----------------------------------------
            ret = logger.CloseApplication(g_appid, out status);
            //----------------------------------------
            // Get the error string
            //----------------------------------------
            logger.GetErrorString(ret, out error_string);
            if (ret != 0)
            {
                //----------------------------------------
                // Display the error code and the message
                //----------------------------------------
                textBox_returnnum.Text = string.Format("LoggerCloseApplication = {0} : {1} ", ret, error_string);
                return;
            }
            //----------------------------------------
            // Get the status string
            //----------------------------------------
            switch (status)
            {
                case (uint)CLoggerConst.LOGGER_STATUS_SUCCESS:
                    status_string = "Successful completion";
                    break;
                case (uint)CLoggerConst.LOGGER_STATUS_FAILURE:
                    status_string = "C-LOGGER exit error";
                    break;
                default:
                    status_string = "Unknown status";
                    break;
            }
            //----------------------------------------
            // Display the error code and the message
            //----------------------------------------
            textBox_returnnum.Text = string.Format("LoggerCloseApplication = {0} : {1} \r\nstatus = {2} : {3}", ret, error_string, status, status_string);
            return;
        }

        //================================================================================
        // Callback routine
        //================================================================================
        unsafe public int CallBackProc(short Id, uint Event, int wParam, int lParam, void* Param)
        {
            int    ret;                    // For return code
            uint   total_sampling_count;   // Total sampling count
            string error_string;           // Error code string
            
            switch (Event)
            {
                case (int)CLoggerConst.LOGGER_PARAM_EVENT_START:
                    textBox_returnnum.Text = "Event that start";
                    break;
                case (int)CLoggerConst.LOGGER_PARAM_EVENT_RPTEND:
                    textBox_returnnum.Text = "Event that repeat end";
                    break;
                case (int)CLoggerConst.LOGGER_PARAM_EVENT_END:
                case (int)CLoggerConst.LOGGER_PARAM_EVENT_OFERR:
                case (int)CLoggerConst.LOGGER_PARAM_EVENT_SCERR:
                    if (Event == (int)CLoggerConst.LOGGER_PARAM_EVENT_END)
                    {
                        textBox_returnnum.Text = "Event that device operation end";
                    }
                    else if (Event == (int)CLoggerConst.LOGGER_PARAM_EVENT_OFERR)
                    {
                        textBox_returnnum.Text = "Event that overflow";
                    }
                    else if (Event == (int)CLoggerConst.LOGGER_PARAM_EVENT_SCERR)
                    {
                        textBox_returnnum.Text = "Event that sampling clock period error";
                    }
                    //----------------------------------------
                    // Stop timer
                    //----------------------------------------
                    timer_SamplingCount.Enabled = false;
                    //----------------------------------------
                    // Get the total sampling count
                    //----------------------------------------
                    total_sampling_count = 0;
                    ret = logger.GetTotalSamplingCount(g_appid, out total_sampling_count);
                    if (ret != 0)
                    {
                        //----------------------------------------
                        // Get the error string
                        //----------------------------------------
                        logger.GetErrorString(ret, out error_string);
                        //----------------------------------------
                        // Display the error code and the message
                        //----------------------------------------
                        textBox_returnnum.Text = string.Format("LoggerGetTotalSamplingCount = {0} : {1} ", ret, error_string);
                    }
                    //----------------------------------------
                    // Display the total sampling count
                    //----------------------------------------
                    textBox_SamplingCount.Text = string.Format("{0}", total_sampling_count);
                    break;
                case (int)CLoggerConst.LOGGER_PARAM_EVENT_DATANUM:
                    textBox_returnnum.Text = "Event that the specified number of data are stored";
                    break;
                default:
                    textBox_returnnum.Text = "Unknown event";
                    break;
            }
            return 0;
        }

        //================================================================================
        // It is the process when the Close button is clicked
        // 
        //================================================================================
        private void button_Close_Click(object sender, EventArgs e)
        {
            uint status = 0;      // For status storage

            //----------------------------------------
            // Close the file(Considering that C-LOGGER may have exited, do not check the result)
            //----------------------------------------
            logger.GraphWindowOperation(g_appid, (ushort)CLoggerConst.LOGGER_PARAM_GRAPH_CLOSE, (ushort)CLoggerConst.LOGGER_PARAM_FILE, 0);
            //----------------------------------------
            // Stop the application and disable access
            //----------------------------------------
            logger.CloseApplication(g_appid, out status);
            //----------------------------------------
            // Close the dialog
            //----------------------------------------
            this.Close();
            return;
        }

        //================================================================================
        // Timer event
        // 
        //================================================================================
        private void timer_SamplingCount_Tick(object sender, EventArgs e)
        {
            int    ret;                    // For return code
            uint   total_sampling_count;   // Total sampling count
            string error_string;           // Error code string

            //----------------------------------------
            // Get the total sampling count
            //----------------------------------------
            total_sampling_count = 0;
            ret = logger.GetTotalSamplingCount(g_appid, out total_sampling_count);
            if (ret != 0)
            {
                //----------------------------------------
                // Get the error string
                //----------------------------------------
                logger.GetErrorString(ret, out error_string);
                //----------------------------------------
                // Display the error code and the message
                //----------------------------------------
                textBox_returnnum.Text = string.Format("LoggerGetTotalSamplingCount = {0} : {1} ", ret, error_string);
                return;
            }
            //----------------------------------------
            // Display the total sampling count
            //----------------------------------------
            textBox_SamplingCount.Text = string.Format("{0}", total_sampling_count);
            return;
        }
    }
}
