﻿using System.Runtime.InteropServices;
// Counter header
using CcntCs;

namespace CounterCallback
{
    public partial class Form1 : Form
    {
        public static short                     Id;                                  // Device ID
        public static short                     ChannelNum;                          // Total number of channels
        uint[]                                  CountMatch = new uint[CHANNEL_NUM];  // Count match times
        public const int                        CHANNEL_NUM = 4;
        const int                               WM_NOTIFY_COUNTUP = 0x0500;
        const int                               WM_NOTIFY_ERROR = 0x0501;
        const int                               WM_NOTIFY_CARRY = 0x0502;
        private System.Windows.Forms.TextBox[]  txt_Count = new System.Windows.Forms.TextBox[CHANNEL_NUM];    // Count value control
        private System.Windows.Forms.TextBox[]  txt_Status = new System.Windows.Forms.TextBox[CHANNEL_NUM];   // Count status control

        // Declare callback routine
        public GCHandle hGC_CountUp;
        public GCHandle hGC_CounterError;
        public GCHandle hGC_CarryBorrow;
        public GCHandle hGC_Timer;
        public PCOUNTUPCALLBACK dele_CountUp;
        public PCOUNTERERRORCALLBACK dele_CounterError;
        public PCARRYBORROWCALLBACK dele_CarryBorrow;
        //---------------------------------------------
        // When using the timer notification event of device,
        // please use the following declaration
        //---------------------------------------------
        //public PTIMERCALLBACK          dele_Timer;
        public IntPtr pCountUp;
        public IntPtr pCounterError;
        public IntPtr pCarryBorrow;
        public IntPtr pTimer;

        Ccnt cnt = new Ccnt();

        unsafe public Form1()
        {
            InitializeComponent();
            //-----------------------------------
            // Control array settings
            //-----------------------------------
            //------------------
            // Count value control
            //------------------
            txt_Count[0] = txtCountValue0;
            txt_Count[1] = txtCountValue1;
            txt_Count[2] = txtCountValue2;
            txt_Count[3] = txtCountValue3;
            //------------------
            // Count status control
            //------------------
            txt_Status[0] = txtCountStatus0;
            txt_Status[1] = txtCountStatus1;
            txt_Status[2] = txtCountStatus2;
            txt_Status[3] = txtCountStatus3;
            //-----------------------------------
            // Initialize the delegate for event notification
            //-----------------------------------
            dele_CountUp = new PCOUNTUPCALLBACK(SetCountUpCallBackProc);
            dele_CounterError = new PCOUNTERERRORCALLBACK(CounterErrorCallBackProc);
            dele_CarryBorrow = new PCARRYBORROWCALLBACK(CarryBorrowCallBackProc);
            //---------------------------------------------
            // When using the timer notification event of device,
            // please use the following settings
            //---------------------------------------------
            //---------------------------------------------
            // Initialize the delegate for timer event notification
            //---------------------------------------------
            //dele_Timer = new PTIMERCALLBACK(TimerCallBackProc);
        }

        //===================================================
        // Dialog initialization
        //===================================================
        private void CounterCallback_Load(object sender, System.EventArgs e)
        {
            short   ch;

            //-----------------------------------
            // Initialize dialog display
            //-----------------------------------
            txtDeviceName.Text = "CNT000";
            //-----------------------------------
            // For each channel
            //-----------------------------------
            for(ch = 0; ch < CHANNEL_NUM; ch++){
                //------------------
                // Count value control
                //------------------
                txt_Count[ch].Text = "";
                //------------------
                // Count status control
                //------------------
                txt_Status[ch].Text = "";
            }
            //-----------------------------------
            // Do not release the delegate
            //-----------------------------------
            if (hGC_CountUp.IsAllocated == false)
            {
                hGC_CountUp = GCHandle.Alloc(dele_CountUp);
            }
            if (hGC_CounterError.IsAllocated == false)
            {
                hGC_CounterError = GCHandle.Alloc(dele_CounterError);
            }
            if (hGC_CarryBorrow.IsAllocated == false)
            {
                hGC_CarryBorrow = GCHandle.Alloc(dele_CarryBorrow);
            }
            /*
            //---------------------------------------------
            // When using the timer notification event of device,
            // please use the following settings
            //---------------------------------------------
            //---------------------------------------------
            // Set the delegate not to release
            //---------------------------------------------
            if(hGC_Timer.IsAllocated == false)
            {
                hGC_Timer = GCHandle.Alloc(dele_Timer);
            }
            */
        }

        //---------------------------------------------
        // CntInit()
        //---------------------------------------------
        private void btnCntInit_Click(object sender, System.EventArgs e)
        {
            string str;
            string buf = new string(' ', 100);
            string error_string = new string(' ', 256);
            int ret;
            short  i;

            //-----------------------------------
            // Get device name
            //-----------------------------------
            buf = txtDeviceName.Text;

            //------------------------------
            // Initialization
            //------------------------------
            ret = cnt.Init(buf, out Id);
            cnt.GetErrorString(ret, out error_string);
            str = string.Format("CntInit ret = {0:d}: {1}", ret, error_string);
            txtRet.Text = str;
            
            if(ret != 0){
                return;
            }
            //-----------------------------
            // Get number of channels
            //-----------------------------
            cnt.GetMaxChannels(Id, out ChannelNum);
            //-----------------------------
            // If the sample control count is exceeded, 
            // the total channel count is corrected to the control count.
            //-----------------------------
            if(ChannelNum > CHANNEL_NUM){
                ChannelNum = CHANNEL_NUM;
            }
            //-----------------------------
            // Toggles the count value and status display according to the total number of channels.
            //-----------------------------
            for(i = 0; i < CHANNEL_NUM; i++){
                //-----------------------------
                // Disables the display when the number of loops exceeds the total number of channels.
                //-----------------------------
                if(i >= ChannelNum){
                    txt_Count[i].Enabled = false;
                    txt_Status[i].Enabled = false;
                //-----------------------------
                // Enables the display when the number of loops is less than or equal to the total number of channels.
                //-----------------------------
                }else{
                    txt_Count[i].Enabled = true;
                    txt_Status[i].Enabled = true;
                }
            }
        }

        //---------------------------------------------
        // Display "Counter Mode Setting" dialog
        //---------------------------------------------
        private void btnCntMode_Click(object sender, System.EventArgs e)
        {
            //------------------------------
            // Display "Counter Mode Setting" dialog
            //------------------------------
            ModeDlg dlg = new ModeDlg();
            dlg.ShowDialog();
            dlg.Dispose();
        }

        //---------------------------------------------
        // Display "Notification Setting" dialog
        //---------------------------------------------
        private void btnCntNotify_Click(object sender, System.EventArgs e)
        {
            //------------------------------
            // Display "Notification Setting" dialog
            //------------------------------
            NotifyDlg dlg = new NotifyDlg();
            dlg.ShowDialog();
            dlg.Dispose();
        }

        //---------------------------------------------
        // Display "Event Setting" dialog
        //---------------------------------------------
        private void btnCntEvent_Click(object sender, System.EventArgs e)
        {
            //------------------------------
            // Display "Event Setting" dialog
            //------------------------------
            EventDlg dlg = new EventDlg();
            dlg.ShowDialog();
            dlg.Dispose();
        }

        //---------------------------------------------
        // Start count
        //---------------------------------------------
        unsafe private void btnCntStart_Click(object sender, System.EventArgs e)
        {
            string str;
            string error_string = new string(' ', 256);
            int ret;
            short[] ChNo = new short[CHANNEL_NUM];
            short i;

            //-----------------------------
            // Callback rountine
            //-----------------------------
            // Count match
            pCountUp = Marshal.GetFunctionPointerForDelegate(dele_CountUp);
            ret = cnt.CountUpCallbackProc(Id, pCountUp, null);
            /*
            //-----------------------------
            // The error check is commented out for devices that do not have the event notification function
            // If you need the error check, uncomment it
            //-----------------------------
            if (ret != 0)
            {
                cnt.GetErrorString(ret, out error_string);
                str = string.Format("CntSetCountUpCallbackProc ret = {0:d}: {1}", ret, error_string);
                txtRet.Text = str;
                return;
            }
            */
            // Counter error
            pCounterError = Marshal.GetFunctionPointerForDelegate(dele_CounterError);
            ret = cnt.CounterErrorCallbackProc(Id, pCounterError, null);
            /*
            //-----------------------------
            // The error check is commented out for devices that do not have the event notification function
            // If you need the error check, uncomment it
            //-----------------------------
            if (ret != 0)
            {
                cnt.GetErrorString(ret, out error_string);
                str = string.Format("CntSetCounterErrorCallbackProc ret = {0:d}: {1}", ret, error_string);
                txtRet.Text = str;
                return;
            }
            */
            // Carry/Borrow
            pCarryBorrow = Marshal.GetFunctionPointerForDelegate(dele_CarryBorrow);
            ret = cnt.CarryBorrowCallbackProc(Id, pCarryBorrow, null);
            /*
            //-----------------------------
            // The error check is commented out for devices that do not have the event notification function
            // If you need the error check, uncomment it
            //-----------------------------
            if (ret != 0)
            {
                cnt.GetErrorString(ret, out error_string);
                str = string.Format("CntCarryBorrowCallbackProc ret = {0:d}: {1}", ret, error_string);
                txtRet.Text = str;
                return;
            }
            */
            /*
            //---------------------------------------------------------
            // When using the timer notification event of device,
            // please use the following function.
            //---------------------------------------------------------
            // Timer
            pTimer = Marshal.GetFunctionPointerForDelegate(dele_Timer);
            // Timer notification
            ret = cnt.TimerCallbackProc(Id, pTimer, null);
            if(ret != 0)
            {
                cnt.GetErrorString(ret, out error_string);
                str = string.Format("CntTimerCallbackProc ret = {0:d}: {1}", ret, error_string);
                txtRet.Text = str;
                return;
            }
            */

            //------------------------------
            // Set parameter
            //------------------------------
            for (i = 0; i < ChannelNum; i++)
            {
                ChNo[i] = i;
            }

            //------------------------------
            // Start count
            //------------------------------
            ret = cnt.StartCount(Id, ChNo, ChannelNum);
            cnt.GetErrorString(ret, out error_string);
            str = string.Format("CntStartCount ret = {0:d}: {1}", ret, error_string);
            txtRet.Text = str;
            if (ret == 0)
            {
                //------------------------------
                // Consider a device that does not have a timer notification function,
                // we use the window timer.
                // Please switch and use, according to the use.
                //------------------------------
                //------------------------------
                // Start timer
                //------------------------------
                timer1.Start();
                //------------------------------
                // When using the timer notification event of device,
                // please use the following function.
                //------------------------------
                //cnt.NotifyTimer(Id, 100, this.Handle);
            }
        }

        //---------------------------------------------
        // Preset counter
        //---------------------------------------------
        private void btnCntPreset_Click(object sender, System.EventArgs e)
        {
            string str;
            string error_string = new string(' ', 256);
            int ret;
            short[] ChNo = new short[CHANNEL_NUM];
            uint[] PresetData = new uint[CHANNEL_NUM];
            short i;

            //------------------------------
            // Set preset value
            //------------------------------
            for (i = 0; i < ChannelNum; i++)
            {
                ChNo[i] = i;
                PresetData[i] = (uint)i * 0x100;
            }

            //------------------------------
            // Preset setting processing
            //------------------------------
            ret = cnt.Preset(Id, ChNo, ChannelNum, PresetData);
            cnt.GetErrorString(ret, out error_string);
            str = string.Format("CntPreset ret = {0:d}: {1}", ret, error_string);
            txtRet.Text = str;
        }

        //---------------------------------------------
        // Reset counter
        //---------------------------------------------
        private void btnCntReset_Click(object sender, System.EventArgs e)
        {
            string str;
            string error_string = new string(' ', 256);
            int ret;
            short[] ChNo = new short[CHANNEL_NUM];
            short i;

            //------------------------------
            // Set parameter
            //------------------------------
            for (i = 0; i < ChannelNum; i++)
            {
                ChNo[i] = i;
            }

            //------------------------------
            // Reset counter
            //------------------------------
            ret = cnt.ZeroClearCount(Id, ChNo, ChannelNum);
            cnt.GetErrorString(ret, out error_string);
            str = string.Format("CntZeroClearCount ret = {0:d}: {1}", ret, error_string);
            txtRet.Text = str;
        }

        //---------------------------------------------
        // Stop count
        //---------------------------------------------
        private void btnCntStop_Click(object sender, System.EventArgs e)
        {
            string str;
            string error_string = new string(' ', 256);
            int ret;
            short[] ChNo = new short[CHANNEL_NUM];
            short i;

            //------------------------------
            // Set parameter
            //------------------------------
            for (i = 0; i < ChannelNum; i++)
            {
                ChNo[i] = i;
            }

            //------------------------------
            // Stop count
            //------------------------------
            ret = cnt.StopCount(Id, ChNo, ChannelNum);
            cnt.GetErrorString(ret, out error_string);
            str = string.Format("CntStopCount ret = {0:d}: {1}", ret, error_string);
            txtRet.Text = str;

            //------------------------------
            // Consider a device that does not have a timer notification function,
            // we use the window timer.
            // Please switch and use, according to the use.
            //------------------------------
            //------------------------------
            // Stop timer
            //------------------------------
            timer1.Stop();
            //------------------------------
            // When using the timer notification event of device,
            // please use the following function.
            //------------------------------
            //cnt.StopNotifyTimer(Id);
        }

        //---------------------------------------------
        // CntExit()
        //---------------------------------------------
        private void btnCntExit_Click(object sender, System.EventArgs e)
        {
            string str;
            string error_string = new string(' ', 256);
            int ret;

            //------------------------------
            // Consider a device that does not have a timer notification function,
            // we use the window timer.
            // Please switch and use, according to the use.
            //------------------------------
            //------------------------------
            // Stop timer
            //------------------------------
            timer1.Stop();
            //------------------------------
            // When using the timer notification event of device,
            // please use the following function.
            //------------------------------
            //cnt.StopNotifyTimer(Id);

            //------------------------------
            // Counter termination processing
            //------------------------------
            ret = cnt.Exit(Id);
            cnt.GetErrorString(ret, out error_string);
            str = string.Format("CntExit ret = {0:d}: {1}", ret, error_string);
            txtRet.Text = str;
        }

        //---------------------------------------------
        // Exit sample program
        //---------------------------------------------
        private void btnExit_Click(object sender, System.EventArgs e)
        {
            int ret;

            //------------------------------
            // Consider a device that does not have a timer notification function,
            // we use the window timer.
            // Please switch and use, according to the use.
            //------------------------------
            //------------------------------
            // Stop timer
            //------------------------------
            timer1.Stop();
            //------------------------------
            // When using the timer notification event of device,
            // please use the following function.
            //------------------------------
            //cnt.StopNotifyTimer(Id);

            //------------------------------
            // Counter termination processing
            //------------------------------
            ret = cnt.Exit(Id);
            //-----------------------------
            // Release the garbage collection handle of the delegate for event notification
            //-----------------------------
            if (hGC_CountUp.IsAllocated == true)
            {
                hGC_CountUp.Free();
            }
            if (hGC_CounterError.IsAllocated == true)
            {
                hGC_CounterError.Free();
            }
            if (hGC_CarryBorrow.IsAllocated == true)
            {
                hGC_CarryBorrow.Free();
            }
            if (hGC_Timer.IsAllocated == true)
            {
                hGC_Timer.Free();
            }
            this.Close();
        }

        delegate void SetTextDelegate(string str);
        delegate void SetCountDataDelegate(uint[] CntData, uint[] StatusData);

        //---------------------------------------------------------
        // Set NotifyLabel(Synchronous function for control operation)
        //---------------------------------------------------------
        void SetNotifyText(string str)
        {
            lblNotify.Text = str;
        }
        //---------------------------------------------------------
        // Set RetTextBox(Synchronous function for control operation)
        //---------------------------------------------------------
        void SetRetText(string str)
        {
            txtRet.Text = str;
        }
        //---------------------------------------------------------
        // Set count data(Synchronous function for control operation)
        //---------------------------------------------------------
        void SetCountDataText(uint[] CntData, uint[] StatusData)
        {
            string str;
            short  i;

            //------------------------------
            // Display data
            //------------------------------
            for (i = 0; i < ChannelNum; i++)
            {
                str = string.Format("{0:D8}", CntData[i]);
                txt_Count[i].Text = str;
                str = string.Format("{0:X8}H", StatusData[i]);
                txt_Status[i].Text = str;
            }
        }
        //---------------------------------------------------------
        // Callback routine
        //---------------------------------------------------------
        unsafe public void SetCountUpCallBackProc(short Id, int wParam, int lParam, void* Param)
        {
            string str;
            int MatchCh;
            MatchCh = (int)(wParam & 0x0000ffff);
            switch (MatchCh)
            {
                case 0: // Count match: 0CH
                    CountMatch[0]++;
                    if (((wParam & 0x0ffff0000) >> 16) == 1)
                    {
                        str = string.Format("Event:\nCount Match!\nChannel No.: 0, UP, Count: {0:X8}(Hex)\n Matched: {1:d} times", lParam, CountMatch[0]);
                    }
                    else
                    {
                        str = string.Format("Event:\nCount Match!\nChannel No.: 0, DOWN, Count: {0:X8}(Hex)\n Matched: {1:d} times", lParam, CountMatch[0]);
                    }
                    this.Invoke(new SetTextDelegate(SetNotifyText), new Object[] { str });
                    break;
                case 1: // Count match: 1CH
                    CountMatch[1]++;
                    if (((wParam & 0x0ffff0000) >> 16) == 1)
                    {
                        str = string.Format("Event:\nCount Match!\nChannel No.: 1, UP, Count: {0:X8}(Hex)\n Matched: {1:d} times", lParam, CountMatch[1]);
                    }
                    else
                    {
                        str = string.Format("Event:\nCount Match!\nChannel No.: 1, DOWN, Count: {0:X8}(Hex)\n Matched: {1:d} times", lParam, CountMatch[1]);
                    }
                    this.Invoke(new SetTextDelegate(SetNotifyText), new Object[] { str });
                    break;
                case 2: // Count match: 2CH
                    CountMatch[2]++;
                    if (((wParam & 0x0ffff0000) >> 16) == 1)
                    {
                        str = string.Format("Event:\nCount Match!\nChannel No.: 2, UP, Count: {0:X8}(Hex)\n Matched: {1:d} times", lParam, CountMatch[2]);
                    }
                    else
                    {
                        str = string.Format("Event:\nCount Match!\nChannel No.: 2, DOWN, Count: {0:X8}(Hex)\n Matched: {1:d} times", lParam, CountMatch[2]);
                    }
                    this.Invoke(new SetTextDelegate(SetNotifyText), new Object[] { str });
                    break;
                case 3: // Count match: 3CH
                    CountMatch[3]++;
                    if (((wParam & 0x0ffff0000) >> 16) == 1)
                    {
                        str = string.Format("Event:\nCount Match!\nChannel No.: 3, UP, Count: {0:X8}(Hex)\n Matched: {1:d} times", lParam, CountMatch[3]);
                    }
                    else
                    {
                        str = string.Format("Event:\nCount Match!\nChannel No.: 3, DOWN, Count: {0:X8}(Hex)\n Matched: {1:d} times", lParam, CountMatch[3]);
                    }
                    this.Invoke(new SetTextDelegate(SetNotifyText), new Object[] { str });
                    break;
            }

            return;
        }

        unsafe public void CounterErrorCallBackProc(short Id, int wParam, int lParam, void* Param)
        {
            string str;
            int ErrType;
            int ErrCh;

            ErrType = (int)(lParam & 0x0000ffff);
            ErrCh = (int)(wParam & 0x0000ffff);
            switch (ErrType)
            {
                case (int)CcntConst.CNT_AI_ERROR:       // Abnormal input
                    str = string.Format("Event:\nAbnormal input error!\nChannel No.: {0:d}", ErrCh);
                    this.Invoke(new SetTextDelegate(SetNotifyText), new Object[] { str });
                    break;
                case (int)CcntConst.CNT_FLT_ERROR:      // Filter
                    str = string.Format("Event:\nFilter error!\nChannel No.: {0:d}", ErrCh);
                    this.Invoke(new SetTextDelegate(SetNotifyText), new Object[] { str });
                    break;
                case (int)CcntConst.CNT_ALM_ERROR:      // Alarm
                    str = string.Format("Event:\nAlarm error!\nChannel No.: {0:d}", ErrCh);
                    this.Invoke(new SetTextDelegate(SetNotifyText), new Object[] { str });
                    break;
            }

            return;
        }

        unsafe public void CarryBorrowCallBackProc(short Id, int wParam, int lParam, void* Param)
        {
            string str;
            int NotifyFac;
            int CarryCh;
            NotifyFac = (int)(lParam & 0x0000ffff);
            CarryCh = (int)(wParam & 0x0000ffff);
            switch (NotifyFac)
            {
                case (int)CcntConst.CNT_CB_CARRY:       // Carry
                    str = string.Format("Event:\nCarry!\nChannel No.: {0:d}", CarryCh);
                    this.Invoke(new SetTextDelegate(SetNotifyText), new Object[] { str });
                    break;
                case (int)CcntConst.CNT_CB_BORROW:      // Borrow
                    str = string.Format("Event:\nBorrow!\nChannel No.: {0:d}", CarryCh);
                    this.Invoke(new SetTextDelegate(SetNotifyText), new Object[] { str });
                    break;
            }

            return;
        }

        //---------------------------------------------------------
        // Consider a device that does not have a timer notification function,
        // we use the window timer.
        // Please switch and use, according to the use.
        //---------------------------------------------------------
        //---------------------------------------------------------
        // Method for window timer
        //---------------------------------------------------------
        private void timer1_Tick(object sender, EventArgs e)
        {
            short[] ChNo = new short[CHANNEL_NUM];
            uint[] CntData = new uint[CHANNEL_NUM];
            uint[] StatusData = new uint[CHANNEL_NUM];
            short i;
            int ret;
            string str;
            string error_string = new string(' ', 256);

            //------------------------------
            // Set parameter
            //------------------------------
            for (i = 0; i < ChannelNum; i++)
            {
                ChNo[i] = i;
                CntData[i] = 0;
                StatusData[i] = 0;
            }
            //------------------------------
            // Get count value
            //------------------------------
            ret = cnt.ReadCount(Id, ChNo, ChannelNum, CntData);
            if (ret != 0)
            {
                cnt.GetErrorString(ret, out error_string);
                str = string.Format("CntReadCount ret = {0:d}: {1}", ret, error_string);
                txtRet.Text = str;
                timer1.Stop();
            }
            //------------------------------
            // Get count status
            //------------------------------
            for (i = 0; i < ChannelNum; i++)
            {
                ret = cnt.ReadStatusEx(Id, i, out StatusData[i]);
                if (ret != 0)
                {
                    cnt.GetErrorString(ret, out error_string);
                    str = string.Format("CntReadStatus ret = {0:d}: {1}", ret, error_string);
                    txtRet.Text = str;
                    timer1.Stop();
                }
            }
            //------------------------------
            // Display data
            //------------------------------
            for (i = 0; i < ChannelNum; i++)
            {
                str = string.Format("{0:D8}", CntData[i]);
                txt_Count[i].Text = str;
                str = string.Format("{0:X8}H", StatusData[i]);
                txt_Status[i].Text = str;
            }
        }

        /*
        //---------------------------------------------------------
        // When using the timer notification event of device,
        // please use the following callback routine.
        //---------------------------------------------------------
        //---------------------------------------------------------
        // Callback routine for timer notification
        //---------------------------------------------------------
        unsafe public void TimerCallBackProc(short Id, int wParam, int lParam, void *Param)
        {
            short[] ChNo = new short[CHANNEL_NUM];
            uint[]  CntData = new uint[CHANNEL_NUM];
            uint[]  StatusData = new uint[CHANNEL_NUM];
            short   i;
            int     ret;
            string  str;
            string  error_string = new string(' ', 256);
            
            //------------------------------
            // Set parameter
            //------------------------------
            for (i=0; i<ChannelNum; i++) 
            {
                ChNo[i] = i;
                CntData[i] = 0;
                StatusData[i] = 0;
            }
            //------------------------------
            // Get count value
            //------------------------------
            ret = cnt.ReadCount(Id, ChNo, ChannelNum, CntData);
            if (ret != 0) 
            {
                cnt.GetErrorString(ret, out error_string);
                str = string.Format("CntReadCnt ret = {0:d}: {1}", ret, error_string);
                this.Invoke(new SetTextDelegate(SetRetText), new Object[] {str});
                cnt.StopNotifyTimer(Id);
            }
            //------------------------------
            // Get count status
            //------------------------------
            for (i=0; i<ChannelNum; i++) 
            {
                ret = cnt.ReadStatusEx(Id, i, out StatusData[i]);
                if (ret != 0) 
                {
                    cnt.GetErrorString(ret, out error_string);
                    str = string.Format("CntReadStatus ret = {0:d}: {1}", ret, error_string);
                    this.Invoke(new SetTextDelegate(SetRetText), new Object[] {str});
                    cnt.StopNotifyTimer(Id);
                }
            }
            //------------------------------
            // Display data
            //------------------------------
            this.Invoke(new SetCountDataDelegate(SetCountDataText), new Object[] {CntData, StatusData});
            return;
        }
        */
    }
}