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

namespace Sampling
{
	/// <summary>
	/// Summary description for ConditionDlg.
	/// </summary>
	public class ConditionDlg : System.Windows.Forms.Form
	{
		public System.Windows.Forms.Button btnCancel;
		public System.Windows.Forms.Button btnOK;
		public System.Windows.Forms.GroupBox Frame3;
		public System.Windows.Forms.RadioButton rdoStopCntWithSamp;
		public System.Windows.Forms.RadioButton rdoStopCntNotWithSamp;
		public System.Windows.Forms.GroupBox Frame4;
		public System.Windows.Forms.TextBox txtNumEvent;
		public System.Windows.Forms.Label Label11;
		public System.Windows.Forms.GroupBox Frame1;
		public System.Windows.Forms.ComboBox cboClockTrg;
		public System.Windows.Forms.ComboBox cboStopTrg;
		public System.Windows.Forms.TextBox txtStopNum;
		public System.Windows.Forms.TextBox txtCompStop;
		public System.Windows.Forms.TextBox txtInternalClock;
		public System.Windows.Forms.TextBox txtCompStart;
		public System.Windows.Forms.ComboBox cboStartTrg;
		public System.Windows.Forms.Label Label10;
		public System.Windows.Forms.Label Label9;
		public System.Windows.Forms.Label Label8;
		public System.Windows.Forms.Label Label7;
		public System.Windows.Forms.Label Label6;
		public System.Windows.Forms.Label Label5;
		public System.Windows.Forms.Label Label4;
		public System.Windows.Forms.Label Label3;
		public System.Windows.Forms.Label Label2;
		public System.Windows.Forms.Label Label1;
		public System.Windows.Forms.GroupBox Frame2;
		public System.Windows.Forms.RadioButton rdoStartCntWithSamp;
		public System.Windows.Forms.RadioButton rdoStartCntNotWithSamp;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public struct StrToNum 
		{													// structure of condition and parameters
			public string	Str;
			public short	Num;
			public StrToNum(string Str, short Num)
			{
				this.Str = Str;
				this.Num = Num;
			}
		} ;
		// Start Condition
		StrToNum[] StartTrgTable = 
		{
			new StrToNum("Software start",							(short)CcntConst.CNTS_START_SOFT				),
			new StrToNum("External signal rising",					(short)CcntConst.CNTS_START_EXT_RISE			),
			new StrToNum("External signal falling",					(short)CcntConst.CNTS_START_EXT_FALL			),
			new StrToNum("Count-match CH0 Compare-register 0",		(short)CcntConst.CNTS_START_CNTMATCH_CH0_REG0	),
			new StrToNum("Count-match CH1 Compare-register 0",		(short)CcntConst.CNTS_START_CNTMATCH_CH1_REG0	),
			new StrToNum("Count-match CH2 Compare-register 0",		(short)CcntConst.CNTS_START_CNTMATCH_CH2_REG0	),
			new StrToNum("Count-match CH3 Compare-register 0",		(short)CcntConst.CNTS_START_CNTMATCH_CH3_REG0	),
			new StrToNum("Count-match CH0 Compare-register 1",		(short)CcntConst.CNTS_START_CNTMATCH_CH0_REG1	),
			new StrToNum("Count-match CH1 Compare-register 1",		(short)CcntConst.CNTS_START_CNTMATCH_CH1_REG1	),
			new StrToNum("Count-match CH2 Compare-register 1",		(short)CcntConst.CNTS_START_CNTMATCH_CH2_REG1	),
			new StrToNum("Count-match CH3 Compare-register 1",		(short)CcntConst.CNTS_START_CNTMATCH_CH3_REG1	),
			new StrToNum("End",										0												)
		};
		// Clock Condition
		StrToNum[] ClockTrgTable = 
		{
			new StrToNum("Internal clock",						(short)CcntConst.CNTS_CLOCK_CLOCK				),
			new StrToNum("External clock",						(short)CcntConst.CNTS_CLOCK_EXT_TRG				),
			new StrToNum("End",									0												)
		};
		// Stop Condition
		StrToNum[] StopTrgTable = 
		{
			new StrToNum("Software stop",						(short)CcntConst.CNTS_STOP_SOFT					),
			new StrToNum("External signal rising",				(short)CcntConst.CNTS_STOP_EXT_RISE				),
			new StrToNum("External signal falling",				(short)CcntConst.CNTS_STOP_EXT_FALL				),
			new StrToNum("Stop transfer by specified times",	(short)CcntConst.CNTS_STOP_NUM					),
			new StrToNum("Count-match CH0 Compare-register 0",	(short)CcntConst.CNTS_STOP_CNTMATCH_CH0_REG0	),
			new StrToNum("Count-match CH1 Compare-register 0",	(short)CcntConst.CNTS_STOP_CNTMATCH_CH1_REG0	),
			new StrToNum("Count-match CH2 Compare-register 0",	(short)CcntConst.CNTS_STOP_CNTMATCH_CH2_REG0	),
			new StrToNum("Count-match CH3 Compare-register 0",	(short)CcntConst.CNTS_STOP_CNTMATCH_CH3_REG0	),
			new StrToNum("Count-match CH0 Compare-register 1",	(short)CcntConst.CNTS_STOP_CNTMATCH_CH0_REG1	),
			new StrToNum("Count-match CH1 Compare-register 1",	(short)CcntConst.CNTS_STOP_CNTMATCH_CH1_REG1	),
			new StrToNum("Count-match CH2 Compare-register 1",	(short)CcntConst.CNTS_STOP_CNTMATCH_CH2_REG1	),
			new StrToNum("Count-match CH3 Compare-register 1",	(short)CcntConst.CNTS_STOP_CNTMATCH_CH3_REG1	),
			new StrToNum("End",									0												)
		};

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

		static string		szStart			= "Software start";
		static string		szClock			= "Internal clock";
		static string		szStop			= "Software stop";
		static uint			InternalClock	= 100000;
		static uint			StopNumber		= 1000;
		public static uint	NumberOfData	= 500;
		static short		StartCountMode	= (short)CcntConst.CNTS_START_CNT_WITH_SAMP;
		static short		StopCountMode	= (short)CcntConst.CNTS_STOP_CNT_WITH_SAMP;

		Ccnt				cnt				= new Ccnt();

		public ConditionDlg()
		{
			//
			// 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.btnCancel = new System.Windows.Forms.Button();
			this.btnOK = new System.Windows.Forms.Button();
			this.Frame3 = new System.Windows.Forms.GroupBox();
			this.rdoStopCntWithSamp = new System.Windows.Forms.RadioButton();
			this.rdoStopCntNotWithSamp = new System.Windows.Forms.RadioButton();
			this.Frame4 = new System.Windows.Forms.GroupBox();
			this.txtNumEvent = new System.Windows.Forms.TextBox();
			this.Label11 = new System.Windows.Forms.Label();
			this.Frame1 = new System.Windows.Forms.GroupBox();
			this.cboClockTrg = new System.Windows.Forms.ComboBox();
			this.cboStopTrg = new System.Windows.Forms.ComboBox();
			this.txtStopNum = new System.Windows.Forms.TextBox();
			this.txtCompStop = new System.Windows.Forms.TextBox();
			this.txtInternalClock = new System.Windows.Forms.TextBox();
			this.txtCompStart = new System.Windows.Forms.TextBox();
			this.cboStartTrg = new System.Windows.Forms.ComboBox();
			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.Label4 = new System.Windows.Forms.Label();
			this.Label3 = new System.Windows.Forms.Label();
			this.Label2 = new System.Windows.Forms.Label();
			this.Label1 = new System.Windows.Forms.Label();
			this.Frame2 = new System.Windows.Forms.GroupBox();
			this.rdoStartCntWithSamp = new System.Windows.Forms.RadioButton();
			this.rdoStartCntNotWithSamp = new System.Windows.Forms.RadioButton();
			this.Frame3.SuspendLayout();
			this.Frame4.SuspendLayout();
			this.Frame1.SuspendLayout();
			this.Frame2.SuspendLayout();
			this.SuspendLayout();
			// 
			// 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(387, 369);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.btnCancel.Size = new System.Drawing.Size(96, 23);
			this.btnCancel.TabIndex = 42;
			this.btnCancel.Text = "Cancel";
			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(280, 369);
			this.btnOK.Name = "btnOK";
			this.btnOK.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.btnOK.Size = new System.Drawing.Size(96, 23);
			this.btnOK.TabIndex = 41;
			this.btnOK.Text = "OK";
			this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
			// 
			// Frame3
			// 
			this.Frame3.BackColor = System.Drawing.SystemColors.Control;
			this.Frame3.Controls.AddRange(new System.Windows.Forms.Control[] {
																				 this.rdoStopCntWithSamp,
																				 this.rdoStopCntNotWithSamp});
			this.Frame3.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Frame3.Location = new System.Drawing.Point(6, 223);
			this.Frame3.Name = "Frame3";
			this.Frame3.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Frame3.Size = new System.Drawing.Size(474, 74);
			this.Frame3.TabIndex = 45;
			this.Frame3.TabStop = false;
			this.Frame3.Text = "Counter Stop Mode";
			// 
			// rdoStopCntWithSamp
			// 
			this.rdoStopCntWithSamp.BackColor = System.Drawing.SystemColors.Control;
			this.rdoStopCntWithSamp.Cursor = System.Windows.Forms.Cursors.Default;
			this.rdoStopCntWithSamp.ForeColor = System.Drawing.SystemColors.ControlText;
			this.rdoStopCntWithSamp.Location = new System.Drawing.Point(12, 43);
			this.rdoStopCntWithSamp.Name = "rdoStopCntWithSamp";
			this.rdoStopCntWithSamp.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.rdoStopCntWithSamp.Size = new System.Drawing.Size(239, 20);
			this.rdoStopCntWithSamp.TabIndex = 21;
			this.rdoStopCntWithSamp.TabStop = true;
			this.rdoStopCntWithSamp.Text = "Stop counter when sampling stops";
			// 
			// rdoStopCntNotWithSamp
			// 
			this.rdoStopCntNotWithSamp.BackColor = System.Drawing.SystemColors.Control;
			this.rdoStopCntNotWithSamp.Cursor = System.Windows.Forms.Cursors.Default;
			this.rdoStopCntNotWithSamp.ForeColor = System.Drawing.SystemColors.ControlText;
			this.rdoStopCntNotWithSamp.Location = new System.Drawing.Point(12, 20);
			this.rdoStopCntNotWithSamp.Name = "rdoStopCntNotWithSamp";
			this.rdoStopCntNotWithSamp.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.rdoStopCntNotWithSamp.Size = new System.Drawing.Size(239, 20);
			this.rdoStopCntNotWithSamp.TabIndex = 20;
			this.rdoStopCntNotWithSamp.TabStop = true;
			this.rdoStopCntNotWithSamp.Text = "Stop counter regardless of sampling";
			// 
			// Frame4
			// 
			this.Frame4.BackColor = System.Drawing.SystemColors.Control;
			this.Frame4.Controls.AddRange(new System.Windows.Forms.Control[] {
																				 this.txtNumEvent,
																				 this.Label11});
			this.Frame4.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Frame4.Location = new System.Drawing.Point(9, 303);
			this.Frame4.Name = "Frame4";
			this.Frame4.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Frame4.Size = new System.Drawing.Size(474, 56);
			this.Frame4.TabIndex = 46;
			this.Frame4.TabStop = false;
			this.Frame4.Text = "Transfer Number Event Notification";
			// 
			// txtNumEvent
			// 
			this.txtNumEvent.AcceptsReturn = true;
			this.txtNumEvent.AutoSize = false;
			this.txtNumEvent.BackColor = System.Drawing.SystemColors.Window;
			this.txtNumEvent.Cursor = System.Windows.Forms.Cursors.IBeam;
			this.txtNumEvent.ForeColor = System.Drawing.SystemColors.WindowText;
			this.txtNumEvent.Location = new System.Drawing.Point(110, 26);
			this.txtNumEvent.MaxLength = 0;
			this.txtNumEvent.Name = "txtNumEvent";
			this.txtNumEvent.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.txtNumEvent.Size = new System.Drawing.Size(80, 20);
			this.txtNumEvent.TabIndex = 23;
			this.txtNumEvent.Text = "";
			// 
			// Label11
			// 
			this.Label11.AutoSize = true;
			this.Label11.BackColor = System.Drawing.SystemColors.Control;
			this.Label11.Cursor = System.Windows.Forms.Cursors.Default;
			this.Label11.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Label11.Location = new System.Drawing.Point(12, 29);
			this.Label11.Name = "Label11";
			this.Label11.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Label11.Size = new System.Drawing.Size(85, 13);
			this.Label11.TabIndex = 24;
			this.Label11.Text = "Number of data:";
			// 
			// Frame1
			// 
			this.Frame1.BackColor = System.Drawing.SystemColors.Control;
			this.Frame1.Controls.AddRange(new System.Windows.Forms.Control[] {
																				 this.cboClockTrg,
																				 this.cboStopTrg,
																				 this.txtStopNum,
																				 this.txtCompStop,
																				 this.txtInternalClock,
																				 this.txtCompStart,
																				 this.cboStartTrg,
																				 this.Label10,
																				 this.Label9,
																				 this.Label8,
																				 this.Label7,
																				 this.Label6,
																				 this.Label5,
																				 this.Label4,
																				 this.Label3,
																				 this.Label2,
																				 this.Label1});
			this.Frame1.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Frame1.Location = new System.Drawing.Point(6, 6);
			this.Frame1.Name = "Frame1";
			this.Frame1.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Frame1.Size = new System.Drawing.Size(474, 131);
			this.Frame1.TabIndex = 43;
			this.Frame1.TabStop = false;
			this.Frame1.Text = "Sampling Condition";
			// 
			// cboClockTrg
			// 
			this.cboClockTrg.BackColor = System.Drawing.SystemColors.Window;
			this.cboClockTrg.Cursor = System.Windows.Forms.Cursors.Default;
			this.cboClockTrg.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboClockTrg.ForeColor = System.Drawing.SystemColors.WindowText;
			this.cboClockTrg.Location = new System.Drawing.Point(50, 46);
			this.cboClockTrg.Name = "cboClockTrg";
			this.cboClockTrg.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cboClockTrg.Size = new System.Drawing.Size(220, 21);
			this.cboClockTrg.TabIndex = 11;
			this.cboClockTrg.SelectedIndexChanged += new System.EventHandler(this.cboClockTrg_SelectedIndexChanged);
			// 
			// cboStopTrg
			// 
			this.cboStopTrg.BackColor = System.Drawing.SystemColors.Window;
			this.cboStopTrg.Cursor = System.Windows.Forms.Cursors.Default;
			this.cboStopTrg.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboStopTrg.ForeColor = System.Drawing.SystemColors.WindowText;
			this.cboStopTrg.Location = new System.Drawing.Point(50, 72);
			this.cboStopTrg.Name = "cboStopTrg";
			this.cboStopTrg.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cboStopTrg.Size = new System.Drawing.Size(220, 21);
			this.cboStopTrg.TabIndex = 12;
			this.cboStopTrg.SelectedIndexChanged += new System.EventHandler(this.cboStopTrg_SelectedIndexChanged);
			// 
			// txtStopNum
			// 
			this.txtStopNum.AcceptsReturn = true;
			this.txtStopNum.AutoSize = false;
			this.txtStopNum.BackColor = System.Drawing.SystemColors.Window;
			this.txtStopNum.Cursor = System.Windows.Forms.Cursors.IBeam;
			this.txtStopNum.ForeColor = System.Drawing.SystemColors.WindowText;
			this.txtStopNum.Location = new System.Drawing.Point(362, 98);
			this.txtStopNum.MaxLength = 0;
			this.txtStopNum.Name = "txtStopNum";
			this.txtStopNum.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.txtStopNum.Size = new System.Drawing.Size(72, 20);
			this.txtStopNum.TabIndex = 28;
			this.txtStopNum.Text = "";
			// 
			// txtCompStop
			// 
			this.txtCompStop.AcceptsReturn = true;
			this.txtCompStop.AutoSize = false;
			this.txtCompStop.BackColor = System.Drawing.SystemColors.Window;
			this.txtCompStop.Cursor = System.Windows.Forms.Cursors.IBeam;
			this.txtCompStop.ForeColor = System.Drawing.SystemColors.WindowText;
			this.txtCompStop.Location = new System.Drawing.Point(362, 72);
			this.txtCompStop.MaxLength = 0;
			this.txtCompStop.Name = "txtCompStop";
			this.txtCompStop.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.txtCompStop.Size = new System.Drawing.Size(72, 20);
			this.txtCompStop.TabIndex = 27;
			this.txtCompStop.Text = "";
			// 
			// txtInternalClock
			// 
			this.txtInternalClock.AcceptsReturn = true;
			this.txtInternalClock.AutoSize = false;
			this.txtInternalClock.BackColor = System.Drawing.SystemColors.Window;
			this.txtInternalClock.Cursor = System.Windows.Forms.Cursors.IBeam;
			this.txtInternalClock.ForeColor = System.Drawing.SystemColors.WindowText;
			this.txtInternalClock.Location = new System.Drawing.Point(362, 46);
			this.txtInternalClock.MaxLength = 0;
			this.txtInternalClock.Name = "txtInternalClock";
			this.txtInternalClock.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.txtInternalClock.Size = new System.Drawing.Size(72, 20);
			this.txtInternalClock.TabIndex = 26;
			this.txtInternalClock.Text = "";
			// 
			// txtCompStart
			// 
			this.txtCompStart.AcceptsReturn = true;
			this.txtCompStart.AutoSize = false;
			this.txtCompStart.BackColor = System.Drawing.SystemColors.Window;
			this.txtCompStart.Cursor = System.Windows.Forms.Cursors.IBeam;
			this.txtCompStart.ForeColor = System.Drawing.SystemColors.WindowText;
			this.txtCompStart.Location = new System.Drawing.Point(362, 20);
			this.txtCompStart.MaxLength = 0;
			this.txtCompStart.Name = "txtCompStart";
			this.txtCompStart.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.txtCompStart.Size = new System.Drawing.Size(72, 20);
			this.txtCompStart.TabIndex = 25;
			this.txtCompStart.Text = "";
			// 
			// cboStartTrg
			// 
			this.cboStartTrg.BackColor = System.Drawing.SystemColors.Window;
			this.cboStartTrg.Cursor = System.Windows.Forms.Cursors.Default;
			this.cboStartTrg.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboStartTrg.ForeColor = System.Drawing.SystemColors.WindowText;
			this.cboStartTrg.Location = new System.Drawing.Point(50, 20);
			this.cboStartTrg.Name = "cboStartTrg";
			this.cboStartTrg.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cboStartTrg.Size = new System.Drawing.Size(220, 21);
			this.cboStartTrg.TabIndex = 10;
			this.cboStartTrg.SelectedIndexChanged += new System.EventHandler(this.cboStartTrg_SelectedIndexChanged);
			// 
			// 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(440, 75);
			this.Label10.Name = "Label10";
			this.Label10.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Label10.Size = new System.Drawing.Size(24, 13);
			this.Label10.TabIndex = 15;
			this.Label10.Text = "Hex";
			// 
			// Label9
			// 
			this.Label9.AutoSize = true;
			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(440, 49);
			this.Label9.Name = "Label9";
			this.Label9.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Label9.Size = new System.Drawing.Size(16, 13);
			this.Label9.TabIndex = 14;
			this.Label9.Text = "ns";
			// 
			// Label8
			// 
			this.Label8.AutoSize = true;
			this.Label8.BackColor = System.Drawing.SystemColors.Control;
			this.Label8.Cursor = System.Windows.Forms.Cursors.Default;
			this.Label8.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Label8.Location = new System.Drawing.Point(440, 23);
			this.Label8.Name = "Label8";
			this.Label8.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Label8.Size = new System.Drawing.Size(24, 13);
			this.Label8.TabIndex = 13;
			this.Label8.Text = "Hex";
			// 
			// 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(274, 101);
			this.Label7.Name = "Label7";
			this.Label7.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Label7.Size = new System.Drawing.Size(74, 13);
			this.Label7.TabIndex = 9;
			this.Label7.Text = "Stop Number:";
			// 
			// Label6
			// 
			this.Label6.AutoSize = true;
			this.Label6.BackColor = System.Drawing.SystemColors.Control;
			this.Label6.Cursor = System.Windows.Forms.Cursors.Default;
			this.Label6.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Label6.Location = new System.Drawing.Point(274, 75);
			this.Label6.Name = "Label6";
			this.Label6.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Label6.Size = new System.Drawing.Size(86, 13);
			this.Label6.TabIndex = 8;
			this.Label6.Text = "Compare Value:";
			// 
			// 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(274, 49);
			this.Label5.Name = "Label5";
			this.Label5.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Label5.Size = new System.Drawing.Size(77, 13);
			this.Label5.TabIndex = 7;
			this.Label5.Text = "Internal Clock:";
			// 
			// 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(274, 23);
			this.Label4.Name = "Label4";
			this.Label4.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Label4.Size = new System.Drawing.Size(86, 13);
			this.Label4.TabIndex = 6;
			this.Label4.Text = "Compare Value:";
			// 
			// 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(12, 75);
			this.Label3.Name = "Label3";
			this.Label3.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Label3.Size = new System.Drawing.Size(31, 13);
			this.Label3.TabIndex = 5;
			this.Label3.Text = "Stop:";
			// 
			// 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(12, 49);
			this.Label2.Name = "Label2";
			this.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Label2.Size = new System.Drawing.Size(36, 13);
			this.Label2.TabIndex = 4;
			this.Label2.Text = "Clock:";
			// 
			// 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(12, 23);
			this.Label1.Name = "Label1";
			this.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Label1.Size = new System.Drawing.Size(31, 13);
			this.Label1.TabIndex = 3;
			this.Label1.Text = "Start:";
			// 
			// Frame2
			// 
			this.Frame2.BackColor = System.Drawing.SystemColors.Control;
			this.Frame2.Controls.AddRange(new System.Windows.Forms.Control[] {
																				 this.rdoStartCntWithSamp,
																				 this.rdoStartCntNotWithSamp});
			this.Frame2.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Frame2.Location = new System.Drawing.Point(6, 143);
			this.Frame2.Name = "Frame2";
			this.Frame2.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Frame2.Size = new System.Drawing.Size(474, 74);
			this.Frame2.TabIndex = 44;
			this.Frame2.TabStop = false;
			this.Frame2.Text = "Counter Start Mode";
			// 
			// rdoStartCntWithSamp
			// 
			this.rdoStartCntWithSamp.BackColor = System.Drawing.SystemColors.Control;
			this.rdoStartCntWithSamp.Cursor = System.Windows.Forms.Cursors.Default;
			this.rdoStartCntWithSamp.ForeColor = System.Drawing.SystemColors.ControlText;
			this.rdoStartCntWithSamp.Location = new System.Drawing.Point(12, 43);
			this.rdoStartCntWithSamp.Name = "rdoStartCntWithSamp";
			this.rdoStartCntWithSamp.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.rdoStartCntWithSamp.Size = new System.Drawing.Size(239, 20);
			this.rdoStartCntWithSamp.TabIndex = 18;
			this.rdoStartCntWithSamp.TabStop = true;
			this.rdoStartCntWithSamp.Text = "Start counter when sampling starts";
			// 
			// rdoStartCntNotWithSamp
			// 
			this.rdoStartCntNotWithSamp.BackColor = System.Drawing.SystemColors.Control;
			this.rdoStartCntNotWithSamp.Cursor = System.Windows.Forms.Cursors.Default;
			this.rdoStartCntNotWithSamp.ForeColor = System.Drawing.SystemColors.ControlText;
			this.rdoStartCntNotWithSamp.Location = new System.Drawing.Point(12, 20);
			this.rdoStartCntNotWithSamp.Name = "rdoStartCntNotWithSamp";
			this.rdoStartCntNotWithSamp.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.rdoStartCntNotWithSamp.Size = new System.Drawing.Size(239, 20);
			this.rdoStartCntNotWithSamp.TabIndex = 17;
			this.rdoStartCntNotWithSamp.TabStop = true;
			this.rdoStartCntNotWithSamp.Text = "Start counter regardless of sampling";
			// 
			// ConditionDlg
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(496, 398);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.btnCancel,
																		  this.btnOK,
																		  this.Frame3,
																		  this.Frame4,
																		  this.Frame1,
																		  this.Frame2});
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "ConditionDlg";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Sampling Condition Setting";
			this.Load += new System.EventHandler(this.ConditionDlg_Load);
			this.Frame3.ResumeLayout(false);
			this.Frame4.ResumeLayout(false);
			this.Frame1.ResumeLayout(false);
			this.Frame2.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		//===================================================
		// Dialog initialization
		//===================================================
		private void ConditionDlg_Load(object sender, System.EventArgs e)
		{
			//--------------------------------
			// Initialize display
			//--------------------------------
			uint	i;
			string	szBuf = new string(' ', 256);

			for (i=0; string.Compare(StartTrgTable[i].Str, "End") != 0; i++) 
			{
				cboStartTrg.Items.Add(StartTrgTable[i].Str);
			}
			for (i=0; string.Compare(ClockTrgTable[i].Str, "End") != 0; i++) 
			{
				cboClockTrg.Items.Add(ClockTrgTable[i].Str);
			}
			for (i=0; string.Compare(StopTrgTable[i].Str, "End") != 0; i++) 
			{
				cboStopTrg.Items.Add(StopTrgTable[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;
			}

			szBuf = string.Format("{0:X}", StartComp);
			txtCompStart.Text = szBuf;
			txtInternalClock.Text = InternalClock.ToString();
			txtStopNum.Text = StopNumber.ToString();
			txtNumEvent.Text = NumberOfData.ToString();
			szBuf = string.Format("{0:X}", StopComp);
			txtCompStop.Text = szBuf;

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

		//===================================================
		// Start condition setting is changed
		//===================================================
		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;
			}
		}

		//===================================================
		// Clock condition setting is changed
		//===================================================
		private void cboClockTrg_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			string	szBuf = new string(' ', 100);
			
			//--------------------------------
			// Enable/Disable internal clock value
			//--------------------------------
			szBuf = cboClockTrg.Text;

			if (string.Compare(szBuf, "Internal clock") == 0) 
			{
				txtInternalClock.Enabled = true;
			} 
			else 
			{
				txtInternalClock.Enabled = false;
			}
		}

		//===================================================
		// Stop condition setting is changed
		//===================================================
		private void cboStopTrg_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			string	szBuf = new string(' ', 100);

			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 button processing
		//===================================================
		private void btnOK_Click(object sender, System.EventArgs e)
		{
			string	error_string = new string(' ', 256);
			string	szTmp = new string(' ', 100);
			short	StartTrg;
			short	ClockTrg;
			short	StopTrg;
			short	i;
			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;
			try
			{
				StartComp = uint.Parse(szTmp, NumberStyles.HexNumber);
			}
			catch (System.FormatException)
			{
				StartComp = 0x100;
			}
			szTmp = txtCompStop.Text;
			try
			{
				StopComp = uint.Parse(szTmp, NumberStyles.HexNumber);
			}
			catch (System.FormatException)
			{
				StopComp = 0x200;
			}
			szTmp = txtInternalClock.Text;
			try
			{
				InternalClock = uint.Parse(szTmp);
			}
			catch (System.FormatException)
			{
				InternalClock = 100000;
			}
			szTmp = txtStopNum.Text;
			try
			{
				StopNumber = uint.Parse(szTmp);
			}
			catch (System.FormatException)
			{
				StopNumber = 1000;
			}
			szTmp = txtNumEvent.Text;
			try
			{
				NumberOfData = uint.Parse(szTmp);
			}
			catch (System.FormatException)
			{
				NumberOfData = 500;
			}

			//--------------------------------
			// Convert setting value to a number
			//--------------------------------
			StartTrg = 0;
			for (i=0; string.Compare(StartTrgTable[i].Str, "End") != 0; i++) 
			{
				if (string.Compare(szStart, StartTrgTable[i].Str) == 0) 
				{
					StartTrg = StartTrgTable[i].Num;
					break;
				}
			}
			ClockTrg = 0;
			for (i=0; string.Compare(ClockTrgTable[i].Str, "End") != 0; i++) 
			{
				if (string.Compare(szClock, ClockTrgTable[i].Str) == 0) 
				{
					ClockTrg = ClockTrgTable[i].Num;
					break;
				}
			}
			StopTrg = 0;
			for (i=0; string.Compare(StopTrgTable[i].Str, "End") != 0; i++) 
			{
				if (string.Compare(szStop, StopTrgTable[i].Str) == 0) 
				{
					StopTrg = StopTrgTable[i].Num;
					break;
				}
			}
			//--------------------------------
			// Set sampling condition
			//--------------------------------
			// Stand-alone
			ret = cnt.SetStandAlone(Sampling.Id);
			if (ret != (int)CcntConst.CNT_ERR_SUCCESS) 
			{
				cnt.GetErrorString(ret, out error_string);
				strMsg = string.Format("CntSetStandAlone ret = {0:d}: {1}", ret, error_string);
				MessageBox.Show(strMsg, Application.ProductName, MessageBoxButtons.OK);
				return;
			}
			// Set start condition
			ret = cnt.SetSamplingStartTrigger(Sampling.Id, StartTrg, StartCountMode, Sampling.CHANNEL_NUM);
			if (ret != (int)CcntConst.CNT_ERR_SUCCESS) 
			{
				cnt.GetErrorString(ret, out error_string);
				strMsg = string.Format("CntSetSamplingStartTrigger ret = {0:d}: {1}", ret, error_string);
				MessageBox.Show(strMsg, Application.ProductName, MessageBoxButtons.OK);
				return;
			}
			switch(StartTrg) 
			{
				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(Sampling.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, Application.ProductName, MessageBoxButtons.OK);
				}
			}
			// Set clock condition
			ret = cnt.SetSamplingClockTrigger(Sampling.Id, ClockTrg);
			if (ret != (int)CcntConst.CNT_ERR_SUCCESS) 
			{
				cnt.GetErrorString(ret, out error_string);
				strMsg = string.Format("CntSetSamplingClockTrigger ret = {0:d}: {1}", ret, error_string);
				MessageBox.Show(strMsg, Application.ProductName, MessageBoxButtons.OK);
				return;
			}
			// Set internal clock value
			if (ClockTrg == (short)CcntConst.CNTS_CLOCK_CLOCK) 
			{
				ret = cnt.SetSamplingInternalClock(Sampling.Id, InternalClock, (short)CcntConst.CNTS_TIM_UNIT_NS);
				if (ret != (int)CcntConst.CNT_ERR_SUCCESS) 
				{
					cnt.GetErrorString(ret, out error_string);
					strMsg = string.Format("CntSetSamplingInternalClock ret = {0:d}: {1}", ret, error_string);
					MessageBox.Show(strMsg, Application.ProductName, MessageBoxButtons.OK);
					return;
				}
			}

			// Set stop condition
			ret = cnt.SetSamplingStopTrigger(Sampling.Id, StopTrg, StopCountMode, Sampling.CHANNEL_NUM);
			if (ret != (int)CcntConst.CNT_ERR_SUCCESS) 
			{
				cnt.GetErrorString(ret, out error_string);
				strMsg = string.Format("CntSetSamplingStopTrigger ret = {0:d}: {1}", ret, error_string);
				MessageBox.Show(strMsg, Application.ProductName, MessageBoxButtons.OK);
				return;
			}
			switch(StopTrg) 
			{
				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(Sampling.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, Application.ProductName, MessageBoxButtons.OK);
				}
			}
			// Set stop number
			if (StopTrg == (short)CcntConst.CNTS_STOP_NUM) 
			{
				ret = cnt.SetSamplingStopNumber(Sampling.Id, StopNumber);
				if (ret != (int)CcntConst.CNT_ERR_SUCCESS) 
				{
					cnt.GetErrorString(ret, out error_string);
					strMsg = string.Format("CntSetSamplingInternalClock ret = {0:d}: {1}", ret, error_string);
					MessageBox.Show(strMsg, Application.ProductName, MessageBoxButtons.OK);
					return;
				}
			}
			this.Close();
		}

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