using System.Diagnostics;
using CaioCs;

namespace AiSamplingInfiniteDev
{
    public partial class Form1 : Form
    {
        //----------------------------------------
        // NXCaioCX^X쐬
        //----------------------------------------
        Caio aio = new Caio();

        //----------------------------------------
        // }N`
        //----------------------------------------
        public const int MAX_AI_RANGE_NUM = 32;    // AiO̓Wzővf

        //----------------------------------------
        // O[oϐ̐錾
        //----------------------------------------
        public static short g_id;                                                                  // foCXANZXpID
        public long         g_sampling_count;                                                      // TvO
        public string       g_file_name = "SamplingData.csv";                                      // TvOf[^o̓t@C
        public short[]      g_ai_range = new short[MAX_AI_RANGE_NUM]{(short)CaioConst.PM10,        // }10V
                                                                     (short)CaioConst.PM5,         // }5V
                                                                     (short)CaioConst.PM25,        // }2.5V
                                                                     (short)CaioConst.PM125,       // }1.25V
                                                                     (short)CaioConst.PM1,         // }1V
                                                                     (short)CaioConst.PM0625,      // }0.625V
                                                                     (short)CaioConst.PM05,        // }0.5V
                                                                     (short)CaioConst.PM03125,     // }0.3125V
                                                                     (short)CaioConst.PM025,       // }0.25V
                                                                     (short)CaioConst.PM0125,      // }0.125V
                                                                     (short)CaioConst.PM01,        // }0.1V
                                                                     (short)CaioConst.PM005,       // }0.05V
                                                                     (short)CaioConst.PM0025,      // }0.025V
                                                                     (short)CaioConst.PM00125,     // }0.0125V
                                                                     (short)CaioConst.PM001,       // }0.01V
                                                                     (short)CaioConst.P10,         // 0`10V
                                                                     (short)CaioConst.P5,          // 0`5V
                                                                     (short)CaioConst.P4095,       // 0`4.095V
                                                                     (short)CaioConst.P25,         // 0`2.5V
                                                                     (short)CaioConst.P125,        // 0`1.25V
                                                                     (short)CaioConst.P1,          // 0`1V
                                                                     (short)CaioConst.P05,         // 0`0.5V
                                                                     (short)CaioConst.P025,        // 0`0.25V
                                                                     (short)CaioConst.P01,         // 0`0.1V
                                                                     (short)CaioConst.P005,        // 0`0.05V
                                                                     (short)CaioConst.P0025,       // 0`0.025V
                                                                     (short)CaioConst.P00125,      // 0`0.0125V
                                                                     (short)CaioConst.P001,        // 0`0.01V
                                                                     (short)CaioConst.P20MA,       // 0`20mA
                                                                     (short)CaioConst.P4TO20MA,    // 4`20mA
                                                                     (short)CaioConst.PM20MA,      // }20mA
                                                                     (short)CaioConst.P1TO5};      // 1`5V

        public Form1()
        {
            InitializeComponent();
        }

        private void AiSamplingInfiniteDev_Load(object sender, EventArgs e)
        {
            //----------------------------------------
            // ftHg{^ݒ
            //----------------------------------------
            AcceptButton = button_Close;
            //----------------------------------------
            // foCX̏\XV
            //----------------------------------------
            textBox_DeviceName.Text = "AIO000";
            //----------------------------------------
            // AiO̓WpR{{bNX̍쐬
            //----------------------------------------
            comboBox_RangeValue.Items.Add("-10 - +10V");
            comboBox_RangeValue.Items.Add("-5 - +5V");
            comboBox_RangeValue.Items.Add("-2.5 - +2.5V");
            comboBox_RangeValue.Items.Add("-1.25 - +1.25V");
            comboBox_RangeValue.Items.Add("-1 - +1V");
            comboBox_RangeValue.Items.Add("-0.625 - +0.625V");
            comboBox_RangeValue.Items.Add("-0.5 - +0.5V");
            comboBox_RangeValue.Items.Add("-0.3125 - +0.3125V");
            comboBox_RangeValue.Items.Add("-0.25 - +0.25V");
            comboBox_RangeValue.Items.Add("-0.125 - +0.125V");
            comboBox_RangeValue.Items.Add("-0.1 - +0.1V");
            comboBox_RangeValue.Items.Add("-0.05 - +0.05V");
            comboBox_RangeValue.Items.Add("-0.025 - +0.025V");
            comboBox_RangeValue.Items.Add("-0.0125 - +0.0125V");
            comboBox_RangeValue.Items.Add("-0.01 - +0.01V");
            comboBox_RangeValue.Items.Add("0 - +10V");
            comboBox_RangeValue.Items.Add("0 - +5V");
            comboBox_RangeValue.Items.Add("0 - +4.095V");
            comboBox_RangeValue.Items.Add("0 - +2.5V");
            comboBox_RangeValue.Items.Add("0 - +1.25V");
            comboBox_RangeValue.Items.Add("0 - +1V");
            comboBox_RangeValue.Items.Add("0 - +0.5V");
            comboBox_RangeValue.Items.Add("0 - +0.25V");
            comboBox_RangeValue.Items.Add("0 - +0.1V");
            comboBox_RangeValue.Items.Add("0 - +0.05V");
            comboBox_RangeValue.Items.Add("0 - +0.025V");
            comboBox_RangeValue.Items.Add("0 - +0.0125V");
            comboBox_RangeValue.Items.Add("0 - +0.01V");
            comboBox_RangeValue.Items.Add("0 - +20mA");
            comboBox_RangeValue.Items.Add("4 - +20mA");
            comboBox_RangeValue.Items.Add("-20mA - +20mA");
            comboBox_RangeValue.Items.Add("1 - +5V");
            //----------------------------------------
            // AiO̓WpR{{bNX̑I0ԂɕύX
            //----------------------------------------
            comboBox_RangeValue.SelectedIndex = 0;
            //----------------------------------------
            // AiO͕pR{{bNX̍쐬
            //----------------------------------------
            comboBox_InpMethod.Items.Add("VOGh");
            comboBox_InpMethod.Items.Add("");
            //----------------------------------------
            // AiO͕pR{{bNX̑I0ԂɕύX
            //----------------------------------------
            comboBox_InpMethod.SelectedIndex = 0;
            //----------------------------------------
            // AiO͂̃`l̏\XV
            //----------------------------------------
            textBox_ChNum.Text = "1";
            //----------------------------------------
            // wTvO񐔊i[Cxggpꍇ̃TvO񐔂̏\XV
            //----------------------------------------
            textBox_SamplingTimes.Text = "1000";
            //----------------------------------------
            // O[oϐ̏
            //----------------------------------------
            g_id             = 0;
            g_sampling_count = 0;
        }

        //================================================================================
        // AioInit{^NbNۂ̏ɂȂ܂
        // foCX̏s܂
        //================================================================================
        private void button_AioInit_Click(object sender, EventArgs e)
        {
            string device_name;     // foCX
            string error_string;    // G[R[h
            int    ret;             // ߂l擾p

            //----------------------------------------
            // foCXeLXg{bNX擾
            //----------------------------------------
            device_name = textBox_DeviceName.Text;
            //----------------------------------------
            // foCX
            // ύXӊ֐(ύXƃAv삵ȂȂ\܂)
            //----------------------------------------
            ret = aio.Init(device_name, out g_id);
            //----------------------------------------
            // G[擾
            //----------------------------------------
            aio.GetErrorString(ret, out error_string);
            //----------------------------------------
            // bZ[W\
            //----------------------------------------
            textBox_ReturnCode.Text = "aio.Init = " + ret.ToString() + "F" + error_string;
        }

        //================================================================================
        // AioResetDevice{^NbNۂ̏ɂȂ܂
        // foCX̃Zbgs܂
        //================================================================================
        private void button_AioResetDev_Click(object sender, EventArgs e)
        {
            string error_string;    // G[R[h
            int    ret;             // ߂l擾p

            //----------------------------------------
            // foCXZbg
            //----------------------------------------
            ret = aio.ResetDevice(g_id);
            //----------------------------------------
            // G[擾
            //----------------------------------------
            aio.GetErrorString(ret, out error_string);
            //----------------------------------------
            // bZ[W\
            //----------------------------------------
            textBox_ReturnCode.Text = "aio.ResetDevice = " + ret.ToString() + "F" + error_string;
        }

        //================================================================================
        // AioSetAiRangeAll{^NbNۂ̏ɂȂ܂
        // AiO͂̓̓W̐ݒs܂
        //================================================================================
        private void button_SetAiRangeAll_Click(object sender, EventArgs e)
        {
            string error_string;    // G[R[h
            int    ret;             // ߂l擾p
            int    index;           // R{{bNX̃CfbNX

            //----------------------------------------
            // GUȈXV
            //----------------------------------------
            this.Refresh();
            //----------------------------------------
            // R{{bNX烌Wݒl̃CfbNX擾
            //----------------------------------------
            index = comboBox_RangeValue.SelectedIndex;
            //----------------------------------------
            // AiO̓W̐ݒ(S`l)
            //----------------------------------------
            ret = aio.SetAiRangeAll(g_id, g_ai_range[index]);
            //----------------------------------------
            // G[擾
            //----------------------------------------
            aio.GetErrorString(ret, out error_string);
            //----------------------------------------
            // bZ[W\
            //----------------------------------------
            textBox_ReturnCode.Text = "aio.SetAiRangeAll = " + ret.ToString() + "F" + error_string;
        }

        //================================================================================
        // AioSetAiInputMethod{^NbNۂ̏ɂȂ܂
        // AiO͕͂̓̐ݒs܂
        //================================================================================
        private void button_SetAiInpMethod_Click(object sender, EventArgs e)
        {
            string error_string;    // G[R[h
            int    ret;             // ߂l擾p
            int    input_method;    // ͕

            //----------------------------------------
            // GUȈXV
            //----------------------------------------
            this.Refresh();
            //----------------------------------------
            // R{{bNX͕ݒl擾
            //----------------------------------------
            input_method = comboBox_InpMethod.SelectedIndex;
            //----------------------------------------
            // AiO͕̐ݒ
            //----------------------------------------
            ret = aio.SetAiInputMethod(g_id, (short)input_method);
            //----------------------------------------
            // G[擾
            //----------------------------------------
            aio.GetErrorString(ret, out error_string);
            //----------------------------------------
            // bZ[W\
            //----------------------------------------
            textBox_ReturnCode.Text = "aio.SetAiInputMethod = " + ret.ToString() + "F" + error_string;
        }

        //================================================================================
        // AioSetAiChannels{^NbNۂ̏ɂȂ܂
        // TvOɎgpAiO̓`l̐ݒs܂
        //================================================================================
        private void button_SetAiChannels_Click(object sender, EventArgs e)
        {
            string error_string;    // G[R[h
            int    ret;             // ߂l擾p
            short  ai_channels;     // `l

            //----------------------------------------
            // eLXg{bNX`l擾
            //----------------------------------------
            if (short.TryParse(textBox_ChNum.Text, out ai_channels) == false)
            {
                ai_channels = 1;
            }
            //----------------------------------------
            // ϊɎgpAiO̓`lݒ
            //----------------------------------------
            ret = aio.SetAiChannels(g_id, ai_channels);
            //----------------------------------------
            // G[擾
            //----------------------------------------
            aio.GetErrorString(ret, out error_string);
            //----------------------------------------
            // bZ[W\
            //----------------------------------------
            textBox_ReturnCode.Text = "aio.SetAiChannels = " + ret.ToString() + "F" + error_string;
        }

        //================================================================================
        // ݒ...{^NbNۂ̏ɂȂ܂
        // ݒ_CAOJ܂
        //================================================================================
        private void button_ConditionSettings_Click(object sender, EventArgs e)
        {
            string error_string;    // G[R[h
            int    ret;             // ߂l擾p

            //----------------------------------------
            // ݒ_CAOJ
            //----------------------------------------
            Condition condition_dlg = new Condition();
            if (condition_dlg.ShowDialog() == DialogResult.OK)
            {
                //----------------------------------------
                // CxgADϊJnCxgAfoCXICxgA
                // wTvO񐔊i[CxgAI[o[t[CxgA
                // TvONbNG[CxgAADϊG[Cxgݒ
                // ύXӊ֐(ύXƃAv삵ȂȂ\܂)
                //----------------------------------------
                ret = aio.SetAiEvent(g_id, Handle, (int)(CaioConst.AIE_START | CaioConst.AIE_END | CaioConst.AIE_DATA_NUM | CaioConst.AIE_OFERR | CaioConst.AIE_SCERR | CaioConst.AIE_ADERR));
                //----------------------------------------
                // G[
                //----------------------------------------
                if (ret != 0)
                {
                    //--------------------
                    // G[擾
                    //--------------------
                    aio.GetErrorString(ret, out error_string);
                    //--------------------
                    // bZ[W\
                    //--------------------
                    textBox_ReturnCode.Text = "ݒFaio.SetAiEvent = " + ret.ToString() + "F" + error_string;
                    return;
                }
                //----------------------------------------
                // ݒ芮̃bZ[W\
                //----------------------------------------
                textBox_ReturnCode.Text = "ݒFI";
            }
            condition_dlg.Dispose();
        }

        //================================================================================
        // AioSetAiEventSamplingTimes{^NbNۂ̏ɂȂ܂
        // wTvO񐔊i[Cxggpꍇ̃TvO̐ݒs܂
        //================================================================================
        private void button_SetAiEventSamplingTimes_Click(object sender, EventArgs e)
        {
            string error_string;      // G[R[h
            int    ret;               // ߂l擾p
            int    sampling_times;    // TvO

            //----------------------------------------
            // eLXg{bNXTvO񐔂擾
            //----------------------------------------
            if (int.TryParse(textBox_SamplingTimes.Text, out sampling_times) == false)
            {
                sampling_times = 1000;
            }
            //----------------------------------------
            // wTvO񐔊i[Cxggpꍇ̃TvOݒ
            //----------------------------------------
            ret = aio.SetAiEventSamplingTimes(g_id, sampling_times);
            //----------------------------------------
            // G[擾
            //----------------------------------------
            aio.GetErrorString(ret, out error_string);
            //----------------------------------------
            // bZ[W\
            //----------------------------------------
            textBox_ReturnCode.Text = "aio.SetAiEventSamplingTimes = " + ret.ToString() + "F" + error_string;
        }

        //================================================================================
        // TvOJn{^NbNۂ̏ɂȂ܂
        // ƃXe[^X̃NAsATvOJns܂
        //================================================================================
        private void button_SamplingStart_Click(object sender, EventArgs e)
        {
            string error_string;    // G[R[h
            string text_string;     // eLXg{bNXXVp
            int    ret;             // ߂l擾p
            int    ai_status;       // AiO̓Xe[^X

            //----------------------------------------
            // NA
            //----------------------------------------
            ret = aio.ResetAiMemory(g_id);
            //----------------------------------------
            // G[
            //----------------------------------------
            if (ret != 0)
            {
                //--------------------
                // G[擾
                //--------------------
                aio.GetErrorString(ret, out error_string);
                //--------------------
                // bZ[W\
                //--------------------
                textBox_ReturnCode.Text = "TvOJnFaio.ResetAiMemory = " + ret.ToString() + "F" + error_string;
                return;
            }
            //----------------------------------------
            // Xe[^XNA
            //----------------------------------------
            ret = aio.ResetAiStatus(g_id);
            //----------------------------------------
            // G[
            //----------------------------------------
            if (ret != 0)
            {
                //--------------------
                // G[擾
                //--------------------
                aio.GetErrorString(ret, out error_string);
                //--------------------
                // bZ[W\
                //--------------------
                textBox_ReturnCode.Text = "TvOJnFaio.ResetAiStatus = " + ret.ToString() + "F" + error_string;
                return;
            }
            //----------------------------------------
            // TvO񐔂
            //----------------------------------------
            g_sampling_count = 0;
            //----------------------------------------
            // f[^t@C폜
            //----------------------------------------
            File.Delete(g_file_name);
            //----------------------------------------
            // TvOJn
            //----------------------------------------
            ret = aio.StartAi(g_id);
            //----------------------------------------
            // G[
            //----------------------------------------
            if (ret != 0)
            {
                //--------------------
                // G[擾
                //--------------------
                aio.GetErrorString(ret, out error_string);
                //--------------------
                // bZ[W\
                //--------------------
                textBox_ReturnCode.Text = "TvOJnFaio.StartAi = " + ret.ToString() + "F" + error_string;
                return;
            }
            //----------------------------------------
            // Xe[^X擾
            //----------------------------------------
            ret = aio.GetAiStatus(g_id, out ai_status);
            //----------------------------------------
            // G[
            //----------------------------------------
            if (ret != 0)
            {
                //--------------------
                // G[擾
                //--------------------
                aio.GetErrorString(ret, out error_string);
                //--------------------
                // bZ[W\
                //--------------------
                textBox_ReturnCode.Text = "TvOJnFaio.GetAiStatus = " + ret.ToString() + "F" + error_string;
                return;
            }
            //----------------------------------------
            // Xe[^X̕\
            //----------------------------------------
            text_string = string.Format("{0:x8}H (", ai_status);
            //--------------------
            // 쒆Xe[^XL
            //--------------------
            if ((ai_status & (int)CaioConst.AIS_BUSY) == (int)CaioConst.AIS_BUSY)
            {
                text_string += "쒆";
            }
            //--------------------
            // 쒆Xe[^X
            //--------------------
            else
            {
                text_string += "~";
            }
            //--------------------
            // JngK҂Xe[^XL
            //--------------------
            if ((ai_status & (int)CaioConst.AIS_START_TRG) == (int)CaioConst.AIS_START_TRG)
            {
                text_string += ", JngK҂";
            }
            //--------------------
            // wTvO񐔊i[Xe[^XL
            //--------------------
            if ((ai_status & (int)CaioConst.AIS_DATA_NUM) == (int)CaioConst.AIS_DATA_NUM)
            {
                text_string += ", w񐔊i[";
            }
            //--------------------
            // I[o[t[Xe[^XL
            //--------------------
            if ((ai_status & (int)CaioConst.AIS_OFERR) == (int)CaioConst.AIS_OFERR)
            {
                text_string += ", I[o[t[";
            }
            //--------------------
            // TvONbNG[Xe[^XL
            //--------------------
            if ((ai_status & (int)CaioConst.AIS_SCERR) == (int)CaioConst.AIS_SCERR)
            {
                text_string += ", TvONbNG[";
            }
            //--------------------
            // ADϊG[Xe[^XL
            //--------------------
            if ((ai_status & (int)CaioConst.AIS_AIERR) == (int)CaioConst.AIS_AIERR)
            {
                text_string += ", ADϊG[";
            }
            //--------------------
            // hCoXybNG[Xe[^XL
            //--------------------
            if ((ai_status & (int)CaioConst.AIS_DRVERR) == (int)CaioConst.AIS_DRVERR)
            {
                text_string += ", hCoXybNG[";
            }
            text_string += ")";
            textBox_Status.Text = text_string;
            //----------------------------------------
            // TvO񐔂XV
            //----------------------------------------
            textBox_TotalSamplingCount.Text = "0";
            //----------------------------------------
            // TvO񐔂XV
            //----------------------------------------
            textBox_SamplingCount.Text = "0";
            //----------------------------------------
            // TvOJñbZ[W\
            //----------------------------------------
            textBox_ReturnCode.Text = "TvOJnFI";
        }

        //================================================================================
        // AioGetAiSamplingCount{^NbNۂ̏ɂȂ܂
        // TvO񐔂擾_CAOɕ\܂
        //================================================================================
        private void button_GetSamplingCount_Click(object sender, EventArgs e)
        {
            string error_string;         // G[R[h
            int    ret;                  // ߂l擾p
            int    ai_sampling_count;    // TvOJEg

            //----------------------------------------
            // TvO񐔂擾
            //----------------------------------------
            ret = aio.GetAiSamplingCount(g_id, out ai_sampling_count);
            //----------------------------------------
            // G[擾
            //----------------------------------------
            aio.GetErrorString(ret, out error_string);
            //----------------------------------------
            // bZ[W\
            //----------------------------------------
            textBox_ReturnCode.Text = "aio.GetAiSamplingCount = " + ret.ToString() + "F" + error_string;
            //----------------------------------------
            // TvO񐔎擾֐Iꍇ
            //----------------------------------------
            if (ret == 0)
            {
                //--------------------
                // TvO񐔂XV
                //--------------------
                textBox_SamplingCount.Text = ai_sampling_count.ToString();
            }
        }

        //================================================================================
        // AioGetAiStatus{^NbNۂ̏ɂȂ܂
        // AiO̓Xe[^X擾_CAOɕ\܂
        //================================================================================
        private void button_GetAiStatus_Click(object sender, EventArgs e)
        {
            string error_string;    // G[R[h
            string text_string;     // eLXg{bNXXVp
            int    ret;             // ߂l擾p
            int    ai_status;       // Xe[^X

            //----------------------------------------
            // Xe[^X擾
            //----------------------------------------
            ret = aio.GetAiStatus(g_id, out ai_status);
            //----------------------------------------
            // G[擾
            //----------------------------------------
            aio.GetErrorString(ret, out error_string);
            //----------------------------------------
            // bZ[W\
            //----------------------------------------
            textBox_ReturnCode.Text = "aio.GetAiStatus = " + ret.ToString() + "F" + error_string;
            //----------------------------------------
            // Xe[^X擾֐Iꍇ
            //----------------------------------------
            if (ret == 0)
            {
                //----------------------------------------
                // Xe[^X̕\
                //----------------------------------------
                text_string = string.Format("{0:x8}H (", ai_status);
                //--------------------
                // 쒆Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_BUSY) == (int)CaioConst.AIS_BUSY)
                {
                    text_string += "쒆";
                }
                //--------------------
                // 쒆Xe[^X
                //--------------------
                else
                {
                    text_string += "~";
                }
                //--------------------
                // JngK҂Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_START_TRG) == (int)CaioConst.AIS_START_TRG)
                {
                    text_string += ", JngK҂";
                }
                //--------------------
                // wTvO񐔊i[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_DATA_NUM) == (int)CaioConst.AIS_DATA_NUM)
                {
                    text_string += ", w񐔊i[";
                }
                //--------------------
                // I[o[t[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_OFERR) == (int)CaioConst.AIS_OFERR)
                {
                    text_string += ", I[o[t[";
                }
                //--------------------
                // TvONbNG[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_SCERR) == (int)CaioConst.AIS_SCERR)
                {
                    text_string += ", TvONbNG[";
                }
                //--------------------
                // ADϊG[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_AIERR) == (int)CaioConst.AIS_AIERR)
                {
                    text_string += ", ADϊG[";
                }
                //--------------------
                // hCoXybNG[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_DRVERR) == (int)CaioConst.AIS_DRVERR)
                {
                    text_string += ", hCoXybNG[";
                }
                text_string += ")";
                textBox_Status.Text = text_string;
            }
        }

        //================================================================================
        // TvO~{^NbNۂ̏ɂȂ܂
        // TvO~R}hs܂
        //================================================================================
        private void button_SamplingStop_Click(object sender, EventArgs e)
        {
            string error_string;    // G[R[h
            int    ret;             // ߂l擾p

            //----------------------------------------
            // TvO~
            //----------------------------------------
            ret = aio.StopAi(g_id);
            //----------------------------------------
            // G[
            //----------------------------------------
            if (ret != 0)
            {
                //--------------------
                // G[擾
                //--------------------
                aio.GetErrorString(ret, out error_string);
                //--------------------
                // bZ[W\
                //--------------------
                textBox_ReturnCode.Text = "TvO~Faio.StopAi = " + ret.ToString() + "F" + error_string;
                return;
            }
            //----------------------------------------
            // TvO~̃bZ[W\
            //----------------------------------------
            textBox_ReturnCode.Text = "TvO~FI";
        }

        //================================================================================
        // AioExit{^NbNۂ̏ɂȂ܂
        // foCX̏Is܂
        //================================================================================
        private void button_AioExit_Click(object sender, EventArgs e)
        {
            string error_string;    // G[R[h
            int    ret;             // ߂l擾p

            //----------------------------------------
            // I̎s
            //----------------------------------------
            ret = aio.Exit(g_id);
            //----------------------------------------
            // G[擾
            //----------------------------------------
            aio.GetErrorString(ret, out error_string);
            //----------------------------------------
            // bZ[W\
            //----------------------------------------
            textBox_ReturnCode.Text = "aio.Exit = " + ret.ToString() + "F" + error_string;
        }

        //================================================================================
        // NbNۂ̏ɂȂ܂
        // foCX̏IsAAvP[VI܂
        //================================================================================
        private void button_Close_Click(object sender, EventArgs e)
        {
            //----------------------------------------
            // I̎s
            //----------------------------------------
            aio.Exit(g_id);
            //----------------------------------------
            // _CAOI
            //----------------------------------------
            this.Close();
        }

        //================================================================================
        // Cxg̓
        // eCxgƂACxgɏs܂
        //================================================================================
        protected override void WndProc(ref Message m)
        {
            string       error_string;         // G[R[h
            string       text_string;          // eLXg{bNXXVp
            int          ret;                  // ߂l擾p
            float[]      ai_data;              // AiOf[^
            int          ai_sampling_count;    // TvOJEg
            int          ai_status;            // Xe[^X
            StreamWriter fp;                   // t@C|C^
            long         i, j;                 // [vJEg
            short        ai_channels;          // `l

            //----------------------------------------
            // ADϊJnCxg
            // Xe[^X̕\s
            //----------------------------------------
            if (m.Msg == (int)CaioConst.AIOM_AIE_START)
            {
                //----------------------------------------
                // Xe[^X擾
                //----------------------------------------
                ret = aio.GetAiStatus(g_id, out ai_status);
                //----------------------------------------
                // G[
                //----------------------------------------
                if (ret != 0)
                {
                    //--------------------
                    // G[擾
                    //--------------------
                    aio.GetErrorString(ret, out error_string);
                    //--------------------
                    // bZ[W\
                    //--------------------
                    textBox_ReturnCode.Text = "ADϊJnCxgFaio.GetAiStatus = " + ret.ToString() + "F" + error_string;
                    return;
                }
                //----------------------------------------
                // Xe[^X̕\
                //----------------------------------------
                text_string = string.Format("{0:x8}H (", ai_status);
                //--------------------
                // 쒆Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_BUSY) == (int)CaioConst.AIS_BUSY)
                {
                    text_string += "쒆";
                }
                //--------------------
                // 쒆Xe[^X
                //--------------------
                else
                {
                    text_string += "~";
                }
                //--------------------
                // JngK҂Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_START_TRG) == (int)CaioConst.AIS_START_TRG)
                {
                    text_string += ", JngK҂";
                }
                //--------------------
                // wTvO񐔊i[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_DATA_NUM) == (int)CaioConst.AIS_DATA_NUM)
                {
                    text_string += ", w񐔊i[";
                }
                //--------------------
                // I[o[t[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_OFERR) == (int)CaioConst.AIS_OFERR)
                {
                    text_string += ", I[o[t[";
                }
                //--------------------
                // TvONbNG[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_SCERR) == (int)CaioConst.AIS_SCERR)
                {
                    text_string += ", TvONbNG[";
                }
                //--------------------
                // ADϊG[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_AIERR) == (int)CaioConst.AIS_AIERR)
                {
                    text_string += ", ADϊG[";
                }
                //--------------------
                // hCoXybNG[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_DRVERR) == (int)CaioConst.AIS_DRVERR)
                {
                    text_string += ", hCoXybNG[";
                }
                text_string += ")";
                textBox_Status.Text = text_string;
                //----------------------------------------
                // Cxg̃bZ[W\
                //----------------------------------------
                textBox_ReturnCode.Text = "ADϊJnCxgFI";
            }
            //----------------------------------------
            // wTvO񐔊i[Cxg
            // f[^̎擾A\s
            //----------------------------------------
            if (m.Msg == (int)CaioConst.AIOM_AIE_DATA_NUM)
            {
                //----------------------------------------
                // Xe[^X擾
                //----------------------------------------
                ret = aio.GetAiStatus(g_id, out ai_status);
                //----------------------------------------
                // G[
                //----------------------------------------
                if (ret != 0)
                {
                    //--------------------
                    // G[擾
                    //--------------------
                    aio.GetErrorString(ret, out error_string);
                    //--------------------
                    // bZ[W\
                    //--------------------
                    textBox_ReturnCode.Text = "wTvO񐔊i[CxgFaio.GetAiStatus = " + ret.ToString() + "F" + error_string;
                    return;
                }
                //----------------------------------------
                // Xe[^X̕\
                //----------------------------------------
                text_string = string.Format("{0:x8}H (", ai_status);
                //--------------------
                // 쒆Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_BUSY) == (int)CaioConst.AIS_BUSY)
                {
                    text_string += "쒆";
                }
                //--------------------
                // 쒆Xe[^X
                //--------------------
                else
                {
                    text_string += "~";
                }
                //--------------------
                // JngK҂Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_START_TRG) == (int)CaioConst.AIS_START_TRG)
                {
                    text_string += ", JngK҂";
                }
                //--------------------
                // wTvO񐔊i[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_DATA_NUM) == (int)CaioConst.AIS_DATA_NUM)
                {
                    text_string += ", w񐔊i[";
                }
                //--------------------
                // I[o[t[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_OFERR) == (int)CaioConst.AIS_OFERR)
                {
                    text_string += ", I[o[t[";
                }
                //--------------------
                // TvONbNG[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_SCERR) == (int)CaioConst.AIS_SCERR)
                {
                    text_string += ", TvONbNG[";
                }
                //--------------------
                // ADϊG[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_AIERR) == (int)CaioConst.AIS_AIERR)
                {
                    text_string += ", ADϊG[";
                }
                //--------------------
                // hCoXybNG[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_DRVERR) == (int)CaioConst.AIS_DRVERR)
                {
                    text_string += ", hCoXybNG[";
                }
                text_string += ")";
                textBox_Status.Text = text_string;
                //----------------------------------------
                // ݂̃TvO񐔂擾
                //----------------------------------------
                ret = aio.GetAiSamplingCount(g_id, out ai_sampling_count);
                //----------------------------------------
                // G[
                //----------------------------------------
                if (ret != 0)
                {
                    //--------------------
                    // G[擾
                    //--------------------
                    aio.GetErrorString(ret, out error_string);
                    //--------------------
                    // bZ[W\
                    //--------------------
                    textBox_ReturnCode.Text = "wTvO񐔊i[CxgFaio.GetAiSamplingCount = " + ret.ToString() + "F" + error_string;
                    return;
                }
                //----------------------------------------
                // TvO񐔂\
                //----------------------------------------
                textBox_SamplingCount.Text = ai_sampling_count.ToString();
                //----------------------------------------
                // `l擾
                //----------------------------------------
                ret = aio.GetAiChannels(g_id, out ai_channels);
                //----------------------------------------
                // G[
                //----------------------------------------
                if (ret != 0)
                {
                    //--------------------
                    // G[擾
                    //--------------------
                    aio.GetErrorString(ret, out error_string);
                    //--------------------
                    // bZ[W\
                    //--------------------
                    textBox_ReturnCode.Text = "wTvO񐔊i[CxgFaio.GetAiChannels = " + ret.ToString() + "F" + error_string;
                    return;
                }
                //----------------------------------------
                // TvOf[^擾
                //----------------------------------------
                //--------------------
                // f[^i[p̔zm
                //--------------------
                try
                {
                    ai_data = new float[ai_sampling_count * ai_channels];
                }
                catch
                {
                    textBox_ReturnCode.Text = "wTvO񐔊i[CxgFf[^i[p̔zmۂɎs";
                    return;
                }
                //----------------------------------------
                // TvOf[^擾
                //----------------------------------------
                ret = aio.GetAiSamplingDataEx(g_id, ref ai_sampling_count, ref ai_data);
                //----------------------------------------
                // G[
                //----------------------------------------
                if (ret != 0)
                {
                    //--------------------
                    // G[擾
                    //--------------------
                    aio.GetErrorString(ret, out error_string);
                    //--------------------
                    // bZ[W\
                    //--------------------
                    textBox_ReturnCode.Text = "wTvO񐔊i[CxgFaio.GetAiSamplingDataEx = " + ret.ToString() + "F" + error_string;
                    return;
                }
                //----------------------------------------
                // TvOf[^t@Cɏo
                //----------------------------------------
                //--------------------
                // TvO񐔂1ȏꍇ
                //--------------------
                if (ai_sampling_count > 0)
                {
                    //--------------------
                    // t@CJ
                    //--------------------
                    try
                    {
                        fp = File.AppendText(g_file_name);
                    }
                    catch
                    {
                        textBox_ReturnCode.Text = "wTvO񐔊i[CxgFFile.AppendText = file open error.";
                        return;
                    }
                    //--------------------
                    // TvO񐔂܂ŏJԂ
                    //--------------------
                    for (i = 0; i < ai_sampling_count; i++)
                    {
                        text_string = "";
                        //--------------------
                        // \p̐
                        //--------------------
                        text_string += string.Format("{0,5},", (i + 1 + g_sampling_count));
                        //--------------------
                        // w肵`l̐JԂ
                        //--------------------
                        for (j = 0; j < ai_channels; j++)
                        {
                            text_string += string.Format(" {0,10:F5}", ai_data[i * ai_channels + j]);
                            //--------------------
                            // ŏI`l̏ꍇsǉ
                            //--------------------
                            if (j == (ai_channels - 1))
                            {
                                text_string += "\r\n";
                            }
                            //--------------------
                            // ŏI`lȊȌꍇJ}ǉ
                            //--------------------
                            else
                            {
                                text_string += ",";
                            }
                        }
                        //--------------------
                        // f[^
                        //--------------------
                        try
                        {
                            fp.Write(text_string);
                        }
                        catch
                        {
                            textBox_ReturnCode.Text = "wTvO񐔊i[CxgFfp.Write = file write error.";
                            fp.Close();
                            return;
                        }
                    }
                    //--------------------
                    // t@C
                    //--------------------
                    fp.Close();
                }
                //----------------------------------------
                // TvO񐔂XV
                //----------------------------------------
                g_sampling_count += ai_sampling_count;
                //----------------------------------------
                // TvO񐔂\
                //----------------------------------------
                textBox_TotalSamplingCount.Text = g_sampling_count.ToString();
                //----------------------------------------
                // Cxg̃bZ[W\
                //----------------------------------------
                textBox_ReturnCode.Text = "wTvO񐔊i[CxgFI";
            }
            //----------------------------------------
            // foCXICxg
            // f[^̎擾A\s
            //----------------------------------------
            if (m.Msg == (int)CaioConst.AIOM_AIE_END)
            {
                //----------------------------------------
                // Xe[^X擾
                //----------------------------------------
                ret = aio.GetAiStatus(g_id, out ai_status);
                //----------------------------------------
                // G[
                //----------------------------------------
                if (ret != 0)
                {
                    //--------------------
                    // G[擾
                    //--------------------
                    aio.GetErrorString(ret, out error_string);
                    //--------------------
                    // bZ[W\
                    //--------------------
                    textBox_ReturnCode.Text = "foCXICxgFaio.GetAiStatus = " + ret.ToString() + "F" + error_string;
                    return;
                }
                //----------------------------------------
                // Xe[^X̕\
                //----------------------------------------
                text_string = string.Format("{0:x8}H (", ai_status);
                //--------------------
                // 쒆Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_BUSY) == (int)CaioConst.AIS_BUSY)
                {
                    text_string += "쒆";
                }
                //--------------------
                // 쒆Xe[^X
                //--------------------
                else
                {
                    text_string += "~";
                }
                //--------------------
                // JngK҂Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_START_TRG) == (int)CaioConst.AIS_START_TRG)
                {
                    text_string += ", JngK҂";
                }
                //--------------------
                // wTvO񐔊i[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_DATA_NUM) == (int)CaioConst.AIS_DATA_NUM)
                {
                    text_string += ", w񐔊i[";
                }
                //--------------------
                // I[o[t[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_OFERR) == (int)CaioConst.AIS_OFERR)
                {
                    text_string += ", I[o[t[";
                }
                //--------------------
                // TvONbNG[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_SCERR) == (int)CaioConst.AIS_SCERR)
                {
                    text_string += ", TvONbNG[";
                }
                //--------------------
                // ADϊG[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_AIERR) == (int)CaioConst.AIS_AIERR)
                {
                    text_string += ", ADϊG[";
                }
                //--------------------
                // hCoXybNG[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_DRVERR) == (int)CaioConst.AIS_DRVERR)
                {
                    text_string += ", hCoXybNG[";
                }
                text_string += ")";
                textBox_Status.Text = text_string;
                //----------------------------------------
                // ݂̃TvO񐔂擾
                //----------------------------------------
                ret = aio.GetAiSamplingCount(g_id, out ai_sampling_count);
                //----------------------------------------
                // G[
                //----------------------------------------
                if (ret != 0)
                {
                    //--------------------
                    // G[擾
                    //--------------------
                    aio.GetErrorString(ret, out error_string);
                    //--------------------
                    // bZ[W\
                    //--------------------
                    textBox_ReturnCode.Text = "foCXICxgFaio.GetAiSamplingCount = " + ret.ToString() + "F" + error_string;
                    return;
                }
                //----------------------------------------
                // TvO񐔂\
                //----------------------------------------
                textBox_SamplingCount.Text = ai_sampling_count.ToString();
                //----------------------------------------
                // `l擾
                //----------------------------------------
                ret = aio.GetAiChannels(g_id, out ai_channels);
                //----------------------------------------
                // G[
                //----------------------------------------
                if (ret != 0)
                {
                    //--------------------
                    // G[擾
                    //--------------------
                    aio.GetErrorString(ret, out error_string);
                    //--------------------
                    // bZ[W\
                    //--------------------
                    textBox_ReturnCode.Text = "foCXICxgFaio.GetAiChannels = " + ret.ToString() + "F" + error_string;
                    return;
                }
                //----------------------------------------
                // TvOf[^擾
                //----------------------------------------
                //--------------------
                // f[^i[p̔zm
                //--------------------
                try
                {
                    ai_data = new float[ai_sampling_count * ai_channels];
                }
                catch
                {
                    textBox_ReturnCode.Text = "foCXICxgFf[^i[p̔zmۂɎs";
                    return;
                }
                //----------------------------------------
                // TvOf[^擾
                //----------------------------------------
                ret = aio.GetAiSamplingDataEx(g_id, ref ai_sampling_count, ref ai_data);
                //----------------------------------------
                // G[
                //----------------------------------------
                if (ret != 0)
                {
                    //--------------------
                    // G[擾
                    //--------------------
                    aio.GetErrorString(ret, out error_string);
                    //--------------------
                    // bZ[W\
                    //--------------------
                    textBox_ReturnCode.Text = "foCXICxgFaio.GetAiSamplingDataEx = " + ret.ToString() + "F" + error_string;
                    return;
                }
                //----------------------------------------
                // TvOf[^t@Cɏo
                //----------------------------------------
                //--------------------
                // TvO񐔂1ȏꍇ
                //--------------------
                if (ai_sampling_count > 0)
                {
                    //--------------------
                    // t@CJ
                    //--------------------
                    try
                    {
                        fp = File.AppendText(g_file_name);
                    }
                    catch
                    {
                        textBox_ReturnCode.Text = "foCXICxgFFile.AppendText = file open error.";
                        return;
                    }
                    //--------------------
                    // TvO񐔂܂ŏJԂ
                    //--------------------
                    for (i = 0; i < ai_sampling_count; i++)
                    {
                        text_string = "";
                        //--------------------
                        // \p̐
                        //--------------------
                        text_string += string.Format("{0,5},", (i + 1 + g_sampling_count));
                        //--------------------
                        // w肵`l̐JԂ
                        //--------------------
                        for (j = 0; j < ai_channels; j++)
                        {
                            text_string += string.Format(" {0,10:F5}", ai_data[i * ai_channels + j]);
                            //--------------------
                            // ŏI`l̏ꍇsǉ
                            //--------------------
                            if (j == (ai_channels - 1))
                            {
                                text_string += "\r\n";
                            }
                            //--------------------
                            // ŏI`lȊȌꍇJ}ǉ
                            //--------------------
                            else
                            {
                                text_string += ",";
                            }
                        }
                        //--------------------
                        // f[^
                        //--------------------
                        try
                        {
                            fp.Write(text_string);
                        }
                        catch
                        {
                            textBox_ReturnCode.Text = "foCXICxgFfp.Write = file write error.";
                            fp.Close();
                            return;
                        }
                    }
                    //--------------------
                    // t@C
                    //--------------------
                    fp.Close();
                }
                //----------------------------------------
                // TvO񐔂XV
                //----------------------------------------
                g_sampling_count += ai_sampling_count;
                //----------------------------------------
                // TvO񐔂\
                //----------------------------------------
                textBox_TotalSamplingCount.Text = g_sampling_count.ToString();
                //----------------------------------------
                // Cxg̃bZ[W\
                //----------------------------------------
                textBox_ReturnCode.Text = "foCXICxgFI";
            }
            //----------------------------------------
            // I[o[t[Cxg
            // Xe[^X̕\s
            //----------------------------------------
            if (m.Msg == (int)CaioConst.AIOM_AIE_OFERR)
            {
                //----------------------------------------
                // Xe[^X擾
                //----------------------------------------
                ret = aio.GetAiStatus(g_id, out ai_status);
                //----------------------------------------
                // G[
                //----------------------------------------
                if (ret != 0)
                {
                    //--------------------
                    // G[擾
                    //--------------------
                    aio.GetErrorString(ret, out error_string);
                    //--------------------
                    // bZ[W\
                    //--------------------
                    textBox_ReturnCode.Text = "I[o[t[Faio.GetAiStatus = " + ret.ToString() + "F" + error_string;
                    return;
                }
                //----------------------------------------
                // Xe[^X̕\
                //----------------------------------------
                text_string = string.Format("{0:x8}H (", ai_status);
                //--------------------
                // 쒆Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_BUSY) == (int)CaioConst.AIS_BUSY)
                {
                    text_string += "쒆";
                }
                //--------------------
                // 쒆Xe[^X
                //--------------------
                else
                {
                    text_string += "~";
                }
                //--------------------
                // JngK҂Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_START_TRG) == (int)CaioConst.AIS_START_TRG)
                {
                    text_string += ", JngK҂";
                }
                //--------------------
                // wTvO񐔊i[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_DATA_NUM) == (int)CaioConst.AIS_DATA_NUM)
                {
                    text_string += ", w񐔊i[";
                }
                //--------------------
                // I[o[t[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_OFERR) == (int)CaioConst.AIS_OFERR)
                {
                    text_string += ", I[o[t[";
                }
                //--------------------
                // TvONbNG[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_SCERR) == (int)CaioConst.AIS_SCERR)
                {
                    text_string += ", TvONbNG[";
                }
                //--------------------
                // ADϊG[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_AIERR) == (int)CaioConst.AIS_AIERR)
                {
                    text_string += ", ADϊG[";
                }
                //--------------------
                // hCoXybNG[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_DRVERR) == (int)CaioConst.AIS_DRVERR)
                {
                    text_string += ", hCoXybNG[";
                }
                text_string += ")";
                textBox_Status.Text = text_string;
                //----------------------------------------
                // Cxg̃bZ[W\
                //----------------------------------------
                textBox_ReturnCode.Text = "I[o[t[FI";
            }
            //----------------------------------------
            // TvONbNG[Cxg
            // Xe[^X̕\s
            //----------------------------------------
            if (m.Msg == (int)CaioConst.AIOM_AIE_SCERR)
            {
                //----------------------------------------
                // Xe[^X擾
                //----------------------------------------
                ret = aio.GetAiStatus(g_id, out ai_status);
                //----------------------------------------
                // G[
                //----------------------------------------
                if (ret != 0)
                {
                    //--------------------
                    // G[擾
                    //--------------------
                    aio.GetErrorString(ret, out error_string);
                    //--------------------
                    // bZ[W\
                    //--------------------
                    textBox_ReturnCode.Text = "TvONbNG[Faio.GetAiStatus = " + ret.ToString() + "F" + error_string;
                    return;
                }
                //----------------------------------------
                // Xe[^X̕\
                //----------------------------------------
                text_string = string.Format("{0:x8}H (", ai_status);
                //--------------------
                // 쒆Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_BUSY) == (int)CaioConst.AIS_BUSY)
                {
                    text_string += "쒆";
                }
                //--------------------
                // 쒆Xe[^X
                //--------------------
                else
                {
                    text_string += "~";
                }
                //--------------------
                // JngK҂Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_START_TRG) == (int)CaioConst.AIS_START_TRG)
                {
                    text_string += ", JngK҂";
                }
                //--------------------
                // wTvO񐔊i[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_DATA_NUM) == (int)CaioConst.AIS_DATA_NUM)
                {
                    text_string += ", w񐔊i[";
                }
                //--------------------
                // I[o[t[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_OFERR) == (int)CaioConst.AIS_OFERR)
                {
                    text_string += ", I[o[t[";
                }
                //--------------------
                // TvONbNG[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_SCERR) == (int)CaioConst.AIS_SCERR)
                {
                    text_string += ", TvONbNG[";
                }
                //--------------------
                // ADϊG[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_AIERR) == (int)CaioConst.AIS_AIERR)
                {
                    text_string += ", ADϊG[";
                }
                //--------------------
                // hCoXybNG[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_DRVERR) == (int)CaioConst.AIS_DRVERR)
                {
                    text_string += ", hCoXybNG[";
                }
                text_string += ")";
                textBox_Status.Text = text_string;
                //----------------------------------------
                // Cxg̃bZ[W\
                //----------------------------------------
                textBox_ReturnCode.Text = "TvONbNG[FI";
            }
            //----------------------------------------
            // ADϊG[Cxg
            // Xe[^X̕\s
            //----------------------------------------
            if (m.Msg == (int)CaioConst.AIOM_AIE_ADERR)
            {
                //----------------------------------------
                // Xe[^X擾
                //----------------------------------------
                ret = aio.GetAiStatus(g_id, out ai_status);
                //----------------------------------------
                // G[
                //----------------------------------------
                if (ret != 0)
                {
                    //--------------------
                    // G[擾
                    //--------------------
                    aio.GetErrorString(ret, out error_string);
                    //--------------------
                    // bZ[W\
                    //--------------------
                    textBox_ReturnCode.Text = "ADϊG[Faio.GetAiStatus = " + ret.ToString() + "F" + error_string;
                    return;
                }
                //----------------------------------------
                // Xe[^X̕\
                //----------------------------------------
                text_string = string.Format("{0:x8}H (", ai_status);
                //--------------------
                // 쒆Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_BUSY) == (int)CaioConst.AIS_BUSY)
                {
                    text_string += "쒆";
                }
                //--------------------
                // 쒆Xe[^X
                //--------------------
                else
                {
                    text_string += "~";
                }
                //--------------------
                // JngK҂Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_START_TRG) == (int)CaioConst.AIS_START_TRG)
                {
                    text_string += ", JngK҂";
                }
                //--------------------
                // wTvO񐔊i[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_DATA_NUM) == (int)CaioConst.AIS_DATA_NUM)
                {
                    text_string += ", w񐔊i[";
                }
                //--------------------
                // I[o[t[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_OFERR) == (int)CaioConst.AIS_OFERR)
                {
                    text_string += ", I[o[t[";
                }
                //--------------------
                // TvONbNG[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_SCERR) == (int)CaioConst.AIS_SCERR)
                {
                    text_string += ", TvONbNG[";
                }
                //--------------------
                // ADϊG[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_AIERR) == (int)CaioConst.AIS_AIERR)
                {
                    text_string += ", ADϊG[";
                }
                //--------------------
                // hCoXybNG[Xe[^XL
                //--------------------
                if ((ai_status & (int)CaioConst.AIS_DRVERR) == (int)CaioConst.AIS_DRVERR)
                {
                    text_string += ", hCoXybNG[";
                }
                text_string += ")";
                textBox_Status.Text = text_string;
                //----------------------------------------
                // Cxg̃bZ[W\
                //----------------------------------------
                textBox_ReturnCode.Text = "ADϊG[FI";
            }
            base.WndProc(ref m);
        }
    }
}