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


namespace Infinite
{
	/// <summary>
	/// Summary description for frmMode.
	/// </summary>
	public class frmMode : System.Windows.Forms.Form
	{
		internal System.Windows.Forms.Button btnOK;
		internal System.Windows.Forms.Button btnCancel;
		internal System.Windows.Forms.Label Label10;
		internal System.Windows.Forms.GroupBox GroupBox1;
		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.Label Label4;
		internal System.Windows.Forms.Label Label3;
		internal System.Windows.Forms.Label Label2;
		internal System.Windows.Forms.Label Label1;
		internal System.Windows.Forms.ComboBox cboCounterMode;
		internal System.Windows.Forms.ComboBox cboFilter;
		internal System.Windows.Forms.ComboBox cboSyncClear;
		internal System.Windows.Forms.ComboBox cboMul;
		internal System.Windows.Forms.ComboBox cboPhase;
		internal System.Windows.Forms.ComboBox cboCountDirection;
		internal System.Windows.Forms.ComboBox cboSignalSource;
		internal System.Windows.Forms.ComboBox cboZPhaseLogic;
		internal System.Windows.Forms.ComboBox cboZPhaseMode;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		Ccnt					cnt			   = new Ccnt();

		public struct StrNum
		{
			public string	Str;
			public ushort	Num;
			public StrNum(string Str, ushort Num)
			{
				this.Str = Str;
				this.Num = Num;
			}
		};

		// Z phase mode
		static StrNum[] ZPhaseMode =
		{
			new StrNum("Not Use",	 (ushort)CcntConst.CNT_ZPHASE_NOT_USE   ),
			new StrNum("Next One",	 (ushort)CcntConst.CNT_ZPHASE_NEXT_ONE  ),
			new StrNum("Every Time", (ushort)CcntConst.CNT_ZPHASE_EVERY_TIME),
			new StrNum("End",		 0									   )
		};
		// Z phase logic
		static StrNum[] ZPhaseLogic = 
		{
			new StrNum("Positive",	    (ushort)CcntConst.CNT_ZLOGIC_POSITIVE  ),
			new StrNum("Negative",	    (ushort)CcntConst.CNT_ZLOGIC_NEGATIVE  ),
			new StrNum("End",		    0									   )
		};
		// External signal source
		static StrNum[] SignalSource = 
		{
			new StrNum("Photocoupler insulation",	 (ushort)CcntConst.CNT_SIGTYPE_ISOLATE      ),
			new StrNum("TTL",	                     (ushort)CcntConst.CNT_SIGTYPE_TTL          ),
			new StrNum("Line Receiver",	             (ushort)CcntConst.CNT_SIGTYPE_LINERECEIVER ),
			new StrNum("End",	                     0									        )
		};
		// Count direction
		static StrNum[] CountDirection = 
		{
			new StrNum("Down Count",	(ushort)CcntConst.CNT_DIR_DOWN  ),
			new StrNum("Up Count",	    (ushort)CcntConst.CNT_DIR_UP    ),
			new StrNum("End",		    0							    )
		};
		// Operation mode
		static StrNum[] Phase = 
		{
			new StrNum("1 Phase",	    (ushort)CcntConst.CNT_MODE_1PHASE     ),
			new StrNum("2 Phase",		(ushort)CcntConst.CNT_MODE_2PHASE     ),
			new StrNum("Gate Control",  (ushort)CcntConst.CNT_MODE_GATECONTROL),
			new StrNum("End",		    0									  )
		};
		// Multiple
		static StrNum[] Mul = 
		{
			new StrNum("X1",	        (ushort)CcntConst.CNT_MUL_X1 ),
			new StrNum("X2",		    (ushort)CcntConst.CNT_MUL_X2 ),
			new StrNum("X4",            (ushort)CcntConst.CNT_MUL_X4 ),
			new StrNum("End",		    0							 )
		};
		// Synd/Async clear
		static StrNum[] SyncClear = 
		{
			new StrNum("Async",		    (ushort)CcntConst.CNT_CLR_ASYNC   ),
			new StrNum("Sync",          (ushort)CcntConst.CNT_CLR_SYNC    ),
			new StrNum("End",		    0								  )
		};
		// Digital filter value
		static StrNum[] Filter = 
		{
			new StrNum("0",		        0x00    ),
			new StrNum("1",             0x01    ),
			new StrNum("2",		        0x02    ),
			new StrNum("3",             0x03    ),
			new StrNum("4",		        0x04    ),
			new StrNum("5",             0x05    ),
			new StrNum("6",		        0x06    ),
			new StrNum("7",             0x07    ),
			new StrNum("8",		        0x08    ),
			new StrNum("9",             0x09    ),
			new StrNum("A",		        0x0a    ),
			new StrNum("B",             0x0b    ),
			new StrNum("C",             0x0c    ),
			new StrNum("D",		        0x0d    ),
			new StrNum("E",             0x0e    ),
			new StrNum("F",             0x0f    ),
			new StrNum("End",		    0       )
		};
		// Counter Mode
		static StrNum[] CounterMode = 
	   {
		   new StrNum("Normal",		    (ushort)CcntConst.CNTS_MODE_NORMAL   ),
		   new StrNum("Differencial",   (ushort)CcntConst.CNTS_MODE_DIFF     ),
		   new StrNum("End",		    0	  						         )
	   };

		// Data initialization
		static string	szZPhaseMode		= "Not Use";
		static string	szZPhaseLogic		= "Negative";
		static string	szSignalSource		= "Line Receiver";
		static string	szCountDirection	= "Up Count";
		static string	szPhase			    = "2 Phase";
		static string	szMul			    = "X1";
		static string	szSyncClear			= "Async";
		static string	szFilter		    = "0";
		static string   szCounterMode		= "Normal";
		short           Id;

		public static ushort str_to_num(StrNum[] strnum, string str)
		{
			short	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;
		}

		public static string num_to_str(StrNum[] strnum, short num)
		{
			short	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 frmMode()
		{
			//
			// 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.btnOK = new System.Windows.Forms.Button();
			this.btnCancel = new System.Windows.Forms.Button();
			this.Label10 = new System.Windows.Forms.Label();
			this.GroupBox1 = new System.Windows.Forms.GroupBox();
			this.Label9 = new System.Windows.Forms.Label();
			this.Label8 = new System.Windows.Forms.Label();
			this.Label7 = new System.Windows.Forms.Label();
			this.Label6 = new System.Windows.Forms.Label();
			this.Label5 = new System.Windows.Forms.Label();
			this.Label4 = new System.Windows.Forms.Label();
			this.Label3 = new System.Windows.Forms.Label();
			this.Label2 = new System.Windows.Forms.Label();
			this.Label1 = new System.Windows.Forms.Label();
			this.cboCounterMode = new System.Windows.Forms.ComboBox();
			this.cboFilter = new System.Windows.Forms.ComboBox();
			this.cboSyncClear = new System.Windows.Forms.ComboBox();
			this.cboMul = new System.Windows.Forms.ComboBox();
			this.cboPhase = new System.Windows.Forms.ComboBox();
			this.cboCountDirection = new System.Windows.Forms.ComboBox();
			this.cboSignalSource = new System.Windows.Forms.ComboBox();
			this.cboZPhaseLogic = new System.Windows.Forms.ComboBox();
			this.cboZPhaseMode = new System.Windows.Forms.ComboBox();
			this.GroupBox1.SuspendLayout();
			this.SuspendLayout();
			// 
			// btnOK
			// 
			this.btnOK.Location = new System.Drawing.Point(184, 364);
			this.btnOK.Name = "btnOK";
			this.btnOK.Size = new System.Drawing.Size(104, 31);
			this.btnOK.TabIndex = 12;
			this.btnOK.Text = "OK";
			this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
			// 
			// btnCancel
			// 
			this.btnCancel.Location = new System.Drawing.Point(304, 364);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.Size = new System.Drawing.Size(104, 31);
			this.btnCancel.TabIndex = 13;
			this.btnCancel.Text = "Cancel";
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			// 
			// Label10
			// 
			this.Label10.Location = new System.Drawing.Point(16, 336);
			this.Label10.Name = "Label10";
			this.Label10.Size = new System.Drawing.Size(224, 19);
			this.Label10.TabIndex = 11;
			this.Label10.Text = "All channels use the same setting.";
			// 
			// GroupBox1
			// 
			this.GroupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.Label9,
																					this.Label8,
																					this.Label7,
																					this.Label6,
																					this.Label5,
																					this.Label4,
																					this.Label3,
																					this.Label2,
																					this.Label1,
																					this.cboCounterMode,
																					this.cboFilter,
																					this.cboSyncClear,
																					this.cboMul,
																					this.cboPhase,
																					this.cboCountDirection,
																					this.cboSignalSource,
																					this.cboZPhaseLogic,
																					this.cboZPhaseMode});
			this.GroupBox1.Location = new System.Drawing.Point(8, 11);
			this.GroupBox1.Name = "GroupBox1";
			this.GroupBox1.Size = new System.Drawing.Size(408, 316);
			this.GroupBox1.TabIndex = 10;
			this.GroupBox1.TabStop = false;
			this.GroupBox1.Text = "Counter Mode";
			// 
			// Label9
			// 
			this.Label9.Location = new System.Drawing.Point(16, 278);
			this.Label9.Name = "Label9";
			this.Label9.Size = new System.Drawing.Size(104, 23);
			this.Label9.TabIndex = 17;
			this.Label9.Text = "Count Mode:";
			// 
			// Label8
			// 
			this.Label8.Location = new System.Drawing.Point(16, 247);
			this.Label8.Name = "Label8";
			this.Label8.Size = new System.Drawing.Size(104, 23);
			this.Label8.TabIndex = 16;
			this.Label8.Text = "Digital Filter:";
			// 
			// Label7
			// 
			this.Label7.Location = new System.Drawing.Point(16, 214);
			this.Label7.Name = "Label7";
			this.Label7.Size = new System.Drawing.Size(104, 23);
			this.Label7.TabIndex = 15;
			this.Label7.Text = "Clear:";
			// 
			// Label6
			// 
			this.Label6.Location = new System.Drawing.Point(16, 183);
			this.Label6.Name = "Label6";
			this.Label6.Size = new System.Drawing.Size(104, 23);
			this.Label6.TabIndex = 14;
			this.Label6.Text = "Multiple:";
			// 
			// Label5
			// 
			this.Label5.Location = new System.Drawing.Point(16, 151);
			this.Label5.Name = "Label5";
			this.Label5.Size = new System.Drawing.Size(120, 24);
			this.Label5.TabIndex = 13;
			this.Label5.Text = "Phase:";
			// 
			// Label4
			// 
			this.Label4.Location = new System.Drawing.Point(16, 120);
			this.Label4.Name = "Label4";
			this.Label4.Size = new System.Drawing.Size(104, 23);
			this.Label4.TabIndex = 12;
			this.Label4.Text = "Count Direction:";
			// 
			// Label3
			// 
			this.Label3.Location = new System.Drawing.Point(16, 88);
			this.Label3.Name = "Label3";
			this.Label3.Size = new System.Drawing.Size(104, 24);
			this.Label3.TabIndex = 11;
			this.Label3.Text = "Signal Type:";
			// 
			// Label2
			// 
			this.Label2.Location = new System.Drawing.Point(16, 57);
			this.Label2.Name = "Label2";
			this.Label2.Size = new System.Drawing.Size(104, 23);
			this.Label2.TabIndex = 10;
			this.Label2.Text = "Z Phase Logic:";
			// 
			// Label1
			// 
			this.Label1.Location = new System.Drawing.Point(16, 26);
			this.Label1.Name = "Label1";
			this.Label1.Size = new System.Drawing.Size(104, 23);
			this.Label1.TabIndex = 9;
			this.Label1.Text = "Z Phase Mode:";
			// 
			// cboCounterMode
			// 
			this.cboCounterMode.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboCounterMode.Location = new System.Drawing.Point(160, 278);
			this.cboCounterMode.Name = "cboCounterMode";
			this.cboCounterMode.Size = new System.Drawing.Size(216, 21);
			this.cboCounterMode.TabIndex = 8;
			// 
			// cboFilter
			// 
			this.cboFilter.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboFilter.Location = new System.Drawing.Point(160, 247);
			this.cboFilter.Name = "cboFilter";
			this.cboFilter.Size = new System.Drawing.Size(216, 21);
			this.cboFilter.TabIndex = 7;
			// 
			// cboSyncClear
			// 
			this.cboSyncClear.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboSyncClear.Location = new System.Drawing.Point(160, 214);
			this.cboSyncClear.Name = "cboSyncClear";
			this.cboSyncClear.Size = new System.Drawing.Size(216, 21);
			this.cboSyncClear.TabIndex = 6;
			// 
			// cboMul
			// 
			this.cboMul.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboMul.Location = new System.Drawing.Point(160, 183);
			this.cboMul.Name = "cboMul";
			this.cboMul.Size = new System.Drawing.Size(216, 21);
			this.cboMul.TabIndex = 5;
			// 
			// cboPhase
			// 
			this.cboPhase.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboPhase.Location = new System.Drawing.Point(160, 151);
			this.cboPhase.Name = "cboPhase";
			this.cboPhase.Size = new System.Drawing.Size(216, 21);
			this.cboPhase.TabIndex = 4;
			// 
			// cboCountDirection
			// 
			this.cboCountDirection.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboCountDirection.Location = new System.Drawing.Point(160, 120);
			this.cboCountDirection.Name = "cboCountDirection";
			this.cboCountDirection.Size = new System.Drawing.Size(216, 21);
			this.cboCountDirection.TabIndex = 3;
			// 
			// cboSignalSource
			// 
			this.cboSignalSource.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboSignalSource.Location = new System.Drawing.Point(160, 88);
			this.cboSignalSource.Name = "cboSignalSource";
			this.cboSignalSource.Size = new System.Drawing.Size(216, 21);
			this.cboSignalSource.TabIndex = 2;
			// 
			// cboZPhaseLogic
			// 
			this.cboZPhaseLogic.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboZPhaseLogic.Location = new System.Drawing.Point(160, 57);
			this.cboZPhaseLogic.Name = "cboZPhaseLogic";
			this.cboZPhaseLogic.Size = new System.Drawing.Size(216, 21);
			this.cboZPhaseLogic.TabIndex = 1;
			// 
			// cboZPhaseMode
			// 
			this.cboZPhaseMode.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboZPhaseMode.ImeMode = System.Windows.Forms.ImeMode.NoControl;
			this.cboZPhaseMode.Location = new System.Drawing.Point(160, 26);
			this.cboZPhaseMode.Name = "cboZPhaseMode";
			this.cboZPhaseMode.Size = new System.Drawing.Size(216, 21);
			this.cboZPhaseMode.TabIndex = 0;
			// 
			// frmMode
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(424, 407);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.btnOK,
																		  this.btnCancel,
																		  this.Label10,
																		  this.GroupBox1});
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "frmMode";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Counter Mode Setting";
			this.Load += new System.EventHandler(this.frmMode_Load);
			this.GroupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		//===================================================
		//	Dialog initialization
		//===================================================
		private void frmMode_Load(object sender, System.EventArgs e)
		{
			//===================================================
			//	Initialize combo boxes
			//===================================================
			short	i;
			// Z phase mode
			for (i=0; string.Compare(ZPhaseMode[i].Str, "End") != 0; i++) 
			{
				cboZPhaseMode.Items.Add(ZPhaseMode[i].Str);
			}
			// Z phase logic
			for (i=0; string.Compare(ZPhaseLogic[i].Str, "End") != 0; i++) 
			{
				cboZPhaseLogic.Items.Add(ZPhaseLogic[i].Str);
			}
			// External signal source
			for (i=0; string.Compare(SignalSource[i].Str, "End") != 0; i++) 
			{
				cboSignalSource.Items.Add(SignalSource[i].Str);
			}
			// Count direction
			for (i=0; string.Compare(CountDirection[i].Str, "End") != 0; i++) 
			{
				cboCountDirection.Items.Add(CountDirection[i].Str);
			}
			// Operation mode
			for (i=0; string.Compare(Phase[i].Str, "End") != 0; i++) 
			{
				cboPhase.Items.Add(Phase[i].Str);
			}
			// Multiple
			for (i=0; string.Compare(Mul[i].Str, "End") != 0; i++) 
			{
				cboMul.Items.Add(Mul[i].Str);
			}
			// Synd/Async clear
			for (i=0; string.Compare(SyncClear[i].Str, "End") != 0; i++) 
			{
				cboSyncClear.Items.Add(SyncClear[i].Str);
			}
			// Digital filter value
			for (i=0; string.Compare(Filter[i].Str, "End") != 0; i++) 
			{
				cboFilter.Items.Add(Filter[i].Str);
			}
			// Counter Mode
			for (i=0; string.Compare(CounterMode[i].Str, "End") != 0; i++) 
			{
				cboCounterMode.Items.Add(CounterMode[i].Str);
			}
			//-------------------------------
			// Set initial data
			//-------------------------------
			cboZPhaseMode.Text = szZPhaseMode;
			cboZPhaseLogic.Text = szZPhaseLogic;
			cboSignalSource.Text = szSignalSource;
			cboCountDirection.Text = szCountDirection;
			cboPhase.Text = szPhase;
			cboMul.Text = szMul;
			cboSyncClear.Text = szSyncClear;
			cboFilter.Text = szFilter;
			cboCounterMode.Text = szCounterMode;

			Id = Infinite.Id;
		}

		//---------------------------------------------
		// Setting completion processing
		//---------------------------------------------
		private void btnOK_Click(object sender, System.EventArgs e)
		{
			short	ChNo;
			string	error_string = new string(' ', 256);
			string	str;
			int	    ret;


			short	wZPhaseMode;
			short	wZPhaseLogic;
			short	wSignalSource;
			short	wCountDirection;
			short	wPhase;
			short	wMul;
			short	wSyncClear;
			short	wFilter;
			short	wCounterMode;

			//-------------------------------
			// Get the set information
			//-------------------------------
			szZPhaseMode = cboZPhaseMode.Text;
			szZPhaseLogic = cboZPhaseLogic.Text;
			szSignalSource = cboSignalSource.Text;
			szCountDirection = cboCountDirection.Text;
			szPhase = cboPhase.Text;
			szMul = cboMul.Text;
			szSyncClear = cboSyncClear.Text;
			szFilter = cboFilter.Text;
			szCounterMode = cboCounterMode.Text;

			wZPhaseMode		= (short)str_to_num(ZPhaseMode, szZPhaseMode);
			wZPhaseLogic	= (short)str_to_num(ZPhaseLogic, szZPhaseLogic);
			wSignalSource	= (short)str_to_num(SignalSource, szSignalSource);
			wCountDirection	= (short)str_to_num(CountDirection, szCountDirection);
			wPhase			= (short)str_to_num(Phase, szPhase);
			wMul			= (short)str_to_num(Mul, szMul);
			wSyncClear		= (short)str_to_num(SyncClear, szSyncClear);
			wFilter			= (short)str_to_num(Filter, szFilter);
			wCounterMode	= (short)str_to_num(CounterMode, szCounterMode);

			//-------------------------------
			// Set the set information to device
			//-------------------------------
			for (ChNo = 0; ChNo<Infinite.CHANNEL_NUM; ChNo++) 
			{
				//---------------------------------------------
				// Set Z phase mode
				//---------------------------------------------
				ret = cnt.SetZMode(Id, ChNo, wZPhaseMode);
				if (ret != 0) 
				{
					cnt.GetErrorString(ret, out error_string);
					str = string.Format("CntSetZMode : ret = {0:d}: {1}", ret, error_string);
					MessageBox.Show(str, "Error", MessageBoxButtons.OK);
					break;
				}
				//---------------------------------------------
				// Set Z phase logic
				//---------------------------------------------
				ret = cnt.SetZLogic(Id, ChNo, wZPhaseLogic);
				if (ret != 0) 
				{
					cnt.GetErrorString(ret, out error_string);
					str = string.Format("CntSetZLogic : ret = {0:d}: {1}", ret, error_string);
					MessageBox.Show(str, "Error", MessageBoxButtons.OK);
					break;
				}
				//---------------------------------------------
				// Set external signal source
				//---------------------------------------------
				ret = cnt.SelectChannelSignal(Id, ChNo, wSignalSource);
				if (ret != 0) 
				{
					cnt.GetErrorString(ret, out error_string);
					str = string.Format("CntSelectChannelSignal : ret = {0:d}: {1}", ret, error_string);
					MessageBox.Show(str, "Error", MessageBoxButtons.OK);
					break;
				}
				//---------------------------------------------
				// Set count direction
				//---------------------------------------------
				ret = cnt.SetCountDirection(Id, ChNo, wCountDirection);
				if (ret != 0) 
				{
					cnt.GetErrorString(ret, out error_string);
					str = string.Format("CntSetCountDirection : ret = {0:d}: {1}", ret, error_string);
					MessageBox.Show(str, "Error", MessageBoxButtons.OK);
					break;
				}
				//---------------------------------------------
				// Set operation mode
				//---------------------------------------------
				ret = cnt.SetOperationMode(Id, ChNo, wPhase, wMul, wSyncClear);
				if (ret != 0) 
				{
					cnt.GetErrorString(ret, out error_string);
					str = string.Format("CntSetOperationMode : ret = {0:d}: {1}", ret, error_string);
					MessageBox.Show(str, "Error", MessageBoxButtons.OK);
					break;
				}
				//---------------------------------------------
				// Set digital filter value
				//---------------------------------------------
				ret = cnt.SetDigitalFilter(Id, ChNo, wFilter);
				if (ret != 0) 
				{
					cnt.GetErrorString(ret, out error_string);
					str = string.Format("CntSetOperationMode : ret = {0:d}: {1}", ret, error_string);
					MessageBox.Show(str, "Error", MessageBoxButtons.OK);
					break;
				}
				//---------------------------------------------
				// Set counter mode
				//---------------------------------------------
				ret = cnt.SetCounterMode(Id, ChNo, wCounterMode);
				if (ret != 0) 
				{
					cnt.GetErrorString(ret, out error_string);
					str = string.Format("CntSetCounterMode : ret = {0:d}: {1}", ret, error_string);
					MessageBox.Show(str, "Error", MessageBoxButtons.OK);
					break;
				}
			}
			this.Close();		
		}

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

	}
}
