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

namespace Sync
{
	/// <summary>
	/// MSampMode の概要の説明です。
	/// </summary>
	public class MSampMode : System.Windows.Forms.Form
	{
		public System.Windows.Forms.Button btnOK;
		public System.Windows.Forms.Button btnCancel;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.ComboBox cboStart;
		private System.Windows.Forms.ComboBox cboStartWith;
		private System.Windows.Forms.ComboBox cboClock;
		private System.Windows.Forms.ComboBox cboStop;
		private System.Windows.Forms.ComboBox cboStopWith;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.Label label10;
		private System.Windows.Forms.Label label11;
		private System.Windows.Forms.Label label12;
		private System.Windows.Forms.Label label13;
		private System.Windows.Forms.Label label14;
		private System.Windows.Forms.Label label15;
		private System.Windows.Forms.TextBox txtCompStart;
		private System.Windows.Forms.TextBox txtInternalClock;
		private System.Windows.Forms.TextBox txtCompStop;
		private System.Windows.Forms.TextBox txtStopNumber;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.TextBox txtNumberData;
		private System.Windows.Forms.Label label16;
		private System.Windows.Forms.GroupBox groupBox3;
		private System.Windows.Forms.RadioButton rdoRing;
		private System.Windows.Forms.RadioButton rdoOnce;
		/// <summary>
		/// 必要なデザイナ変数です。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public struct StrExtNum
		{
			public string	Str;
			public short	Num;
			public short	ExtSig;
			public StrExtNum(string Str, short Num, short ExtSig)
			{
				this.Str = Str;
				this.Num = Num;
				this.ExtSig = ExtSig;
			}
		};
	
		// Sampling Start
		static StrExtNum[] Start =
		{
			new StrExtNum("ソフトウェアスタート",			(short)CcntConst.CNTS_START_SOFT				,(short)CcntConst.CNTS_EXT_START_SOFT			),
			new StrExtNum("外部信号立ち上がり",				(short)CcntConst.CNTS_START_EXT_RISE			,(short)CcntConst.CNTS_EXT_START_EXT_RISE		),
			new StrExtNum("外部信号立ち下がり",				(short)CcntConst.CNTS_START_EXT_FALL			,(short)CcntConst.CNTS_EXT_START_EXT_FALL		),
			new StrExtNum("カウント一致CH0 比較レジスタ0",	(short)CcntConst.CNTS_START_CNTMATCH_CH0_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH0_REG0	),
			new StrExtNum("カウント一致CH1 比較レジスタ0",	(short)CcntConst.CNTS_START_CNTMATCH_CH1_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH1_REG0	),
			new StrExtNum("カウント一致CH2 比較レジスタ0",	(short)CcntConst.CNTS_START_CNTMATCH_CH2_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH2_REG0	),
			new StrExtNum("カウント一致CH3 比較レジスタ0",	(short)CcntConst.CNTS_START_CNTMATCH_CH3_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH3_REG0	),
			new StrExtNum("カウント一致CH4 比較レジスタ0",	(short)CcntConst.CNTS_START_CNTMATCH_CH4_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH4_REG0	),
			new StrExtNum("カウント一致CH5 比較レジスタ0",	(short)CcntConst.CNTS_START_CNTMATCH_CH5_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH5_REG0	),
			new StrExtNum("カウント一致CH6 比較レジスタ0",	(short)CcntConst.CNTS_START_CNTMATCH_CH6_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH6_REG0	),
			new StrExtNum("カウント一致CH7 比較レジスタ0",	(short)CcntConst.CNTS_START_CNTMATCH_CH7_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH7_REG0	),
			new StrExtNum("カウント一致CH0 比較レジスタ1",	(short)CcntConst.CNTS_START_CNTMATCH_CH0_REG1	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH0_REG1	),
			new StrExtNum("カウント一致CH1 比較レジスタ1",	(short)CcntConst.CNTS_START_CNTMATCH_CH1_REG1	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH1_REG1	),
			new StrExtNum("カウント一致CH2 比較レジスタ1",	(short)CcntConst.CNTS_START_CNTMATCH_CH2_REG1	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH2_REG1	),
			new StrExtNum("カウント一致CH3 比較レジスタ1",	(short)CcntConst.CNTS_START_CNTMATCH_CH3_REG1	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH3_REG1	),
			new StrExtNum("カウント一致CH4 比較レジスタ1",	(short)CcntConst.CNTS_START_CNTMATCH_CH4_REG1	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH4_REG1	),
			new StrExtNum("カウント一致CH5 比較レジスタ1",	(short)CcntConst.CNTS_START_CNTMATCH_CH5_REG1	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH5_REG1	),
			new StrExtNum("カウント一致CH6 比較レジスタ1",	(short)CcntConst.CNTS_START_CNTMATCH_CH6_REG1	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH6_REG1	),
			new StrExtNum("カウント一致CH7 比較レジスタ1",	(short)CcntConst.CNTS_START_CNTMATCH_CH7_REG1	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH7_REG1	),
			new StrExtNum("End",							0												,0												)
		};
		// Counter Start
		static StrExtNum[] StartWith =
		{
			new StrExtNum("サンプリングとは無関係に開始",	(short)CcntConst.CNTS_START_CNT_NOT_WITH_SAMP	,0												),
			new StrExtNum("サンプリングと同時に開始",		(short)CcntConst.CNTS_START_CNT_WITH_SAMP		,0												),
			new StrExtNum("End",							0												,0												)
		};
		// Sampling Clock
		static StrExtNum[] Clock =
		{			
			new StrExtNum("内部クロック",					(short)CcntConst.CNTS_CLOCK_CLOCK				,(short)CcntConst.CNTS_EXT_CLOCK				),
			new StrExtNum("外部クロック",					(short)CcntConst.CNTS_CLOCK_EXT_TRG				,(short)CcntConst.CNTS_EXT_EXT_TRG				),
			new StrExtNum("End",							0							,0								)
		};
		// Sampling Stop
		static StrExtNum[] Stop = 
		{
			new StrExtNum("ソフトウェアストップ",			(short)CcntConst.CNTS_STOP_SOFT					,(short)CcntConst.CNTS_EXT_STOP_SOFT			),
			new StrExtNum("外部信号立ち上がり",				(short)CcntConst.CNTS_STOP_EXT_RISE				,(short)CcntConst.CNTS_EXT_STOP_EXT_RISE		),
			new StrExtNum("外部信号立ち下がり",				(short)CcntConst.CNTS_STOP_EXT_FALL				,(short)CcntConst.CNTS_EXT_STOP_EXT_FALL		),
			new StrExtNum("指定個数転送完了",				(short)CcntConst.CNTS_STOP_NUM					,(short)CcntConst.CNTS_EXT_TRNSNUM				),
			new StrExtNum("カウント一致CH0 比較レジスタ0",	(short)CcntConst.CNTS_STOP_CNTMATCH_CH0_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH0_REG0	),
			new StrExtNum("カウント一致CH1 比較レジスタ0",	(short)CcntConst.CNTS_STOP_CNTMATCH_CH1_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH1_REG0	),
			new StrExtNum("カウント一致CH2 比較レジスタ0",	(short)CcntConst.CNTS_STOP_CNTMATCH_CH2_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH2_REG0	),
			new StrExtNum("カウント一致CH3 比較レジスタ0",	(short)CcntConst.CNTS_STOP_CNTMATCH_CH3_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH3_REG0	),
			new StrExtNum("カウント一致CH4 比較レジスタ0",	(short)CcntConst.CNTS_STOP_CNTMATCH_CH4_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH4_REG0	),
			new StrExtNum("カウント一致CH5 比較レジスタ0",	(short)CcntConst.CNTS_STOP_CNTMATCH_CH5_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH5_REG0	),
			new StrExtNum("カウント一致CH6 比較レジスタ0",	(short)CcntConst.CNTS_STOP_CNTMATCH_CH6_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH6_REG0	),
			new StrExtNum("カウント一致CH7 比較レジスタ0",	(short)CcntConst.CNTS_STOP_CNTMATCH_CH7_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH7_REG0	),
			new StrExtNum("カウント一致CH0 比較レジスタ1",	(short)CcntConst.CNTS_STOP_CNTMATCH_CH0_REG1	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH0_REG1	),
			new StrExtNum("カウント一致CH1 比較レジスタ1",	(short)CcntConst.CNTS_STOP_CNTMATCH_CH1_REG1	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH1_REG1	),
			new StrExtNum("カウント一致CH2 比較レジスタ1",	(short)CcntConst.CNTS_STOP_CNTMATCH_CH2_REG1	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH2_REG1	),
			new StrExtNum("カウント一致CH3 比較レジスタ1",	(short)CcntConst.CNTS_STOP_CNTMATCH_CH3_REG1	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH3_REG1	),
			new StrExtNum("カウント一致CH4 比較レジスタ1",	(short)CcntConst.CNTS_STOP_CNTMATCH_CH4_REG1	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH4_REG1	),
			new StrExtNum("カウント一致CH5 比較レジスタ1",	(short)CcntConst.CNTS_STOP_CNTMATCH_CH5_REG1	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH5_REG1	),
			new StrExtNum("カウント一致CH6 比較レジスタ1",	(short)CcntConst.CNTS_STOP_CNTMATCH_CH6_REG1	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH6_REG1	),
			new StrExtNum("カウント一致CH7 比較レジスタ1",	(short)CcntConst.CNTS_STOP_CNTMATCH_CH7_REG1	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH7_REG1	),
			new StrExtNum("End",							0												,0												)
		};
		// Counter Stop
		static StrExtNum[] StopWith = 
		{
			new StrExtNum("サンプリングとは無関係に停止",	(short)CcntConst.CNTS_STOP_CNT_NOT_WITH_SAMP	,0												),
			new StrExtNum("サンプリングと同時に停止",		(short)CcntConst.CNTS_STOP_CNT_WITH_SAMP		,0												),
			new StrExtNum("End",							0												,0												)
		};

		static string			szStart			= "ソフトウェアスタート";
		static string			szStartWith		= "サンプリングとは無関係に開始";
		static string			szClock			= "内部クロック";
		static string			szStop			= "ソフトウェアストップ";
		static string			szStopWith		= "サンプリングとは無関係に停止";
		static uint				StartComp		= 0x100;
		static uint				InternalClock	= 1000;
		static uint				StopComp		= 0x200;
		static uint				StopNum			= 1000;
		public static uint		M_NotifyCount	= 500;
		public static short		M_IsRing		= (short)CcntConst.CNTS_WRITE_ONCE;
		Ccnt					cnt				= new Ccnt();

		static short str_to_num(StrExtNum[] strnum, string str)
		{
			ushort	i;
			for (i=0; string.Compare(strnum[i].Str, "End") != 0; i++) {
				if (string.Compare(strnum[i].Str, str) == 0) {
					return strnum[i].Num;
				}
			}
			return 0;
		}

		static short str_to_extsig(StrExtNum[] strnum, string str)
		{
			ushort	i;
			for (i=0; string.Compare(strnum[i].Str, "End") != 0; i++) {
				if (string.Compare(strnum[i].Str, str) == 0) {
					return strnum[i].ExtSig;
				}
			}
			return 0;
		}

		static string num_to_str(StrExtNum[] strnum, short num)
		{
			ushort	i;
			for (i=0; string.Compare(strnum[i].Str, "End") != 0; i++) {
				if (strnum[i].Num  == num) {
					return strnum[i].Str;
				}
			}
			return strnum[0].Str;
		}

		public MSampMode()
		{
			//
			// 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.btnOK = new System.Windows.Forms.Button();
			this.btnCancel = new System.Windows.Forms.Button();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.label15 = new System.Windows.Forms.Label();
			this.label14 = new System.Windows.Forms.Label();
			this.label13 = new System.Windows.Forms.Label();
			this.txtStopNumber = 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.label12 = new System.Windows.Forms.Label();
			this.label11 = new System.Windows.Forms.Label();
			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.cboStopWith = new System.Windows.Forms.ComboBox();
			this.cboStop = new System.Windows.Forms.ComboBox();
			this.cboClock = new System.Windows.Forms.ComboBox();
			this.cboStartWith = new System.Windows.Forms.ComboBox();
			this.cboStart = new System.Windows.Forms.ComboBox();
			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.groupBox2 = new System.Windows.Forms.GroupBox();
			this.txtNumberData = new System.Windows.Forms.TextBox();
			this.label16 = new System.Windows.Forms.Label();
			this.groupBox3 = new System.Windows.Forms.GroupBox();
			this.rdoRing = new System.Windows.Forms.RadioButton();
			this.rdoOnce = new System.Windows.Forms.RadioButton();
			this.groupBox1.SuspendLayout();
			this.groupBox2.SuspendLayout();
			this.groupBox3.SuspendLayout();
			this.SuspendLayout();
			// 
			// 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(392, 248);
			this.btnOK.Name = "btnOK";
			this.btnOK.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.btnOK.Size = new System.Drawing.Size(96, 23);
			this.btnOK.TabIndex = 0;
			this.btnOK.Text = "OK";
			this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
			// 
			// 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(504, 248);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.btnCancel.Size = new System.Drawing.Size(96, 23);
			this.btnCancel.TabIndex = 1;
			this.btnCancel.Text = "Cancel";
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.label15,
																					this.label14,
																					this.label13,
																					this.txtStopNumber,
																					this.txtCompStop,
																					this.txtInternalClock,
																					this.txtCompStart,
																					this.label12,
																					this.label11,
																					this.label10,
																					this.label9,
																					this.label8,
																					this.label7,
																					this.label6,
																					this.cboStopWith,
																					this.cboStop,
																					this.cboClock,
																					this.cboStartWith,
																					this.cboStart,
																					this.label5,
																					this.label4,
																					this.label3,
																					this.label2,
																					this.label1});
			this.groupBox1.Location = new System.Drawing.Point(8, 8);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(592, 160);
			this.groupBox1.TabIndex = 2;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "サンプリングモード";
			// 
			// label15
			// 
			this.label15.AutoSize = true;
			this.label15.Location = new System.Drawing.Point(560, 80);
			this.label15.Name = "label15";
			this.label15.Size = new System.Drawing.Size(16, 12);
			this.label15.TabIndex = 23;
			this.label15.Text = "ns";
			// 
			// label14
			// 
			this.label14.AutoSize = true;
			this.label14.Location = new System.Drawing.Point(560, 106);
			this.label14.Name = "label14";
			this.label14.Size = new System.Drawing.Size(24, 12);
			this.label14.TabIndex = 22;
			this.label14.Text = "Hex";
			// 
			// label13
			// 
			this.label13.AutoSize = true;
			this.label13.Location = new System.Drawing.Point(560, 28);
			this.label13.Name = "label13";
			this.label13.Size = new System.Drawing.Size(24, 12);
			this.label13.TabIndex = 21;
			this.label13.Text = "Hex";
			// 
			// txtStopNumber
			// 
			this.txtStopNumber.Location = new System.Drawing.Point(456, 129);
			this.txtStopNumber.Name = "txtStopNumber";
			this.txtStopNumber.Size = new System.Drawing.Size(96, 19);
			this.txtStopNumber.TabIndex = 20;
			this.txtStopNumber.Text = "";
			// 
			// txtCompStop
			// 
			this.txtCompStop.Location = new System.Drawing.Point(456, 103);
			this.txtCompStop.Name = "txtCompStop";
			this.txtCompStop.Size = new System.Drawing.Size(96, 19);
			this.txtCompStop.TabIndex = 19;
			this.txtCompStop.Text = "";
			// 
			// txtInternalClock
			// 
			this.txtInternalClock.Location = new System.Drawing.Point(456, 77);
			this.txtInternalClock.Name = "txtInternalClock";
			this.txtInternalClock.Size = new System.Drawing.Size(96, 19);
			this.txtInternalClock.TabIndex = 18;
			this.txtInternalClock.Text = "";
			// 
			// txtCompStart
			// 
			this.txtCompStart.Location = new System.Drawing.Point(456, 25);
			this.txtCompStart.Name = "txtCompStart";
			this.txtCompStart.Size = new System.Drawing.Size(96, 19);
			this.txtCompStart.TabIndex = 17;
			this.txtCompStart.Text = "";
			// 
			// label12
			// 
			this.label12.AutoSize = true;
			this.label12.Location = new System.Drawing.Point(384, 132);
			this.label12.Name = "label12";
			this.label12.Size = new System.Drawing.Size(60, 12);
			this.label12.TabIndex = 16;
			this.label12.Text = "停止個数：";
			// 
			// label11
			// 
			this.label11.AutoSize = true;
			this.label11.Location = new System.Drawing.Point(384, 106);
			this.label11.Name = "label11";
			this.label11.Size = new System.Drawing.Size(48, 12);
			this.label11.TabIndex = 15;
			this.label11.Text = "比較値：";
			// 
			// label10
			// 
			this.label10.AutoSize = true;
			this.label10.Location = new System.Drawing.Point(384, 80);
			this.label10.Name = "label10";
			this.label10.Size = new System.Drawing.Size(69, 12);
			this.label10.TabIndex = 14;
			this.label10.Text = "内部クロック：";
			// 
			// label9
			// 
			this.label9.AutoSize = true;
			this.label9.Location = new System.Drawing.Point(384, 28);
			this.label9.Name = "label9";
			this.label9.Size = new System.Drawing.Size(48, 12);
			this.label9.TabIndex = 13;
			this.label9.Text = "比較値：";
			// 
			// label8
			// 
			this.label8.AutoSize = true;
			this.label8.Location = new System.Drawing.Point(304, 106);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(56, 12);
			this.label8.TabIndex = 12;
			this.label8.Text = "->ExtSig3";
			// 
			// label7
			// 
			this.label7.AutoSize = true;
			this.label7.Location = new System.Drawing.Point(304, 80);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(56, 12);
			this.label7.TabIndex = 11;
			this.label7.Text = "->ExtSig1";
			// 
			// label6
			// 
			this.label6.AutoSize = true;
			this.label6.Location = new System.Drawing.Point(304, 28);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(56, 12);
			this.label6.TabIndex = 10;
			this.label6.Text = "->ExtSig2";
			// 
			// cboStopWith
			// 
			this.cboStopWith.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboStopWith.Location = new System.Drawing.Point(124, 128);
			this.cboStopWith.Name = "cboStopWith";
			this.cboStopWith.Size = new System.Drawing.Size(180, 20);
			this.cboStopWith.TabIndex = 9;
			// 
			// cboStop
			// 
			this.cboStop.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboStop.Location = new System.Drawing.Point(124, 102);
			this.cboStop.Name = "cboStop";
			this.cboStop.Size = new System.Drawing.Size(180, 20);
			this.cboStop.TabIndex = 8;
			this.cboStop.SelectedIndexChanged += new System.EventHandler(this.cboStop_SelectedIndexChanged);
			// 
			// cboClock
			// 
			this.cboClock.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboClock.Location = new System.Drawing.Point(124, 76);
			this.cboClock.Name = "cboClock";
			this.cboClock.Size = new System.Drawing.Size(180, 20);
			this.cboClock.TabIndex = 7;
			this.cboClock.SelectedIndexChanged += new System.EventHandler(this.cboClock_SelectedIndexChanged);
			// 
			// cboStartWith
			// 
			this.cboStartWith.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboStartWith.Location = new System.Drawing.Point(124, 50);
			this.cboStartWith.Name = "cboStartWith";
			this.cboStartWith.Size = new System.Drawing.Size(180, 20);
			this.cboStartWith.TabIndex = 6;
			// 
			// cboStart
			// 
			this.cboStart.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboStart.Location = new System.Drawing.Point(124, 24);
			this.cboStart.Name = "cboStart";
			this.cboStart.Size = new System.Drawing.Size(180, 20);
			this.cboStart.TabIndex = 5;
			this.cboStart.SelectedIndexChanged += new System.EventHandler(this.cboStart_SelectedIndexChanged);
			// 
			// label5
			// 
			this.label5.AutoSize = true;
			this.label5.Location = new System.Drawing.Point(9, 132);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(109, 12);
			this.label5.TabIndex = 4;
			this.label5.Text = "カウンタストップモード：";
			// 
			// label4
			// 
			this.label4.AutoSize = true;
			this.label4.Location = new System.Drawing.Point(9, 106);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(70, 12);
			this.label4.TabIndex = 3;
			this.label4.Text = "ストップ条件：";
			// 
			// label3
			// 
			this.label3.AutoSize = true;
			this.label3.Location = new System.Drawing.Point(9, 80);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(69, 12);
			this.label3.TabIndex = 2;
			this.label3.Text = "クロック条件：";
			// 
			// label2
			// 
			this.label2.AutoSize = true;
			this.label2.Location = new System.Drawing.Point(9, 54);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(112, 12);
			this.label2.TabIndex = 1;
			this.label2.Text = "カウンタスタートモード：";
			// 
			// label1
			// 
			this.label1.AutoSize = true;
			this.label1.Location = new System.Drawing.Point(9, 28);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(72, 12);
			this.label1.TabIndex = 0;
			this.label1.Text = "スタート条件：";
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.txtNumberData,
																					this.label16});
			this.groupBox2.Location = new System.Drawing.Point(8, 176);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(320, 56);
			this.groupBox2.TabIndex = 3;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "転送個数イベント通知";
			// 
			// txtNumberData
			// 
			this.txtNumberData.Location = new System.Drawing.Point(125, 21);
			this.txtNumberData.Name = "txtNumberData";
			this.txtNumberData.Size = new System.Drawing.Size(96, 19);
			this.txtNumberData.TabIndex = 18;
			this.txtNumberData.Text = "";
			// 
			// label16
			// 
			this.label16.AutoSize = true;
			this.label16.Location = new System.Drawing.Point(80, 24);
			this.label16.Name = "label16";
			this.label16.Size = new System.Drawing.Size(35, 12);
			this.label16.TabIndex = 1;
			this.label16.Text = "個数：";
			// 
			// groupBox3
			// 
			this.groupBox3.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.rdoRing,
																					this.rdoOnce});
			this.groupBox3.Location = new System.Drawing.Point(336, 176);
			this.groupBox3.Name = "groupBox3";
			this.groupBox3.Size = new System.Drawing.Size(264, 56);
			this.groupBox3.TabIndex = 4;
			this.groupBox3.TabStop = false;
			this.groupBox3.Text = "転送方式";
			// 
			// rdoRing
			// 
			this.rdoRing.Location = new System.Drawing.Point(129, 24);
			this.rdoRing.Name = "rdoRing";
			this.rdoRing.Size = new System.Drawing.Size(96, 16);
			this.rdoRing.TabIndex = 1;
			this.rdoRing.Text = "無限回転送";
			// 
			// rdoOnce
			// 
			this.rdoOnce.Location = new System.Drawing.Point(10, 24);
			this.rdoOnce.Name = "rdoOnce";
			this.rdoOnce.Size = new System.Drawing.Size(88, 16);
			this.rdoOnce.TabIndex = 0;
			this.rdoOnce.Text = "1回転送";
			// 
			// MSampMode
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
			this.ClientSize = new System.Drawing.Size(608, 278);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.groupBox3,
																		  this.groupBox2,
																		  this.groupBox1,
																		  this.btnOK,
																		  this.btnCancel});
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "MSampMode";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "マスターサンプリング条件設定";
			this.Load += new System.EventHandler(this.MSampMode_Load);
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.groupBox3.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		//===================================================
		//	ダイアログ初期化
		//===================================================
		private void MSampMode_Load(object sender, System.EventArgs e)
		{
			short	i;
			string	szBuf = new string(' ', 100);

			//--------------------------------
			// 表示初期化
			//--------------------------------
			// Start
			for (i=0; string.Compare(Start[i].Str, "End") != 0; i++) 
			{
				cboStart.Items.Add(Start[i].Str);
			}
			// Start with
			for (i=0; string.Compare(StartWith[i].Str, "End") != 0; i++) 
			{
				cboStartWith.Items.Add(StartWith[i].Str);
			}
			// Clock
			for (i=0; string.Compare(Clock[i].Str, "End") != 0; i++) 
			{
				cboClock.Items.Add(Clock[i].Str);
			}
			// Stop
			for (i=0; string.Compare(Stop[i].Str, "End") != 0; i++) 
			{
				cboStop.Items.Add(Stop[i].Str);
			}
			// Stop with
			for (i=0; string.Compare(StopWith[i].Str, "End") != 0; i++) 
			{
				cboStopWith.Items.Add(StopWith[i].Str);
			}

			cboStart.Text = szStart;
			cboStartWith.Text = szStartWith;
			cboClock.Text = szClock;
			cboStop.Text = szStop;
			cboStopWith.Text = szStopWith;

			szBuf = string.Format("{0:X}", StartComp);
			txtCompStart.Text = szBuf;
			szBuf = InternalClock.ToString();
			txtInternalClock.Text = szBuf;
			szBuf = string.Format("{0:X}", StopComp);
			txtCompStop.Text = szBuf;
			szBuf = StopNum.ToString();
			txtStopNumber.Text  = szBuf;
			szBuf = M_NotifyCount.ToString();
			txtNumberData.Text = szBuf;

			if (M_IsRing == (short)CcntConst.CNTS_WRITE_ONCE) 
			{
				rdoOnce.Checked = true;
				rdoRing.Checked = false;
			} 
			else 
			{
				rdoOnce.Checked = false;
				rdoRing.Checked = true;
			}
		
			cboStart_SelectedIndexChanged(cboStart, new System.EventArgs());
			cboClock_SelectedIndexChanged(cboClock, new System.EventArgs());
			cboStop_SelectedIndexChanged(cboStop, new System.EventArgs());
		}

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

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

		//===================================================
		//	クロック条件設定変更
		//===================================================
		private void cboClock_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			string	szBuf = new string(' ', 100);
			szBuf = cboClock.Text;
			if (string.Compare(szBuf, "内部クロック") == 0) 
			{
				txtInternalClock.Enabled = true;
			} 
			else 
			{
				txtInternalClock.Enabled = false;
			}
		}

		//===================================================
		//	ストップ条件設定変更
		//===================================================
		private void cboStop_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			string	szBuf = new string(' ', 100);
			szBuf = cboStop.Text;
			if (szBuf.StartsWith ("カウント一致")) 
			{
				txtCompStop.Enabled = true;
			} 
			else 
			{
				txtCompStop.Enabled = false;
			}
			if (string.Compare(szBuf, "指定個数転送完了") == 0) 
			{
				txtStopNumber.Enabled = true;
			} 
			else 
			{
				txtStopNumber.Enabled = false;
			}
		}

		//===================================================
		//	OKボタン処理
		//===================================================
		private void btnOK_Click(object sender, System.EventArgs e)
		{
			string	szBuf = new string(' ', 100);
			bool	Checked;
			short	dwStart;
			short	ExtSig1, ExtSig2, ExtSig3;
			short	wStartWith;
			short	dwClock;
			short	dwStop;
			short	wStopWith;
			int		ret;
			string	strMsg;
			ushort	CompChNo;
			ushort	CompRegNo;
			string	error_string = new string(' ', 256);

			//--------------------------------
			// 表示データを取得
			//--------------------------------
			szStart = cboStart.Text;
			szStartWith = cboStartWith.Text;
			szClock = cboClock.Text;
			szStop = cboStop.Text;
			szStopWith = cboStopWith.Text;

			szBuf = txtCompStart.Text;
			try
			{
				StartComp = uint.Parse(szBuf, NumberStyles.HexNumber);
			}
			catch (System.FormatException)
			{
				StartComp = 0x100;
			}

			szBuf = txtInternalClock.Text;
			try
			{
				InternalClock = uint.Parse(szBuf);
			}
			catch (System.FormatException)
			{
				InternalClock = 1000;
			}

			szBuf = txtCompStop.Text;
			try
			{
				StopComp = uint.Parse(szBuf, NumberStyles.HexNumber);
			}
			catch (System.FormatException)
			{
				StopComp = 0x200;
			}

			szBuf = txtStopNumber.Text;
			try
			{
				StopNum = uint.Parse(szBuf);
			}
			catch (System.FormatException)
			{
				StopNum = 1000;
			}

			szBuf = txtNumberData.Text;
			try
			{
				M_NotifyCount = uint.Parse(szBuf);
			}
			catch (System.FormatException)
			{
				M_NotifyCount = 500;
			}

			Checked = rdoOnce.Checked;

			//--------------------------------
			// 設定値を数値に変換
			//--------------------------------
			dwStart = str_to_num(Start, szStart);
			ExtSig2 = str_to_extsig(Start, szStart);
			wStartWith = str_to_num(StartWith, szStartWith);

			dwClock = str_to_num(Clock, szClock);
			ExtSig1 = str_to_extsig(Clock, szClock);

			dwStop = str_to_num(Stop, szStop);
			ExtSig3 = str_to_extsig(Stop, szStop);
			wStopWith = str_to_num(StopWith, szStopWith);

			if (Checked	== true) 
			{
				M_IsRing = (short)CcntConst.CNTS_WRITE_ONCE;
			} 
			else 
			{
				M_IsRing = (short)CcntConst.CNTS_WRITE_RING;
			}

			//--------------------------------
			// サンプリング条件を設定
			//--------------------------------
			ret = cnt.SetMaster(Sync.M_Id, ExtSig1, ExtSig2, ExtSig3, 1, 1);
			if (ret != 0) 
			{
				cnt.GetErrorString(ret, out error_string);
				strMsg = string.Format("CntSetMaster ret = {0:d}: {1}", ret, error_string);
				MessageBox.Show(strMsg, Application.ProductName, MessageBoxButtons.OK);
			}
			ret = cnt.SetSamplingStartTrigger(Sync.M_Id, dwStart, wStartWith, Sync.CHANNEL_NUM);
			if (ret != 0) 
			{
				cnt.GetErrorString(ret, out error_string);
				strMsg = string.Format("CntSetSamplingStartTrigger ret = {0:d}: {1}", ret, error_string);
				MessageBox.Show(strMsg, Application.ProductName, MessageBoxButtons.OK);
			}
			ret = cnt.SetSamplingClockTrigger(Sync.M_Id, dwClock);
			if (ret != 0) 
			{
				cnt.GetErrorString(ret, out error_string);
				strMsg = string.Format("CntSetSamplingClockTrigger ret = {0:d}: {1}", ret, error_string);
				MessageBox.Show(strMsg, Application.ProductName, MessageBoxButtons.OK);
			}
			ret = cnt.SetSamplingStopTrigger(Sync.M_Id, dwStop, wStopWith, Sync.CHANNEL_NUM);
			if (ret != 0) 
			{
				cnt.GetErrorString(ret, out error_string);
				strMsg = string.Format("CntSetSamplingStopTrigger ret = {0:d}: {1}", ret, error_string);
				MessageBox.Show(strMsg, Application.ProductName, MessageBoxButtons.OK);
			}
			ret = cnt.SetSamplingInternalClock(Sync.M_Id, InternalClock, (short)CcntConst.CNTS_TIM_UNIT_NS);
			if (ret != 0) 
			{
				cnt.GetErrorString(ret, out error_string);
				strMsg = string.Format("CntSetSamplingInternalClock ret = {0:d}: {1}", ret, error_string);
				MessageBox.Show(strMsg, Application.ProductName, MessageBoxButtons.OK);
			}
			ret = cnt.SetSamplingStopNumber(Sync.M_Id, StopNum);
			if (ret != 0) 
			{
				cnt.GetErrorString(ret, out error_string);
				strMsg = string.Format("CntSetSamplingStopNumber ret = {0:d}: {1}", ret, error_string);
				MessageBox.Show(strMsg, Application.ProductName, MessageBoxButtons.OK);
			}

			switch(dwStart) 
			{
				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 = 0xffff; CompRegNo = 0xffff; break;
			}
			if (CompChNo != 0xffff && CompRegNo != 0xffff) 
			{

				ret = cnt.NotifyCountUp(Sync.M_Id, (short)CompChNo, (short)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);
				}
			}
			switch(dwStop) 
			{
				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 = 0xffff; CompRegNo = 0xffff; break;
			}
			if (CompChNo != 0xffff && CompRegNo != 0xffff) 
			{
				ret = cnt.NotifyCountUp(Sync.M_Id, (short)CompChNo, (short)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);
				}
			}
			this.Close();
		}

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