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

namespace Infinite
{
	/// <summary>
	/// Summary description for frmCondition.
	/// </summary>
	public class frmCondition : System.Windows.Forms.Form
	{
		internal System.Windows.Forms.GroupBox GroupBox2;
		internal System.Windows.Forms.RadioButton rdoStartCntwithSamp;
		internal System.Windows.Forms.RadioButton rdoStartCntNotwithSamp;
		internal System.Windows.Forms.Button btnCancel;
		internal System.Windows.Forms.Button btnOK;
		internal System.Windows.Forms.GroupBox GroupBox4;
		internal System.Windows.Forms.Label Label11;
		internal System.Windows.Forms.TextBox txtNumEvent;
		internal System.Windows.Forms.GroupBox GroupBox3;
		internal System.Windows.Forms.RadioButton rdoStopCntwithSamp;
		internal System.Windows.Forms.RadioButton rdoStopCntNotwithSamp;
		internal System.Windows.Forms.GroupBox GroupBox1;
		internal System.Windows.Forms.Label Label10;
		internal System.Windows.Forms.Label Label9;
		internal System.Windows.Forms.Label Label8;
		internal System.Windows.Forms.Label Label7;
		internal System.Windows.Forms.Label Label6;
		internal System.Windows.Forms.Label Label5;
		internal System.Windows.Forms.TextBox txtStopNum;
		internal System.Windows.Forms.TextBox txtCompStop;
		internal System.Windows.Forms.TextBox txtInternalClock;
		internal System.Windows.Forms.Label Label4;
		internal System.Windows.Forms.TextBox txtCompStart;
		internal System.Windows.Forms.Label Label3;
		internal System.Windows.Forms.Label Label2;
		internal System.Windows.Forms.ComboBox cboStopTrg;
		internal System.Windows.Forms.ComboBox cboClockTrg;
		internal System.Windows.Forms.Label Label1;
		internal System.Windows.Forms.ComboBox cboStartTrg;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		Ccnt					cnt			   = new Ccnt();

		// Start Condition
		static frmMode.StrNum[] StartTrg =
		{
			new frmMode.StrNum("Software Start",	                        (ushort)CcntConst.CNTS_START_SOFT               ),
			new frmMode.StrNum("External Signal Rising",		            (ushort)CcntConst.CNTS_START_EXT_RISE           ),
			new frmMode.StrNum("External Signal Falling",		            (ushort)CcntConst.CNTS_START_EXT_FALL           ),
			new frmMode.StrNum("Count-match Ch0 Compare-register 0",	    (ushort)CcntConst.CNTS_START_CNTMATCH_CH0_REG0  ),
			new frmMode.StrNum("Count-match Ch1 Compare-register 0",		(ushort)CcntConst.CNTS_START_CNTMATCH_CH1_REG0  ),
			new frmMode.StrNum("Count-match Ch2 Compare-register 0",		(ushort)CcntConst.CNTS_START_CNTMATCH_CH2_REG0  ),
			new frmMode.StrNum("Count-match Ch3 Compare-register 0",	    (ushort)CcntConst.CNTS_START_CNTMATCH_CH3_REG1  ),
			new frmMode.StrNum("Count-match Ch0 Compare-register 1",		(ushort)CcntConst.CNTS_START_CNTMATCH_CH0_REG1  ),
			new frmMode.StrNum("Count-match Ch1 Compare-register 1",		(ushort)CcntConst.CNTS_START_CNTMATCH_CH1_REG1  ),
			new frmMode.StrNum("Count-match Ch2 Compare-register 1",		(ushort)CcntConst.CNTS_START_CNTMATCH_CH2_REG1  ),
			new frmMode.StrNum("Count-match Ch3 Compare-register 1",		(ushort)CcntConst.CNTS_START_CNTMATCH_CH3_REG1  ),
			new frmMode.StrNum("End",		                                0									            )
		};

		// Clock Condition
		static frmMode.StrNum[] ClockTrg =
		{
			new frmMode.StrNum("Internal Clock",	            (ushort)CcntConst.CNTS_CLOCK_CLOCK     ),
			new frmMode.StrNum("External Clock",		        (ushort)CcntConst.CNTS_CLOCK_EXT_TRG   ),
			new frmMode.StrNum("End",		                    0									   )
		};

		// Stop Condition
		static frmMode.StrNum[] StopTrg =
		{
			new frmMode.StrNum("Software Stop",	                            (ushort)CcntConst.CNTS_STOP_SOFT               ),
			new frmMode.StrNum("External Signal Rising",		            (ushort)CcntConst.CNTS_STOP_EXT_RISE           ),
			new frmMode.StrNum("External Signal Falling",		            (ushort)CcntConst.CNTS_STOP_EXT_FALL           ),
			new frmMode.StrNum("Stop Transfer by Specified Times",		    (ushort)CcntConst.CNTS_STOP_NUM                ),
			new frmMode.StrNum("Count-match Ch0 Compare-register 0",	    (ushort)CcntConst.CNTS_STOP_CNTMATCH_CH0_REG0  ),
			new frmMode.StrNum("Count-match Ch1 Compare-register 0",		(ushort)CcntConst.CNTS_STOP_CNTMATCH_CH1_REG0  ),
			new frmMode.StrNum("Count-match Ch2 Compare-register 0",		(ushort)CcntConst.CNTS_STOP_CNTMATCH_CH2_REG0  ),
			new frmMode.StrNum("Count-match Ch3 Compare-register 0",	    (ushort)CcntConst.CNTS_STOP_CNTMATCH_CH3_REG0  ),
			new frmMode.StrNum("Count-match Ch0 Compare-register 1",		(ushort)CcntConst.CNTS_STOP_CNTMATCH_CH0_REG1  ),
			new frmMode.StrNum("Count-match Ch1 Compare-register 1",		(ushort)CcntConst.CNTS_STOP_CNTMATCH_CH1_REG1  ),
			new frmMode.StrNum("Count-match Ch2 Compare-register 1",		(ushort)CcntConst.CNTS_STOP_CNTMATCH_CH2_REG1  ),
			new frmMode.StrNum("Count-match Ch3 Compare-register 1",		(ushort)CcntConst.CNTS_STOP_CNTMATCH_CH3_REG1  ),
			new frmMode.StrNum("End",		                                0									           )
		};

		static uint	    StartComp		= 0x100;
		static uint	    StopComp		= 0x200;

		string			szStart	        = "Software Start";
		string			szClock	        = "Internal Clock";
		string			szStop		    = "Software Stop";
		int	        Mask			= 0xFF;
		uint	        InternalClock	= 100000;
		uint	        StopNumber		= 1000;
		int	        NumberOfData	= 500;
		short			StartCountMode	= (short)CcntConst.CNTS_START_CNT_WITH_SAMP;
		short			StopCountMode	= (short)CcntConst.CNTS_STOP_CNT_WITH_SAMP;
		short       	Id;

		public frmCondition()
		{
			//
			// 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.GroupBox2 = new System.Windows.Forms.GroupBox();
			this.rdoStartCntwithSamp = new System.Windows.Forms.RadioButton();
			this.rdoStartCntNotwithSamp = new System.Windows.Forms.RadioButton();
			this.btnCancel = new System.Windows.Forms.Button();
			this.btnOK = new System.Windows.Forms.Button();
			this.GroupBox4 = new System.Windows.Forms.GroupBox();
			this.Label11 = new System.Windows.Forms.Label();
			this.txtNumEvent = new System.Windows.Forms.TextBox();
			this.GroupBox3 = new System.Windows.Forms.GroupBox();
			this.rdoStopCntwithSamp = new System.Windows.Forms.RadioButton();
			this.rdoStopCntNotwithSamp = new System.Windows.Forms.RadioButton();
			this.GroupBox1 = new System.Windows.Forms.GroupBox();
			this.Label10 = new System.Windows.Forms.Label();
			this.Label9 = new System.Windows.Forms.Label();
			this.Label8 = new System.Windows.Forms.Label();
			this.Label7 = new System.Windows.Forms.Label();
			this.Label6 = new System.Windows.Forms.Label();
			this.Label5 = new System.Windows.Forms.Label();
			this.txtStopNum = new System.Windows.Forms.TextBox();
			this.txtCompStop = new System.Windows.Forms.TextBox();
			this.txtInternalClock = new System.Windows.Forms.TextBox();
			this.Label4 = new System.Windows.Forms.Label();
			this.txtCompStart = new System.Windows.Forms.TextBox();
			this.Label3 = new System.Windows.Forms.Label();
			this.Label2 = new System.Windows.Forms.Label();
			this.cboStopTrg = new System.Windows.Forms.ComboBox();
			this.cboClockTrg = new System.Windows.Forms.ComboBox();
			this.Label1 = new System.Windows.Forms.Label();
			this.cboStartTrg = new System.Windows.Forms.ComboBox();
			this.GroupBox2.SuspendLayout();
			this.GroupBox4.SuspendLayout();
			this.GroupBox3.SuspendLayout();
			this.GroupBox1.SuspendLayout();
			this.SuspendLayout();
			// 
			// GroupBox2
			// 
			this.GroupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.rdoStartCntwithSamp,
																					this.rdoStartCntNotwithSamp});
			this.GroupBox2.Location = new System.Drawing.Point(7, 178);
			this.GroupBox2.Name = "GroupBox2";
			this.GroupBox2.Size = new System.Drawing.Size(545, 75);
			this.GroupBox2.TabIndex = 15;
			this.GroupBox2.TabStop = false;
			this.GroupBox2.Text = "Counter Start Mode";
			// 
			// rdoStartCntwithSamp
			// 
			this.rdoStartCntwithSamp.Location = new System.Drawing.Point(16, 47);
			this.rdoStartCntwithSamp.Name = "rdoStartCntwithSamp";
			this.rdoStartCntwithSamp.Size = new System.Drawing.Size(200, 18);
			this.rdoStartCntwithSamp.TabIndex = 1;
			this.rdoStartCntwithSamp.Text = "Start counter when sampling starts";
			// 
			// rdoStartCntNotwithSamp
			// 
			this.rdoStartCntNotwithSamp.Location = new System.Drawing.Point(16, 19);
			this.rdoStartCntNotwithSamp.Name = "rdoStartCntNotwithSamp";
			this.rdoStartCntNotwithSamp.Size = new System.Drawing.Size(232, 28);
			this.rdoStartCntNotwithSamp.TabIndex = 0;
			this.rdoStartCntNotwithSamp.Text = "Start counter regardless of sampling";
			// 
			// btnCancel
			// 
			this.btnCancel.Location = new System.Drawing.Point(440, 410);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.Size = new System.Drawing.Size(104, 30);
			this.btnCancel.TabIndex = 19;
			this.btnCancel.Text = "Cancel";
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			// 
			// btnOK
			// 
			this.btnOK.Location = new System.Drawing.Point(320, 410);
			this.btnOK.Name = "btnOK";
			this.btnOK.Size = new System.Drawing.Size(104, 30);
			this.btnOK.TabIndex = 18;
			this.btnOK.Text = "OK";
			this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
			// 
			// GroupBox4
			// 
			this.GroupBox4.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.Label11,
																					this.txtNumEvent});
			this.GroupBox4.Location = new System.Drawing.Point(7, 346);
			this.GroupBox4.Name = "GroupBox4";
			this.GroupBox4.Size = new System.Drawing.Size(545, 56);
			this.GroupBox4.TabIndex = 17;
			this.GroupBox4.TabStop = false;
			this.GroupBox4.Text = "Transfer Number Event Notification";
			// 
			// Label11
			// 
			this.Label11.Location = new System.Drawing.Point(168, 28);
			this.Label11.Name = "Label11";
			this.Label11.Size = new System.Drawing.Size(144, 23);
			this.Label11.TabIndex = 1;
			this.Label11.Text = "Each data notification";
			// 
			// txtNumEvent
			// 
			this.txtNumEvent.Location = new System.Drawing.Point(32, 22);
			this.txtNumEvent.Name = "txtNumEvent";
			this.txtNumEvent.Size = new System.Drawing.Size(112, 20);
			this.txtNumEvent.TabIndex = 0;
			this.txtNumEvent.Text = "TextBox5";
			// 
			// GroupBox3
			// 
			this.GroupBox3.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.rdoStopCntwithSamp,
																					this.rdoStopCntNotwithSamp});
			this.GroupBox3.Location = new System.Drawing.Point(7, 262);
			this.GroupBox3.Name = "GroupBox3";
			this.GroupBox3.Size = new System.Drawing.Size(545, 74);
			this.GroupBox3.TabIndex = 16;
			this.GroupBox3.TabStop = false;
			this.GroupBox3.Text = "Counter Stop Mode";
			// 
			// rdoStopCntwithSamp
			// 
			this.rdoStopCntwithSamp.Location = new System.Drawing.Point(16, 47);
			this.rdoStopCntwithSamp.Name = "rdoStopCntwithSamp";
			this.rdoStopCntwithSamp.Size = new System.Drawing.Size(200, 18);
			this.rdoStopCntwithSamp.TabIndex = 1;
			this.rdoStopCntwithSamp.Text = "Stop counter when sampling stops";
			// 
			// rdoStopCntNotwithSamp
			// 
			this.rdoStopCntNotwithSamp.Location = new System.Drawing.Point(16, 19);
			this.rdoStopCntNotwithSamp.Name = "rdoStopCntNotwithSamp";
			this.rdoStopCntNotwithSamp.Size = new System.Drawing.Size(232, 28);
			this.rdoStopCntNotwithSamp.TabIndex = 0;
			this.rdoStopCntNotwithSamp.Text = "Stop counter regardless of sampling";
			// 
			// GroupBox1
			// 
			this.GroupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.Label10,
																					this.Label9,
																					this.Label8,
																					this.Label7,
																					this.Label6,
																					this.Label5,
																					this.txtStopNum,
																					this.txtCompStop,
																					this.txtInternalClock,
																					this.Label4,
																					this.txtCompStart,
																					this.Label3,
																					this.Label2,
																					this.cboStopTrg,
																					this.cboClockTrg,
																					this.Label1,
																					this.cboStartTrg});
			this.GroupBox1.Location = new System.Drawing.Point(7, 11);
			this.GroupBox1.Name = "GroupBox1";
			this.GroupBox1.Size = new System.Drawing.Size(545, 158);
			this.GroupBox1.TabIndex = 14;
			this.GroupBox1.TabStop = false;
			this.GroupBox1.Text = "Sampling Condition";
			// 
			// Label10
			// 
			this.Label10.Location = new System.Drawing.Point(518, 100);
			this.Label10.Name = "Label10";
			this.Label10.Size = new System.Drawing.Size(24, 23);
			this.Label10.TabIndex = 16;
			this.Label10.Text = "Hex";
			// 
			// Label9
			// 
			this.Label9.Location = new System.Drawing.Point(518, 67);
			this.Label9.Name = "Label9";
			this.Label9.Size = new System.Drawing.Size(24, 24);
			this.Label9.TabIndex = 15;
			this.Label9.Text = "ns";
			// 
			// Label8
			// 
			this.Label8.Location = new System.Drawing.Point(518, 35);
			this.Label8.Name = "Label8";
			this.Label8.Size = new System.Drawing.Size(24, 23);
			this.Label8.TabIndex = 14;
			this.Label8.Text = "Hex";
			// 
			// Label7
			// 
			this.Label7.Location = new System.Drawing.Point(315, 123);
			this.Label7.Name = "Label7";
			this.Label7.Size = new System.Drawing.Size(106, 24);
			this.Label7.TabIndex = 13;
			this.Label7.Text = "Stop Number:";
			// 
			// Label6
			// 
			this.Label6.Location = new System.Drawing.Point(315, 92);
			this.Label6.Name = "Label6";
			this.Label6.Size = new System.Drawing.Size(106, 23);
			this.Label6.TabIndex = 12;
			this.Label6.Text = "Comparison Value:";
			// 
			// Label5
			// 
			this.Label5.Location = new System.Drawing.Point(315, 60);
			this.Label5.Name = "Label5";
			this.Label5.Size = new System.Drawing.Size(106, 24);
			this.Label5.TabIndex = 11;
			this.Label5.Text = "Internal Clock:";
			// 
			// txtStopNum
			// 
			this.txtStopNum.Location = new System.Drawing.Point(429, 123);
			this.txtStopNum.Name = "txtStopNum";
			this.txtStopNum.Size = new System.Drawing.Size(88, 20);
			this.txtStopNum.TabIndex = 10;
			this.txtStopNum.Text = "TextBox4";
			// 
			// txtCompStop
			// 
			this.txtCompStop.Location = new System.Drawing.Point(429, 92);
			this.txtCompStop.Name = "txtCompStop";
			this.txtCompStop.Size = new System.Drawing.Size(88, 20);
			this.txtCompStop.TabIndex = 9;
			this.txtCompStop.Text = "TextBox3";
			// 
			// txtInternalClock
			// 
			this.txtInternalClock.Location = new System.Drawing.Point(429, 60);
			this.txtInternalClock.Name = "txtInternalClock";
			this.txtInternalClock.Size = new System.Drawing.Size(88, 20);
			this.txtInternalClock.TabIndex = 8;
			this.txtInternalClock.Text = "TextBox2";
			// 
			// Label4
			// 
			this.Label4.Location = new System.Drawing.Point(315, 28);
			this.Label4.Name = "Label4";
			this.Label4.Size = new System.Drawing.Size(106, 23);
			this.Label4.TabIndex = 7;
			this.Label4.Text = "Comparison Value:";
			// 
			// txtCompStart
			// 
			this.txtCompStart.Location = new System.Drawing.Point(429, 28);
			this.txtCompStart.Name = "txtCompStart";
			this.txtCompStart.Size = new System.Drawing.Size(88, 20);
			this.txtCompStart.TabIndex = 6;
			this.txtCompStart.Text = "TextBox1";
			// 
			// Label3
			// 
			this.Label3.Location = new System.Drawing.Point(16, 92);
			this.Label3.Name = "Label3";
			this.Label3.Size = new System.Drawing.Size(88, 23);
			this.Label3.TabIndex = 5;
			this.Label3.Text = "Stop Condition:";
			// 
			// Label2
			// 
			this.Label2.Location = new System.Drawing.Point(16, 60);
			this.Label2.Name = "Label2";
			this.Label2.Size = new System.Drawing.Size(88, 24);
			this.Label2.TabIndex = 4;
			this.Label2.Text = "Clock Condition:";
			// 
			// cboStopTrg
			// 
			this.cboStopTrg.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboStopTrg.Location = new System.Drawing.Point(104, 92);
			this.cboStopTrg.Name = "cboStopTrg";
			this.cboStopTrg.Size = new System.Drawing.Size(208, 21);
			this.cboStopTrg.TabIndex = 3;
			this.cboStopTrg.SelectedIndexChanged += new System.EventHandler(this.cboStopTrg_SelectedIndexChanged);
			// 
			// cboClockTrg
			// 
			this.cboClockTrg.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboClockTrg.Location = new System.Drawing.Point(104, 60);
			this.cboClockTrg.Name = "cboClockTrg";
			this.cboClockTrg.Size = new System.Drawing.Size(208, 21);
			this.cboClockTrg.TabIndex = 2;
			this.cboClockTrg.SelectedIndexChanged += new System.EventHandler(this.cboClockTrg_SelectedIndexChanged);
			// 
			// Label1
			// 
			this.Label1.Location = new System.Drawing.Point(16, 28);
			this.Label1.Name = "Label1";
			this.Label1.Size = new System.Drawing.Size(88, 23);
			this.Label1.TabIndex = 1;
			this.Label1.Text = "Start Condition:";
			// 
			// cboStartTrg
			// 
			this.cboStartTrg.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboStartTrg.Location = new System.Drawing.Point(104, 28);
			this.cboStartTrg.Name = "cboStartTrg";
			this.cboStartTrg.Size = new System.Drawing.Size(208, 21);
			this.cboStartTrg.TabIndex = 0;
			this.cboStartTrg.SelectedIndexChanged += new System.EventHandler(this.cboStartTrg_SelectedIndexChanged);
			// 
			// frmCondition
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(560, 453);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.GroupBox2,
																		  this.btnCancel,
																		  this.btnOK,
																		  this.GroupBox4,
																		  this.GroupBox3,
																		  this.GroupBox1});
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "frmCondition";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Infinite Sampling Condition Setting";
			this.Load += new System.EventHandler(this.frmCondition_Load);
			this.GroupBox2.ResumeLayout(false);
			this.GroupBox4.ResumeLayout(false);
			this.GroupBox3.ResumeLayout(false);
			this.GroupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		//===================================================
		//	Dialog initialization
		//===================================================
		private void frmCondition_Load(object sender, System.EventArgs e)
		{
			//--------------------------------
			// Initialize dialog display
			//--------------------------------
			int	i;

			for (i = 0; string.Compare(StartTrg[i].Str, "End") != 0; i++) 
			{
				cboStartTrg.Items.Add(StartTrg[i].Str);
			}
			for (i = 0; string.Compare(ClockTrg[i].Str, "End") != 0; i++) 
			{
				cboClockTrg.Items.Add(ClockTrg[i].Str);
			}
			for (i = 0; string.Compare(StopTrg[i].Str, "End") != 0; i++) 
			{
				cboStopTrg.Items.Add(StopTrg[i].Str);
			}

			cboStartTrg.Text = szStart;
			cboClockTrg.Text = szClock;
			cboStopTrg.Text = szStop;

			if (StartCountMode == (short)CcntConst.CNTS_START_CNT_NOT_WITH_SAMP) 
			{
				rdoStartCntNotwithSamp.Checked = true;
				rdoStartCntwithSamp.Checked = false;
			}
			else
			{
				rdoStartCntNotwithSamp.Checked = false;
				rdoStartCntwithSamp.Checked = true;
			}
			if (StopCountMode == (short)CcntConst.CNTS_STOP_CNT_NOT_WITH_SAMP) 
			{
				rdoStopCntNotwithSamp.Checked = true;
				rdoStopCntwithSamp.Checked = false;
			}
			else
			{
				rdoStopCntNotwithSamp.Checked = false;
				rdoStopCntwithSamp.Checked = true;
			}
			txtCompStart.Text = string.Format("{0:X}", StartComp);
			txtInternalClock.Text = string.Format("{0:d}", InternalClock);
			txtStopNum.Text = string.Format("{0:d}", StopNumber);
			txtNumEvent.Text = string.Format("{0:d}", NumberOfData);
			txtCompStop.Text = string.Format("{0:X}", StopComp);

			Id = Infinite.Id;

			cboStartTrg_SelectedIndexChanged(cboStartTrg, new System.EventArgs());
			cboClockTrg_SelectedIndexChanged(cboClockTrg, new System.EventArgs());
			cboStopTrg_SelectedIndexChanged(cboStopTrg, new System.EventArgs());		
		}

		//===================================================
		//	Change start condition setting
		//===================================================
		private void cboStartTrg_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			string	szBuf = new string(' ', 100);

			szBuf = cboStartTrg.Text;
			if (szBuf.StartsWith("Count-match")) 
			{
				txtCompStart.Enabled = true;
			} 
			else 
			{
				txtCompStart.Enabled = false;
			}
		}

		//===================================================
		//	Change clock condition setting
		//===================================================
		private void cboClockTrg_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			string	szBuf = new string(' ', 100);
			//--------------------------------
			// Change validity of internal clock value
			//--------------------------------
			szBuf = cboClockTrg.Text;
			if (string.Compare(szBuf, "Internal Clock") == 0) 
			{
				txtInternalClock.Enabled = true;
			} 
			else 
			{
				txtInternalClock.Enabled = false;
			}
		}

		//===================================================
		//	Change stop condition setting
		//===================================================
		private void cboStopTrg_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			string	szBuf = new string(' ', 100);
			//--------------------------------
			// Change validity of stop number
			//--------------------------------
			szBuf = cboStopTrg.Text;
			if (szBuf.StartsWith("Count-match")) 
			{
				txtCompStop.Enabled = true;
			} 
			else 
			{
				txtCompStop.Enabled = false;
			}
			if (string.Compare(szBuf, "Stop Transfer by Specified Times") == 0) 
			{
				txtStopNum.Enabled = true;
			} 
			else 
			{
				txtStopNum.Enabled = false;
			}
		}

		//===================================================
		//	OK processing
		//===================================================
		private void btnOK_Click(object sender, System.EventArgs e)
		{
			string	error_string = new string(' ', 256);
			string	szTmp = new string(' ', 100);
			short	wStartTrg;
			short	wClockTrg;
			short	wStopTrg;
			int  	ret;
			string	strMsg;
			short	CompChNo;
			short	CompRegNo;

			//--------------------------------
			// Get displayed data
			//--------------------------------
			szStart = cboStartTrg.Text;
			szClock = cboClockTrg.Text;
			szStop = cboStopTrg.Text;

			if (rdoStartCntNotwithSamp.Checked == true) 
			{
				StartCountMode = (short)CcntConst.CNTS_START_CNT_NOT_WITH_SAMP;
			}
			else
			{
				StartCountMode = (short)CcntConst.CNTS_START_CNT_WITH_SAMP;
			}
			if (rdoStopCntNotwithSamp.Checked == true) 
			{
				StopCountMode = (short)CcntConst.CNTS_STOP_CNT_NOT_WITH_SAMP;
			}
			else
			{
				StopCountMode = (short)CcntConst.CNTS_STOP_CNT_WITH_SAMP;
			}
			szTmp = txtCompStart.Text;
			StartComp = uint.Parse(szTmp, NumberStyles.HexNumber);
			szTmp = txtCompStop.Text;
			StopComp = uint.Parse(szTmp, NumberStyles.HexNumber);

			Mask = int.Parse(szTmp, NumberStyles.HexNumber);
			szTmp = txtInternalClock.Text;
			InternalClock = uint.Parse(szTmp);
			szTmp = txtStopNum.Text;
			StopNumber = uint.Parse(szTmp);
			szTmp = txtNumEvent.Text;
			NumberOfData = int.Parse(szTmp);

			//--------------------------------
			// Convert the set value to numerical value
			//--------------------------------
			wStartTrg = 0;
			wStartTrg = (short)frmMode.str_to_num(StartTrg, szStart);

			wClockTrg = 0;
			wClockTrg = (short)frmMode.str_to_num(ClockTrg,szClock);

			wStopTrg = 0;
			wStopTrg = (short)frmMode.str_to_num(StopTrg,szStop);
			//--------------------------------
			// Set sampling condition
			//--------------------------------
			// StandAlone
			ret = cnt.SetStandAlone(Id);
			if (ret != (short)CcntConst.CNT_ERR_SUCCESS) 
			{
				cnt.GetErrorString(ret, out error_string);
				strMsg = string.Format("CntSetStandAlone ret = {0:d}: {1}", ret, error_string);
				MessageBox.Show(strMsg, "",MessageBoxButtons.OK);
				return;
			}
			// Set start condition
			ret = cnt.SetSamplingStartTrigger(Id, wStartTrg, StartCountMode, (short)Infinite.CHANNEL_NUM);
			if (ret != (short)CcntConst.CNT_ERR_SUCCESS) 
			{
				cnt.GetErrorString(ret, out error_string);
				strMsg = string.Format("CntSetSamplingStartTrigger ret = {0:d}: {1}", ret, error_string);
				MessageBox.Show(strMsg, "", MessageBoxButtons.OK);
				return;
			}
			switch(wStartTrg) 
			{
				case (short)CcntConst.CNTS_START_CNTMATCH_CH0_REG0:
					CompChNo = 0;
					CompRegNo = 0;
					break;
				case (short)CcntConst.CNTS_START_CNTMATCH_CH1_REG0:	
					CompChNo = 1;
					CompRegNo = 0; 
					break;
				case (short)CcntConst.CNTS_START_CNTMATCH_CH2_REG0:
					CompChNo = 2; 
					CompRegNo = 0;
					break;
				case (short)CcntConst.CNTS_START_CNTMATCH_CH3_REG0:
					CompChNo = 3; 
					CompRegNo = 0; 
					break;
				case (short)CcntConst.CNTS_START_CNTMATCH_CH4_REG0:	
					CompChNo = 4; 
					CompRegNo = 0;
					break;
				case (short)CcntConst.CNTS_START_CNTMATCH_CH5_REG0:
					CompChNo = 5; 
					CompRegNo = 0;
					break;
				case (short)CcntConst.CNTS_START_CNTMATCH_CH6_REG0:
					CompChNo = 6; 
					CompRegNo = 0;
					break;
				case (short)CcntConst.CNTS_START_CNTMATCH_CH7_REG0:
					CompChNo = 7; 
					CompRegNo = 0;
					break;
				case (short)CcntConst.CNTS_START_CNTMATCH_CH0_REG1:
					CompChNo = 0; 
					CompRegNo = 1;
					break;
				case (short)CcntConst.CNTS_START_CNTMATCH_CH1_REG1:	
					CompChNo = 1;
					CompRegNo = 1;
					break;
				case (short)CcntConst.CNTS_START_CNTMATCH_CH2_REG1:
					CompChNo = 2;
					CompRegNo = 1;
					break;
				case (short)CcntConst.CNTS_START_CNTMATCH_CH3_REG1:
					CompChNo = 3;
					CompRegNo = 1;
					break;
				case (short)CcntConst.CNTS_START_CNTMATCH_CH4_REG1:
					CompChNo = 4; 
					CompRegNo = 1;
					break;
				case (short)CcntConst.CNTS_START_CNTMATCH_CH5_REG1:
					CompChNo = 5;
					CompRegNo = 1; 
					break;
				case (short)CcntConst.CNTS_START_CNTMATCH_CH6_REG1:
					CompChNo = 6;
					CompRegNo = 1;
					break;
				case (short)CcntConst.CNTS_START_CNTMATCH_CH7_REG1:
					CompChNo = 7;
					CompRegNo = 1;
					break;
				default:				
					CompChNo = 0xfff; 
					CompRegNo = 0xfff;
					break;
			}
			if (CompChNo != 0xfff && CompRegNo != 0xfff) 
			{
				ret = cnt.NotifyCountUp(Id, CompChNo, CompRegNo, StartComp, (IntPtr)0);
				if (ret != 0) 
				{
					cnt.GetErrorString(ret, out error_string);
					strMsg = string.Format("CntNotifyCountUp ret = {0:d}: {1}", ret, error_string);
					MessageBox.Show(strMsg, "", MessageBoxButtons.OK);
				}
			}

			// Set clock condition
			ret = cnt.SetSamplingClockTrigger(Id, wClockTrg);
			if (ret != (short)CcntConst.CNT_ERR_SUCCESS) 
			{
				cnt.GetErrorString(ret, out error_string);
				strMsg= string.Format("CntSetSamplingClockTrigger ret = {0:d}: {1}", ret, error_string);
				MessageBox.Show(strMsg, "", MessageBoxButtons.OK);
				return;
			}
			// Set internal clock value
			if (wClockTrg == (short)CcntConst.CNTS_CLOCK_CLOCK) 
			{
				ret = cnt.SetSamplingInternalClock(Id, InternalClock, (short)CcntConst.CNTS_TIM_UNIT_NS);
				if (ret != (short)CcntConst.CNT_ERR_SUCCESS) 
				{
					cnt.GetErrorString(ret, out error_string);
					strMsg = string.Format("CntSetSamplingInternalClock ret = {0:d}: {1}", ret, error_string);
					MessageBox.Show(strMsg, "", MessageBoxButtons.OK);
					return;
				}
			}

			// Set stop condition
			ret = cnt.SetSamplingStopTrigger(Id, wStopTrg, StopCountMode, (short)Infinite.CHANNEL_NUM);
			if (ret != (short)CcntConst.CNT_ERR_SUCCESS) 
			{
				cnt.GetErrorString(ret, out error_string);
				strMsg = string.Format("CntSetSamplingStopTrigger ret = {0:d}: {1}", ret, error_string);
				MessageBox.Show(strMsg, "", MessageBoxButtons.OK);
				return;
			}
			switch(wStopTrg) 
			{
				case (short)CcntConst.CNTS_STOP_CNTMATCH_CH0_REG0:
					CompChNo = 0;
					CompRegNo = 0;
					break;
				case (short)CcntConst.CNTS_STOP_CNTMATCH_CH1_REG0:
					CompChNo = 1;
					CompRegNo = 0;
					break;
				case (short)CcntConst.CNTS_STOP_CNTMATCH_CH2_REG0:	
					CompChNo = 2;
					CompRegNo = 0;
					break;
				case (short)CcntConst.CNTS_STOP_CNTMATCH_CH3_REG0:
					CompChNo = 3;
					CompRegNo = 0;
					break;
				case (short)CcntConst.CNTS_STOP_CNTMATCH_CH4_REG0:	
					CompChNo = 4;
					CompRegNo = 0;
					break;
				case (short)CcntConst.CNTS_STOP_CNTMATCH_CH5_REG0:
					CompChNo = 5;
					CompRegNo = 0; break;
				case (short)CcntConst.CNTS_STOP_CNTMATCH_CH6_REG0:
					CompChNo = 6;
					CompRegNo = 0;
					break;
				case (short)CcntConst.CNTS_STOP_CNTMATCH_CH7_REG0:	
					CompChNo = 7; 
					CompRegNo = 0;
					break;
				case (short)CcntConst.CNTS_STOP_CNTMATCH_CH0_REG1:
					CompChNo = 0;
					CompRegNo = 1; 
					break;
				case (short)CcntConst.CNTS_STOP_CNTMATCH_CH1_REG1:
					CompChNo = 1; 
					CompRegNo = 1; 
					break;
				case (short)CcntConst.CNTS_STOP_CNTMATCH_CH2_REG1:
					CompChNo = 2;
					CompRegNo = 1;
					break;
				case (short)CcntConst.CNTS_STOP_CNTMATCH_CH3_REG1:
					CompChNo = 3;
					CompRegNo = 1;
					break;
				case (short)CcntConst.CNTS_STOP_CNTMATCH_CH4_REG1:
					CompChNo = 4; 
					CompRegNo = 1;
					break;
				case (short)CcntConst.CNTS_STOP_CNTMATCH_CH5_REG1:
					CompChNo = 5; 
					CompRegNo = 1; 
					break;
				case (short)CcntConst.CNTS_STOP_CNTMATCH_CH6_REG1:	
					CompChNo = 6; 
					CompRegNo = 1; 
					break;
				case (short)CcntConst.CNTS_STOP_CNTMATCH_CH7_REG1:
					CompChNo = 7; 
					CompRegNo = 1;
					break;
				default:			
					CompChNo = 0xfff; 
					CompRegNo = 0xfff; 
					break;
			}
			if (CompChNo != 0xfff && CompRegNo != 0xfff) 
			{
				ret = cnt.NotifyCountUp(Id, CompChNo, CompRegNo, StopComp, (IntPtr)0);
				if (ret != 0) 
				{
					cnt.GetErrorString(ret, out error_string);
					strMsg = string.Format("CntNotifyCountUp ret = {0:d}: {1}", ret, error_string);
					MessageBox.Show(strMsg, "", MessageBoxButtons.OK);
				}
			}
			// Set stop number
			if (wStopTrg == (short)CcntConst.CNTS_STOP_NUM) 
			{
				ret = cnt.SetSamplingStopNumber(Id, StopNumber);
				if (ret != (short)CcntConst.CNT_ERR_SUCCESS) 
				{
					cnt.GetErrorString(ret, out error_string);
					strMsg = string.Format("CntSetSamplingInternalClock ret = {0:d}: {1}", ret, error_string);
					MessageBox.Show(strMsg, "", MessageBoxButtons.OK);
					return;
				}
			}
			this.Close();
		}

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