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


namespace Counter
{
    /// <summary>
    /// Event の概要の説明です。
    /// </summary>
    public class frmEvent : System.Windows.Forms.Form
    {
        public System.Windows.Forms.Label Label8;
        public System.Windows.Forms.Button btnCancel;
        public System.Windows.Forms.ToolTip ToolTip1;
        public System.Windows.Forms.Label Label9;
        public System.Windows.Forms.GroupBox Frame4;
        public System.Windows.Forms.GroupBox Frame6;
        public System.Windows.Forms.Button btnOutPulse;
        public System.Windows.Forms.TextBox txtData;
        public System.Windows.Forms.TextBox txtChNo;
        public System.Windows.Forms.Label Label6;
        public System.Windows.Forms.Label Label5;
        public System.Windows.Forms.ComboBox cboPulseLength;
        public System.Windows.Forms.GroupBox Frame5;
        public System.Windows.Forms.RadioButton rdoAlarmError;
        public System.Windows.Forms.RadioButton rdoFilterError;
        public System.Windows.Forms.RadioButton rdoAiError;
        public System.Windows.Forms.RadioButton rdoCountMatch1;
        public System.Windows.Forms.RadioButton rdoCountMatch0;
        public System.Windows.Forms.RadioButton rdoGenOutput;
        public System.Windows.Forms.Label Label4;
        public System.Windows.Forms.Button btnOK;
        public System.Windows.Forms.GroupBox Frame7;
        public System.Windows.Forms.ComboBox cboCount;
        public System.Windows.Forms.Label Label7;
        public System.Windows.Forms.GroupBox Frame1;
        public System.Windows.Forms.GroupBox Frame3;
        public System.Windows.Forms.ComboBox cboRF1;
        public System.Windows.Forms.GroupBox Frame2;
        public System.Windows.Forms.TextBox txtPresetReg;
        public System.Windows.Forms.ComboBox cboRF0;
        public System.Windows.Forms.Label Label3;
        public System.Windows.Forms.Label Label2;
        public System.Windows.Forms.ComboBox cboInputEvent;
        public System.Windows.Forms.Label Label1;
        private System.ComponentModel.IContainer components = null;

        // 信号入力イベント
        static frmMode.StrNum[] InputEvent = 
        {
            new frmMode.StrNum("汎用入力",             (short)CcntConst.CNT_IEVENT_GENINP),
            new frmMode.StrNum("カウンタ 開始/停止",   (short)CcntConst.CNT_IEVENT_STARTSTOP),
            new frmMode.StrNum("カウンタ プリセット",  (short)CcntConst.CNT_IEVENT_PRESET),
            new frmMode.StrNum("カウンタ クリア",      (short)CcntConst.CNT_IEVENT_CLEAR),
            new frmMode.StrNum("End",                  0)
        };    
        
        // カウンタイベント
        static frmMode.StrNum[] CountEvent = 
        {
            new frmMode.StrNum("なし",                 (short)CcntConst.CNT_MATCH_NONE),
            new frmMode.StrNum("プリセット",           (short)CcntConst.CNT_MATCH_PRESET),
            new frmMode.StrNum("クリア",               (short)CcntConst.CNT_MATCH_CLEAR),
            new frmMode.StrNum("End",                  0)
        };

        // 立ち上がり/立下り
        static frmMode.StrNum[] RF = 
        {
            new frmMode.StrNum("立ち上がり",           (short)CcntConst.CNT_INP_RIZE),
            new frmMode.StrNum("立ち下り",             (short)CcntConst.CNT_INP_FALL),
            new frmMode.StrNum("なし",                 (short)CcntConst.CNT_INP_NONE),
            new frmMode.StrNum("End",                  0)
        };

        // パルス幅
        static frmMode.StrNum[] PulseLength = 
        {
            new frmMode.StrNum("0",                    0x00),
            new frmMode.StrNum("1",                    0x01),
            new frmMode.StrNum("2",                    0x02),
            new frmMode.StrNum("3",                    0x03),
            new frmMode.StrNum("4",                    0x04),
            new frmMode.StrNum("5",                    0x05),
            new frmMode.StrNum("6",                    0x06),
            new frmMode.StrNum("7",                    0x07),
            new frmMode.StrNum("8",                    0x08),
            new frmMode.StrNum("9",                    0x09),
            new frmMode.StrNum("A",                    0x0A),
            new frmMode.StrNum("B",                    0x0B),
            new frmMode.StrNum("C",                    0x0C),
            new frmMode.StrNum("D",                    0x0D),
            new frmMode.StrNum("E",                    0x0E),
            new frmMode.StrNum("F",                    0x0F),
            new frmMode.StrNum("End",                  0)
        };

        static string  szInputEvent = "汎用入力";
        static int     PresetReg = 0x1000;
        static short   RF0 = (short)CcntConst.CNT_INP_NONE;
        static short   RF1 = (short)CcntConst.CNT_INP_NONE;
        static int     OutputEvent = (int)CcntConst.CNT_OEVENT_GENOUT;
        static string  szPulseLength = "0";
        static string  szCount = "なし";
        public Label label10;
        Ccnt cnt    = new Ccnt();

        public frmEvent()
        {
            //
            // 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.components = new System.ComponentModel.Container();
            this.Label8 = new System.Windows.Forms.Label();
            this.btnCancel = new System.Windows.Forms.Button();
            this.ToolTip1 = new System.Windows.Forms.ToolTip(this.components);
            this.Label9 = new System.Windows.Forms.Label();
            this.Frame4 = new System.Windows.Forms.GroupBox();
            this.Frame6 = new System.Windows.Forms.GroupBox();
            this.btnOutPulse = new System.Windows.Forms.Button();
            this.txtData = new System.Windows.Forms.TextBox();
            this.txtChNo = new System.Windows.Forms.TextBox();
            this.Label6 = new System.Windows.Forms.Label();
            this.Label5 = new System.Windows.Forms.Label();
            this.cboPulseLength = new System.Windows.Forms.ComboBox();
            this.Frame5 = new System.Windows.Forms.GroupBox();
            this.rdoAlarmError = new System.Windows.Forms.RadioButton();
            this.rdoFilterError = new System.Windows.Forms.RadioButton();
            this.rdoAiError = new System.Windows.Forms.RadioButton();
            this.rdoCountMatch1 = new System.Windows.Forms.RadioButton();
            this.rdoCountMatch0 = new System.Windows.Forms.RadioButton();
            this.rdoGenOutput = new System.Windows.Forms.RadioButton();
            this.Label4 = new System.Windows.Forms.Label();
            this.btnOK = new System.Windows.Forms.Button();
            this.Frame7 = new System.Windows.Forms.GroupBox();
            this.cboCount = new System.Windows.Forms.ComboBox();
            this.Label7 = new System.Windows.Forms.Label();
            this.Frame1 = new System.Windows.Forms.GroupBox();
            this.Frame3 = new System.Windows.Forms.GroupBox();
            this.cboRF1 = new System.Windows.Forms.ComboBox();
            this.Frame2 = new System.Windows.Forms.GroupBox();
            this.txtPresetReg = new System.Windows.Forms.TextBox();
            this.cboRF0 = new System.Windows.Forms.ComboBox();
            this.Label3 = new System.Windows.Forms.Label();
            this.Label2 = new System.Windows.Forms.Label();
            this.cboInputEvent = new System.Windows.Forms.ComboBox();
            this.Label1 = new System.Windows.Forms.Label();
            this.label10 = new System.Windows.Forms.Label();
            this.Frame4.SuspendLayout();
            this.Frame6.SuspendLayout();
            this.Frame5.SuspendLayout();
            this.Frame7.SuspendLayout();
            this.Frame1.SuspendLayout();
            this.Frame3.SuspendLayout();
            this.Frame2.SuspendLayout();
            this.SuspendLayout();
            // 
            // Label8
            // 
            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(516, 97);
            this.Label8.Name = "Label8";
            this.Label8.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label8.Size = new System.Drawing.Size(193, 33);
            this.Label8.TabIndex = 46;
            this.Label8.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(620, 289);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.btnCancel.Size = new System.Drawing.Size(89, 24);
            this.btnCancel.TabIndex = 41;
            this.btnCancel.Text = "ｷｬﾝｾﾙ";
            this.btnCancel.UseVisualStyleBackColor = false;
            this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
            // 
            // Label9
            // 
            this.Label9.BackColor = System.Drawing.SystemColors.Control;
            this.Label9.Cursor = System.Windows.Forms.Cursors.Default;
            this.Label9.ForeColor = System.Drawing.SystemColors.ControlText;
            this.Label9.Location = new System.Drawing.Point(516, 161);
            this.Label9.Name = "Label9";
            this.Label9.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label9.Size = new System.Drawing.Size(193, 33);
            this.Label9.TabIndex = 45;
            this.Label9.Text = "カウント一致レジスタの設定は通知設定 ダイアログで行います。";
            // 
            // Frame4
            // 
            this.Frame4.BackColor = System.Drawing.SystemColors.Control;
            this.Frame4.Controls.Add(this.label10);
            this.Frame4.Controls.Add(this.Frame6);
            this.Frame4.Controls.Add(this.cboPulseLength);
            this.Frame4.Controls.Add(this.Frame5);
            this.Frame4.Controls.Add(this.Label4);
            this.Frame4.ForeColor = System.Drawing.SystemColors.ControlText;
            this.Frame4.Location = new System.Drawing.Point(252, 9);
            this.Frame4.Name = "Frame4";
            this.Frame4.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Frame4.Size = new System.Drawing.Size(257, 305);
            this.Frame4.TabIndex = 43;
            this.Frame4.TabStop = false;
            this.Frame4.Text = "イベント信号出力";
            // 
            // Frame6
            // 
            this.Frame6.BackColor = System.Drawing.SystemColors.Control;
            this.Frame6.Controls.Add(this.btnOutPulse);
            this.Frame6.Controls.Add(this.txtData);
            this.Frame6.Controls.Add(this.txtChNo);
            this.Frame6.Controls.Add(this.Label6);
            this.Frame6.Controls.Add(this.Label5);
            this.Frame6.ForeColor = System.Drawing.SystemColors.ControlText;
            this.Frame6.Location = new System.Drawing.Point(8, 216);
            this.Frame6.Name = "Frame6";
            this.Frame6.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Frame6.Size = new System.Drawing.Size(241, 81);
            this.Frame6.TabIndex = 22;
            this.Frame6.TabStop = false;
            this.Frame6.Text = "汎用出力";
            // 
            // btnOutPulse
            // 
            this.btnOutPulse.BackColor = System.Drawing.SystemColors.Control;
            this.btnOutPulse.Cursor = System.Windows.Forms.Cursors.Default;
            this.btnOutPulse.ForeColor = System.Drawing.SystemColors.ControlText;
            this.btnOutPulse.Location = new System.Drawing.Point(152, 32);
            this.btnOutPulse.Name = "btnOutPulse";
            this.btnOutPulse.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.btnOutPulse.Size = new System.Drawing.Size(81, 24);
            this.btnOutPulse.TabIndex = 27;
            this.btnOutPulse.Text = "信号出力";
            this.btnOutPulse.UseVisualStyleBackColor = false;
            this.btnOutPulse.Click += new System.EventHandler(this.btnOutPulse_Click);
            // 
            // txtData
            // 
            this.txtData.AcceptsReturn = true;
            this.txtData.BackColor = System.Drawing.SystemColors.Window;
            this.txtData.Cursor = System.Windows.Forms.Cursors.IBeam;
            this.txtData.ForeColor = System.Drawing.SystemColors.WindowText;
            this.txtData.Location = new System.Drawing.Point(88, 48);
            this.txtData.MaxLength = 0;
            this.txtData.Name = "txtData";
            this.txtData.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.txtData.Size = new System.Drawing.Size(57, 18);
            this.txtData.TabIndex = 26;
            this.txtData.Text = "Text2";
            // 
            // txtChNo
            // 
            this.txtChNo.AcceptsReturn = true;
            this.txtChNo.BackColor = System.Drawing.SystemColors.Window;
            this.txtChNo.Cursor = System.Windows.Forms.Cursors.IBeam;
            this.txtChNo.ForeColor = System.Drawing.SystemColors.WindowText;
            this.txtChNo.Location = new System.Drawing.Point(88, 24);
            this.txtChNo.MaxLength = 0;
            this.txtChNo.Name = "txtChNo";
            this.txtChNo.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.txtChNo.Size = new System.Drawing.Size(57, 18);
            this.txtChNo.TabIndex = 25;
            this.txtChNo.Text = "Text2";
            // 
            // Label6
            // 
            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, 49);
            this.Label6.Name = "Label6";
            this.Label6.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label6.Size = new System.Drawing.Size(65, 17);
            this.Label6.TabIndex = 24;
            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, 27);
            this.Label5.Name = "Label5";
            this.Label5.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label5.Size = new System.Drawing.Size(72, 12);
            this.Label5.TabIndex = 23;
            this.Label5.Text = "チャネル番号：";
            // 
            // cboPulseLength
            // 
            this.cboPulseLength.BackColor = System.Drawing.SystemColors.Window;
            this.cboPulseLength.Cursor = System.Windows.Forms.Cursors.Default;
            this.cboPulseLength.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cboPulseLength.ForeColor = System.Drawing.SystemColors.WindowText;
            this.cboPulseLength.Location = new System.Drawing.Point(106, 189);
            this.cboPulseLength.Name = "cboPulseLength";
            this.cboPulseLength.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.cboPulseLength.Size = new System.Drawing.Size(70, 20);
            this.cboPulseLength.TabIndex = 21;
            // 
            // Frame5
            // 
            this.Frame5.BackColor = System.Drawing.SystemColors.Control;
            this.Frame5.Controls.Add(this.rdoAlarmError);
            this.Frame5.Controls.Add(this.rdoFilterError);
            this.Frame5.Controls.Add(this.rdoAiError);
            this.Frame5.Controls.Add(this.rdoCountMatch1);
            this.Frame5.Controls.Add(this.rdoCountMatch0);
            this.Frame5.Controls.Add(this.rdoGenOutput);
            this.Frame5.ForeColor = System.Drawing.SystemColors.ControlText;
            this.Frame5.Location = new System.Drawing.Point(8, 24);
            this.Frame5.Name = "Frame5";
            this.Frame5.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Frame5.Size = new System.Drawing.Size(241, 153);
            this.Frame5.TabIndex = 13;
            this.Frame5.TabStop = false;
            this.Frame5.Text = "タイプ：";
            // 
            // rdoAlarmError
            // 
            this.rdoAlarmError.BackColor = System.Drawing.SystemColors.Control;
            this.rdoAlarmError.Cursor = System.Windows.Forms.Cursors.Default;
            this.rdoAlarmError.ForeColor = System.Drawing.SystemColors.ControlText;
            this.rdoAlarmError.Location = new System.Drawing.Point(16, 128);
            this.rdoAlarmError.Name = "rdoAlarmError";
            this.rdoAlarmError.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.rdoAlarmError.Size = new System.Drawing.Size(153, 17);
            this.rdoAlarmError.TabIndex = 19;
            this.rdoAlarmError.TabStop = true;
            this.rdoAlarmError.Text = "アラームエラー";
            this.rdoAlarmError.UseVisualStyleBackColor = false;
            this.rdoAlarmError.CheckedChanged += new System.EventHandler(this.rdoAlarmError_CheckedChanged);
            // 
            // rdoFilterError
            // 
            this.rdoFilterError.BackColor = System.Drawing.SystemColors.Control;
            this.rdoFilterError.Cursor = System.Windows.Forms.Cursors.Default;
            this.rdoFilterError.ForeColor = System.Drawing.SystemColors.ControlText;
            this.rdoFilterError.Location = new System.Drawing.Point(16, 108);
            this.rdoFilterError.Name = "rdoFilterError";
            this.rdoFilterError.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.rdoFilterError.Size = new System.Drawing.Size(153, 17);
            this.rdoFilterError.TabIndex = 18;
            this.rdoFilterError.TabStop = true;
            this.rdoFilterError.Text = "デジタルフィルタエラー";
            this.rdoFilterError.UseVisualStyleBackColor = false;
            this.rdoFilterError.CheckedChanged += new System.EventHandler(this.rdoFilterError_CheckedChanged);
            // 
            // rdoAiError
            // 
            this.rdoAiError.BackColor = System.Drawing.SystemColors.Control;
            this.rdoAiError.Cursor = System.Windows.Forms.Cursors.Default;
            this.rdoAiError.ForeColor = System.Drawing.SystemColors.ControlText;
            this.rdoAiError.Location = new System.Drawing.Point(16, 87);
            this.rdoAiError.Name = "rdoAiError";
            this.rdoAiError.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.rdoAiError.Size = new System.Drawing.Size(153, 17);
            this.rdoAiError.TabIndex = 17;
            this.rdoAiError.TabStop = true;
            this.rdoAiError.Text = "異常入力エラー";
            this.rdoAiError.UseVisualStyleBackColor = false;
            this.rdoAiError.CheckedChanged += new System.EventHandler(this.rdoAiError_CheckedChanged);
            // 
            // rdoCountMatch1
            // 
            this.rdoCountMatch1.BackColor = System.Drawing.SystemColors.Control;
            this.rdoCountMatch1.Cursor = System.Windows.Forms.Cursors.Default;
            this.rdoCountMatch1.ForeColor = System.Drawing.SystemColors.ControlText;
            this.rdoCountMatch1.Location = new System.Drawing.Point(16, 66);
            this.rdoCountMatch1.Name = "rdoCountMatch1";
            this.rdoCountMatch1.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.rdoCountMatch1.Size = new System.Drawing.Size(153, 17);
            this.rdoCountMatch1.TabIndex = 16;
            this.rdoCountMatch1.TabStop = true;
            this.rdoCountMatch1.Text = "カウント一致 REG1";
            this.rdoCountMatch1.UseVisualStyleBackColor = false;
            this.rdoCountMatch1.CheckedChanged += new System.EventHandler(this.rdoCountMatch1_CheckedChanged);
            // 
            // rdoCountMatch0
            // 
            this.rdoCountMatch0.BackColor = System.Drawing.SystemColors.Control;
            this.rdoCountMatch0.Cursor = System.Windows.Forms.Cursors.Default;
            this.rdoCountMatch0.ForeColor = System.Drawing.SystemColors.ControlText;
            this.rdoCountMatch0.Location = new System.Drawing.Point(16, 45);
            this.rdoCountMatch0.Name = "rdoCountMatch0";
            this.rdoCountMatch0.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.rdoCountMatch0.Size = new System.Drawing.Size(153, 17);
            this.rdoCountMatch0.TabIndex = 15;
            this.rdoCountMatch0.TabStop = true;
            this.rdoCountMatch0.Text = "カウント一致 REG0";
            this.rdoCountMatch0.UseVisualStyleBackColor = false;
            this.rdoCountMatch0.CheckedChanged += new System.EventHandler(this.rdoCountMatch0_CheckedChanged);
            // 
            // rdoGenOutput
            // 
            this.rdoGenOutput.BackColor = System.Drawing.SystemColors.Control;
            this.rdoGenOutput.Cursor = System.Windows.Forms.Cursors.Default;
            this.rdoGenOutput.ForeColor = System.Drawing.SystemColors.ControlText;
            this.rdoGenOutput.Location = new System.Drawing.Point(16, 24);
            this.rdoGenOutput.Name = "rdoGenOutput";
            this.rdoGenOutput.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.rdoGenOutput.Size = new System.Drawing.Size(153, 17);
            this.rdoGenOutput.TabIndex = 14;
            this.rdoGenOutput.TabStop = true;
            this.rdoGenOutput.Text = "汎用出力";
            this.rdoGenOutput.UseVisualStyleBackColor = false;
            this.rdoGenOutput.CheckedChanged += new System.EventHandler(this.rdoGenOutput_CheckedChanged);
            // 
            // 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(16, 192);
            this.Label4.Name = "Label4";
            this.Label4.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label4.Size = new System.Drawing.Size(84, 12);
            this.Label4.TabIndex = 20;
            this.Label4.Text = "パルス幅(係数)：";
            // 
            // 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(524, 289);
            this.btnOK.Name = "btnOK";
            this.btnOK.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.btnOK.Size = new System.Drawing.Size(89, 24);
            this.btnOK.TabIndex = 0;
            this.btnOK.Text = "OK";
            this.btnOK.UseVisualStyleBackColor = false;
            this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
            // 
            // Frame7
            // 
            this.Frame7.BackColor = System.Drawing.SystemColors.Control;
            this.Frame7.Controls.Add(this.cboCount);
            this.Frame7.Controls.Add(this.Label7);
            this.Frame7.ForeColor = System.Drawing.SystemColors.ControlText;
            this.Frame7.Location = new System.Drawing.Point(516, 9);
            this.Frame7.Name = "Frame7";
            this.Frame7.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Frame7.Size = new System.Drawing.Size(193, 65);
            this.Frame7.TabIndex = 44;
            this.Frame7.TabStop = false;
            this.Frame7.Text = "カウント一致イベント";
            // 
            // cboCount
            // 
            this.cboCount.BackColor = System.Drawing.SystemColors.Window;
            this.cboCount.Cursor = System.Windows.Forms.Cursors.Default;
            this.cboCount.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cboCount.ForeColor = System.Drawing.SystemColors.WindowText;
            this.cboCount.Location = new System.Drawing.Point(64, 28);
            this.cboCount.Name = "cboCount";
            this.cboCount.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.cboCount.Size = new System.Drawing.Size(121, 20);
            this.cboCount.TabIndex = 30;
            this.cboCount.SelectedIndexChanged += new System.EventHandler(this.cboCount_SelectedIndexChanged);
            // 
            // 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, 32);
            this.Label7.Name = "Label7";
            this.Label7.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label7.Size = new System.Drawing.Size(37, 12);
            this.Label7.TabIndex = 29;
            this.Label7.Text = "タイプ：";
            // 
            // Frame1
            // 
            this.Frame1.BackColor = System.Drawing.SystemColors.Control;
            this.Frame1.Controls.Add(this.Frame3);
            this.Frame1.Controls.Add(this.Frame2);
            this.Frame1.Controls.Add(this.cboInputEvent);
            this.Frame1.Controls.Add(this.Label1);
            this.Frame1.ForeColor = System.Drawing.SystemColors.ControlText;
            this.Frame1.Location = new System.Drawing.Point(12, 9);
            this.Frame1.Name = "Frame1";
            this.Frame1.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Frame1.Size = new System.Drawing.Size(233, 305);
            this.Frame1.TabIndex = 42;
            this.Frame1.TabStop = false;
            this.Frame1.Text = "イベント信号入力";
            // 
            // Frame3
            // 
            this.Frame3.BackColor = System.Drawing.SystemColors.Control;
            this.Frame3.Controls.Add(this.cboRF1);
            this.Frame3.ForeColor = System.Drawing.SystemColors.ControlText;
            this.Frame3.Location = new System.Drawing.Point(8, 168);
            this.Frame3.Name = "Frame3";
            this.Frame3.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Frame3.Size = new System.Drawing.Size(217, 73);
            this.Frame3.TabIndex = 10;
            this.Frame3.TabStop = false;
            this.Frame3.Text = "RF1 (停止)";
            // 
            // cboRF1
            // 
            this.cboRF1.BackColor = System.Drawing.SystemColors.Window;
            this.cboRF1.Cursor = System.Windows.Forms.Cursors.Default;
            this.cboRF1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cboRF1.ForeColor = System.Drawing.SystemColors.WindowText;
            this.cboRF1.Location = new System.Drawing.Point(8, 32);
            this.cboRF1.Name = "cboRF1";
            this.cboRF1.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.cboRF1.Size = new System.Drawing.Size(177, 20);
            this.cboRF1.TabIndex = 11;
            // 
            // Frame2
            // 
            this.Frame2.BackColor = System.Drawing.SystemColors.Control;
            this.Frame2.Controls.Add(this.txtPresetReg);
            this.Frame2.Controls.Add(this.cboRF0);
            this.Frame2.Controls.Add(this.Label3);
            this.Frame2.Controls.Add(this.Label2);
            this.Frame2.ForeColor = System.Drawing.SystemColors.ControlText;
            this.Frame2.Location = new System.Drawing.Point(8, 64);
            this.Frame2.Name = "Frame2";
            this.Frame2.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Frame2.Size = new System.Drawing.Size(217, 89);
            this.Frame2.TabIndex = 5;
            this.Frame2.TabStop = false;
            this.Frame2.Text = "RF0 (クリア/プリセット/開始)";
            // 
            // txtPresetReg
            // 
            this.txtPresetReg.AcceptsReturn = true;
            this.txtPresetReg.BackColor = System.Drawing.SystemColors.Window;
            this.txtPresetReg.Cursor = System.Windows.Forms.Cursors.IBeam;
            this.txtPresetReg.ForeColor = System.Drawing.SystemColors.WindowText;
            this.txtPresetReg.Location = new System.Drawing.Point(112, 53);
            this.txtPresetReg.MaxLength = 0;
            this.txtPresetReg.Name = "txtPresetReg";
            this.txtPresetReg.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.txtPresetReg.Size = new System.Drawing.Size(73, 18);
            this.txtPresetReg.TabIndex = 8;
            this.txtPresetReg.Text = "Text1";
            // 
            // cboRF0
            // 
            this.cboRF0.BackColor = System.Drawing.SystemColors.Window;
            this.cboRF0.Cursor = System.Windows.Forms.Cursors.Default;
            this.cboRF0.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cboRF0.ForeColor = System.Drawing.SystemColors.WindowText;
            this.cboRF0.Location = new System.Drawing.Point(8, 24);
            this.cboRF0.Name = "cboRF0";
            this.cboRF0.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.cboRF0.Size = new System.Drawing.Size(177, 20);
            this.cboRF0.TabIndex = 6;
            // 
            // 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(192, 56);
            this.Label3.Name = "Label3";
            this.Label3.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label3.Size = new System.Drawing.Size(25, 12);
            this.Label3.TabIndex = 9;
            this.Label3.Text = "Hex";
            // 
            // 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, 56);
            this.Label2.Name = "Label2";
            this.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label2.Size = new System.Drawing.Size(92, 12);
            this.Label2.TabIndex = 7;
            this.Label2.Text = "プリセット レジスタ：";
            // 
            // cboInputEvent
            // 
            this.cboInputEvent.BackColor = System.Drawing.SystemColors.Window;
            this.cboInputEvent.Cursor = System.Windows.Forms.Cursors.Default;
            this.cboInputEvent.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cboInputEvent.ForeColor = System.Drawing.SystemColors.WindowText;
            this.cboInputEvent.Location = new System.Drawing.Point(56, 20);
            this.cboInputEvent.Name = "cboInputEvent";
            this.cboInputEvent.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.cboInputEvent.Size = new System.Drawing.Size(145, 20);
            this.cboInputEvent.TabIndex = 4;
            this.cboInputEvent.SelectedIndexChanged += new System.EventHandler(this.cboInputEvent_SelectedIndexChanged);
            // 
            // 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, 24);
            this.Label1.Name = "Label1";
            this.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label1.Size = new System.Drawing.Size(37, 12);
            this.Label1.TabIndex = 3;
            this.Label1.Text = "タイプ：";
            // 
            // 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(182, 192);
            this.label10.Name = "label10";
            this.label10.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.label10.Size = new System.Drawing.Size(25, 12);
            this.label10.TabIndex = 23;
            this.label10.Text = "Hex";
            // 
            // frmEvent
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
            this.ClientSize = new System.Drawing.Size(720, 322);
            this.Controls.Add(this.btnCancel);
            this.Controls.Add(this.Label9);
            this.Controls.Add(this.Frame4);
            this.Controls.Add(this.btnOK);
            this.Controls.Add(this.Frame7);
            this.Controls.Add(this.Frame1);
            this.Controls.Add(this.Label8);
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "frmEvent";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "ハードウェアイベント設定";
            this.Load += new System.EventHandler(this.frmEvent_Load);
            this.Frame4.ResumeLayout(false);
            this.Frame4.PerformLayout();
            this.Frame6.ResumeLayout(false);
            this.Frame6.PerformLayout();
            this.Frame5.ResumeLayout(false);
            this.Frame7.ResumeLayout(false);
            this.Frame7.PerformLayout();
            this.Frame1.ResumeLayout(false);
            this.Frame1.PerformLayout();
            this.Frame3.ResumeLayout(false);
            this.Frame2.ResumeLayout(false);
            this.Frame2.PerformLayout();
            this.ResumeLayout(false);

        }
        #endregion

        //===================================================
        //    ダイアログ初期化
        //===================================================
        private void frmEvent_Load(object sender, System.EventArgs e)
        {
            //===================================================
            //    コンボボックス初期化
            //===================================================
            short    i;
            for( i = 0; string.Compare(InputEvent[i].Str, "End") != 0; i++ )
            {
                cboInputEvent.Items.Add(InputEvent[i].Str);
            }
            for (i=0; string.Compare(RF[i].Str, "End") != 0; i++)
            {
                cboRF0.Items.Add(RF[i].Str);
            }
            for (i=0; string.Compare(RF[i].Str, "End") != 0; i++)
            {
                cboRF1.Items.Add(RF[i].Str);
            }
            for (i=0; string.Compare(PulseLength[i].Str, "End") != 0; i++)
            {
                cboPulseLength.Items.Add(PulseLength[i].Str);
            }          
            for (i=0; string.Compare(CountEvent[i].Str, "End") != 0; i++)
            {
                cboCount.Items.Add(CountEvent[i].Str);
            }          
            //===================================================
            //    データ初期化
            //===================================================
            // イベント信号入力
            string    szBuf = new string(' ', 100);
            cboInputEvent.Text = szInputEvent;
            szBuf              = string.Format("{0:X}", PresetReg);
            txtPresetReg.Text  = szBuf;
            cboRF0.Text        = frmMode.num_to_str(RF, RF0);
            cboRF1.Text        = frmMode.num_to_str(RF, RF1);
            cboCount.Text      = szCount;
            cboInputEvent_SelectedIndexChanged(cboInputEvent, new System.EventArgs());
            // イベント信号出力
            if (OutputEvent == (int)CcntConst.CNT_OEVENT_GENOUT) 
            {
                rdoGenOutput.Checked   = true;
                cboPulseLength.Enabled = false;
                txtChNo.Enabled        = true;
                txtData.Enabled        = true;
                btnOutPulse.Enabled    = true;
            }
            if ((OutputEvent & (int)CcntConst.CNT_OEVENT_MATCH0) != 0)
            {
                rdoCountMatch0.Checked = true;
                cboPulseLength.Enabled = true;
                txtChNo.Enabled        = false;
                txtData.Enabled        = false;
                btnOutPulse.Enabled    = false;
            }
            if ((OutputEvent & (int)CcntConst.CNT_OEVENT_MATCH1) != 0)
            {
                rdoCountMatch1.Checked = true;
                cboPulseLength.Enabled = true;
                txtChNo.Enabled        = false;
                txtData.Enabled        = false;
                btnOutPulse.Enabled    = false;
            }
            if ((OutputEvent & (int)CcntConst.CNT_OEVENT_AIERR) != 0) 
            {
                rdoAiError.Checked     = true;
                cboPulseLength.Enabled = true;
                txtChNo.Enabled        = false;
                txtData.Enabled        = false;
                btnOutPulse.Enabled    = false;
            }
            if ((OutputEvent & (int)CcntConst.CNT_OEVENT_FLTERR) != 0) 
            {
                rdoFilterError.Checked = true;
                cboPulseLength.Enabled = true;
                txtChNo.Enabled        = false;
                txtData.Enabled        = false;
                btnOutPulse.Enabled    = false;
            }
            if ((OutputEvent & (int)CcntConst.CNT_OEVENT_ALMERR) != 0) 
            {
                rdoAlarmError.Checked  = true;
                cboPulseLength.Enabled = true;
                txtChNo.Enabled        = false;
                txtData.Enabled        = false;
                btnOutPulse.Enabled    = false;
            }
            cboPulseLength.Text = szPulseLength;
            txtChNo.Text = "0";
            txtData.Text = "1";
        }

        //---------------------------------------------
        // 設定完了処理
        //---------------------------------------------
        private void btnOK_Click(object sender, System.EventArgs e)
        {
            uint      dwInputEvent;
            short     wPulseLength;
            uint      dwCountEvent;
            short     ChNo;
            int       ret;
            string    str;
            string    buf = new string(' ', 100);
            string    error_string = new string(' ', 256);

            //-------------------------------
            // 設定情報取得
            //-------------------------------
            // イベント信号入力
            szInputEvent = cboInputEvent.Text;
            dwInputEvent = (uint)frmMode.str_to_num(InputEvent, szInputEvent);

            buf = txtPresetReg.Text;
            PresetReg = int.Parse(buf, NumberStyles.HexNumber);

            buf = cboRF0.Text;
            RF0 = frmMode.str_to_num(RF, buf);

            buf = cboRF1.Text;
            RF1 = frmMode.str_to_num(RF, buf);
            // イベント信号出力
            OutputEvent = (int)CcntConst.CNT_OEVENT_GENOUT;

            if (rdoCountMatch0.Checked == true) 
            {
                OutputEvent |= (int)CcntConst.CNT_OEVENT_MATCH0;
            }
            else if (rdoCountMatch1.Checked == true) 
            {
                OutputEvent |= (int)CcntConst.CNT_OEVENT_MATCH1;
            }
            else if (rdoAiError.Checked == true) 
            {
                OutputEvent |= (int)CcntConst.CNT_OEVENT_AIERR;
            }
            else if (rdoFilterError.Checked == true) 
            {
                OutputEvent |= (int)CcntConst.CNT_OEVENT_FLTERR;
            }
            else if (rdoAlarmError.Checked == true) 
            {
                OutputEvent |= (int)CcntConst.CNT_OEVENT_ALMERR;
            }
            szPulseLength  = cboPulseLength.Text;
            wPulseLength   = frmMode.str_to_num(PulseLength, szPulseLength);
            // カウント一致イベント
            szCount        = cboCount.Text;
            dwCountEvent   = (uint)frmMode.str_to_num(CountEvent, szCount);

            //-------------------------------
            // 設定情報をデバイスへセット
            //-------------------------------
            for (ChNo=0; ChNo<frmCounter.ChannelNum; ChNo++) 
            {
                //---------------------------------------------
                // 制御入力信号のハードウェアイベント設定
                //---------------------------------------------
                ret = cnt.SetInputHardwareEvent(frmCounter.Id, ChNo, dwInputEvent, RF0, RF1, 0);
                if (ret != 0) 
                {
                    cnt.GetErrorString(ret, out error_string);
                    str = string.Format("CntSetInputHardwareEvent : ret = {0:X} h\n {1}", ret, error_string);
                    MessageBox.Show(str, "Error", MessageBoxButtons.OK);
                    goto ERR_END;
                }
                //---------------------------------------------
                // プリセットレジスタの設定
                //---------------------------------------------
                if (dwInputEvent == (uint)CcntConst.CNT_IEVENT_PRESET || dwCountEvent == (uint)CcntConst.CNT_MATCH_PRESET)
                {
                    ret = cnt.SetPresetRegister(frmCounter.Id, ChNo, (uint)PresetReg, 0);
                    if (ret != 0) 
                    {
                        cnt.GetErrorString(ret, out error_string);
                        str = string.Format("CntSetPresetRegister : ret = {0:X} h\n {1}", ret, error_string);
                        MessageBox.Show(str, "Error", MessageBoxButtons.OK);
                        goto ERR_END;
                    }
                }
                //---------------------------------------------
                // 制御出力信号のハードウェアイベント設定
                //---------------------------------------------
                ret = cnt.SetOutputHardwareEvent(frmCounter.Id, ChNo, 0, (uint)OutputEvent, wPulseLength);
                if (ret != 0) 
                {
                    cnt.GetErrorString(ret, out error_string);
                    str = string.Format("CntSetOutputHardwareEvent : ret = {0:X} h\n {1}", ret, error_string);
                    MessageBox.Show(str, "Error", MessageBoxButtons.OK);
                    goto ERR_END;
                }
                //---------------------------------------------
                // カウント一致のハードウェアイベント設定
                //---------------------------------------------
                ret = cnt.SetCountMatchHardwareEvent(frmCounter.Id, ChNo, 0, dwCountEvent, 0);
                if (ret != 0) 
                {
                    cnt.GetErrorString(ret, out error_string);
                    str = string.Format("CntSetCountMatchHardwareEvent : ret = {0:X} h\n {1}", ret, error_string);
                    MessageBox.Show(str, "Error", MessageBoxButtons.OK);
                    goto ERR_END;
                }
            }
            ERR_END:
                this.Close();
        }

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

        //---------------------------------------------
        // イベント信号入力 設定
        //---------------------------------------------
        private void cboInputEvent_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            string    szInput = new string(' ', 100);
            string    szCount = new string(' ', 100);

            szInput = cboInputEvent.Text;
            szCount = cboCount.Text;
            if (string.Compare(szInput, "汎用入力") == 0) 
            {
                cboRF0.Text          = "None";
                cboRF1.Text          = "None";
                cboRF0.Enabled       = false;
                cboRF1.Enabled       = false;
                txtPresetReg.Enabled = false;
            }
            if (string.Compare(szInput, "カウンタ 開始/停止") == 0) 
            {
                cboRF0.Enabled       = true;
                cboRF1.Enabled       = true;
                txtPresetReg.Enabled = false;
            }
            if (string.Compare(szInput, "カウンタ プリセット") == 0) 
            {
                cboRF0.Enabled       = true;
                cboRF1.Text          = "None";
                cboRF1.Enabled       = false;
                txtPresetReg.Enabled = true;
            }
            if (string.Compare(szInput, "カウンタ クリア") == 0) 
            {
                cboRF0.Enabled       = true;
                cboRF1.Text          = "None";
                cboRF1.Enabled       = false;
                txtPresetReg.Enabled = false;
            }
            if (string.Compare(szCount, "プリセット") == 0) 
            {
                txtPresetReg.Enabled = true;
            }

        }

        private void cboCount_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            cboInputEvent_SelectedIndexChanged(cboInputEvent, new System.EventArgs());
        }

        //---------------------------------------------
        // イベント信号出力 設定
        //---------------------------------------------
        private void rdoGenOutput_CheckedChanged(object sender, System.EventArgs e)
        {
            cboPulseLength.Enabled = false;
            txtChNo.Enabled        = true;
            txtData.Enabled        = true;
            btnOutPulse.Enabled    = true;
        }

        private void rdoCountMatch0_CheckedChanged(object sender, System.EventArgs e)
        {
            cboPulseLength.Enabled = true;
            txtChNo.Enabled = false;
            txtData.Enabled = false;
            btnOutPulse.Enabled = false;

        }

        private void rdoCountMatch1_CheckedChanged(object sender, System.EventArgs e)
        {
            cboPulseLength.Enabled = true;
            txtChNo.Enabled        = false;
            txtData.Enabled        = false;
            btnOutPulse.Enabled    = false;
        }

        private void rdoAiError_CheckedChanged(object sender, System.EventArgs e)
        {
            cboPulseLength.Enabled = true;
            txtChNo.Enabled        = false;
            txtData.Enabled        = false;
            btnOutPulse.Enabled    = false;
        }

        private void rdoFilterError_CheckedChanged(object sender, System.EventArgs e)
        {
            cboPulseLength.Enabled = true;
            txtChNo.Enabled        = false;
            txtData.Enabled        = false;
            btnOutPulse.Enabled    = false;
        }

        private void rdoAlarmError_CheckedChanged(object sender, System.EventArgs e)
        {
            cboPulseLength.Enabled = true;
            txtChNo.Enabled        = false;
            txtData.Enabled        = false;
            btnOutPulse.Enabled    = false;
        }

        //---------------------------------------------
        // 信号出力 処理
        //---------------------------------------------
        private void btnOutPulse_Click(object sender, System.EventArgs e)
        {
            string    buf = new string(' ', 100);
            short     ChNo;
            byte      Data;
            int       ret;
            string    str;
            string    error_string = new string(' ', 256);

            buf = txtChNo.Text;
            try
            {
                ChNo = short.Parse(buf);
            }
            catch (System.FormatException)
            {
                ChNo = 0;
            }
            buf = txtData.Text;
            try
            {
                Data = byte.Parse(buf);
            }
            catch (System.FormatException)
            {
                Data = 0;
            }

            //---------------------------------------------
            // 汎用出力処理
            //---------------------------------------------
            ret = cnt.OutputDOBit(frmCounter.Id, ChNo, 0, Data);
            if (ret != 0) 
            {
                cnt.GetErrorString(ret, out error_string);
                str = string.Format("CntOutPulse : ret = {0:X} h\n {1}", ret, error_string);
                MessageBox.Show(str, "Error", MessageBoxButtons.OK);
            }

        }


    }
}
