﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Globalization;
// Counter header
using CcntCs;

namespace CounterCallback
{
    /// <summary>
    /// Summary description for EventDlg.
    /// </summary>
    public class EventDlg : System.Windows.Forms.Form
    {
        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.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;
        public System.Windows.Forms.GroupBox Frame7;
        public System.Windows.Forms.ComboBox cboCount;
        public System.Windows.Forms.Label Label7;
        public System.Windows.Forms.Label Label8;
        public System.Windows.Forms.Button btnCancel;
        public System.Windows.Forms.Button btnOK;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        // Signal input event
        static ModeDlg.StrNum[] InputEvent = 
        {
            new ModeDlg.StrNum("General Input",        (short)CcntConst.CNT_IEVENT_GENINP),
            new ModeDlg.StrNum("Counter Start/Stop",   (short)CcntConst.CNT_IEVENT_STARTSTOP),
            new ModeDlg.StrNum("Counter Preset",       (short)CcntConst.CNT_IEVENT_PRESET),
            new ModeDlg.StrNum("Counter Clear",        (short)CcntConst.CNT_IEVENT_CLEAR),
            new ModeDlg.StrNum("End",                  0)
        };    
        
        // Counter event
        static ModeDlg.StrNum[] CountEvent = 
        {
            new ModeDlg.StrNum("None",                 (short)CcntConst.CNT_MATCH_NONE),
            new ModeDlg.StrNum("Preset",               (short)CcntConst.CNT_MATCH_PRESET),
            new ModeDlg.StrNum("Clear",                (short)CcntConst.CNT_MATCH_CLEAR),
            new ModeDlg.StrNum("End",                  0)
        };

        // Rise/Fall
        static ModeDlg.StrNum[] RF = 
        {
            new ModeDlg.StrNum("Rise",                 (short)CcntConst.CNT_INP_RIZE),
            new ModeDlg.StrNum("Fall",                 (short)CcntConst.CNT_INP_FALL),
            new ModeDlg.StrNum("None",                 (short)CcntConst.CNT_INP_NONE),
            new ModeDlg.StrNum("End",                  0)
        };

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

        static string  szInputEvent = "General Input";
        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 = "None";
        public Label label10;
        Ccnt cnt    = new Ccnt();

        public EventDlg()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            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.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.Frame7 = new System.Windows.Forms.GroupBox();
            this.cboCount = new System.Windows.Forms.ComboBox();
            this.Label7 = new System.Windows.Forms.Label();
            this.Label8 = new System.Windows.Forms.Label();
            this.btnCancel = new System.Windows.Forms.Button();
            this.btnOK = new System.Windows.Forms.Button();
            this.label10 = new System.Windows.Forms.Label();
            this.Frame4.SuspendLayout();
            this.Frame6.SuspendLayout();
            this.Frame5.SuspendLayout();
            this.Frame1.SuspendLayout();
            this.Frame3.SuspendLayout();
            this.Frame2.SuspendLayout();
            this.Frame7.SuspendLayout();
            this.SuspendLayout();
            // 
            // 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(480, 170);
            this.Label9.Name = "Label9";
            this.Label9.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label9.Size = new System.Drawing.Size(176, 36);
            this.Label9.TabIndex = 45;
            this.Label9.Text = "The count match register is set in the Notification Setting dialog.";
            // 
            // 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(223, 7);
            this.Frame4.Name = "Frame4";
            this.Frame4.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Frame4.Size = new System.Drawing.Size(249, 318);
            this.Frame4.TabIndex = 43;
            this.Frame4.TabStop = false;
            this.Frame4.Text = "Event Signal Output";
            // 
            // 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, 220);
            this.Frame6.Name = "Frame6";
            this.Frame6.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Frame6.Size = new System.Drawing.Size(232, 87);
            this.Frame6.TabIndex = 9;
            this.Frame6.TabStop = false;
            this.Frame6.Text = "General Output";
            // 
            // 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(144, 34);
            this.btnOutPulse.Name = "btnOutPulse";
            this.btnOutPulse.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.btnOutPulse.Size = new System.Drawing.Size(81, 26);
            this.btnOutPulse.TabIndex = 27;
            this.btnOutPulse.Text = "Signal Output";
            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, 52);
            this.txtData.MaxLength = 0;
            this.txtData.Name = "txtData";
            this.txtData.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.txtData.Size = new System.Drawing.Size(48, 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, 26);
            this.txtChNo.MaxLength = 0;
            this.txtChNo.Name = "txtChNo";
            this.txtChNo.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.txtChNo.Size = new System.Drawing.Size(48, 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, 52);
            this.Label6.Name = "Label6";
            this.Label6.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label6.Size = new System.Drawing.Size(65, 18);
            this.Label6.TabIndex = 24;
            this.Label6.Text = "Data:";
            // 
            // 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, 30);
            this.Label5.Name = "Label5";
            this.Label5.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label5.Size = new System.Drawing.Size(68, 12);
            this.Label5.TabIndex = 23;
            this.Label5.Text = "Channel No.:";
            // 
            // 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(157, 193);
            this.cboPulseLength.Name = "cboPulseLength";
            this.cboPulseLength.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.cboPulseLength.Size = new System.Drawing.Size(56, 20);
            this.cboPulseLength.TabIndex = 8;
            // 
            // 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, 20);
            this.Frame5.Name = "Frame5";
            this.Frame5.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Frame5.Size = new System.Drawing.Size(232, 165);
            this.Frame5.TabIndex = 7;
            this.Frame5.TabStop = false;
            this.Frame5.Text = "Type:";
            // 
            // 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, 138);
            this.rdoAlarmError.Name = "rdoAlarmError";
            this.rdoAlarmError.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.rdoAlarmError.Size = new System.Drawing.Size(153, 18);
            this.rdoAlarmError.TabIndex = 19;
            this.rdoAlarmError.TabStop = true;
            this.rdoAlarmError.Text = "Alarm Error";
            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, 116);
            this.rdoFilterError.Name = "rdoFilterError";
            this.rdoFilterError.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.rdoFilterError.Size = new System.Drawing.Size(153, 18);
            this.rdoFilterError.TabIndex = 18;
            this.rdoFilterError.TabStop = true;
            this.rdoFilterError.Text = "Digital Filter Error";
            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, 93);
            this.rdoAiError.Name = "rdoAiError";
            this.rdoAiError.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.rdoAiError.Size = new System.Drawing.Size(153, 19);
            this.rdoAiError.TabIndex = 17;
            this.rdoAiError.TabStop = true;
            this.rdoAiError.Text = "Abnormal Input Error";
            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, 71);
            this.rdoCountMatch1.Name = "rdoCountMatch1";
            this.rdoCountMatch1.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.rdoCountMatch1.Size = new System.Drawing.Size(153, 19);
            this.rdoCountMatch1.TabIndex = 16;
            this.rdoCountMatch1.TabStop = true;
            this.rdoCountMatch1.Text = "Count Match 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, 48);
            this.rdoCountMatch0.Name = "rdoCountMatch0";
            this.rdoCountMatch0.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.rdoCountMatch0.Size = new System.Drawing.Size(153, 18);
            this.rdoCountMatch0.TabIndex = 15;
            this.rdoCountMatch0.TabStop = true;
            this.rdoCountMatch0.Text = "Count Match 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, 26);
            this.rdoGenOutput.Name = "rdoGenOutput";
            this.rdoGenOutput.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.rdoGenOutput.Size = new System.Drawing.Size(153, 18);
            this.rdoGenOutput.TabIndex = 14;
            this.rdoGenOutput.TabStop = true;
            this.rdoGenOutput.Text = "General Output";
            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, 196);
            this.Label4.Name = "Label4";
            this.Label4.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label4.Size = new System.Drawing.Size(135, 12);
            this.Label4.TabIndex = 20;
            this.Label4.Text = "Pulse Width (Coefficient):";
            // 
            // 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(8, 7);
            this.Frame1.Name = "Frame1";
            this.Frame1.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Frame1.Size = new System.Drawing.Size(208, 318);
            this.Frame1.TabIndex = 42;
            this.Frame1.TabStop = false;
            this.Frame1.Text = "Event Signal Input";
            // 
            // 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, 180);
            this.Frame3.Name = "Frame3";
            this.Frame3.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Frame3.Size = new System.Drawing.Size(192, 78);
            this.Frame3.TabIndex = 5;
            this.Frame3.TabStop = false;
            this.Frame3.Text = "RF1 (Stop)";
            // 
            // 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(48, 34);
            this.cboRF1.Name = "cboRF1";
            this.cboRF1.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.cboRF1.Size = new System.Drawing.Size(112, 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, 68);
            this.Frame2.Name = "Frame2";
            this.Frame2.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Frame2.Size = new System.Drawing.Size(192, 96);
            this.Frame2.TabIndex = 4;
            this.Frame2.TabStop = false;
            this.Frame2.Text = "RF0 (Clear/Preset/Start)";
            // 
            // 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(91, 57);
            this.txtPresetReg.MaxLength = 0;
            this.txtPresetReg.Name = "txtPresetReg";
            this.txtPresetReg.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.txtPresetReg.Size = new System.Drawing.Size(64, 20);
            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(49, 26);
            this.cboRF0.Name = "cboRF0";
            this.cboRF0.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.cboRF0.Size = new System.Drawing.Size(112, 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(159, 60);
            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(7, 60);
            this.Label2.Name = "Label2";
            this.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label2.Size = new System.Drawing.Size(87, 12);
            this.Label2.TabIndex = 7;
            this.Label2.Text = "Preset Register:";
            // 
            // 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, 21);
            this.cboInputEvent.Name = "cboInputEvent";
            this.cboInputEvent.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.cboInputEvent.Size = new System.Drawing.Size(112, 20);
            this.cboInputEvent.TabIndex = 3;
            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, 26);
            this.Label1.Name = "Label1";
            this.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label1.Size = new System.Drawing.Size(32, 12);
            this.Label1.TabIndex = 3;
            this.Label1.Text = "Type:";
            // 
            // 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(479, 7);
            this.Frame7.Name = "Frame7";
            this.Frame7.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Frame7.Size = new System.Drawing.Size(177, 71);
            this.Frame7.TabIndex = 44;
            this.Frame7.TabStop = false;
            this.Frame7.Text = "Count Match Event";
            // 
            // 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(56, 30);
            this.cboCount.Name = "cboCount";
            this.cboCount.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.cboCount.Size = new System.Drawing.Size(104, 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, 34);
            this.Label7.Name = "Label7";
            this.Label7.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label7.Size = new System.Drawing.Size(32, 12);
            this.Label7.TabIndex = 29;
            this.Label7.Text = "Type:";
            // 
            // 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(480, 103);
            this.Label8.Name = "Label8";
            this.Label8.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label8.Size = new System.Drawing.Size(176, 35);
            this.Label8.TabIndex = 46;
            this.Label8.Text = "All channels use the same setting.";
            // 
            // 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(569, 299);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.btnCancel.Size = new System.Drawing.Size(87, 26);
            this.btnCancel.TabIndex = 41;
            this.btnCancel.Text = "Cancel";
            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(475, 299);
            this.btnOK.Name = "btnOK";
            this.btnOK.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.btnOK.Size = new System.Drawing.Size(87, 26);
            this.btnOK.TabIndex = 40;
            this.btnOK.Text = "OK";
            this.btnOK.UseVisualStyleBackColor = false;
            this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
            // 
            // 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(219, 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 = 21;
            this.label10.Text = "Hex";
            // 
            // EventDlg
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
            this.ClientSize = new System.Drawing.Size(664, 358);
            this.Controls.Add(this.Label9);
            this.Controls.Add(this.Frame4);
            this.Controls.Add(this.Frame1);
            this.Controls.Add(this.Frame7);
            this.Controls.Add(this.Label8);
            this.Controls.Add(this.btnCancel);
            this.Controls.Add(this.btnOK);
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "EventDlg";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Hardware Event Setting";
            this.Load += new System.EventHandler(this.EventDlg_Load);
            this.Frame4.ResumeLayout(false);
            this.Frame4.PerformLayout();
            this.Frame6.ResumeLayout(false);
            this.Frame6.PerformLayout();
            this.Frame5.ResumeLayout(false);
            this.Frame1.ResumeLayout(false);
            this.Frame1.PerformLayout();
            this.Frame3.ResumeLayout(false);
            this.Frame2.ResumeLayout(false);
            this.Frame2.PerformLayout();
            this.Frame7.ResumeLayout(false);
            this.Frame7.PerformLayout();
            this.ResumeLayout(false);

        }
        #endregion

        //===================================================
        // Dialog initialization
        //===================================================
        private void EventDlg_Load(object sender, System.EventArgs e)
        {
            //===================================================
            // Initialize ComboBox
            //===================================================
            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);
            }          
            //===================================================
            // Initialize data
            //===================================================
            // Event signal input
            string szBuf = new string(' ', 100);
            
            cboInputEvent.Text = szInputEvent;
            szBuf              = string.Format("{0:X}", PresetReg);
            txtPresetReg.Text  = szBuf;
            cboRF0.Text        =ModeDlg.num_to_str(RF, RF0);
            cboRF1.Text        = ModeDlg.num_to_str(RF, RF1);
            cboCount.Text      = szCount;
            cboInputEvent_SelectedIndexChanged(cboInputEvent, new System.EventArgs());
            // Event signal output
            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)
            {
                rdoCountMatch0.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";

        }

        //---------------------------------------------
        // OK button processing
        //---------------------------------------------
        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);

            //-------------------------------
            // Get setting information
            //-------------------------------
            // Event signal input
            szInputEvent = cboInputEvent.Text;
            dwInputEvent = (uint)ModeDlg.str_to_num(InputEvent, szInputEvent);

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

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

            buf = cboRF1.Text;
            RF1 = ModeDlg.str_to_num(RF, buf);
            // Event signal output
            OutputEvent = (int)CcntConst.CNT_OEVENT_GENOUT;
    
            if (rdoCountMatch0.Checked == true) 
            {
                OutputEvent |= (int)CcntConst.CNT_OEVENT_MATCH0;
            }
            else if (rdoCountMatch0.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 = ModeDlg.str_to_num(PulseLength, szPulseLength);
            // Count match event
            szCount = cboCount.Text;
            dwCountEvent = (uint)ModeDlg.str_to_num(CountEvent, szCount);

            //-------------------------------
            // Set setting information to device
            //-------------------------------
            for (ChNo=0; ChNo<CounterCallback.ChannelNum; ChNo++) 
            {
                //---------------------------------------------
                // Set hardware event of control input signal
                //---------------------------------------------
                ret = cnt.SetInputHardwareEvent(CounterCallback.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;
                }
                //---------------------------------------------
                // Set preset register
                //---------------------------------------------
                if (dwInputEvent == (uint)CcntConst.CNT_IEVENT_PRESET || dwCountEvent == (uint)CcntConst.CNT_MATCH_PRESET) 
                {
                    ret = cnt.SetPresetRegister(CounterCallback.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;
                    }
                }
                //---------------------------------------------
                // Set hardware event of control output signal
                //---------------------------------------------
                ret = cnt.SetOutputHardwareEvent(CounterCallback.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;
                }
                //---------------------------------------------
                // Set hardware event of count match
                //---------------------------------------------
                ret = cnt.SetCountMatchHardwareEvent(CounterCallback.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();
        }

        //---------------------------------------------
        // Cancel button processing
        //---------------------------------------------
        private void btnCancel_Click(object sender, System.EventArgs e)
        {
            this.Close();
        }

        //---------------------------------------------
        // Set event signal input
        //---------------------------------------------
        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, "General Input") == 0) 
            {
                cboRF0.Text = "None";
                cboRF1.Text = "None";
                cboRF0.Enabled = false;
                cboRF1.Enabled = false;
                txtPresetReg.Enabled = false;
            }
            if (string.Compare(szInput, "Counter Start/Stop") == 0) 
            {
                cboRF0.Enabled = true;
                cboRF1.Enabled = true;
                txtPresetReg.Enabled = false;
            }
            if (string.Compare(szInput, "Counter Start/Stop") == 0) 
            {
                cboRF0.Enabled = true;
                cboRF1.Text = "None";
                cboRF1.Enabled = false;
                txtPresetReg.Enabled = true;
            }
            if (string.Compare(szInput, "Counter Clear") == 0) 
            {
                cboRF0.Enabled = true;
                cboRF1.Text = "None";
                cboRF1.Enabled = false;
                txtPresetReg.Enabled = false;
            }
            if (string.Compare(szCount, "Preset") == 0) 
            {
                txtPresetReg.Enabled = true;
            }
        }

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

        //---------------------------------------------
        // Set event signal output
        //---------------------------------------------
        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;
        }

        //---------------------------------------------
        // Output signal
        //---------------------------------------------
        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;
            }

            //---------------------------------------------
            // General output processing
            //---------------------------------------------
            ret = cnt.OutputDOBit(CounterCallback.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);
            }
        }
    }
}
