﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
// カウンタヘッダー
using CcntCs;


namespace Counter
{
    /// <summary>
    /// Mode の概要の説明です。
    /// </summary>
    public class frmMode : System.Windows.Forms.Form
    {
        public System.Windows.Forms.Button btnCancel;
        public System.Windows.Forms.Button btnOK;
        public System.Windows.Forms.GroupBox Frame1;
        public System.Windows.Forms.ComboBox cboFilter;
        public System.Windows.Forms.ComboBox cboSyncClear;
        public System.Windows.Forms.ComboBox cboMul;
        public System.Windows.Forms.ComboBox cboPhase;
        public System.Windows.Forms.ComboBox cboCountDirection;
        public System.Windows.Forms.ComboBox cboSignalSource;
        public System.Windows.Forms.ComboBox cboZPhaseLogic;
        public System.Windows.Forms.ComboBox cboZPhaseMode;
        public System.Windows.Forms.Label Label8;
        public System.Windows.Forms.Label Label7;
        public System.Windows.Forms.Label Label6;
        public System.Windows.Forms.Label Label5;
        public System.Windows.Forms.Label Label4;
        public System.Windows.Forms.Label Label3;
        public System.Windows.Forms.Label Label2;
        public System.Windows.Forms.Label Label1;
        private System.ComponentModel.IContainer components = null;

        public struct StrNum
        {
            public string    Str;
            public short     Num;
            public           StrNum(string Str, short Num)
            {
                this.Str = Str;
                this.Num = Num;
            }
        };

        // Z相使用方法
        static StrNum[] ZPhaseMode = 
        {
            new StrNum("未使用",               (short)CcntConst.CNT_ZPHASE_NOT_USE),
            new StrNum("1回",                  (short)CcntConst.CNT_ZPHASE_NEXT_ONE),
            new StrNum("毎回",                 (short)CcntConst.CNT_ZPHASE_EVERY_TIME),
            new StrNum("End",                  0)
        };        
        // Z相論理
        static StrNum[] ZPhaseLogic = 
        {
            new StrNum("正論理",               (short)CcntConst.CNT_ZLOGIC_POSITIVE),
            new StrNum("負論理",               (short)CcntConst.CNT_ZLOGIC_NEGATIVE),
            new StrNum("End",                  0)
        };
        // 外部信号源
        static StrNum[] SignalSource = 
        {
            new StrNum("フォトカプラ絶縁",     (short)CcntConst.CNT_SIGTYPE_ISOLATE),
            new StrNum("TTL",                  (short)CcntConst.CNT_SIGTYPE_TTL),
            new StrNum("差動",                 (short)CcntConst.CNT_SIGTYPE_LINERECEIVER),
            new StrNum("End",                  0)
        };
        // カウント方向
        static StrNum[] CountDirection = 
        {
            new StrNum("ダウンカウント",       (short)CcntConst.CNT_DIR_DOWN),
            new StrNum("アップカウント",       (short)CcntConst.CNT_DIR_UP),
            new StrNum("End",                  0)
        };
        // 動作モード
        static StrNum[] Phase = 
        {
            new StrNum("単相",                 (short)CcntConst.CNT_MODE_1PHASE),
            new StrNum("2相",                  (short)CcntConst.CNT_MODE_2PHASE),
            new StrNum("ゲートコントロール",   (short)CcntConst.CNT_MODE_GATECONTROL),
            new StrNum("End",                  0)
        };    
        // 逓倍
        static StrNum[] Mul = 
        {
            new StrNum("1逓倍",                (short)CcntConst.CNT_MUL_X1),
            new StrNum("2逓倍",                (short)CcntConst.CNT_MUL_X2),
            new StrNum("4逓倍",                (short)CcntConst.CNT_MUL_X4),
            new StrNum("End",                  0)
        };
        // 同期/非同期クリア
        static StrNum[] SyncClear = 
        {
            new StrNum("非同期クリア",         (short)CcntConst.CNT_CLR_ASYNC),
            new StrNum("同期クリア",           (short)CcntConst.CNT_CLR_SYNC),
            new StrNum("End",                  0)
        };
        // デジタルフィルタ値
        static StrNum[] Filter = 
        {
            new StrNum("0",                    0x00),
            new StrNum("1",                    0x01),
            new StrNum("2",                    0x02),
            new StrNum("3",                    0x03),
            new StrNum("4",                    0x04),
            new StrNum("5",                    0x05),
            new StrNum("6",                    0x06),
            new StrNum("7",                    0x07),
            new StrNum("8",                    0x08),
            new StrNum("9",                    0x09),
            new StrNum("A",                    0x0a),
            new StrNum("B",                    0x0b),
            new StrNum("C",                    0x0c),
            new StrNum("D",                    0x0d),
            new StrNum("E",                    0x0e),
            new StrNum("F",                    0x0f),
            new StrNum("10",                   0x10),
            new StrNum("11",                   0x11),
            new StrNum("12",                   0x12),
            new StrNum("13",                   0x13),
            new StrNum("14",                   0x14),
            new StrNum("End",                  0)
        };

        // データ初期化
        static string                         szZPhaseMode = "未使用";
        static string                         szZPhaseLogic = "負論理";
        static string                         szSignalSource = "差動";
        static string                         szCountDirection = "アップカウント";
        static string                         szPhase = "2相";
        static string                         szMul = "1逓倍";
        static string                         szSyncClear = "非同期クリア";
        static string                         szFilter = "0";
        private System.Windows.Forms.Label    label9;
        public Label label10;
        Ccnt cnt = new Ccnt();

        public static short str_to_num(StrNum[] strnum, string str)
        {
            short    i;

            for (i=0; string.Compare(strnum[i].Str, "End") != 0; i++) 
            {
                if (string.Compare(strnum[i].Str, str) == 0) 
                {
                    return strnum[i].Num;
                }
            }
            return 0;
        }

        public static string num_to_str(StrNum[] strnum, short num)
        {
            short    i;

            for (i=0; string.Compare(strnum[i].Str, "End") != 0; i++) 
            {
                if (strnum[i].Num  == num) 
                {
                    return strnum[i].Str;
                }
            }
            return strnum[0].Str;
        }

        public frmMode()
        {
            //
            // Windows フォーム デザイナ サポートに必要です。
            //
            InitializeComponent();

            //
            // TODO: InitializeComponent 呼び出しの後に、コンストラクタ コードを追加してください。
            //
        }

        /// <summary>
        /// 使用されているリソースに後処理を実行します。
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// デザイナ サポートに必要なメソッドです。このメソッドの内容を
        /// コード エディタで変更しないでください。
        /// </summary>
        private void InitializeComponent()
        {
            this.label9 = new System.Windows.Forms.Label();
            this.btnCancel = new System.Windows.Forms.Button();
            this.btnOK = new System.Windows.Forms.Button();
            this.Frame1 = new System.Windows.Forms.GroupBox();
            this.cboFilter = new System.Windows.Forms.ComboBox();
            this.cboSyncClear = new System.Windows.Forms.ComboBox();
            this.cboMul = new System.Windows.Forms.ComboBox();
            this.cboPhase = new System.Windows.Forms.ComboBox();
            this.cboCountDirection = new System.Windows.Forms.ComboBox();
            this.cboSignalSource = new System.Windows.Forms.ComboBox();
            this.cboZPhaseLogic = new System.Windows.Forms.ComboBox();
            this.cboZPhaseMode = new System.Windows.Forms.ComboBox();
            this.Label8 = new System.Windows.Forms.Label();
            this.Label7 = new System.Windows.Forms.Label();
            this.Label6 = new System.Windows.Forms.Label();
            this.Label5 = new System.Windows.Forms.Label();
            this.Label4 = new System.Windows.Forms.Label();
            this.Label3 = new System.Windows.Forms.Label();
            this.Label2 = new System.Windows.Forms.Label();
            this.Label1 = new System.Windows.Forms.Label();
            this.label10 = new System.Windows.Forms.Label();
            this.Frame1.SuspendLayout();
            this.SuspendLayout();
            // 
            // label9
            // 
            this.label9.Location = new System.Drawing.Point(17, 243);
            this.label9.Name = "label9";
            this.label9.Size = new System.Drawing.Size(352, 24);
            this.label9.TabIndex = 10;
            this.label9.Text = "全てのチャネルにおいて同一の設定となります。";
            // 
            // btnCancel
            // 
            this.btnCancel.BackColor = System.Drawing.SystemColors.Control;
            this.btnCancel.Cursor = System.Windows.Forms.Cursors.Default;
            this.btnCancel.ForeColor = System.Drawing.SystemColors.ControlText;
            this.btnCancel.Location = new System.Drawing.Point(249, 267);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.btnCancel.Size = new System.Drawing.Size(97, 24);
            this.btnCancel.TabIndex = 8;
            this.btnCancel.Text = "ｷｬﾝｾﾙ";
            this.btnCancel.UseVisualStyleBackColor = false;
            this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
            // 
            // btnOK
            // 
            this.btnOK.BackColor = System.Drawing.SystemColors.Control;
            this.btnOK.Cursor = System.Windows.Forms.Cursors.Default;
            this.btnOK.ForeColor = System.Drawing.SystemColors.ControlText;
            this.btnOK.Location = new System.Drawing.Point(137, 267);
            this.btnOK.Name = "btnOK";
            this.btnOK.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.btnOK.Size = new System.Drawing.Size(97, 24);
            this.btnOK.TabIndex = 0;
            this.btnOK.Text = "OK";
            this.btnOK.UseVisualStyleBackColor = false;
            this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
            // 
            // Frame1
            // 
            this.Frame1.BackColor = System.Drawing.SystemColors.Control;
            this.Frame1.Controls.Add(this.label10);
            this.Frame1.Controls.Add(this.cboFilter);
            this.Frame1.Controls.Add(this.cboSyncClear);
            this.Frame1.Controls.Add(this.cboMul);
            this.Frame1.Controls.Add(this.cboPhase);
            this.Frame1.Controls.Add(this.cboCountDirection);
            this.Frame1.Controls.Add(this.cboSignalSource);
            this.Frame1.Controls.Add(this.cboZPhaseLogic);
            this.Frame1.Controls.Add(this.cboZPhaseMode);
            this.Frame1.Controls.Add(this.Label8);
            this.Frame1.Controls.Add(this.Label7);
            this.Frame1.Controls.Add(this.Label6);
            this.Frame1.Controls.Add(this.Label5);
            this.Frame1.Controls.Add(this.Label4);
            this.Frame1.Controls.Add(this.Label3);
            this.Frame1.Controls.Add(this.Label2);
            this.Frame1.Controls.Add(this.Label1);
            this.Frame1.ForeColor = System.Drawing.SystemColors.ControlText;
            this.Frame1.Location = new System.Drawing.Point(16, 11);
            this.Frame1.Name = "Frame1";
            this.Frame1.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Frame1.Size = new System.Drawing.Size(370, 225);
            this.Frame1.TabIndex = 9;
            this.Frame1.TabStop = false;
            this.Frame1.Text = "カウンタ モード";
            // 
            // cboFilter
            // 
            this.cboFilter.BackColor = System.Drawing.SystemColors.Window;
            this.cboFilter.Cursor = System.Windows.Forms.Cursors.Default;
            this.cboFilter.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cboFilter.ForeColor = System.Drawing.SystemColors.WindowText;
            this.cboFilter.Location = new System.Drawing.Point(132, 192);
            this.cboFilter.Name = "cboFilter";
            this.cboFilter.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.cboFilter.Size = new System.Drawing.Size(201, 20);
            this.cboFilter.TabIndex = 18;
            // 
            // cboSyncClear
            // 
            this.cboSyncClear.BackColor = System.Drawing.SystemColors.Window;
            this.cboSyncClear.Cursor = System.Windows.Forms.Cursors.Default;
            this.cboSyncClear.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cboSyncClear.ForeColor = System.Drawing.SystemColors.WindowText;
            this.cboSyncClear.Location = new System.Drawing.Point(132, 168);
            this.cboSyncClear.Name = "cboSyncClear";
            this.cboSyncClear.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.cboSyncClear.Size = new System.Drawing.Size(201, 20);
            this.cboSyncClear.TabIndex = 17;
            // 
            // cboMul
            // 
            this.cboMul.BackColor = System.Drawing.SystemColors.Window;
            this.cboMul.Cursor = System.Windows.Forms.Cursors.Default;
            this.cboMul.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cboMul.ForeColor = System.Drawing.SystemColors.WindowText;
            this.cboMul.Location = new System.Drawing.Point(132, 144);
            this.cboMul.Name = "cboMul";
            this.cboMul.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.cboMul.Size = new System.Drawing.Size(201, 20);
            this.cboMul.TabIndex = 16;
            // 
            // cboPhase
            // 
            this.cboPhase.BackColor = System.Drawing.SystemColors.Window;
            this.cboPhase.Cursor = System.Windows.Forms.Cursors.Default;
            this.cboPhase.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cboPhase.ForeColor = System.Drawing.SystemColors.WindowText;
            this.cboPhase.Location = new System.Drawing.Point(132, 120);
            this.cboPhase.Name = "cboPhase";
            this.cboPhase.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.cboPhase.Size = new System.Drawing.Size(201, 20);
            this.cboPhase.TabIndex = 15;
            // 
            // cboCountDirection
            // 
            this.cboCountDirection.BackColor = System.Drawing.SystemColors.Window;
            this.cboCountDirection.Cursor = System.Windows.Forms.Cursors.Default;
            this.cboCountDirection.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cboCountDirection.ForeColor = System.Drawing.SystemColors.WindowText;
            this.cboCountDirection.Location = new System.Drawing.Point(132, 96);
            this.cboCountDirection.Name = "cboCountDirection";
            this.cboCountDirection.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.cboCountDirection.Size = new System.Drawing.Size(201, 20);
            this.cboCountDirection.TabIndex = 14;
            // 
            // cboSignalSource
            // 
            this.cboSignalSource.BackColor = System.Drawing.SystemColors.Window;
            this.cboSignalSource.Cursor = System.Windows.Forms.Cursors.Default;
            this.cboSignalSource.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cboSignalSource.ForeColor = System.Drawing.SystemColors.WindowText;
            this.cboSignalSource.Location = new System.Drawing.Point(132, 72);
            this.cboSignalSource.Name = "cboSignalSource";
            this.cboSignalSource.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.cboSignalSource.Size = new System.Drawing.Size(201, 20);
            this.cboSignalSource.TabIndex = 13;
            // 
            // cboZPhaseLogic
            // 
            this.cboZPhaseLogic.BackColor = System.Drawing.SystemColors.Window;
            this.cboZPhaseLogic.Cursor = System.Windows.Forms.Cursors.Default;
            this.cboZPhaseLogic.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cboZPhaseLogic.ForeColor = System.Drawing.SystemColors.WindowText;
            this.cboZPhaseLogic.Location = new System.Drawing.Point(132, 48);
            this.cboZPhaseLogic.Name = "cboZPhaseLogic";
            this.cboZPhaseLogic.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.cboZPhaseLogic.Size = new System.Drawing.Size(201, 20);
            this.cboZPhaseLogic.TabIndex = 12;
            // 
            // cboZPhaseMode
            // 
            this.cboZPhaseMode.BackColor = System.Drawing.SystemColors.Window;
            this.cboZPhaseMode.Cursor = System.Windows.Forms.Cursors.Default;
            this.cboZPhaseMode.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cboZPhaseMode.ForeColor = System.Drawing.SystemColors.WindowText;
            this.cboZPhaseMode.Location = new System.Drawing.Point(132, 24);
            this.cboZPhaseMode.Name = "cboZPhaseMode";
            this.cboZPhaseMode.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.cboZPhaseMode.Size = new System.Drawing.Size(201, 20);
            this.cboZPhaseMode.TabIndex = 11;
            // 
            // Label8
            // 
            this.Label8.AutoSize = true;
            this.Label8.BackColor = System.Drawing.SystemColors.Control;
            this.Label8.Cursor = System.Windows.Forms.Cursors.Default;
            this.Label8.ForeColor = System.Drawing.SystemColors.ControlText;
            this.Label8.Location = new System.Drawing.Point(8, 196);
            this.Label8.Name = "Label8";
            this.Label8.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label8.Size = new System.Drawing.Size(94, 12);
            this.Label8.TabIndex = 10;
            this.Label8.Text = "デジタルフィルタ値：";
            // 
            // Label7
            // 
            this.Label7.AutoSize = true;
            this.Label7.BackColor = System.Drawing.SystemColors.Control;
            this.Label7.Cursor = System.Windows.Forms.Cursors.Default;
            this.Label7.ForeColor = System.Drawing.SystemColors.ControlText;
            this.Label7.Location = new System.Drawing.Point(8, 172);
            this.Label7.Name = "Label7";
            this.Label7.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label7.Size = new System.Drawing.Size(35, 12);
            this.Label7.TabIndex = 9;
            this.Label7.Text = "クリア：";
            // 
            // Label6
            // 
            this.Label6.AutoSize = true;
            this.Label6.BackColor = System.Drawing.SystemColors.Control;
            this.Label6.Cursor = System.Windows.Forms.Cursors.Default;
            this.Label6.ForeColor = System.Drawing.SystemColors.ControlText;
            this.Label6.Location = new System.Drawing.Point(8, 148);
            this.Label6.Name = "Label6";
            this.Label6.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label6.Size = new System.Drawing.Size(35, 12);
            this.Label6.TabIndex = 8;
            this.Label6.Text = "逓倍：";
            // 
            // Label5
            // 
            this.Label5.AutoSize = true;
            this.Label5.BackColor = System.Drawing.SystemColors.Control;
            this.Label5.Cursor = System.Windows.Forms.Cursors.Default;
            this.Label5.ForeColor = System.Drawing.SystemColors.ControlText;
            this.Label5.Location = new System.Drawing.Point(8, 124);
            this.Label5.Name = "Label5";
            this.Label5.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label5.Size = new System.Drawing.Size(35, 12);
            this.Label5.TabIndex = 7;
            this.Label5.Text = "相数：";
            // 
            // Label4
            // 
            this.Label4.AutoSize = true;
            this.Label4.BackColor = System.Drawing.SystemColors.Control;
            this.Label4.Cursor = System.Windows.Forms.Cursors.Default;
            this.Label4.ForeColor = System.Drawing.SystemColors.ControlText;
            this.Label4.Location = new System.Drawing.Point(8, 100);
            this.Label4.Name = "Label4";
            this.Label4.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label4.Size = new System.Drawing.Size(70, 12);
            this.Label4.TabIndex = 6;
            this.Label4.Text = "カウント方向：";
            // 
            // Label3
            // 
            this.Label3.AutoSize = true;
            this.Label3.BackColor = System.Drawing.SystemColors.Control;
            this.Label3.Cursor = System.Windows.Forms.Cursors.Default;
            this.Label3.ForeColor = System.Drawing.SystemColors.ControlText;
            this.Label3.Location = new System.Drawing.Point(8, 76);
            this.Label3.Name = "Label3";
            this.Label3.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label3.Size = new System.Drawing.Size(71, 12);
            this.Label3.TabIndex = 5;
            this.Label3.Text = "外部信号源：";
            // 
            // Label2
            // 
            this.Label2.AutoSize = true;
            this.Label2.BackColor = System.Drawing.SystemColors.Control;
            this.Label2.Cursor = System.Windows.Forms.Cursors.Default;
            this.Label2.ForeColor = System.Drawing.SystemColors.ControlText;
            this.Label2.Location = new System.Drawing.Point(8, 52);
            this.Label2.Name = "Label2";
            this.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label2.Size = new System.Drawing.Size(54, 12);
            this.Label2.TabIndex = 4;
            this.Label2.Text = "Z相論理：";
            // 
            // Label1
            // 
            this.Label1.AutoSize = true;
            this.Label1.BackColor = System.Drawing.SystemColors.Control;
            this.Label1.Cursor = System.Windows.Forms.Cursors.Default;
            this.Label1.ForeColor = System.Drawing.SystemColors.ControlText;
            this.Label1.Location = new System.Drawing.Point(8, 28);
            this.Label1.Name = "Label1";
            this.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label1.Size = new System.Drawing.Size(58, 12);
            this.Label1.TabIndex = 3;
            this.Label1.Text = "Z相モード：";
            // 
            // label10
            // 
            this.label10.AutoSize = true;
            this.label10.BackColor = System.Drawing.SystemColors.Control;
            this.label10.Cursor = System.Windows.Forms.Cursors.Default;
            this.label10.ForeColor = System.Drawing.SystemColors.ControlText;
            this.label10.Location = new System.Drawing.Point(339, 196);
            this.label10.Name = "label10";
            this.label10.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.label10.Size = new System.Drawing.Size(25, 12);
            this.label10.TabIndex = 11;
            this.label10.Text = "Hex";
            // 
            // frmMode
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
            this.ClientSize = new System.Drawing.Size(398, 302);
            this.Controls.Add(this.btnCancel);
            this.Controls.Add(this.btnOK);
            this.Controls.Add(this.Frame1);
            this.Controls.Add(this.label9);
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "frmMode";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "カウンタモード設定";
            this.Load += new System.EventHandler(this.frmMode_Load);
            this.Frame1.ResumeLayout(false);
            this.Frame1.PerformLayout();
            this.ResumeLayout(false);

        }
        #endregion

        //===================================================
        //    ダイアログ初期化
        //===================================================
        private void frmMode_Load(object sender, System.EventArgs e)
        {
            //===================================================
            //    コンボボックス初期化
            //===================================================
            short    i;
            // Z相使用方法
            for (i=0; string.Compare(ZPhaseMode[i].Str, "End") != 0; i++) 
            {
                cboZPhaseMode.Items.Add(ZPhaseMode[i].Str);
            }
            // Z相論理
            for (i=0; string.Compare(ZPhaseLogic[i].Str, "End") != 0; i++) 
            {
                cboZPhaseLogic.Items.Add(ZPhaseLogic[i].Str);
            }
            // 外部信号源
            for (i=0; string.Compare(SignalSource[i].Str, "End") != 0; i++) 
            {
                cboSignalSource.Items.Add(SignalSource[i].Str);
            }
            // カウント方向
            for (i=0; string.Compare(CountDirection[i].Str, "End") != 0; i++) 
            {
                cboCountDirection.Items.Add(CountDirection[i].Str);
            }
            // 動作モード
            for (i=0; string.Compare(Phase[i].Str, "End") != 0; i++) 
            {
                cboPhase.Items.Add(Phase[i].Str);
            }
            // 逓倍
            for (i=0; string.Compare(Mul[i].Str, "End") != 0; i++) 
            {
                cboMul.Items.Add(Mul[i].Str);
            }
            // 同期/非同期クリア
            for (i=0; string.Compare(SyncClear[i].Str, "End") != 0; i++) 
            {
                cboSyncClear.Items.Add(SyncClear[i].Str);
            }
            // デジタルフィルタ値
            for (i=0; string.Compare(Filter[i].Str, "End") != 0; i++) 
            {
                cboFilter.Items.Add(Filter[i].Str);
            }
            //-------------------------------
            // 初期データのセット
            //-------------------------------
            cboZPhaseMode.Text        = szZPhaseMode;
            cboZPhaseLogic.Text       = szZPhaseLogic;
            cboSignalSource.Text      = szSignalSource;
            cboCountDirection.Text    = szCountDirection;
            cboPhase.Text             = szPhase;
            cboMul.Text               = szMul;
            cboSyncClear.Text         = szSyncClear;
            cboFilter.Text            = szFilter;
        }

        //---------------------------------------------
        // 設定完了処理
        //---------------------------------------------
        private void btnOK_Click(object sender, System.EventArgs e)
        {
            short     ChNo;
            int       ret;
            string    str;
            string    error_string = new string(' ', 256);
            short     wZPhaseMode;
            short     wZPhaseLogic;
            short     wSignalSource;
            short     wCountDirection;
            short     wPhase;
            short     wMul;
            short     wSyncClear;
            short     wFilter;

            //-------------------------------
            // 設定情報の取得
            //-------------------------------
            szZPhaseMode       = cboZPhaseMode.Text;
            szZPhaseLogic      = cboZPhaseLogic.Text;
            szSignalSource     = cboSignalSource.Text;
            szCountDirection   = cboCountDirection.Text;
            szPhase            = cboPhase.Text;
            szMul              = cboMul.Text;
            szSyncClear        = cboSyncClear.Text;
            szFilter           = cboFilter.Text;

            wZPhaseMode        = str_to_num(ZPhaseMode, szZPhaseMode);
            wZPhaseLogic       = str_to_num(ZPhaseLogic, szZPhaseLogic);
            wSignalSource      = str_to_num(SignalSource, szSignalSource);
            wCountDirection    = str_to_num(CountDirection, szCountDirection);
            wPhase             = str_to_num(Phase, szPhase);
            wMul               = str_to_num(Mul, szMul);
            wSyncClear         = str_to_num(SyncClear, szSyncClear);
            wFilter            = str_to_num(Filter, szFilter);

            //-------------------------------
            // 設定情報をデバイスへセット
            //-------------------------------
            for (ChNo = 0; ChNo<frmCounter.ChannelNum; ChNo++) 
            {
                //---------------------------------------------
                // Z相使用方法 設定
                //---------------------------------------------
                ret = cnt.SetZMode(frmCounter.Id, ChNo, wZPhaseMode);
                if (ret != 0) 
                {
                    cnt.GetErrorString(ret, out error_string);
                    str = string.Format("CntSetZMode : ret = {0:X} h\n {1}", ret, error_string);
                    MessageBox.Show(str, "Error", MessageBoxButtons.OK);
                    break;
                }
                //---------------------------------------------
                // Z相論理 設定
                //---------------------------------------------
                ret = cnt.SetZLogic(frmCounter.Id, ChNo, wZPhaseLogic);
                if (ret != 0) 
                {
                    cnt.GetErrorString(ret, out error_string);
                    str = string.Format("CntSetZLogic : ret = {0:X} h\n {1}", ret, error_string);
                    MessageBox.Show(str, "Error", MessageBoxButtons.OK);
                    break;
                }
                //---------------------------------------------
                // 外部信号源 設定
                //---------------------------------------------
                ret = cnt.SelectChannelSignal(frmCounter.Id, ChNo, wSignalSource);
                if (ret != 0) 
                {
                    cnt.GetErrorString(ret, out error_string);
                    str = string.Format("CntSelectChannelSignal : ret = {0:X} h\n {1}", ret, error_string);
                    MessageBox.Show(str, "Error", MessageBoxButtons.OK);
                    break;
                }
                //---------------------------------------------
                // カウント方向 設定
                //---------------------------------------------
                ret = cnt.SetCountDirection(frmCounter.Id, ChNo, wCountDirection);
                if (ret != 0) 
                {
                    cnt.GetErrorString(ret, out error_string);
                    str = string.Format("CntSetCountDirection : ret = {0:X} h\n {1}", ret, error_string);
                    MessageBox.Show(str, "Error", MessageBoxButtons.OK);
                    break;
                }
                //---------------------------------------------
                // 動作モード 設定
                //---------------------------------------------
                ret = cnt.SetOperationMode(frmCounter.Id, ChNo, wPhase, wMul, wSyncClear);
                if (ret != 0) 
                {
                    cnt.GetErrorString(ret, out error_string);
                    str = string.Format("CntSetOperationMode : ret = {0:X} h\n {1}", ret, error_string);
                    MessageBox.Show(str, "Error", MessageBoxButtons.OK);
                    break;
                }
                //---------------------------------------------
                // デジタルフィルタ値 設定
                //---------------------------------------------
                ret = cnt.SetDigitalFilter(frmCounter.Id, ChNo, wFilter);
                if (ret != 0) 
                {
                    cnt.GetErrorString(ret, out error_string);
                    str = string.Format("CntSetOperationMode : ret = {0:X} h\n {1}", ret, error_string);
                    MessageBox.Show(str, "Error", MessageBoxButtons.OK);
                    break;
                }
            }
            this.Close();
        }

        //---------------------------------------------
        // キャンセル処理
        //---------------------------------------------
        private void btnCancel_Click(object sender, System.EventArgs e)
        {
            this.Close();
        }
    }
}
