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

namespace Sync
{
	/// <summary>
	/// Summary description for MSampMode.
	/// </summary>
	public class MSampMode : System.Windows.Forms.Form
	{
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Label label15;
		private System.Windows.Forms.Label label14;
		private System.Windows.Forms.Label label13;
		private System.Windows.Forms.TextBox txtStopNumber;
		private System.Windows.Forms.TextBox txtCompStop;
		private System.Windows.Forms.TextBox txtInternalClock;
		private System.Windows.Forms.TextBox txtCompStart;
		private System.Windows.Forms.Label label12;
		private System.Windows.Forms.Label label11;
		private System.Windows.Forms.Label label10;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.ComboBox cboStopWith;
		private System.Windows.Forms.ComboBox cboStop;
		private System.Windows.Forms.ComboBox cboClock;
		private System.Windows.Forms.ComboBox cboStartWith;
		private System.Windows.Forms.ComboBox cboStart;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label1;
		public System.Windows.Forms.Button btnCancel;
		private System.Windows.Forms.GroupBox groupBox3;
		private System.Windows.Forms.RadioButton rdoRing;
		private System.Windows.Forms.RadioButton rdoOnce;
		public System.Windows.Forms.Button btnOK;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.TextBox txtNumberData;
		private System.Windows.Forms.Label label16;
		/// <summary>
		/// Required designer variable.
		/// </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("Software start",							(short)CcntConst.CNTS_START_SOFT				,(short)CcntConst.CNTS_EXT_START_SOFT			),
			new StrExtNum("External signal rising",					(short)CcntConst.CNTS_START_EXT_RISE			,(short)CcntConst.CNTS_EXT_START_EXT_RISE		),
			new StrExtNum("External signal falling",				(short)CcntConst.CNTS_START_EXT_FALL			,(short)CcntConst.CNTS_EXT_START_EXT_FALL		),
			new StrExtNum("Count-match CH0 Compare-register 0",		(short)CcntConst.CNTS_START_CNTMATCH_CH0_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH0_REG0	),
			new StrExtNum("Count-match CH1 Compare-register 0",		(short)CcntConst.CNTS_START_CNTMATCH_CH1_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH1_REG0	),
			new StrExtNum("Count-match CH2 Compare-register 0",		(short)CcntConst.CNTS_START_CNTMATCH_CH2_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH2_REG0	),
			new StrExtNum("Count-match CH3 Compare-register 0",		(short)CcntConst.CNTS_START_CNTMATCH_CH3_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH3_REG0	),
			new StrExtNum("Count-match CH4 Compare-register 0",		(short)CcntConst.CNTS_START_CNTMATCH_CH4_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH4_REG0	),
			new StrExtNum("Count-match CH5 Compare-register 0",		(short)CcntConst.CNTS_START_CNTMATCH_CH5_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH5_REG0	),
			new StrExtNum("Count-match CH6 Compare-register 0",		(short)CcntConst.CNTS_START_CNTMATCH_CH6_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH6_REG0	),
			new StrExtNum("Count-match CH7 Compare-register 0",		(short)CcntConst.CNTS_START_CNTMATCH_CH7_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH7_REG0	),
			new StrExtNum("Count-match CH0 Compare-register 1",		(short)CcntConst.CNTS_START_CNTMATCH_CH0_REG1	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH0_REG1	),
			new StrExtNum("Count-match CH1 Compare-register 1",		(short)CcntConst.CNTS_START_CNTMATCH_CH1_REG1	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH1_REG1	),
			new StrExtNum("Count-match CH2 Compare-register 1",		(short)CcntConst.CNTS_START_CNTMATCH_CH2_REG1	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH2_REG1	),
			new StrExtNum("Count-match CH3 Compare-register 1",		(short)CcntConst.CNTS_START_CNTMATCH_CH3_REG1	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH3_REG1	),
			new StrExtNum("Count-match CH4 Compare-register 1",		(short)CcntConst.CNTS_START_CNTMATCH_CH4_REG1	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH4_REG1	),
			new StrExtNum("Count-match CH5 Compare-register 1",		(short)CcntConst.CNTS_START_CNTMATCH_CH5_REG1	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH5_REG1	),
			new StrExtNum("Count-match CH6 Compare-register 1",		(short)CcntConst.CNTS_START_CNTMATCH_CH6_REG1	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH6_REG1	),
			new StrExtNum("Count-match CH7 Compare-register 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("Start counter regardless of sampling",	(short)CcntConst.CNTS_START_CNT_NOT_WITH_SAMP	,0												),
			new StrExtNum("Start counter when sampling starts",		(short)CcntConst.CNTS_START_CNT_WITH_SAMP		,0												),
			new StrExtNum("End",									0												,0												)
		};
		// Sampling Clock
		static StrExtNum[] Clock =
		{			
			new StrExtNum("Internal clock",							(short)CcntConst.CNTS_CLOCK_CLOCK				,(short)CcntConst.CNTS_EXT_CLOCK				),
			new StrExtNum("External clock",							(short)CcntConst.CNTS_CLOCK_EXT_TRG				,(short)CcntConst.CNTS_EXT_EXT_TRG				),
			new StrExtNum("End",									0												,0								)
		};
		// Sampling Stop
		static StrExtNum[] Stop = 
		{
			new StrExtNum("Software stop",							(short)CcntConst.CNTS_STOP_SOFT					,(short)CcntConst.CNTS_EXT_STOP_SOFT			),
			new StrExtNum("External signal rising",					(short)CcntConst.CNTS_STOP_EXT_RISE				,(short)CcntConst.CNTS_EXT_STOP_EXT_RISE		),
			new StrExtNum("External signal falling",				(short)CcntConst.CNTS_STOP_EXT_FALL				,(short)CcntConst.CNTS_EXT_STOP_EXT_FALL		),
			new StrExtNum("Stop transfer by specified times",		(short)CcntConst.CNTS_STOP_NUM					,(short)CcntConst.CNTS_EXT_TRNSNUM				),
			new StrExtNum("Count-match CH0 Compare-register 0",		(short)CcntConst.CNTS_STOP_CNTMATCH_CH0_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH0_REG0	),
			new StrExtNum("Count-match CH1 Compare-register 0",		(short)CcntConst.CNTS_STOP_CNTMATCH_CH1_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH1_REG0	),
			new StrExtNum("Count-match CH2 Compare-register 0",		(short)CcntConst.CNTS_STOP_CNTMATCH_CH2_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH2_REG0	),
			new StrExtNum("Count-match CH3 Compare-register 0",		(short)CcntConst.CNTS_STOP_CNTMATCH_CH3_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH3_REG0	),
			new StrExtNum("Count-match CH4 Compare-register 0",		(short)CcntConst.CNTS_STOP_CNTMATCH_CH4_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH4_REG0	),
			new StrExtNum("Count-match CH5 Compare-register 0",		(short)CcntConst.CNTS_STOP_CNTMATCH_CH5_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH5_REG0	),
			new StrExtNum("Count-match CH6 Compare-register 0",		(short)CcntConst.CNTS_STOP_CNTMATCH_CH6_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH6_REG0	),
			new StrExtNum("Count-match CH7 Compare-register 0",		(short)CcntConst.CNTS_STOP_CNTMATCH_CH7_REG0	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH7_REG0	),
			new StrExtNum("Count-match CH0 Compare-register 1",		(short)CcntConst.CNTS_STOP_CNTMATCH_CH0_REG1	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH0_REG1	),
			new StrExtNum("Count-match CH1 Compare-register 1",		(short)CcntConst.CNTS_STOP_CNTMATCH_CH1_REG1	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH1_REG1	),
			new StrExtNum("Count-match CH2 Compare-register 1",		(short)CcntConst.CNTS_STOP_CNTMATCH_CH2_REG1	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH2_REG1	),
			new StrExtNum("Count-match CH3 Compare-register 1",		(short)CcntConst.CNTS_STOP_CNTMATCH_CH3_REG1	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH3_REG1	),
			new StrExtNum("Count-match CH4 Compare-register 1",		(short)CcntConst.CNTS_STOP_CNTMATCH_CH4_REG1	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH4_REG1	),
			new StrExtNum("Count-match CH5 Compare-register 1",		(short)CcntConst.CNTS_STOP_CNTMATCH_CH5_REG1	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH5_REG1	),
			new StrExtNum("Count-match CH6 Compare-register 1",		(short)CcntConst.CNTS_STOP_CNTMATCH_CH6_REG1	,(short)CcntConst.CNTS_EXT_CNTMATCH_CH6_REG1	),
			new StrExtNum("Count-match CH7 Compare-register 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("Stop counter regardless of sampling",	(short)CcntConst.CNTS_STOP_CNT_NOT_WITH_SAMP	,0												),
			new StrExtNum("Stop counter when sampling stops",		(short)CcntConst.CNTS_STOP_CNT_WITH_SAMP		,0												),
			new StrExtNum("End",									0												,0												)
		};

		static string       szStart = "Software start";
		static string       szStartWith = "Start counter regardless of sampling";
		static string       szClock = "Internal clock";
		static string       szStop = "Software stop";
		static string       szStopWith = "Stop counter regardless of sampling";
		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()
		{
			//
			// 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.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.btnCancel = new System.Windows.Forms.Button();
			this.groupBox3 = new System.Windows.Forms.GroupBox();
			this.rdoRing = new System.Windows.Forms.RadioButton();
			this.rdoOnce = new System.Windows.Forms.RadioButton();
			this.btnOK = new System.Windows.Forms.Button();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.txtNumberData = new System.Windows.Forms.TextBox();
			this.label16 = new System.Windows.Forms.Label();
			this.groupBox1.SuspendLayout();
			this.groupBox3.SuspendLayout();
			this.groupBox2.SuspendLayout();
			this.SuspendLayout();
			// 
			// 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(616, 186);
			this.groupBox1.TabIndex = 7;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Sampling Mode";
			// 
			// label15
			// 
			this.label15.AutoSize = true;
			this.label15.Location = new System.Drawing.Point(584, 93);
			this.label15.Name = "label15";
			this.label15.Size = new System.Drawing.Size(16, 13);
			this.label15.TabIndex = 23;
			this.label15.Text = "ns";
			// 
			// label14
			// 
			this.label14.AutoSize = true;
			this.label14.Location = new System.Drawing.Point(584, 123);
			this.label14.Name = "label14";
			this.label14.Size = new System.Drawing.Size(24, 13);
			this.label14.TabIndex = 22;
			this.label14.Text = "Hex";
			// 
			// label13
			// 
			this.label13.AutoSize = true;
			this.label13.Location = new System.Drawing.Point(584, 33);
			this.label13.Name = "label13";
			this.label13.Size = new System.Drawing.Size(24, 13);
			this.label13.TabIndex = 21;
			this.label13.Text = "Hex";
			// 
			// txtStopNumber
			// 
			this.txtStopNumber.Location = new System.Drawing.Point(496, 150);
			this.txtStopNumber.Name = "txtStopNumber";
			this.txtStopNumber.Size = new System.Drawing.Size(80, 20);
			this.txtStopNumber.TabIndex = 20;
			this.txtStopNumber.Text = "";
			// 
			// txtCompStop
			// 
			this.txtCompStop.Location = new System.Drawing.Point(496, 120);
			this.txtCompStop.Name = "txtCompStop";
			this.txtCompStop.Size = new System.Drawing.Size(80, 20);
			this.txtCompStop.TabIndex = 19;
			this.txtCompStop.Text = "";
			// 
			// txtInternalClock
			// 
			this.txtInternalClock.Location = new System.Drawing.Point(496, 90);
			this.txtInternalClock.Name = "txtInternalClock";
			this.txtInternalClock.Size = new System.Drawing.Size(80, 20);
			this.txtInternalClock.TabIndex = 18;
			this.txtInternalClock.Text = "";
			// 
			// txtCompStart
			// 
			this.txtCompStart.Location = new System.Drawing.Point(496, 29);
			this.txtCompStart.Name = "txtCompStart";
			this.txtCompStart.Size = new System.Drawing.Size(80, 20);
			this.txtCompStart.TabIndex = 17;
			this.txtCompStart.Text = "";
			// 
			// label12
			// 
			this.label12.AutoSize = true;
			this.label12.Location = new System.Drawing.Point(405, 154);
			this.label12.Name = "label12";
			this.label12.Size = new System.Drawing.Size(74, 13);
			this.label12.TabIndex = 16;
			this.label12.Text = "Stop Number:";
			// 
			// label11
			// 
			this.label11.AutoSize = true;
			this.label11.Location = new System.Drawing.Point(405, 123);
			this.label11.Name = "label11";
			this.label11.Size = new System.Drawing.Size(86, 13);
			this.label11.TabIndex = 15;
			this.label11.Text = "Compare Value:";
			// 
			// label10
			// 
			this.label10.AutoSize = true;
			this.label10.Location = new System.Drawing.Point(405, 93);
			this.label10.Name = "label10";
			this.label10.Size = new System.Drawing.Size(77, 13);
			this.label10.TabIndex = 14;
			this.label10.Text = "Internal Clock:";
			// 
			// label9
			// 
			this.label9.AutoSize = true;
			this.label9.Location = new System.Drawing.Point(405, 33);
			this.label9.Name = "label9";
			this.label9.Size = new System.Drawing.Size(86, 13);
			this.label9.TabIndex = 13;
			this.label9.Text = "Compare Value:";
			// 
			// label8
			// 
			this.label8.AutoSize = true;
			this.label8.Location = new System.Drawing.Point(344, 123);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(54, 13);
			this.label8.TabIndex = 12;
			this.label8.Text = "->ExtSig3";
			// 
			// label7
			// 
			this.label7.AutoSize = true;
			this.label7.Location = new System.Drawing.Point(344, 93);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(54, 13);
			this.label7.TabIndex = 11;
			this.label7.Text = "->ExtSig1";
			// 
			// label6
			// 
			this.label6.AutoSize = true;
			this.label6.Location = new System.Drawing.Point(344, 33);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(54, 13);
			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, 149);
			this.cboStopWith.Name = "cboStopWith";
			this.cboStopWith.Size = new System.Drawing.Size(220, 21);
			this.cboStopWith.TabIndex = 9;
			// 
			// cboStop
			// 
			this.cboStop.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboStop.Location = new System.Drawing.Point(124, 119);
			this.cboStop.Name = "cboStop";
			this.cboStop.Size = new System.Drawing.Size(220, 21);
			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, 88);
			this.cboClock.Name = "cboClock";
			this.cboClock.Size = new System.Drawing.Size(220, 21);
			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, 58);
			this.cboStartWith.Name = "cboStartWith";
			this.cboStartWith.Size = new System.Drawing.Size(220, 21);
			this.cboStartWith.TabIndex = 6;
			// 
			// cboStart
			// 
			this.cboStart.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboStart.Location = new System.Drawing.Point(124, 28);
			this.cboStart.Name = "cboStart";
			this.cboStart.Size = new System.Drawing.Size(220, 21);
			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, 154);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(105, 13);
			this.label5.TabIndex = 4;
			this.label5.Text = "Counter Stop Mode:";
			// 
			// label4
			// 
			this.label4.AutoSize = true;
			this.label4.Location = new System.Drawing.Point(9, 123);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(31, 13);
			this.label4.TabIndex = 3;
			this.label4.Text = "Stop:";
			// 
			// label3
			// 
			this.label3.AutoSize = true;
			this.label3.Location = new System.Drawing.Point(9, 93);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(36, 13);
			this.label3.TabIndex = 2;
			this.label3.Text = "Clock:";
			// 
			// label2
			// 
			this.label2.AutoSize = true;
			this.label2.Location = new System.Drawing.Point(9, 63);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(106, 13);
			this.label2.TabIndex = 1;
			this.label2.Text = "Counter Start Mode:";
			// 
			// label1
			// 
			this.label1.AutoSize = true;
			this.label1.Location = new System.Drawing.Point(9, 33);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(31, 13);
			this.label1.TabIndex = 0;
			this.label1.Text = "Start:";
			// 
			// 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(528, 279);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.btnCancel.Size = new System.Drawing.Size(96, 26);
			this.btnCancel.TabIndex = 6;
			this.btnCancel.Text = "Cancel";
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			// 
			// groupBox3
			// 
			this.groupBox3.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.rdoRing,
																					this.rdoOnce});
			this.groupBox3.Location = new System.Drawing.Point(328, 204);
			this.groupBox3.Name = "groupBox3";
			this.groupBox3.Size = new System.Drawing.Size(296, 65);
			this.groupBox3.TabIndex = 9;
			this.groupBox3.TabStop = false;
			this.groupBox3.Text = "Transfer Mode";
			// 
			// rdoRing
			// 
			this.rdoRing.Location = new System.Drawing.Point(144, 28);
			this.rdoRing.Name = "rdoRing";
			this.rdoRing.Size = new System.Drawing.Size(96, 19);
			this.rdoRing.TabIndex = 1;
			this.rdoRing.Text = "Ring";
			// 
			// rdoOnce
			// 
			this.rdoOnce.Location = new System.Drawing.Point(32, 28);
			this.rdoOnce.Name = "rdoOnce";
			this.rdoOnce.Size = new System.Drawing.Size(88, 19);
			this.rdoOnce.TabIndex = 0;
			this.rdoOnce.Text = "Once";
			// 
			// 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(424, 279);
			this.btnOK.Name = "btnOK";
			this.btnOK.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.btnOK.Size = new System.Drawing.Size(96, 26);
			this.btnOK.TabIndex = 5;
			this.btnOK.Text = "OK";
			this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.txtNumberData,
																					this.label16});
			this.groupBox2.Location = new System.Drawing.Point(8, 204);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(296, 65);
			this.groupBox2.TabIndex = 8;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "Transfer Number Event Notification";
			// 
			// txtNumberData
			// 
			this.txtNumberData.Location = new System.Drawing.Point(112, 24);
			this.txtNumberData.Name = "txtNumberData";
			this.txtNumberData.Size = new System.Drawing.Size(96, 20);
			this.txtNumberData.TabIndex = 18;
			this.txtNumberData.Text = "";
			// 
			// label16
			// 
			this.label16.AutoSize = true;
			this.label16.Location = new System.Drawing.Point(9, 28);
			this.label16.Name = "label16";
			this.label16.Size = new System.Drawing.Size(85, 13);
			this.label16.TabIndex = 1;
			this.label16.Text = "Number of data:";
			// 
			// MSampMode
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(632, 312);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.groupBox1,
																		  this.btnCancel,
																		  this.groupBox3,
																		  this.btnOK,
																		  this.groupBox2});
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "MSampMode";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Sampling Condition Setting for Master";
			this.Load += new System.EventHandler(this.MSampMode_Load);
			this.groupBox1.ResumeLayout(false);
			this.groupBox3.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		//===================================================
		// Dialog initialization
		//===================================================
		private void MSampMode_Load(object sender, System.EventArgs e)
		{
			short	i;
			string	szBuf = new string(' ', 100);

			//--------------------------------
			// Initialize display
			//--------------------------------
			// 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());
		}

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

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

		//===================================================
		// Clock condition setting is changed
		//===================================================
		private void cboClock_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			string	szBuf = new string(' ', 100);
			szBuf = cboClock.Text;
			if (string.Compare(szBuf, "Internal clock") == 0) 
			{
				txtInternalClock.Enabled = true;
			} 
			else 
			{
				txtInternalClock.Enabled = false;
			}
		}

		//===================================================
		// Stop condition setting is changed
		//===================================================
		private void cboStop_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			string	szBuf = new string(' ', 100);
			szBuf = cboStop.Text;
			if (szBuf.StartsWith ("Count-match")) 
			{
				txtCompStop.Enabled = true;
			} 
			else 
			{
				txtCompStop.Enabled = false;
			}
			if (string.Compare(szBuf, "Stop transfer by specified times") == 0) 
			{
				txtStopNumber.Enabled = true;
			} 
			else 
			{
				txtStopNumber.Enabled = false;
			}
		}

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

			//--------------------------------
			// Get displayed data
			//--------------------------------
			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;

			//--------------------------------
			// Convert setting value to a number
			//--------------------------------
			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;
			}

			//--------------------------------
			// Set sampling condition
			//--------------------------------
			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();
		}

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