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

namespace Infinite
{
	/// <summary>
	/// 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.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;
		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;
		/// <summary>
		/// 必要なデザイナ変数です。
		/// </summary>
		private System.ComponentModel.Container components = null;

		Ccnt					cnt			   = new Ccnt();

		// Start Condition
		static frmMode.StrNum[] StartTrg =
		{
			new frmMode.StrNum("ソフトウェアスタート",	            (ushort)CcntConst.CNTS_START_SOFT               ),
			new frmMode.StrNum("外部信号立ち上がり",		        (ushort)CcntConst.CNTS_START_EXT_RISE           ),
			new frmMode.StrNum("外部信号立ち下がり",		        (ushort)CcntConst.CNTS_START_EXT_FALL           ),
			new frmMode.StrNum("カウント一致CH0 比較レジスタ0",	    (ushort)CcntConst.CNTS_START_CNTMATCH_CH0_REG0  ),
			new frmMode.StrNum("カウント一致CH1 比較レジスタ0",		(ushort)CcntConst.CNTS_START_CNTMATCH_CH1_REG0  ),
			new frmMode.StrNum("カウント一致CH2 比較レジスタ0",		(ushort)CcntConst.CNTS_START_CNTMATCH_CH2_REG0  ),
			new frmMode.StrNum("カウント一致CH3 比較レジスタ0",	    (ushort)CcntConst.CNTS_START_CNTMATCH_CH3_REG1  ),
			new frmMode.StrNum("カウント一致CH0 比較レジスタ1",		(ushort)CcntConst.CNTS_START_CNTMATCH_CH0_REG1  ),
			new frmMode.StrNum("カウント一致CH1 比較レジスタ1",		(ushort)CcntConst.CNTS_START_CNTMATCH_CH1_REG1  ),
			new frmMode.StrNum("カウント一致CH2 比較レジスタ1",		(ushort)CcntConst.CNTS_START_CNTMATCH_CH2_REG1  ),
			new frmMode.StrNum("カウント一致CH3 比較レジスタ1",		(ushort)CcntConst.CNTS_START_CNTMATCH_CH3_REG1  ),
			new frmMode.StrNum("End",		                        0									            )
		};

		// Clock Condition
		static frmMode.StrNum[] ClockTrg =
		{
			new frmMode.StrNum("内部クロック",	            (ushort)CcntConst.CNTS_CLOCK_CLOCK     ),
			new frmMode.StrNum("外部クロック",		        (ushort)CcntConst.CNTS_CLOCK_EXT_TRG   ),
			new frmMode.StrNum("End",		                0									   )
		};

        // Stop Condition
		static frmMode.StrNum[] StopTrg =
		{
			new frmMode.StrNum("ソフトウェアストップ",	            (ushort)CcntConst.CNTS_STOP_SOFT                ),
			new frmMode.StrNum("外部信号立ち上がり",		        (ushort)CcntConst.CNTS_STOP_EXT_RISE            ),
			new frmMode.StrNum("外部信号立ち下がり",		        (ushort)CcntConst.CNTS_STOP_EXT_FALL            ),
			new frmMode.StrNum("指定個数転送完了",		            (ushort)CcntConst.CNTS_STOP_NUM                 ),
			new frmMode.StrNum("カウント一致CH0 比較レジスタ0",	    (ushort)CcntConst.CNTS_STOP_CNTMATCH_CH0_REG0  ),
			new frmMode.StrNum("カウント一致CH1 比較レジスタ0",		(ushort)CcntConst.CNTS_STOP_CNTMATCH_CH1_REG0  ),
			new frmMode.StrNum("カウント一致CH2 比較レジスタ0",		(ushort)CcntConst.CNTS_STOP_CNTMATCH_CH2_REG0  ),
			new frmMode.StrNum("カウント一致CH3 比較レジスタ0",	    (ushort)CcntConst.CNTS_STOP_CNTMATCH_CH3_REG0  ),
			new frmMode.StrNum("カウント一致CH0 比較レジスタ1",		(ushort)CcntConst.CNTS_STOP_CNTMATCH_CH0_REG1  ),
			new frmMode.StrNum("カウント一致CH1 比較レジスタ1",		(ushort)CcntConst.CNTS_STOP_CNTMATCH_CH1_REG1  ),
			new frmMode.StrNum("カウント一致CH2 比較レジスタ1",		(ushort)CcntConst.CNTS_STOP_CNTMATCH_CH2_REG1  ),
			new frmMode.StrNum("カウント一致CH3 比較レジスタ1",		(ushort)CcntConst.CNTS_STOP_CNTMATCH_CH3_REG1  ),
			new frmMode.StrNum("End",		                        0									            )
		};

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

		string			szStart	        = "ソフトウェアスタート";
		string			szClock	        = "内部クロック";
		string			szStop		    = "ソフトウェアストップ";
		long	        Mask			= 0xFF;
		uint	        InternalClock	= 100000;
		uint	        StopNumber		= 1000;
		long	        NumberOfData	= 500;
		short			StartCountMode	= (short)CcntConst.CNTS_START_CNT_WITH_SAMP;
		short			StopCountMode	= (short)CcntConst.CNTS_STOP_CNT_WITH_SAMP;
		short       	Id;



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

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

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

		#region Windows Form Designer generated code
		/// <summary>
		/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
		/// コード エディタで変更しないでください。
		/// </summary>
		private void InitializeComponent()
		{
			this.GroupBox2 = new System.Windows.Forms.GroupBox();
			this.rdoStartCntwithSamp = new System.Windows.Forms.RadioButton();
			this.rdoStartCntNotwithSamp = 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.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.GroupBox2.SuspendLayout();
			this.GroupBox1.SuspendLayout();
			this.GroupBox4.SuspendLayout();
			this.GroupBox3.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, 154);
			this.GroupBox2.Name = "GroupBox2";
			this.GroupBox2.Size = new System.Drawing.Size(480, 64);
			this.GroupBox2.TabIndex = 9;
			this.GroupBox2.TabStop = false;
			this.GroupBox2.Text = "カウンタスタート モード";
			// 
			// rdoStartCntwithSamp
			// 
			this.rdoStartCntwithSamp.Location = new System.Drawing.Point(16, 40);
			this.rdoStartCntwithSamp.Name = "rdoStartCntwithSamp";
			this.rdoStartCntwithSamp.Size = new System.Drawing.Size(200, 16);
			this.rdoStartCntwithSamp.TabIndex = 1;
			this.rdoStartCntwithSamp.Text = "サンプリングと同時にカウンタスタート";
			// 
			// rdoStartCntNotwithSamp
			// 
			this.rdoStartCntNotwithSamp.Location = new System.Drawing.Point(16, 16);
			this.rdoStartCntNotwithSamp.Name = "rdoStartCntNotwithSamp";
			this.rdoStartCntNotwithSamp.Size = new System.Drawing.Size(232, 24);
			this.rdoStartCntNotwithSamp.TabIndex = 0;
			this.rdoStartCntNotwithSamp.Text = "サンプリングとは無関係にカウンタスタート";
			// 
			// 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, 10);
			this.GroupBox1.Name = "GroupBox1";
			this.GroupBox1.Size = new System.Drawing.Size(480, 136);
			this.GroupBox1.TabIndex = 8;
			this.GroupBox1.TabStop = false;
			this.GroupBox1.Text = "サンプリング条件";
			// 
			// Label10
			// 
			this.Label10.Location = new System.Drawing.Point(451, 86);
			this.Label10.Name = "Label10";
			this.Label10.Size = new System.Drawing.Size(24, 20);
			this.Label10.TabIndex = 16;
			this.Label10.Text = "Hex";
			// 
			// Label9
			// 
			this.Label9.Location = new System.Drawing.Point(451, 58);
			this.Label9.Name = "Label9";
			this.Label9.Size = new System.Drawing.Size(24, 20);
			this.Label9.TabIndex = 15;
			this.Label9.Text = "ns";
			// 
			// Label8
			// 
			this.Label8.Location = new System.Drawing.Point(451, 30);
			this.Label8.Name = "Label8";
			this.Label8.Size = new System.Drawing.Size(24, 20);
			this.Label8.TabIndex = 14;
			this.Label8.Text = "Hex";
			// 
			// Label7
			// 
			this.Label7.Location = new System.Drawing.Point(279, 106);
			this.Label7.Name = "Label7";
			this.Label7.Size = new System.Drawing.Size(80, 20);
			this.Label7.TabIndex = 13;
			this.Label7.Text = "停止個数：";
			// 
			// Label6
			// 
			this.Label6.Location = new System.Drawing.Point(279, 79);
			this.Label6.Name = "Label6";
			this.Label6.Size = new System.Drawing.Size(80, 20);
			this.Label6.TabIndex = 12;
			this.Label6.Text = "比較値：";
			// 
			// Label5
			// 
			this.Label5.Location = new System.Drawing.Point(279, 52);
			this.Label5.Name = "Label5";
			this.Label5.Size = new System.Drawing.Size(79, 20);
			this.Label5.TabIndex = 11;
			this.Label5.Text = "内部クロック：";
			// 
			// txtStopNum
			// 
			this.txtStopNum.Location = new System.Drawing.Point(362, 106);
			this.txtStopNum.Name = "txtStopNum";
			this.txtStopNum.Size = new System.Drawing.Size(88, 19);
			this.txtStopNum.TabIndex = 10;
			this.txtStopNum.Text = "TextBox4";
			// 
			// txtCompStop
			// 
			this.txtCompStop.Location = new System.Drawing.Point(362, 79);
			this.txtCompStop.Name = "txtCompStop";
			this.txtCompStop.Size = new System.Drawing.Size(88, 19);
			this.txtCompStop.TabIndex = 9;
			this.txtCompStop.Text = "TextBox3";
			// 
			// txtInternalClock
			// 
			this.txtInternalClock.Location = new System.Drawing.Point(362, 52);
			this.txtInternalClock.Name = "txtInternalClock";
			this.txtInternalClock.Size = new System.Drawing.Size(88, 19);
			this.txtInternalClock.TabIndex = 8;
			this.txtInternalClock.Text = "TextBox2";
			// 
			// Label4
			// 
			this.Label4.Location = new System.Drawing.Point(279, 24);
			this.Label4.Name = "Label4";
			this.Label4.Size = new System.Drawing.Size(80, 20);
			this.Label4.TabIndex = 7;
			this.Label4.Text = "比較値：";
			// 
			// txtCompStart
			// 
			this.txtCompStart.Location = new System.Drawing.Point(362, 24);
			this.txtCompStart.Name = "txtCompStart";
			this.txtCompStart.Size = new System.Drawing.Size(88, 19);
			this.txtCompStart.TabIndex = 6;
			this.txtCompStart.Text = "TextBox1";
			// 
			// Label3
			// 
			this.Label3.Location = new System.Drawing.Point(16, 79);
			this.Label3.Name = "Label3";
			this.Label3.Size = new System.Drawing.Size(72, 20);
			this.Label3.TabIndex = 5;
			this.Label3.Text = "ストップ条件：";
			// 
			// Label2
			// 
			this.Label2.Location = new System.Drawing.Point(16, 52);
			this.Label2.Name = "Label2";
			this.Label2.Size = new System.Drawing.Size(72, 20);
			this.Label2.TabIndex = 4;
			this.Label2.Text = "クロック条件：";
			// 
			// cboStopTrg
			// 
			this.cboStopTrg.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboStopTrg.Location = new System.Drawing.Point(88, 79);
			this.cboStopTrg.Name = "cboStopTrg";
			this.cboStopTrg.Size = new System.Drawing.Size(184, 20);
			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(88, 52);
			this.cboClockTrg.Name = "cboClockTrg";
			this.cboClockTrg.Size = new System.Drawing.Size(184, 20);
			this.cboClockTrg.TabIndex = 2;
			this.cboClockTrg.SelectedIndexChanged += new System.EventHandler(this.cboClockTrg_SelectedIndexChanged);
			// 
			// Label1
			// 
			this.Label1.Location = new System.Drawing.Point(16, 24);
			this.Label1.Name = "Label1";
			this.Label1.Size = new System.Drawing.Size(72, 20);
			this.Label1.TabIndex = 1;
			this.Label1.Text = "スタート条件：";
			// 
			// cboStartTrg
			// 
			this.cboStartTrg.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboStartTrg.Location = new System.Drawing.Point(88, 24);
			this.cboStartTrg.Name = "cboStartTrg";
			this.cboStartTrg.Size = new System.Drawing.Size(184, 20);
			this.cboStartTrg.TabIndex = 0;
			this.cboStartTrg.SelectedIndexChanged += new System.EventHandler(this.cboStartTrg_SelectedIndexChanged);
			// 
			// btnCancel
			// 
			this.btnCancel.Location = new System.Drawing.Point(375, 354);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.Size = new System.Drawing.Size(104, 26);
			this.btnCancel.TabIndex = 13;
			this.btnCancel.Text = "ｷｬﾝｾﾙ";
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			// 
			// btnOK
			// 
			this.btnOK.Location = new System.Drawing.Point(255, 354);
			this.btnOK.Name = "btnOK";
			this.btnOK.Size = new System.Drawing.Size(104, 26);
			this.btnOK.TabIndex = 12;
			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, 298);
			this.GroupBox4.Name = "GroupBox4";
			this.GroupBox4.Size = new System.Drawing.Size(480, 48);
			this.GroupBox4.TabIndex = 11;
			this.GroupBox4.TabStop = false;
			this.GroupBox4.Text = "転送個数イベント通知";
			// 
			// Label11
			// 
			this.Label11.Location = new System.Drawing.Point(168, 24);
			this.Label11.Name = "Label11";
			this.Label11.Size = new System.Drawing.Size(112, 20);
			this.Label11.TabIndex = 1;
			this.Label11.Text = "データ毎に通知";
			// 
			// txtNumEvent
			// 
			this.txtNumEvent.Location = new System.Drawing.Point(32, 19);
			this.txtNumEvent.Name = "txtNumEvent";
			this.txtNumEvent.Size = new System.Drawing.Size(112, 19);
			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, 226);
			this.GroupBox3.Name = "GroupBox3";
			this.GroupBox3.Size = new System.Drawing.Size(480, 64);
			this.GroupBox3.TabIndex = 10;
			this.GroupBox3.TabStop = false;
			this.GroupBox3.Text = "カウンタストップ モード";
			// 
			// rdoStopCntwithSamp
			// 
			this.rdoStopCntwithSamp.Location = new System.Drawing.Point(16, 40);
			this.rdoStopCntwithSamp.Name = "rdoStopCntwithSamp";
			this.rdoStopCntwithSamp.Size = new System.Drawing.Size(200, 16);
			this.rdoStopCntwithSamp.TabIndex = 1;
			this.rdoStopCntwithSamp.Text = "サンプリングと同時にカウンタストップ";
			// 
			// rdoStopCntNotwithSamp
			// 
			this.rdoStopCntNotwithSamp.Location = new System.Drawing.Point(16, 16);
			this.rdoStopCntNotwithSamp.Name = "rdoStopCntNotwithSamp";
			this.rdoStopCntNotwithSamp.Size = new System.Drawing.Size(232, 24);
			this.rdoStopCntNotwithSamp.TabIndex = 0;
			this.rdoStopCntNotwithSamp.Text = "サンプリングとは無関係にカウンタストップ";
			// 
			// frmCondition
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
			this.ClientSize = new System.Drawing.Size(494, 390);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.GroupBox2,
																		  this.GroupBox1,
																		  this.btnCancel,
																		  this.btnOK,
																		  this.GroupBox4,
																		  this.GroupBox3});
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "frmCondition";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "無限サンプリング条件設定";
			this.Load += new System.EventHandler(this.frmCondition_Load);
			this.GroupBox2.ResumeLayout(false);
			this.GroupBox1.ResumeLayout(false);
			this.GroupBox4.ResumeLayout(false);
			this.GroupBox3.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion


		//===================================================
		//	ダイアログ初期化
		//===================================================
		private void frmCondition_Load(object sender, System.EventArgs e)
		{
			//--------------------------------
			// 表示初期化
			//--------------------------------
			long	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());
	
		}

		//===================================================
		//	スタート条件設定変更
		//===================================================
		private void cboStartTrg_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			string	szBuf = new string(' ', 100);

			szBuf = cboStartTrg.Text;
			if (szBuf.StartsWith("カウント一致")) 
			{
				txtCompStart.Enabled = true;
			} 
			else 
			{
				txtCompStart.Enabled = false;
			}

		}

		//===================================================
		//	クロック条件設定変更
		//===================================================
		private void cboClockTrg_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			string	szBuf = new string(' ', 100);
			//--------------------------------
			// 内部クロック値の有効/無効を切り替え
			//--------------------------------
			szBuf = cboClockTrg.Text;
			if (string.Compare(szBuf, "内部クロック") == 0) 
			{
				txtInternalClock.Enabled = true;
			} 
			else 
			{
				txtInternalClock.Enabled = false;
			}

		}

		//===================================================
		//	ストップ条件設定変更
		//===================================================
		private void cboStopTrg_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			string	szBuf = new string(' ', 100);
			//--------------------------------
			// 停止個数の有効/無効を切り替え
			//--------------------------------
			szBuf = cboStopTrg.Text;
			if (szBuf.StartsWith("カウント一致")) 
			{
				txtCompStop.Enabled = true;
			} 
			else 
			{
				txtCompStop.Enabled = false;
			}
			if (string.Compare(szBuf, "指定個数転送完了") == 0) 
			{
				txtStopNum.Enabled = true;
			} 
			else 
			{
				txtStopNum.Enabled = false;
			}

		}

		//===================================================
		//	OKボタン処理
		//===================================================
		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;

			//--------------------------------
			// 表示データを取得
			//--------------------------------
			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);

			//--------------------------------
			// 設定値を数値に変換
			//--------------------------------
			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);
			//--------------------------------
			// サンプリング条件を設定
			//--------------------------------
			// スタンドアローン
			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;
			}
			// スタート条件設定
			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);
				}
			}

			// クロック条件設定
			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;
			}
			// 内部クロック値設定
			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;
				}
			}

			// ストップ条件設定
			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);
				}
			}
			// 停止個数設定
			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();
		}

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

	}
}
