using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text;
using System.Runtime.InteropServices;
using System.Globalization;

namespace Counter
{
	/// <summary>
	/// Form1 ̊Tv̐łB
	/// </summary>
	public class Counter : System.Windows.Forms.Form
	{
		internal System.Windows.Forms.Label Label13;
		internal System.Windows.Forms.Label Label11;
		internal System.Windows.Forms.Label Label7;
		internal System.Windows.Forms.GroupBox GroupBox3;
		internal System.Windows.Forms.GroupBox GroupBox1;
		internal System.Windows.Forms.Label Label3;
		internal System.Windows.Forms.Label Label1;
		internal System.Windows.Forms.Label Label2;
		internal System.Windows.Forms.Label Label10;
		internal System.Windows.Forms.Label Label9;
		internal System.Windows.Forms.Label Label8;
		internal System.Windows.Forms.Label Label6;
		internal System.Windows.Forms.Label Label5;
		internal System.Windows.Forms.Label Label4;
		internal System.Windows.Forms.GroupBox GroupBox2;
		internal System.Windows.Forms.Button btnCntExit;
		internal System.Windows.Forms.Button btnCntStop;
		internal System.Windows.Forms.Button btnCntPreset;
		internal System.Windows.Forms.Button btnCntCompare;
		internal System.Windows.Forms.Button btnCntInit;
		internal System.Windows.Forms.TextBox txtPreset7;
		internal System.Windows.Forms.TextBox txtPreset6;
		internal System.Windows.Forms.TextBox txtPreset5;
		internal System.Windows.Forms.TextBox txtPreset4;
		internal System.Windows.Forms.TextBox txtPreset3;
		internal System.Windows.Forms.TextBox txtPreset2;
		internal System.Windows.Forms.TextBox txtPreset1;
		internal System.Windows.Forms.TextBox txtPreset0;
		internal System.Windows.Forms.RadioButton rdoPreset1;
		internal System.Windows.Forms.RadioButton rdoPreset0;
		internal System.Windows.Forms.TextBox txtCh7;
		internal System.Windows.Forms.TextBox txtCh6;
		internal System.Windows.Forms.TextBox txtCh5;
		internal System.Windows.Forms.TextBox txtCh4;
		internal System.Windows.Forms.TextBox txtCh3;
		internal System.Windows.Forms.TextBox txtCh2;
		internal System.Windows.Forms.TextBox txtCh1;
		internal System.Windows.Forms.TextBox txtCh0;
		internal System.Windows.Forms.RadioButton rdoCh1;
		internal System.Windows.Forms.RadioButton rdoCh0;
		internal System.Windows.Forms.TextBox txtErr;
		internal System.Windows.Forms.TextBox txtStart;
		internal System.Windows.Forms.ComboBox cboDeviceName;
		internal System.Windows.Forms.Button btnCntStart;
		internal System.Windows.Forms.Button btnExit;
		internal System.Windows.Forms.TextBox txtReturnCode;
		internal System.Windows.Forms.Button btnCntMode;
		internal System.Windows.Forms.TextBox txtStatus7;
		internal System.Windows.Forms.TextBox txtStatus6;
		internal System.Windows.Forms.TextBox txtStatus5;
		internal System.Windows.Forms.TextBox txtStatus4;
		internal System.Windows.Forms.TextBox txtStatus3;
		internal System.Windows.Forms.TextBox txtStatus2;
		internal System.Windows.Forms.TextBox txtStatus1;
		internal System.Windows.Forms.TextBox txtStatus0;
		private System.Windows.Forms.Timer CntTimer;
		private System.ComponentModel.IContainer components;

		//---------------------------------------------------------
		// O[oϐ
		//---------------------------------------------------------
		Int32				Ret;									// ߂l
		StringBuilder	szError = new StringBuilder(256);		// G[
		string			szReturnCode = new string(' ', 256);	// \G[
		string			szText = new string(' ', 100);			//e|
		// ǉf[^
		TextBox[]		m_Ch = new TextBox[8];					// JEglRg[
		TextBox[]		m_Status = new TextBox[8];				// Xe[^XlRg[
		TextBox[]		m_Preset = new TextBox[8];				// vZbglRg[
		uint[]			CompCount = new uint[8];				// rv

		public Counter()
		{
			//
			// Windows tH[ fUCi T|[gɕKvłB
			//
			InitializeComponent();

			//
			// TODO: InitializeComponent ĂяǒɁARXgN^ R[hǉĂB
			//
		}

		/// <summary>
		/// gpĂ郊\[XɌ㏈s܂B
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// fUCi T|[gɕKvȃ\bhłB̃\bh̓e
		/// R[h GfB^ŕύXȂłB
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			this.btnCntExit = new System.Windows.Forms.Button();
			this.btnCntStop = new System.Windows.Forms.Button();
			this.btnCntPreset = new System.Windows.Forms.Button();
			this.btnCntCompare = new System.Windows.Forms.Button();
			this.btnCntInit = new System.Windows.Forms.Button();
			this.Label13 = new System.Windows.Forms.Label();
			this.Label11 = new System.Windows.Forms.Label();
			this.Label7 = new System.Windows.Forms.Label();
			this.GroupBox3 = new System.Windows.Forms.GroupBox();
			this.txtPreset7 = new System.Windows.Forms.TextBox();
			this.txtPreset6 = new System.Windows.Forms.TextBox();
			this.txtPreset5 = new System.Windows.Forms.TextBox();
			this.txtPreset4 = new System.Windows.Forms.TextBox();
			this.txtPreset3 = new System.Windows.Forms.TextBox();
			this.txtPreset2 = new System.Windows.Forms.TextBox();
			this.txtPreset1 = new System.Windows.Forms.TextBox();
			this.txtPreset0 = new System.Windows.Forms.TextBox();
			this.rdoPreset1 = new System.Windows.Forms.RadioButton();
			this.rdoPreset0 = new System.Windows.Forms.RadioButton();
			this.GroupBox1 = new System.Windows.Forms.GroupBox();
			this.txtCh7 = new System.Windows.Forms.TextBox();
			this.txtCh6 = new System.Windows.Forms.TextBox();
			this.txtCh5 = new System.Windows.Forms.TextBox();
			this.txtCh4 = new System.Windows.Forms.TextBox();
			this.txtCh3 = new System.Windows.Forms.TextBox();
			this.txtCh2 = new System.Windows.Forms.TextBox();
			this.txtCh1 = new System.Windows.Forms.TextBox();
			this.txtCh0 = new System.Windows.Forms.TextBox();
			this.rdoCh1 = new System.Windows.Forms.RadioButton();
			this.rdoCh0 = new System.Windows.Forms.RadioButton();
			this.txtErr = new System.Windows.Forms.TextBox();
			this.txtStart = new System.Windows.Forms.TextBox();
			this.Label3 = new System.Windows.Forms.Label();
			this.Label1 = new System.Windows.Forms.Label();
			this.Label2 = new System.Windows.Forms.Label();
			this.cboDeviceName = new System.Windows.Forms.ComboBox();
			this.btnCntStart = new System.Windows.Forms.Button();
			this.btnExit = new System.Windows.Forms.Button();
			this.txtReturnCode = new System.Windows.Forms.TextBox();
			this.Label10 = new System.Windows.Forms.Label();
			this.btnCntMode = new System.Windows.Forms.Button();
			this.Label9 = new System.Windows.Forms.Label();
			this.Label8 = 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.GroupBox2 = new System.Windows.Forms.GroupBox();
			this.txtStatus7 = new System.Windows.Forms.TextBox();
			this.txtStatus6 = new System.Windows.Forms.TextBox();
			this.txtStatus5 = new System.Windows.Forms.TextBox();
			this.txtStatus4 = new System.Windows.Forms.TextBox();
			this.txtStatus3 = new System.Windows.Forms.TextBox();
			this.txtStatus2 = new System.Windows.Forms.TextBox();
			this.txtStatus1 = new System.Windows.Forms.TextBox();
			this.txtStatus0 = new System.Windows.Forms.TextBox();
			this.CntTimer = new System.Windows.Forms.Timer(this.components);
			this.GroupBox3.SuspendLayout();
			this.GroupBox1.SuspendLayout();
			this.GroupBox2.SuspendLayout();
			this.SuspendLayout();
			// 
			// btnCntExit
			// 
			this.btnCntExit.Location = new System.Drawing.Point(423, 345);
			this.btnCntExit.Name = "btnCntExit";
			this.btnCntExit.Size = new System.Drawing.Size(104, 24);
			this.btnCntExit.TabIndex = 11;
			this.btnCntExit.Text = "CntExit";
			this.btnCntExit.Click += new System.EventHandler(this.btnCntExit_Click);
			// 
			// btnCntStop
			// 
			this.btnCntStop.Location = new System.Drawing.Point(423, 257);
			this.btnCntStop.Name = "btnCntStop";
			this.btnCntStop.Size = new System.Drawing.Size(104, 24);
			this.btnCntStop.TabIndex = 10;
			this.btnCntStop.Text = "CntStopCount";
			this.btnCntStop.Click += new System.EventHandler(this.btnCntStop_Click);
			// 
			// btnCntPreset
			// 
			this.btnCntPreset.Location = new System.Drawing.Point(423, 225);
			this.btnCntPreset.Name = "btnCntPreset";
			this.btnCntPreset.Size = new System.Drawing.Size(104, 24);
			this.btnCntPreset.TabIndex = 9;
			this.btnCntPreset.Text = "CntPreset";
			this.btnCntPreset.Click += new System.EventHandler(this.btnCntPreset_Click);
			// 
			// btnCntCompare
			// 
			this.btnCntCompare.Location = new System.Drawing.Point(423, 137);
			this.btnCntCompare.Name = "btnCntCompare";
			this.btnCntCompare.Size = new System.Drawing.Size(104, 24);
			this.btnCntCompare.TabIndex = 7;
			this.btnCntCompare.Text = "rݒ...";
			this.btnCntCompare.Click += new System.EventHandler(this.btnCntCompare_Click);
			// 
			// btnCntInit
			// 
			this.btnCntInit.Location = new System.Drawing.Point(423, 9);
			this.btnCntInit.Name = "btnCntInit";
			this.btnCntInit.Size = new System.Drawing.Size(104, 24);
			this.btnCntInit.TabIndex = 0;
			this.btnCntInit.Text = "CntInit";
			this.btnCntInit.Click += new System.EventHandler(this.btnCntInit_Click);
			// 
			// Label13
			// 
			this.Label13.Location = new System.Drawing.Point(8, 384);
			this.Label13.Name = "Label13";
			this.Label13.Size = new System.Drawing.Size(60, 15);
			this.Label13.TabIndex = 77;
			this.Label13.Text = "߂lF";
			// 
			// Label11
			// 
			this.Label11.Location = new System.Drawing.Point(9, 341);
			this.Label11.Name = "Label11";
			this.Label11.Size = new System.Drawing.Size(48, 16);
			this.Label11.TabIndex = 74;
			this.Label11.Text = "7";
			// 
			// Label7
			// 
			this.Label7.Location = new System.Drawing.Point(9, 246);
			this.Label7.Name = "Label7";
			this.Label7.Size = new System.Drawing.Size(48, 16);
			this.Label7.TabIndex = 70;
			this.Label7.Text = "3";
			// 
			// GroupBox3
			// 
			this.GroupBox3.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.txtPreset7,
																					this.txtPreset6,
																					this.txtPreset5,
																					this.txtPreset4,
																					this.txtPreset3,
																					this.txtPreset2,
																					this.txtPreset1,
																					this.txtPreset0,
																					this.rdoPreset1,
																					this.rdoPreset0});
			this.GroupBox3.Location = new System.Drawing.Point(302, 97);
			this.GroupBox3.Name = "GroupBox3";
			this.GroupBox3.Size = new System.Drawing.Size(107, 272);
			this.GroupBox3.TabIndex = 5;
			this.GroupBox3.TabStop = false;
			this.GroupBox3.Text = "vZbgl";
			// 
			// txtPreset7
			// 
			this.txtPreset7.Location = new System.Drawing.Point(8, 240);
			this.txtPreset7.Name = "txtPreset7";
			this.txtPreset7.Size = new System.Drawing.Size(88, 19);
			this.txtPreset7.TabIndex = 9;
			this.txtPreset7.Text = "TextBox8";
			// 
			// txtPreset6
			// 
			this.txtPreset6.Location = new System.Drawing.Point(8, 216);
			this.txtPreset6.Name = "txtPreset6";
			this.txtPreset6.Size = new System.Drawing.Size(88, 19);
			this.txtPreset6.TabIndex = 8;
			this.txtPreset6.Text = "TextBox7";
			// 
			// txtPreset5
			// 
			this.txtPreset5.Location = new System.Drawing.Point(8, 192);
			this.txtPreset5.Name = "txtPreset5";
			this.txtPreset5.Size = new System.Drawing.Size(88, 19);
			this.txtPreset5.TabIndex = 7;
			this.txtPreset5.Text = "TextBox6";
			// 
			// txtPreset4
			// 
			this.txtPreset4.Location = new System.Drawing.Point(8, 168);
			this.txtPreset4.Name = "txtPreset4";
			this.txtPreset4.Size = new System.Drawing.Size(88, 19);
			this.txtPreset4.TabIndex = 6;
			this.txtPreset4.Text = "TextBox5";
			// 
			// txtPreset3
			// 
			this.txtPreset3.Location = new System.Drawing.Point(8, 144);
			this.txtPreset3.Name = "txtPreset3";
			this.txtPreset3.Size = new System.Drawing.Size(88, 19);
			this.txtPreset3.TabIndex = 5;
			this.txtPreset3.Text = "TextBox4";
			// 
			// txtPreset2
			// 
			this.txtPreset2.Location = new System.Drawing.Point(8, 120);
			this.txtPreset2.Name = "txtPreset2";
			this.txtPreset2.Size = new System.Drawing.Size(88, 19);
			this.txtPreset2.TabIndex = 4;
			this.txtPreset2.Text = "TextBox3";
			// 
			// txtPreset1
			// 
			this.txtPreset1.Location = new System.Drawing.Point(8, 96);
			this.txtPreset1.Name = "txtPreset1";
			this.txtPreset1.Size = new System.Drawing.Size(88, 19);
			this.txtPreset1.TabIndex = 3;
			this.txtPreset1.Text = "TextBox2";
			// 
			// txtPreset0
			// 
			this.txtPreset0.Location = new System.Drawing.Point(8, 72);
			this.txtPreset0.Name = "txtPreset0";
			this.txtPreset0.Size = new System.Drawing.Size(88, 19);
			this.txtPreset0.TabIndex = 2;
			this.txtPreset0.Text = "TextBox1";
			// 
			// rdoPreset1
			// 
			this.rdoPreset1.Location = new System.Drawing.Point(24, 40);
			this.rdoPreset1.Name = "rdoPreset1";
			this.rdoPreset1.Size = new System.Drawing.Size(60, 20);
			this.rdoPreset1.TabIndex = 1;
			this.rdoPreset1.Text = "16i";
			this.rdoPreset1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.rdoPreset1_MouseDown);
			// 
			// rdoPreset0
			// 
			this.rdoPreset0.Checked = true;
			this.rdoPreset0.Location = new System.Drawing.Point(24, 18);
			this.rdoPreset0.Name = "rdoPreset0";
			this.rdoPreset0.Size = new System.Drawing.Size(60, 20);
			this.rdoPreset0.TabIndex = 0;
			this.rdoPreset0.TabStop = true;
			this.rdoPreset0.Text = "10i";
			this.rdoPreset0.MouseDown += new System.Windows.Forms.MouseEventHandler(this.rdoPreset0_MouseDown);
			// 
			// GroupBox1
			// 
			this.GroupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.txtCh7,
																					this.txtCh6,
																					this.txtCh5,
																					this.txtCh4,
																					this.txtCh3,
																					this.txtCh2,
																					this.txtCh1,
																					this.txtCh0,
																					this.rdoCh1,
																					this.rdoCh0});
			this.GroupBox1.Location = new System.Drawing.Point(60, 97);
			this.GroupBox1.Name = "GroupBox1";
			this.GroupBox1.Size = new System.Drawing.Size(131, 272);
			this.GroupBox1.TabIndex = 3;
			this.GroupBox1.TabStop = false;
			this.GroupBox1.Text = "JEgl";
			// 
			// txtCh7
			// 
			this.txtCh7.Location = new System.Drawing.Point(8, 240);
			this.txtCh7.Name = "txtCh7";
			this.txtCh7.Size = new System.Drawing.Size(112, 19);
			this.txtCh7.TabIndex = 9;
			this.txtCh7.Text = "TextBox8";
			// 
			// txtCh6
			// 
			this.txtCh6.Location = new System.Drawing.Point(8, 216);
			this.txtCh6.Name = "txtCh6";
			this.txtCh6.Size = new System.Drawing.Size(112, 19);
			this.txtCh6.TabIndex = 8;
			this.txtCh6.Text = "TextBox7";
			// 
			// txtCh5
			// 
			this.txtCh5.Location = new System.Drawing.Point(8, 192);
			this.txtCh5.Name = "txtCh5";
			this.txtCh5.Size = new System.Drawing.Size(112, 19);
			this.txtCh5.TabIndex = 7;
			this.txtCh5.Text = "TextBox6";
			// 
			// txtCh4
			// 
			this.txtCh4.Location = new System.Drawing.Point(8, 168);
			this.txtCh4.Name = "txtCh4";
			this.txtCh4.Size = new System.Drawing.Size(112, 19);
			this.txtCh4.TabIndex = 6;
			this.txtCh4.Text = "TextBox5";
			// 
			// txtCh3
			// 
			this.txtCh3.Location = new System.Drawing.Point(8, 144);
			this.txtCh3.Name = "txtCh3";
			this.txtCh3.Size = new System.Drawing.Size(112, 19);
			this.txtCh3.TabIndex = 5;
			this.txtCh3.Text = "TextBox4";
			// 
			// txtCh2
			// 
			this.txtCh2.Location = new System.Drawing.Point(8, 120);
			this.txtCh2.Name = "txtCh2";
			this.txtCh2.Size = new System.Drawing.Size(112, 19);
			this.txtCh2.TabIndex = 4;
			this.txtCh2.Text = "TextBox3";
			// 
			// txtCh1
			// 
			this.txtCh1.Location = new System.Drawing.Point(8, 96);
			this.txtCh1.Name = "txtCh1";
			this.txtCh1.Size = new System.Drawing.Size(112, 19);
			this.txtCh1.TabIndex = 3;
			this.txtCh1.Text = "TextBox2";
			// 
			// txtCh0
			// 
			this.txtCh0.Location = new System.Drawing.Point(8, 72);
			this.txtCh0.Name = "txtCh0";
			this.txtCh0.Size = new System.Drawing.Size(112, 19);
			this.txtCh0.TabIndex = 2;
			this.txtCh0.Text = "TextBox1";
			// 
			// rdoCh1
			// 
			this.rdoCh1.Location = new System.Drawing.Point(24, 40);
			this.rdoCh1.Name = "rdoCh1";
			this.rdoCh1.Size = new System.Drawing.Size(60, 20);
			this.rdoCh1.TabIndex = 1;
			this.rdoCh1.Text = "16i";
			this.rdoCh1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.rdoCh1_MouseDown);
			// 
			// rdoCh0
			// 
			this.rdoCh0.Checked = true;
			this.rdoCh0.Location = new System.Drawing.Point(24, 18);
			this.rdoCh0.Name = "rdoCh0";
			this.rdoCh0.Size = new System.Drawing.Size(60, 20);
			this.rdoCh0.TabIndex = 0;
			this.rdoCh0.TabStop = true;
			this.rdoCh0.Text = "10i";
			this.rdoCh0.MouseDown += new System.Windows.Forms.MouseEventHandler(this.rdoCh0_MouseDown);
			// 
			// txtErr
			// 
			this.txtErr.Location = new System.Drawing.Point(143, 65);
			this.txtErr.Name = "txtErr";
			this.txtErr.Size = new System.Drawing.Size(32, 19);
			this.txtErr.TabIndex = 2;
			this.txtErr.Text = "";
			// 
			// txtStart
			// 
			this.txtStart.Location = new System.Drawing.Point(61, 65);
			this.txtStart.Name = "txtStart";
			this.txtStart.Size = new System.Drawing.Size(32, 19);
			this.txtStart.TabIndex = 1;
			this.txtStart.Text = "";
			// 
			// Label3
			// 
			this.Label3.Location = new System.Drawing.Point(140, 49);
			this.Label3.Name = "Label3";
			this.Label3.Size = new System.Drawing.Size(92, 16);
			this.Label3.TabIndex = 61;
			this.Label3.Text = "G[WX^F";
			// 
			// Label1
			// 
			this.Label1.Location = new System.Drawing.Point(9, 14);
			this.Label1.Name = "Label1";
			this.Label1.Size = new System.Drawing.Size(71, 16);
			this.Label1.TabIndex = 59;
			this.Label1.Text = "foCXF";
			// 
			// Label2
			// 
			this.Label2.Location = new System.Drawing.Point(60, 49);
			this.Label2.Name = "Label2";
			this.Label2.Size = new System.Drawing.Size(80, 16);
			this.Label2.TabIndex = 60;
			this.Label2.Text = "NWX^F";
			// 
			// cboDeviceName
			// 
			this.cboDeviceName.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboDeviceName.Location = new System.Drawing.Point(80, 10);
			this.cboDeviceName.Name = "cboDeviceName";
			this.cboDeviceName.Size = new System.Drawing.Size(200, 20);
			this.cboDeviceName.TabIndex = 15;
			// 
			// btnCntStart
			// 
			this.btnCntStart.Location = new System.Drawing.Point(423, 193);
			this.btnCntStart.Name = "btnCntStart";
			this.btnCntStart.Size = new System.Drawing.Size(104, 24);
			this.btnCntStart.TabIndex = 8;
			this.btnCntStart.Text = "CntStartCount";
			this.btnCntStart.Click += new System.EventHandler(this.btnCntStart_Click);
			// 
			// btnExit
			// 
			this.btnExit.Location = new System.Drawing.Point(423, 401);
			this.btnExit.Name = "btnExit";
			this.btnExit.Size = new System.Drawing.Size(104, 24);
			this.btnExit.TabIndex = 12;
			this.btnExit.Text = "Exit";
			this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
			// 
			// txtReturnCode
			// 
			this.txtReturnCode.Location = new System.Drawing.Point(72, 384);
			this.txtReturnCode.Name = "txtReturnCode";
			this.txtReturnCode.Size = new System.Drawing.Size(328, 19);
			this.txtReturnCode.TabIndex = 14;
			this.txtReturnCode.Text = "TextBox26";
			// 
			// Label10
			// 
			this.Label10.Location = new System.Drawing.Point(9, 317);
			this.Label10.Name = "Label10";
			this.Label10.Size = new System.Drawing.Size(48, 16);
			this.Label10.TabIndex = 73;
			this.Label10.Text = "6";
			// 
			// btnCntMode
			// 
			this.btnCntMode.Location = new System.Drawing.Point(423, 102);
			this.btnCntMode.Name = "btnCntMode";
			this.btnCntMode.Size = new System.Drawing.Size(104, 24);
			this.btnCntMode.TabIndex = 6;
			this.btnCntMode.Text = "[hݒ...";
			this.btnCntMode.Click += new System.EventHandler(this.btnCntMode_Click);
			// 
			// Label9
			// 
			this.Label9.Location = new System.Drawing.Point(9, 293);
			this.Label9.Name = "Label9";
			this.Label9.Size = new System.Drawing.Size(48, 16);
			this.Label9.TabIndex = 72;
			this.Label9.Text = "5";
			// 
			// Label8
			// 
			this.Label8.Location = new System.Drawing.Point(9, 269);
			this.Label8.Name = "Label8";
			this.Label8.Size = new System.Drawing.Size(48, 16);
			this.Label8.TabIndex = 71;
			this.Label8.Text = "4";
			// 
			// Label6
			// 
			this.Label6.Location = new System.Drawing.Point(9, 222);
			this.Label6.Name = "Label6";
			this.Label6.Size = new System.Drawing.Size(48, 16);
			this.Label6.TabIndex = 69;
			this.Label6.Text = "2";
			// 
			// Label5
			// 
			this.Label5.Location = new System.Drawing.Point(9, 197);
			this.Label5.Name = "Label5";
			this.Label5.Size = new System.Drawing.Size(48, 16);
			this.Label5.TabIndex = 68;
			this.Label5.Text = "1";
			// 
			// Label4
			// 
			this.Label4.Location = new System.Drawing.Point(9, 173);
			this.Label4.Name = "Label4";
			this.Label4.Size = new System.Drawing.Size(48, 16);
			this.Label4.TabIndex = 65;
			this.Label4.Text = "0";
			// 
			// GroupBox2
			// 
			this.GroupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.txtStatus7,
																					this.txtStatus6,
																					this.txtStatus5,
																					this.txtStatus4,
																					this.txtStatus3,
																					this.txtStatus2,
																					this.txtStatus1,
																					this.txtStatus0});
			this.GroupBox2.Location = new System.Drawing.Point(200, 97);
			this.GroupBox2.Name = "GroupBox2";
			this.GroupBox2.Size = new System.Drawing.Size(91, 272);
			this.GroupBox2.TabIndex = 4;
			this.GroupBox2.TabStop = false;
			this.GroupBox2.Text = "Xe[^X";
			// 
			// txtStatus7
			// 
			this.txtStatus7.Location = new System.Drawing.Point(8, 240);
			this.txtStatus7.Name = "txtStatus7";
			this.txtStatus7.Size = new System.Drawing.Size(72, 19);
			this.txtStatus7.TabIndex = 9;
			this.txtStatus7.Text = "TextBox8";
			// 
			// txtStatus6
			// 
			this.txtStatus6.Location = new System.Drawing.Point(8, 216);
			this.txtStatus6.Name = "txtStatus6";
			this.txtStatus6.Size = new System.Drawing.Size(72, 19);
			this.txtStatus6.TabIndex = 8;
			this.txtStatus6.Text = "TextBox7";
			// 
			// txtStatus5
			// 
			this.txtStatus5.Location = new System.Drawing.Point(8, 192);
			this.txtStatus5.Name = "txtStatus5";
			this.txtStatus5.Size = new System.Drawing.Size(72, 19);
			this.txtStatus5.TabIndex = 7;
			this.txtStatus5.Text = "TextBox6";
			// 
			// txtStatus4
			// 
			this.txtStatus4.Location = new System.Drawing.Point(8, 168);
			this.txtStatus4.Name = "txtStatus4";
			this.txtStatus4.Size = new System.Drawing.Size(72, 19);
			this.txtStatus4.TabIndex = 6;
			this.txtStatus4.Text = "TextBox5";
			// 
			// txtStatus3
			// 
			this.txtStatus3.Location = new System.Drawing.Point(8, 144);
			this.txtStatus3.Name = "txtStatus3";
			this.txtStatus3.Size = new System.Drawing.Size(72, 19);
			this.txtStatus3.TabIndex = 5;
			this.txtStatus3.Text = "TextBox4";
			// 
			// txtStatus2
			// 
			this.txtStatus2.Location = new System.Drawing.Point(8, 120);
			this.txtStatus2.Name = "txtStatus2";
			this.txtStatus2.Size = new System.Drawing.Size(72, 19);
			this.txtStatus2.TabIndex = 4;
			this.txtStatus2.Text = "TextBox3";
			// 
			// txtStatus1
			// 
			this.txtStatus1.Location = new System.Drawing.Point(8, 96);
			this.txtStatus1.Name = "txtStatus1";
			this.txtStatus1.Size = new System.Drawing.Size(72, 19);
			this.txtStatus1.TabIndex = 3;
			this.txtStatus1.Text = "TextBox2";
			// 
			// txtStatus0
			// 
			this.txtStatus0.Location = new System.Drawing.Point(8, 72);
			this.txtStatus0.Name = "txtStatus0";
			this.txtStatus0.Size = new System.Drawing.Size(72, 19);
			this.txtStatus0.TabIndex = 2;
			this.txtStatus0.Text = "TextBox1";
			// 
			// CntTimer
			// 
			this.CntTimer.Tick += new System.EventHandler(this.CntTimer_Tick);
			// 
			// Counter
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
			this.ClientSize = new System.Drawing.Size(536, 435);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.btnCntExit,
																		  this.btnCntStop,
																		  this.btnCntPreset,
																		  this.btnCntCompare,
																		  this.btnCntInit,
																		  this.Label13,
																		  this.Label11,
																		  this.Label7,
																		  this.GroupBox3,
																		  this.GroupBox1,
																		  this.txtErr,
																		  this.txtStart,
																		  this.Label3,
																		  this.Label1,
																		  this.Label2,
																		  this.cboDeviceName,
																		  this.btnCntStart,
																		  this.btnExit,
																		  this.txtReturnCode,
																		  this.Label10,
																		  this.btnCntMode,
																		  this.Label9,
																		  this.Label8,
																		  this.Label6,
																		  this.Label5,
																		  this.Label4,
																		  this.GroupBox2});
			this.Font = new System.Drawing.Font("lr oSVbN", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128)));
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "Counter";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "JE^Tv";
			this.Load += new System.EventHandler(this.Counter_Load);
			this.GroupBox3.ResumeLayout(false);
			this.GroupBox1.ResumeLayout(false);
			this.GroupBox2.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// AvP[ṼC Gg |CgłB
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Counter());
		}

		//---------------------------------------------------------
		//	_CAO
		//---------------------------------------------------------
		private void Counter_Load(object sender, System.EventArgs e)
		{
			short	i;
			uint	PresetData;
			//-----------------------------------
			// foCX̌o
			//-----------------------------------
			short	Index;
			short	GroupID, UnitID, DeviceID;
			StringBuilder	DeviceName = new StringBuilder(256);
			StringBuilder	Device = new StringBuilder(256);
			GroupID = 0;
			UnitID = 0;
			DeviceID = 0;
			for (Index=0; ; Index++)
			{
				Ret = CNT.Ccapcnt.CntQueryDeviceName(Index, ref GroupID, ref UnitID, ref DeviceID, DeviceName, Device);
				if (Ret != CNT.Ccapcnt.CNT_ERR_SUCCESS)
				{
					break;
				}
				cboDeviceName.Items.Add(DeviceName);
			}
			cboDeviceName.SelectedIndex = 0;
			//-----------------------------------
			// ʃACȅ
			//-----------------------------------
			txtReturnCode.Text = "";
			rdoCh0.Checked = true;
			rdoPreset0.Checked = true;
			// JEgl
			m_Ch[0] = txtCh0;
			m_Ch[1] = txtCh1;
			m_Ch[2] = txtCh2;
			m_Ch[3] = txtCh3;
			m_Ch[4] = txtCh4;
			m_Ch[5] = txtCh5;
			m_Ch[6] = txtCh6;
			m_Ch[7] = txtCh7;
			for (i=0; i<8; i++)
			{
				m_Ch[i].Text = "";
			}
			// Xe[^X
			m_Status[0] = txtStatus0;
			m_Status[1] = txtStatus1;
			m_Status[2] = txtStatus2;
			m_Status[3] = txtStatus3;
			m_Status[4] = txtStatus4;
			m_Status[5] = txtStatus5;
			m_Status[6] = txtStatus6;
			m_Status[7] = txtStatus7;
			for (i=0; i<8; i++)
			{
				m_Status[i].Text = "";
			}
			// vZbgl
			m_Preset[0] = txtPreset0;
			m_Preset[1] = txtPreset1;
			m_Preset[2] = txtPreset2;
			m_Preset[3] = txtPreset3;
			m_Preset[4] = txtPreset4;
			m_Preset[5] = txtPreset5;
			m_Preset[6] = txtPreset6;
			m_Preset[7] = txtPreset7;
			for (i=0; i<8; i++)
			{
				PresetData = (uint)i * 100;
				szText = string.Format("{0:d}", PresetData);
				m_Preset[i].Text = szText;
			}
		}

		//---------------------------------------------------------
		//	
		//---------------------------------------------------------
		private void btnCntInit_Click(object sender, System.EventArgs e)
		{
			string	szDeviceName = new string(' ', 100);
			short	i;
			//-----------------------------
			// ʂfoCX擾
			//-----------------------------
			szDeviceName = cboDeviceName.Text;
			//-----------------------------
			// sȂAID擾
			//-----------------------------
			Ret = CNT.Ccapcnt.CntInit(szDeviceName, ref Common.Id);
			//-----------------------------
			// G[
			//-----------------------------
			CNT.Ccapcnt.CntGetErrorString(Ret, szError);
			szReturnCode = "CntInit : " + szError;
			txtReturnCode.Text = szReturnCode;
			if (Ret != CNT.Ccapcnt.CNT_ERR_SUCCESS)
			{
				return;
			}
			//-----------------------------
			// `l擾
			//-----------------------------
			CNT.Ccapcnt.CntGetMaxChannels(Common.Id, ref Common.ChannelNum);
			//-----------------------------
			// JE^AXe[^XAvZbg
			// \̖
			//-----------------------------
			for (i=0; i<8; i++)
			{
				if (i < Common.ChannelNum)
				{
					m_Ch[i].Enabled = true;
					m_Status[i].Enabled = true;
					m_Preset[i].Enabled = true;
				} 
				else 
				{
					m_Ch[i].Enabled = false;
					m_Status[i].Enabled = false;
					m_Preset[i].Enabled = false;
				}
			}
			//-----------------------------
			// ^C}N
			//-----------------------------
			CntTimer.Enabled = true;
		}

		//---------------------------------------------------------
		//	[h_CAO\
		//---------------------------------------------------------
		private void btnCntMode_Click(object sender, System.EventArgs e)
		{
			//-----------------------------
			// _CAO[_ŕ\
			//-----------------------------
			Mode	ModeDlg = new Mode();
			ModeDlg.ShowDialog();
			ModeDlg.Dispose();
		}

		//---------------------------------------------------------
		//	r_CAO\
		//---------------------------------------------------------
		private void btnCntCompare_Click(object sender, System.EventArgs e)
		{
			//-----------------------------
			// _CAO[_ŕ\
			//-----------------------------	
			Comp	CompDlg = new Comp();
			CompDlg.ShowDialog();
			CompDlg.Dispose();
		}

		//---------------------------------------------------------
		//	JE^X^[g
		//---------------------------------------------------------
		private void btnCntStart_Click(object sender, System.EventArgs e)
		{
			short[]	ChNo = new short[8];
			short	i;
			//-----------------------------
			// p[^̐ݒ
			//-----------------------------
			for (i=0; i<Common.ChannelNum; i++)
			{
				ChNo[i] = i;
			}
			//-----------------------------
			// JE^X^[g
			//-----------------------------
			GCHandle Pter = GCHandle.Alloc(ChNo, GCHandleType.Pinned);
			Ret = CNT.Ccapcnt.CntStartCount(Common.Id, ChNo, Common.ChannelNum);
			Pter.Free();
			//-----------------------------
			// G[
			//-----------------------------
			CNT.Ccapcnt.CntGetErrorString(Ret, szError);
			szReturnCode = "CntStartCount : " + szError;
			txtReturnCode.Text = szReturnCode;
			if (Ret != CNT.Ccapcnt.CNT_ERR_SUCCESS)
			{
				return;
			}
		}

		//---------------------------------------------------------
		//	vZbg
		//---------------------------------------------------------
		private void btnCntPreset_Click(object sender, System.EventArgs e)
		{
			short[]	ChNo = new short[8];
			Int32[]	PresetData = new Int32[8];
			short	i;
			//-----------------------------
			// ʂ̃f[^擾ƃp[^̐ݒ
			//-----------------------------
			for (i=0; i<Common.ChannelNum; i++)
			{
				ChNo[i] = i;
				szText = m_Preset[i].Text;
                try
                {
                    if (rdoPreset0.Checked == true)
                    {
                        PresetData[i] = Int32.Parse(szText);
                    }
                    else
                    {
                        PresetData[i] = Int32.Parse(szText, NumberStyles.HexNumber);
                    }
                }
                catch (System.FormatException)
                {
                    PresetData[i] = 0;
                }	
			}
			//-----------------------------
			// vZbg
			//-----------------------------
			GCHandle PterChNo = GCHandle.Alloc(ChNo, GCHandleType.Pinned);
			GCHandle PterPreData = GCHandle.Alloc(PresetData, GCHandleType.Pinned);
			Ret = CNT.Ccapcnt.CntPreset(Common.Id, ChNo, Common.ChannelNum, PresetData);
			PterChNo.Free();
			PterPreData.Free();
			//-----------------------------
			// G[
			//-----------------------------
			CNT.Ccapcnt.CntGetErrorString(Ret, szError);
			szReturnCode = "CntPreset : " + szError;
			txtReturnCode.Text = szReturnCode;
		}

		//---------------------------------------------------------
		//	JE^Xgbv
		//---------------------------------------------------------
		private void btnCntStop_Click(object sender, System.EventArgs e)
		{
			short[]	ChNo = new short[8];
			short	i;
			//-----------------------------
			// p[^̐ݒ
			//-----------------------------
			for (i=0; i<Common.ChannelNum; i++)
			{
				ChNo[i] = i;
			}
			//-----------------------------
			// JE^Xgbv
			//-----------------------------
			GCHandle Pter = GCHandle.Alloc(ChNo, GCHandleType.Pinned);
			Ret = CNT.Ccapcnt.CntStopCount(Common.Id, ChNo, Common.ChannelNum);
			Pter.Free();
			//-----------------------------
			// G[
			//-----------------------------
			CNT.Ccapcnt.CntGetErrorString(Ret, szError);
			szReturnCode = "CntStopCount : " + szError;
			txtReturnCode.Text = szReturnCode;
		}

		//---------------------------------------------------------
		//	I
		//---------------------------------------------------------
		private void btnCntExit_Click(object sender, System.EventArgs e)
		{
			//-----------------------------
			// ^C}~
			//-----------------------------
			CntTimer.Enabled = false;
			//-----------------------------
			// Is
			//-----------------------------
			Ret = CNT.Ccapcnt.CntExit(Common.Id);
			//-----------------------------
			// G[
			//-----------------------------
			CNT.Ccapcnt.CntGetErrorString(Ret, szError);
			szReturnCode = "CntExit : " + szError;
			txtReturnCode.Text = szReturnCode;	
		}

		//---------------------------------------------------------
		//	_CAOI
		//---------------------------------------------------------
		private void btnExit_Click(object sender, System.EventArgs e)
		{
			//-----------------------------
			// ^C}~
			//-----------------------------
			CntTimer.Enabled = false;
			//-----------------------------
			// Is
			//-----------------------------
			Ret = CNT.Ccapcnt.CntExit(Common.Id);
			//-----------------------------
			// _CAOI
			//-----------------------------
			this.Close();
		}

		private void Counter_Closed(object sender, System.EventArgs e)
		{
			//-----------------------------------
			// Is
			//-----------------------------------
			Ret = CNT.Ccapcnt.CntExit(Common.Id);	
		}

		//---------------------------------------------------------
		//	^C}
		//---------------------------------------------------------
		private void CntTimer_Tick(object sender, System.EventArgs e)
		{
			short[]	ChNo = new short[8];
			int[]	CountData = new int[8];
			short[]	Sts = new short[8];
			short	i;
			bool	bIs10;
			byte	Start, Err;
			Start = 0;
			Err = 0;
			//-----------------------------
			// NWX^l擾
			//-----------------------------
			Ret = CNT.Ccapcnt.CntGetRemoteStatus(Common.Id, ref Start, ref Err);
			//-----------------------------
			// G[
			//-----------------------------
			if (Ret != CNT.Ccapcnt.CNT_ERR_SUCCESS)
			{
				CNT.Ccapcnt.CntGetErrorString(Ret, szError);
				szReturnCode = "CntGetRemoteStatus : " + szError;
				txtReturnCode.Text = szReturnCode;
				return;
			}
			//-----------------------------
			// p[^ݒ
			//-----------------------------
			for (i=0; i<Common.ChannelNum; i++)
			{
				ChNo[i] = i;
				CountData[i] = 0;
			}
			//-----------------------------
			// JEgl擾
			//-----------------------------
			GCHandle PterChNo = GCHandle.Alloc(ChNo, GCHandleType.Pinned);
			GCHandle PterCntData = GCHandle.Alloc(CountData, GCHandleType.Pinned);
			Ret = CNT.Ccapcnt.CntReadCount(Common.Id, ChNo, Common.ChannelNum, CountData);
			PterChNo.Free();
			PterCntData.Free();
			//-----------------------------
			// G[
			//-----------------------------
			if (Ret != CNT.Ccapcnt.CNT_ERR_SUCCESS)
			{
				CNT.Ccapcnt.CntGetErrorString(Ret, szError);
				szReturnCode = "CntReadCount : " + szError;
				txtReturnCode.Text = szReturnCode;
				return;
			}
			//-----------------------------
			// Xe[^X擾
			//-----------------------------
			for (i=0; i<Common.ChannelNum; i++)
			{
				Ret = CNT.Ccapcnt.CntReadStatus(Common.Id, i, ref Sts[i]);
				//-----------------------------
				// G[
				//-----------------------------
				if (Ret != CNT.Ccapcnt.CNT_ERR_SUCCESS)
				{
					CNT.Ccapcnt.CntGetErrorString(Ret, szError);
					szReturnCode = "CntReadStatus : " + szError;
					txtReturnCode.Text = szReturnCode;
					return;
				}
			}
			//-----------------------------
			// JEgf[^AXe[^Xf[^\
			//-----------------------------
			szText = string.Format("{0:X2}", Start);
			txtStart.Text = szText;
			szText = string.Format("{0:X2}", Err);
			txtErr.Text = szText;
			bIs10 = rdoCh0.Checked;
			for (i=0; i<Common.ChannelNum; i++)
			{
				if (bIs10 == true)
				{
					szText = string.Format("{0:d}", CountData[i]);
				} 
				else 
				{
					szText = string.Format("{0:X8}", CountData[i]);
				}
				m_Ch[i].Text = szText;
				szText = string.Format("{0:X2}", Sts[i]);
				m_Status[i].Text = szText;
			}
		}

		//---------------------------------------------------------
		//	10i^16iϊ
		//---------------------------------------------------------
		//	`lf[^F10i
		private void rdoCh0_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			CntTimer_Tick(CntTimer, new System.EventArgs());		
		}

		//	`lf[^F16i
		private void rdoCh1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			CntTimer_Tick(CntTimer, new System.EventArgs());		
		}

		//	vZbgf[^F10i
		private void rdoPreset0_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			//-----------------------------
			// ʂ̃f[^擾ƕ\̕ύX
			//-----------------------------
			short	i;
			Int32	PresetData;
			for (i=0; i<8; i++)
			{
				szText = m_Preset[i].Text;
                try
                {
                    PresetData = Int32.Parse(szText, NumberStyles.HexNumber);
                }
                catch (System.FormatException)
                {
                    PresetData = 0;
                }	
				szText = string.Format("{0:d}", PresetData);
				m_Preset[i].Text = szText;
			}
		}

		//	vZbgf[^F16i
		private void rdoPreset1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			//-----------------------------
			// ʂ̃f[^擾ƕ\̕ύX
			//-----------------------------
			short	i;
			Int32	PresetData;
			for (i=0; i<8; i++)
			{
				szText = m_Preset[i].Text;
                try
                {
                    PresetData = Int32.Parse(szText);
                }
                catch (System.FormatException)
                {
                    PresetData = 0;
                }	
				szText = string.Format("{0:X8}", PresetData);
				m_Preset[i].Text = szText;
			}
		}
	}
}