using CdigCs;

namespace Sync
{
    public partial class Form1 : Form
    {
        /// <summary>
        /// Creat the instance of class Cdig
        /// </summary>
        Cdig dig = new Cdig();
        public const int MAX_SAMPLES = 1000;            // The definition of the maximum number of acquiring samples  : 1000

        public short m_Id1;                             // Device1 ID
        public short m_Id2;                             // Device2 ID
        public float[] m_Data1 = new float[MAX_SAMPLES];// Array of retrieving data for Device1
        public float[] m_Data2 = new float[MAX_SAMPLES];// Array of retrieving data for Device2
        public int m_Samples1;                          // Number of retrieved samples for Device1
        public int m_Samples2;                          // Number of retrieved samples for Device2

        public Form1()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Init Dialog
        /// </summary>
        private void Form1_Load(object sender, System.EventArgs e)
        {
            // Initialize input range

            // Device1
            comboBoxRange1.ResetText();
            comboBoxRange1.Items.AddRange(new object[]
                {
                    "-20 - +20V",
                    "-10 - +10V",
                    "-5 - +5V",
                    "-2 - +2V",
                    "-1 - +1V",
                    "-0.5 - +0.5V",
                    "-0.2 - +0.2V",
                    "-0.1 - +0.1V",
                    "-0.05 - +0.05V",
                    "-0.02 - +0.02V"}
                );

            // Device2
            comboBoxRange2.ResetText();
            comboBoxRange2.Items.AddRange(new object[]
                {
                    "-20 - +20V",
                    "-10 - +10V",
                    "-5 - +5V",
                    "-2 - +2V",
                    "-1 - +1V",
                    "-0.5 - +0.5V",
                    "-0.2 - +0.2V",
                    "-0.1 - +0.1V",
                    "-0.05 - +0.05V",
                    "-0.02 - +0.02V"}
                );
        }

        /// <summary>
        /// Init handling
        /// </summary>
        private void buttonInit_Click(object sender, System.EventArgs e)
        {
            int Ret;
            string ErrorString;

            //-------------------------------------
            // Device1
            //-------------------------------------
            //--------------------------------
            // Init handling
            //--------------------------------
            Ret = dig.Init(textBoxDevice1.Text, out m_Id1);
            if (Ret != 0)
            {
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo1.Text = "dig.Init = " + Ret.ToString() + " : " + ErrorString;
                return;
            }

            //--------------------------------
            // Reset device
            //--------------------------------
            Ret = dig.ResetDevice(m_Id1);
            if (Ret != 0)
            {
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo1.Text = "dig.ResetDevice = " + Ret.ToString() + " : " + ErrorString;
                return;
            }

            textBoxInfo1.Text = "Init : Normality completion";

            //-------------------------------------
            // Device2
            //-------------------------------------
            //--------------------------------
            // Init handling
            //--------------------------------
            Ret = dig.Init(textBoxDevice2.Text, out m_Id2);
            if (Ret != 0)
            {
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo2.Text = "dig.Init = " + Ret.ToString() + " : " + ErrorString;
                return;
            }

            //--------------------------------
            // Reset device
            //--------------------------------
            Ret = dig.ResetDevice(m_Id2);
            if (Ret != 0)
            {
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo2.Text = "dig.ResetDevice = " + Ret.ToString() + " : " + ErrorString;
                return;
            }

            textBoxInfo2.Text = "Init : Normality completion";
        }

        /// <summary>
        /// Set input range for device1
        /// </summary>
        private void comboBoxRange1_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            int Index;      // The selected index value of input range combobox
            float Range;    // Input range
            Index = comboBoxRange1.SelectedIndex;
            switch (Index)
            {
                case 0: Range = Cdig.DIG_RANGE_40VPP; break;
                case 1: Range = Cdig.DIG_RANGE_20VPP; break;
                case 2: Range = Cdig.DIG_RANGE_10VPP; break;
                case 3: Range = Cdig.DIG_RANGE_4VPP; break;
                case 4: Range = Cdig.DIG_RANGE_2VPP; break;
                case 5: Range = Cdig.DIG_RANGE_1VPP; break;
                case 6: Range = Cdig.DIG_RANGE_400MVPP; break;
                case 7: Range = Cdig.DIG_RANGE_200MVPP; break;
                case 8: Range = Cdig.DIG_RANGE_100MVPP; break;
                case 9: Range = Cdig.DIG_RANGE_40MVPP; break;
                default: Range = 0; break;
            }

            //--------------------------
            // Set input range of channel0
            //--------------------------
            int Ret;
            Ret = dig.SetRange(m_Id1, Cdig.DIG_CHANNEL0, Range);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo1.Text = "dig.SetRange = " + Ret.ToString() + " : " + ErrorString;
                return;
            }

            textBoxInfo1.Text = "Set input range : Normality completion";
        }

        /// <summary>
        /// Set input range for device2
        /// </summary>
        private void comboBoxRange2_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            int Index;      // The selected index value of input range combobox
            float Range;    // Input range
            Index = comboBoxRange2.SelectedIndex;
            switch (Index)
            {
                case 0: Range = Cdig.DIG_RANGE_40VPP; break;
                case 1: Range = Cdig.DIG_RANGE_20VPP; break;
                case 2: Range = Cdig.DIG_RANGE_10VPP; break;
                case 3: Range = Cdig.DIG_RANGE_4VPP; break;
                case 4: Range = Cdig.DIG_RANGE_2VPP; break;
                case 5: Range = Cdig.DIG_RANGE_1VPP; break;
                case 6: Range = Cdig.DIG_RANGE_400MVPP; break;
                case 7: Range = Cdig.DIG_RANGE_200MVPP; break;
                case 8: Range = Cdig.DIG_RANGE_100MVPP; break;
                case 9: Range = Cdig.DIG_RANGE_40MVPP; break;
                default: Range = 0; break;
            }

            //--------------------------
            // Set input range of channel0
            //--------------------------
            int Ret;
            Ret = dig.SetRange(m_Id2, Cdig.DIG_CHANNEL0, Range);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo2.Text = "dig.SetRange = " + Ret.ToString() + " : " + ErrorString;
                return;
            }

            textBoxInfo2.Text = "Set input range : Normality completion";
        }

        /// <summary>
        /// Start acquisition
        /// </summary>
        private void buttonStart_Click(object sender, System.EventArgs e)
        {
            int Ret;        // Return value
            //---------------------------------
            // Initialize variable
            //---------------------------------
            m_Samples1 = 0;
            m_Samples2 = 0;
            listBoxData1.Items.Clear();
            listBoxData2.Items.Clear();

            //-------------------------------------------
            // Set deivce1
            //-------------------------------------------
            //---------------------------------
            // Set operation mode : Data logger mode
            //---------------------------------
            Ret = dig.SetDigitizerMode(m_Id1, Cdig.DIG_MODE_LOGGER);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo1.Text = "dig.SetDigitizerMode = " + Ret.ToString() + " : " + ErrorString;
                return;
            }
            //---------------------------------
            // Set Event Controller Unit : Synchronous bus signal line 1 - pre-trigger satisfaction
            //---------------------------------
            Ret = dig.SetEcuSignal(m_Id1, Cdig.DIG_ECU_DEST_SYNC1, Cdig.DIG_ECU_SRC_PRETRG);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo1.Text = "dig.SetEcuSignal = " + Ret.ToString() + " : " + ErrorString;
                return;
            }
            //---------------------------------
            // Set sampling clock source : Crystal oscillator of board
            //---------------------------------
            Ret = dig.SetClockSource(m_Id1, Cdig.DIG_ECU_SRC_CLOCK);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo1.Text = "dig.SetClockSource = " + Ret.ToString() + " : " + ErrorString;
                return;
            }
            //---------------------------------
            // Set sampling clock : 1000usec  (set value * 10 + 10 (nsec))
            //---------------------------------
            Ret = dig.SetSampleClock(m_Id1, 99999);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo1.Text = "dig.SetSampleClock = " + Ret.ToString() + " : " + ErrorString;
                return;
            }
            //---------------------------------
            // Set the number of acquiring records : 1
            //---------------------------------
            Ret = dig.SetRecordNumber(m_Id1, 1);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo1.Text = "dig.SetRecordNumber = " + Ret.ToString() + " : " + ErrorString;
                return;
            }
            //---------------------------------
            // Set the number of pre-trigger samples : 1000
            //---------------------------------
            Ret = dig.SetPreSampleTimes(m_Id1, MAX_SAMPLES);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo1.Text = "dig.SetPreSampleTimes = " + Ret.ToString() + " : " + ErrorString;
                return;
            }
            //---------------------------------
            // Set the number of post-trigger samples : 0
            //---------------------------------
            Ret = dig.SetPostSampleTimes(m_Id1, 0);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo1.Text = "dig.SetPostSampleTimes = " + Ret.ToString() + " : " + ErrorString;
                return;
            }
            //---------------------------------
            // Set channel : Enable channel0 only
            //---------------------------------
            // Enable channel0
            Ret = dig.SetChannel(m_Id1, Cdig.DIG_CHANNEL0, Cdig.DIG_ENABLE);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo1.Text = "dig.SetChannel = " + Ret.ToString() + " : " + ErrorString;
                return;
            }
            // Disable channel1
            Ret = dig.SetChannel(m_Id1, Cdig.DIG_CHANNEL1, Cdig.DIG_DISABLE);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo1.Text = "dig.SetChannel = " + Ret.ToString() + " : " + ErrorString;
                return;
            }
            //---------------------------------
            // Sets the type of pre-trigger : Auto
            //---------------------------------
            Ret = dig.SetPreTriggerType(m_Id1, Cdig.DIG_TRIGGERTYPE_AUTO);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo1.Text = "dig.SetPreTriggerType = " + Ret.ToString() + " : " + ErrorString;
                return;
            }

            //-------------------------------------------
            // Set deivce2
            //-------------------------------------------
            //---------------------------------
            // Set operation mode : Data logger mode
            //---------------------------------
            Ret = dig.SetDigitizerMode(m_Id2, Cdig.DIG_MODE_LOGGER);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo2.Text = "dig.SetDigitizerMode = " + Ret.ToString() + " : " + ErrorString;
                return;
            }
            //---------------------------------
            // Set sampling clock source : Crystal oscillator of board
            //---------------------------------
            Ret = dig.SetClockSource(m_Id2, Cdig.DIG_ECU_SRC_CLOCK);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo2.Text = "dig.SetClockSource = " + Ret.ToString() + " : " + ErrorString;
                return;
            }
            //---------------------------------
            // Set sampling clock : 1000usec  (set value * 10 + 10 (nsec))
            //---------------------------------
            Ret = dig.SetSampleClock(m_Id2, 99999);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo2.Text = "dig.SetSampleClock = " + Ret.ToString() + " : " + ErrorString;
                return;
            }
            //---------------------------------
            // Set the number of acquiring records : 1
            //---------------------------------
            Ret = dig.SetRecordNumber(m_Id2, 1);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo2.Text = "dig.SetRecordNumber = " + Ret.ToString() + " : " + ErrorString;
                return;
            }
            //---------------------------------
            // Set the number of pre-trigger samples : 1000
            //---------------------------------
            Ret = dig.SetPreSampleTimes(m_Id2, MAX_SAMPLES);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo2.Text = "dig.SetPreSampleTimes = " + Ret.ToString() + " : " + ErrorString;
                return;
            }
            //---------------------------------
            // Set the number of post-trigger samples : 0
            //---------------------------------
            Ret = dig.SetPostSampleTimes(m_Id2, 0);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo2.Text = "dig.SetPostSampleTimes = " + Ret.ToString() + " : " + ErrorString;
                return;
            }
            //---------------------------------
            // Set channel : Enable channel0 only
            //---------------------------------
            // Enable channel0
            Ret = dig.SetChannel(m_Id2, Cdig.DIG_CHANNEL0, Cdig.DIG_ENABLE);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo2.Text = "dig.SetChannel = " + Ret.ToString() + " : " + ErrorString;
                return;
            }
            // Disable channel1
            Ret = dig.SetChannel(m_Id2, Cdig.DIG_CHANNEL1, Cdig.DIG_DISABLE);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo2.Text = "dig.SetChannel = " + Ret.ToString() + " : " + ErrorString;
                return;
            }
            //---------------------------------
            // Set the type of pre-trigger : Digital edge 
            //---------------------------------
            Ret = dig.SetPreTriggerType(m_Id2, Cdig.DIG_TRIGGERTYPE_DIEDGE);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo2.Text = "dig.SetPreTriggerType = " + Ret.ToString() + " : " + ErrorString;
                return;
            }
            //---------------------------------
            // Set pre-trigger : Signal source = Synchronous bus 1, Direction = Rising edge, Count = 1
            //---------------------------------
            Ret = dig.SetPreTriggerDiEdge(m_Id2, Cdig.DIG_ECU_SRC_SYNC1, 0, 1);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo2.Text = "dig.SetPreTriggerDiEdge = " + Ret.ToString() + " : " + ErrorString;
                return;
            }

            //---------------------------------
            // Operation start : Start device2 first
            //---------------------------------
            Ret = dig.Start(m_Id2);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo2.Text = "dig.Start = " + Ret.ToString() + " : " + ErrorString;
                return;
            }
            textBoxInfo2.Text = "Start acquisition : Normality completion";

            Ret = dig.Start(m_Id1);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo1.Text = "dig.Start = " + Ret.ToString() + " : " + ErrorString;
                return;
            }
            textBoxInfo1.Text = "Start acquisition : Normality completion";

            //---------------------------------
            // Polling until the operation status is changed to be OFF
            //---------------------------------
            int Status1, Status2;

            do
            {
                //---------------------------------
                // In order to enable the dialog operation
                //---------------------------------
                System.Windows.Forms.Application.DoEvents();
                //------------------------------------------------------------
                // Device1
                //------------------------------------------------------------
                //---------------------------------
                // Get the number of samples stored in driver memory
                //---------------------------------
                Ret = dig.GetDriverMemorySamples(m_Id1, out m_Samples1);
                if (Ret != 0)
                {
                    string ErrorString;
                    dig.GetErrorString(Ret, out ErrorString);
                    textBoxInfo1.Text = "dig.GetDriverMemorySamples = " + Ret.ToString() + " : " + ErrorString;
                    return;
                }
                labelCount1.Text = m_Samples1.ToString();
                //---------------------------------
                // Get the operation status
                //---------------------------------
                Ret = dig.GetStatus(m_Id1, out Status1);
                if (Ret != 0)
                {
                    string ErrorString;
                    dig.GetErrorString(Ret, out ErrorString);
                    textBoxInfo1.Text = "dig.GetStatus = " + Ret.ToString() + " : " + ErrorString;
                    return;
                }
                labelStatus1.Text = Status1.ToString("X") + "H";
                //------------------------------------------------------------
                // Device2
                //------------------------------------------------------------
                //---------------------------------
                // Get the number of samples stored in driver memory
                //---------------------------------
                Ret = dig.GetDriverMemorySamples(m_Id2, out m_Samples2);
                if (Ret != 0)
                {
                    string ErrorString;
                    dig.GetErrorString(Ret, out ErrorString);
                    textBoxInfo2.Text = "dig.GetDriverMemorySamples = " + Ret.ToString() + " : " + ErrorString;
                    return;
                }
                labelCount2.Text = m_Samples2.ToString();
                //---------------------------------
                // Get the operation status
                //---------------------------------
                Ret = dig.GetStatus(m_Id2, out Status2);
                if (Ret != 0)
                {
                    string ErrorString;
                    dig.GetErrorString(Ret, out ErrorString);
                    textBoxInfo2.Text = "dig.GetStatus = " + Ret.ToString() + " : " + ErrorString;
                    return;
                }
                labelStatus2.Text = Status2.ToString("X") + "H";
            } while (((Status1 | Status2) & Cdig.DIG_STATUS_BUSY) == Cdig.DIG_STATUS_BUSY);

            //------------------------------------------------------------
            // Device1
            //------------------------------------------------------------
            //---------------------------------
            // After operation stop, get the number of samples which are being stored in driver memory
            //---------------------------------
            Ret = dig.GetDriverMemorySamples(m_Id1, out m_Samples1);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo1.Text = "dig.GetDriverMemorySamples = " + Ret.ToString() + " : " + ErrorString;
                return;
            }
            labelCount1.Text = m_Samples1.ToString();
            //---------------------------------
            // Retrieve the acquisition data
            //---------------------------------
            int TriggerPoint1;          // Position of the first data after the establishment of the post-trigger
            if (m_Samples1 > 0)
            {
                // Adjust to prevent the retrieved number of sampling from exceeding the size of array for storing data
                if (m_Samples1 > MAX_SAMPLES)
                {
                    m_Samples1 = MAX_SAMPLES;
                }
                Ret = dig.ReadSamples(m_Id1, ref m_Samples1, ref m_Data1, out TriggerPoint1);
                if (Ret != 0)
                {
                    string ErrorString;
                    dig.GetErrorString(Ret, out ErrorString);
                    textBoxInfo1.Text = "dig.ReadSamples = " + Ret.ToString() + " : " + ErrorString;
                    return;
                }
                //---------------------------------
                // Display the retrieved data
                //---------------------------------
                for (int i = 0; i < m_Samples1; i++)
                {
                    listBoxData1.Items.Add(String.Format("{0:D}\t{1:F3}", i + 1, m_Data1[i]));
                }
            }

            //------------------------------------------------------------
            // Device2
            //------------------------------------------------------------
            //---------------------------------
            // After operation stop, get the number of samples which are being stored in driver memory
            //---------------------------------
            Ret = dig.GetDriverMemorySamples(m_Id2, out m_Samples2);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo2.Text = "dig.GetDriverMemorySamples = " + Ret.ToString() + " : " + ErrorString;
                return;
            }
            labelCount2.Text = m_Samples2.ToString();
            //---------------------------------
            // Retrieve the acquisition data
            //---------------------------------
            int TriggerPoint2;          // Position of the first data after the establishment of the post-trigger
            if (m_Samples2 > 0)
            {
                // Adjust to prevent the retrieved number of sampling from exceeding the size of array for storing data
                if (m_Samples2 > MAX_SAMPLES)
                {
                    m_Samples2 = MAX_SAMPLES;
                }
                Ret = dig.ReadSamples(m_Id2, ref m_Samples2, ref m_Data2, out TriggerPoint2);
                if (Ret != 0)
                {
                    string ErrorString;
                    dig.GetErrorString(Ret, out ErrorString);
                    textBoxInfo2.Text = "dig.ReadSamples = " + Ret.ToString() + " : " + ErrorString;
                    return;
                }
                //---------------------------------
                // Display the retrieved data
                //---------------------------------
                for (int i = 0; i < m_Samples2; i++)
                {
                    listBoxData2.Items.Add(String.Format("{0:D}\t{1:F3}", i + 1, m_Data2[i]));
                }
            }
        }

        /// <summary>
        /// Get status
        /// </summary>
        private void buttonInfo_Click(object sender, System.EventArgs e)
        {
            int Ret;        // Return value
            int Status;     // Status
            int Samples;    // Number of retrieved samples

            //------------------------------------------------------------
            // Device1
            //------------------------------------------------------------
            //---------------------------------
            // Get the number of samples stored in driver memory
            //---------------------------------
            Ret = dig.GetDriverMemorySamples(m_Id1, out Samples);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo1.Text = "dig.GetDriverMemorySamples = " + Ret.ToString() + " : " + ErrorString;
                return;
            }
            labelCount1.Text = Samples.ToString();
            //---------------------------------
            // Get the operation status
            //---------------------------------
            Ret = dig.GetStatus(m_Id1, out Status);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo1.Text = "dig.GetStatus = " + Ret.ToString() + " : " + ErrorString;
                return;
            }
            labelStatus1.Text = Status.ToString("X") + "H";
            textBoxInfo1.Text = "Get status : Normality completion";

            //------------------------------------------------------------
            // Device2
            //------------------------------------------------------------
            //---------------------------------
            // Get the number of samples stored in driver memory
            //---------------------------------
            Ret = dig.GetDriverMemorySamples(m_Id2, out Samples);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo2.Text = "dig.GetDriverMemorySamples = " + Ret.ToString() + " : " + ErrorString;
                return;
            }
            labelCount2.Text = Samples.ToString();
            //---------------------------------
            // Get the operation status
            //---------------------------------
            Ret = dig.GetStatus(m_Id2, out Status);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo2.Text = "dig.GetStatus = " + Ret.ToString() + " : " + ErrorString;
                return;
            }
            labelStatus2.Text = Status.ToString("X") + "H";
            textBoxInfo2.Text = "Get status : Normality completion";
        }

        /// <summary>
        /// Stop acquisition
        /// </summary>
        private void buttonStop_Click(object sender, System.EventArgs e)
        {
            int Ret;        // Return value

            //------------------------------------------------------------
            // Device1
            //------------------------------------------------------------
            Ret = dig.Stop(m_Id1);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo1.Text = "dig.Stop = " + Ret.ToString() + " : " + ErrorString;
                return;
            }
            textBoxInfo1.Text = "Stop acquisition : Normality completion";

            //------------------------------------------------------------
            // Device2
            //------------------------------------------------------------
            Ret = dig.Stop(m_Id2);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo2.Text = "dig.Stop = " + Ret.ToString() + " : " + ErrorString;
                return;
            }
            textBoxInfo2.Text = "Stop acquisition : Normality completion";
        }

        /// <summary>
        /// Exit handling
        /// </summary>
        private void buttonExit_Click(object sender, System.EventArgs e)
        {
            int Ret;    // Return value

            //------------------------------------------------------------
            // Device1
            //------------------------------------------------------------
            Ret = dig.Exit(m_Id1);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo1.Text = "dig.Exit = " + Ret.ToString() + " : " + ErrorString;
                return;
            }
            textBoxInfo1.Text = "Exit : Normality completion";
            //------------------------------------------------------------
            // Device2
            //------------------------------------------------------------
            Ret = dig.Exit(m_Id2);
            if (Ret != 0)
            {
                string ErrorString;
                dig.GetErrorString(Ret, out ErrorString);
                textBoxInfo2.Text = "dig.Exit = " + Ret.ToString() + " : " + ErrorString;
                return;
            }
            textBoxInfo2.Text = "Exit : Normality completion";
        }

        /// <summary>
        /// Close Form
        /// </summary>
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            // Exit handling
            dig.Exit(m_Id1);
            dig.Exit(m_Id2);
        }
    }
}