﻿// 通常版カウンタ用サンプル
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using CcntCs;

namespace Counter
{
	/// <summary>
	/// Counter の概要の説明です。
	/// </summary>
	public class Counter : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label_DeviceName;
		private System.Windows.Forms.Label label_Channel0;
		private System.Windows.Forms.Label label_Channel1;
		private System.Windows.Forms.Label label_Channel2;
		private System.Windows.Forms.Label label_Channel3;
		private System.Windows.Forms.Label label_Channel4;
		private System.Windows.Forms.Label label_Channel5;
		private System.Windows.Forms.Label label_Channel6;
		private System.Windows.Forms.Label label_Channel7;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.TextBox textBox_DeviceName;
		private System.Windows.Forms.GroupBox groupBox_CountValue;
		private System.Windows.Forms.RadioButton radioButtonCountValue_Dec;
		private System.Windows.Forms.RadioButton radioButton_CountValue_Hex;
		private System.Windows.Forms.TextBox textBox_CountValue_Channel0;
		private System.Windows.Forms.TextBox textBox_CountValue_Channel1;
		private System.Windows.Forms.TextBox textBox_CountValue_Channel2;
		private System.Windows.Forms.TextBox textBox_CountValue_Channel3;
		private System.Windows.Forms.TextBox textBox_CountValue_Channel4;
		private System.Windows.Forms.TextBox textBox_CountValue_Channel5;
		private System.Windows.Forms.TextBox textBox_CountValue_Channel6;
		private System.Windows.Forms.TextBox textBox_CountValue_Channel7;
		private System.Windows.Forms.GroupBox groupBox_Status;
		private System.Windows.Forms.TextBox textBox_Status_Channel7;
		private System.Windows.Forms.TextBox textBox_Status_Channel6;
		private System.Windows.Forms.TextBox textBox_Status_Channel5;
		private System.Windows.Forms.TextBox textBox_Status_Channel4;
		private System.Windows.Forms.TextBox textBox_Status_Channel3;
		private System.Windows.Forms.TextBox textBox_Status_Channel2;
		private System.Windows.Forms.TextBox textBox_Status_Channel1;
		private System.Windows.Forms.TextBox textBox_Status_Channel0;
		private System.Windows.Forms.GroupBox groupBox_PresetValue;
		private System.Windows.Forms.RadioButton radioButton_PresetValue_Hex;
		private System.Windows.Forms.RadioButton radioButton_PresetValue_Dec;
		private System.Windows.Forms.TextBox textBox_PresetValue_Channel7;
		private System.Windows.Forms.TextBox textBox_PresetValue_Channel6;
		private System.Windows.Forms.TextBox textBox_PresetValue_Channel5;
		private System.Windows.Forms.TextBox textBox_PresetValue_Channel4;
		private System.Windows.Forms.TextBox textBox_PresetValue_Channel3;
		private System.Windows.Forms.TextBox textBox_PresetValue_Channel2;
		private System.Windows.Forms.TextBox textBox_PresetValue_Channel1;
		private System.Windows.Forms.TextBox textBox_PresetValue_Channel0;
		private System.Windows.Forms.Button button_CntInit;
		private System.Windows.Forms.Button button_ModeSet;
		private System.Windows.Forms.Button button_ComparisonSet;
		private System.Windows.Forms.Button button_CntStartCount;
		private System.Windows.Forms.Button button_CntPreset;
		private System.Windows.Forms.Button button_CntStopCount;
		private System.Windows.Forms.Button button_CntExit;
		private System.Windows.Forms.Button button_Exit;
		private System.Windows.Forms.TextBox textBox_Comparison_result;
		private System.Windows.Forms.TextBox textBox_ReturnCode;
		/// <summary>
		/// 必要なデザイナ変数です。
		/// </summary>
		private System.ComponentModel.IContainer components;

		private System.Windows.Forms.TextBox[] m_CH = new System.Windows.Forms.TextBox[8];
		private System.Windows.Forms.TextBox[] m_Status = new System.Windows.Forms.TextBox[8];
		private System.Windows.Forms.TextBox[] m_Preset = new System.Windows.Forms.TextBox[8];

		private System.Windows.Forms.Timer timer1;

		/// <summary>
		/// クラスCcntインスタンス作成
		/// </summary>
		Ccnt cnt=new Ccnt();

		public static IntPtr m_Handle;
		public static short  m_Id;
		public static short  m_ChannelNum;
		public uint[]        PresetData = new uint[8] { 0, 100, 200, 300, 400, 500, 600, 700 };
		public int           MatchCount;

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

			//
			// TODO: InitializeComponent 呼び出しの後に、コンストラクタ コードを追加してください。
			//
			m_CH[0] = textBox_CountValue_Channel0;
			m_CH[1] = textBox_CountValue_Channel1;
			m_CH[2] = textBox_CountValue_Channel2;
			m_CH[3] = textBox_CountValue_Channel3;
			m_CH[4] = textBox_CountValue_Channel4;
			m_CH[5] = textBox_CountValue_Channel5;
			m_CH[6] = textBox_CountValue_Channel6;
			m_CH[7] = textBox_CountValue_Channel7;

			m_Status[0] = textBox_Status_Channel0;
			m_Status[1] = textBox_Status_Channel1;
			m_Status[2] = textBox_Status_Channel2;
			m_Status[3] = textBox_Status_Channel3;
			m_Status[4] = textBox_Status_Channel4;
			m_Status[5] = textBox_Status_Channel5;
			m_Status[6] = textBox_Status_Channel6;
			m_Status[7] = textBox_Status_Channel7;

			m_Preset[0] = textBox_PresetValue_Channel0;
			m_Preset[1] = textBox_PresetValue_Channel1;
			m_Preset[2] = textBox_PresetValue_Channel2;
			m_Preset[3] = textBox_PresetValue_Channel3;
			m_Preset[4] = textBox_PresetValue_Channel4;
			m_Preset[5] = textBox_PresetValue_Channel5;
			m_Preset[6] = textBox_PresetValue_Channel6;
			m_Preset[7] = textBox_PresetValue_Channel7;

			m_Handle = this.Handle;
		}

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

		#region Windows Form Designer generated code
		/// <summary>
		/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
		/// コード エディタで変更しないでください。
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			this.label_DeviceName = new System.Windows.Forms.Label();
			this.label_Channel0 = new System.Windows.Forms.Label();
			this.label_Channel1 = new System.Windows.Forms.Label();
			this.label_Channel2 = new System.Windows.Forms.Label();
			this.label_Channel3 = new System.Windows.Forms.Label();
			this.label_Channel4 = new System.Windows.Forms.Label();
			this.label_Channel5 = new System.Windows.Forms.Label();
			this.label_Channel6 = new System.Windows.Forms.Label();
			this.label_Channel7 = new System.Windows.Forms.Label();
			this.label8 = new System.Windows.Forms.Label();
			this.label9 = new System.Windows.Forms.Label();
			this.textBox_DeviceName = new System.Windows.Forms.TextBox();
			this.groupBox_CountValue = new System.Windows.Forms.GroupBox();
			this.textBox_CountValue_Channel7 = new System.Windows.Forms.TextBox();
			this.textBox_CountValue_Channel6 = new System.Windows.Forms.TextBox();
			this.textBox_CountValue_Channel5 = new System.Windows.Forms.TextBox();
			this.textBox_CountValue_Channel4 = new System.Windows.Forms.TextBox();
			this.textBox_CountValue_Channel3 = new System.Windows.Forms.TextBox();
			this.textBox_CountValue_Channel2 = new System.Windows.Forms.TextBox();
			this.textBox_CountValue_Channel1 = new System.Windows.Forms.TextBox();
			this.textBox_CountValue_Channel0 = new System.Windows.Forms.TextBox();
			this.radioButton_CountValue_Hex = new System.Windows.Forms.RadioButton();
			this.radioButtonCountValue_Dec = new System.Windows.Forms.RadioButton();
			this.groupBox_Status = new System.Windows.Forms.GroupBox();
			this.textBox_Status_Channel7 = new System.Windows.Forms.TextBox();
			this.textBox_Status_Channel6 = new System.Windows.Forms.TextBox();
			this.textBox_Status_Channel5 = new System.Windows.Forms.TextBox();
			this.textBox_Status_Channel4 = new System.Windows.Forms.TextBox();
			this.textBox_Status_Channel3 = new System.Windows.Forms.TextBox();
			this.textBox_Status_Channel2 = new System.Windows.Forms.TextBox();
			this.textBox_Status_Channel1 = new System.Windows.Forms.TextBox();
			this.textBox_Status_Channel0 = new System.Windows.Forms.TextBox();
			this.groupBox_PresetValue = new System.Windows.Forms.GroupBox();
			this.textBox_PresetValue_Channel7 = new System.Windows.Forms.TextBox();
			this.textBox_PresetValue_Channel6 = new System.Windows.Forms.TextBox();
			this.textBox_PresetValue_Channel5 = new System.Windows.Forms.TextBox();
			this.textBox_PresetValue_Channel4 = new System.Windows.Forms.TextBox();
			this.textBox_PresetValue_Channel3 = new System.Windows.Forms.TextBox();
			this.textBox_PresetValue_Channel2 = new System.Windows.Forms.TextBox();
			this.textBox_PresetValue_Channel1 = new System.Windows.Forms.TextBox();
			this.textBox_PresetValue_Channel0 = new System.Windows.Forms.TextBox();
			this.radioButton_PresetValue_Hex = new System.Windows.Forms.RadioButton();
			this.radioButton_PresetValue_Dec = new System.Windows.Forms.RadioButton();
			this.button_CntInit = new System.Windows.Forms.Button();
			this.button_ModeSet = new System.Windows.Forms.Button();
			this.button_ComparisonSet = new System.Windows.Forms.Button();
			this.button_CntStartCount = new System.Windows.Forms.Button();
			this.button_CntPreset = new System.Windows.Forms.Button();
			this.button_CntStopCount = new System.Windows.Forms.Button();
			this.button_CntExit = new System.Windows.Forms.Button();
			this.button_Exit = new System.Windows.Forms.Button();
			this.textBox_Comparison_result = new System.Windows.Forms.TextBox();
			this.textBox_ReturnCode = new System.Windows.Forms.TextBox();
			this.timer1 = new System.Windows.Forms.Timer(this.components);
			this.groupBox_CountValue.SuspendLayout();
			this.groupBox_Status.SuspendLayout();
			this.groupBox_PresetValue.SuspendLayout();
			this.SuspendLayout();
			// 
			// label_DeviceName
			// 
			this.label_DeviceName.Location = new System.Drawing.Point(16, 16);
			this.label_DeviceName.Name = "label_DeviceName";
			this.label_DeviceName.Size = new System.Drawing.Size(80, 16);
			this.label_DeviceName.TabIndex = 0;
			this.label_DeviceName.Text = "デバイス名：";
			// 
			// label_Channel0
			// 
			this.label_Channel0.Location = new System.Drawing.Point(16, 128);
			this.label_Channel0.Name = "label_Channel0";
			this.label_Channel0.Size = new System.Drawing.Size(80, 16);
			this.label_Channel0.TabIndex = 1;
			this.label_Channel0.Text = "ﾁｬﾈﾙ0：";
			// 
			// label_Channel1
			// 
			this.label_Channel1.Location = new System.Drawing.Point(16, 160);
			this.label_Channel1.Name = "label_Channel1";
			this.label_Channel1.Size = new System.Drawing.Size(80, 16);
			this.label_Channel1.TabIndex = 2;
			this.label_Channel1.Text = "ﾁｬﾈﾙ1：";
			// 
			// label_Channel2
			// 
			this.label_Channel2.Location = new System.Drawing.Point(16, 192);
			this.label_Channel2.Name = "label_Channel2";
			this.label_Channel2.Size = new System.Drawing.Size(80, 16);
			this.label_Channel2.TabIndex = 3;
			this.label_Channel2.Text = "ﾁｬﾈﾙ2：";
			// 
			// label_Channel3
			// 
			this.label_Channel3.Location = new System.Drawing.Point(16, 224);
			this.label_Channel3.Name = "label_Channel3";
			this.label_Channel3.Size = new System.Drawing.Size(80, 16);
			this.label_Channel3.TabIndex = 4;
			this.label_Channel3.Text = "ﾁｬﾈﾙ3：";
			// 
			// label_Channel4
			// 
			this.label_Channel4.Location = new System.Drawing.Point(16, 256);
			this.label_Channel4.Name = "label_Channel4";
			this.label_Channel4.Size = new System.Drawing.Size(80, 16);
			this.label_Channel4.TabIndex = 5;
			this.label_Channel4.Text = "ﾁｬﾈﾙ4：";
			// 
			// label_Channel5
			// 
			this.label_Channel5.Location = new System.Drawing.Point(16, 288);
			this.label_Channel5.Name = "label_Channel5";
			this.label_Channel5.Size = new System.Drawing.Size(80, 16);
			this.label_Channel5.TabIndex = 6;
			this.label_Channel5.Text = "ﾁｬﾈﾙ5：";
			// 
			// label_Channel6
			// 
			this.label_Channel6.Location = new System.Drawing.Point(16, 320);
			this.label_Channel6.Name = "label_Channel6";
			this.label_Channel6.Size = new System.Drawing.Size(80, 16);
			this.label_Channel6.TabIndex = 7;
			this.label_Channel6.Text = "ﾁｬﾈﾙ6：";
			// 
			// label_Channel7
			// 
			this.label_Channel7.Location = new System.Drawing.Point(16, 352);
			this.label_Channel7.Name = "label_Channel7";
			this.label_Channel7.Size = new System.Drawing.Size(80, 16);
			this.label_Channel7.TabIndex = 8;
			this.label_Channel7.Text = "ﾁｬﾈﾙ7：";
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(16, 400);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(104, 16);
			this.label8.TabIndex = 9;
			this.label8.Text = "比較結果：";
			// 
			// label9
			// 
			this.label9.Location = new System.Drawing.Point(16, 432);
			this.label9.Name = "label9";
			this.label9.Size = new System.Drawing.Size(80, 16);
			this.label9.TabIndex = 10;
			this.label9.Text = "戻り値：";
			// 
			// textBox_DeviceName
			// 
			this.textBox_DeviceName.Location = new System.Drawing.Point(120, 16);
			this.textBox_DeviceName.Name = "textBox_DeviceName";
			this.textBox_DeviceName.TabIndex = 14;
			this.textBox_DeviceName.Text = "CNT000";
			// 
			// groupBox_CountValue
			// 
			this.groupBox_CountValue.Controls.AddRange(new System.Windows.Forms.Control[] {
																							  this.textBox_CountValue_Channel7,
																							  this.textBox_CountValue_Channel6,
																							  this.textBox_CountValue_Channel5,
																							  this.textBox_CountValue_Channel4,
																							  this.textBox_CountValue_Channel3,
																							  this.textBox_CountValue_Channel2,
																							  this.textBox_CountValue_Channel1,
																							  this.textBox_CountValue_Channel0,
																							  this.radioButton_CountValue_Hex,
																							  this.radioButtonCountValue_Dec});
			this.groupBox_CountValue.Location = new System.Drawing.Point(104, 56);
			this.groupBox_CountValue.Name = "groupBox_CountValue";
			this.groupBox_CountValue.Size = new System.Drawing.Size(128, 328);
			this.groupBox_CountValue.TabIndex = 11;
			this.groupBox_CountValue.TabStop = false;
			this.groupBox_CountValue.Text = "カウント値";
			// 
			// textBox_CountValue_Channel7
			// 
			this.textBox_CountValue_Channel7.Location = new System.Drawing.Point(14, 296);
			this.textBox_CountValue_Channel7.Name = "textBox_CountValue_Channel7";
			this.textBox_CountValue_Channel7.TabIndex = 9;
			this.textBox_CountValue_Channel7.Text = "";
			this.textBox_CountValue_Channel7.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_CountValue_Channel6
			// 
			this.textBox_CountValue_Channel6.Location = new System.Drawing.Point(14, 264);
			this.textBox_CountValue_Channel6.Name = "textBox_CountValue_Channel6";
			this.textBox_CountValue_Channel6.TabIndex = 8;
			this.textBox_CountValue_Channel6.Text = "";
			this.textBox_CountValue_Channel6.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_CountValue_Channel5
			// 
			this.textBox_CountValue_Channel5.Location = new System.Drawing.Point(14, 232);
			this.textBox_CountValue_Channel5.Name = "textBox_CountValue_Channel5";
			this.textBox_CountValue_Channel5.TabIndex = 7;
			this.textBox_CountValue_Channel5.Text = "";
			this.textBox_CountValue_Channel5.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_CountValue_Channel4
			// 
			this.textBox_CountValue_Channel4.Location = new System.Drawing.Point(14, 200);
			this.textBox_CountValue_Channel4.Name = "textBox_CountValue_Channel4";
			this.textBox_CountValue_Channel4.TabIndex = 6;
			this.textBox_CountValue_Channel4.Text = "";
			this.textBox_CountValue_Channel4.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_CountValue_Channel3
			// 
			this.textBox_CountValue_Channel3.Location = new System.Drawing.Point(14, 168);
			this.textBox_CountValue_Channel3.Name = "textBox_CountValue_Channel3";
			this.textBox_CountValue_Channel3.TabIndex = 5;
			this.textBox_CountValue_Channel3.Text = "";
			this.textBox_CountValue_Channel3.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_CountValue_Channel2
			// 
			this.textBox_CountValue_Channel2.Location = new System.Drawing.Point(14, 136);
			this.textBox_CountValue_Channel2.Name = "textBox_CountValue_Channel2";
			this.textBox_CountValue_Channel2.TabIndex = 4;
			this.textBox_CountValue_Channel2.Text = "";
			this.textBox_CountValue_Channel2.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_CountValue_Channel1
			// 
			this.textBox_CountValue_Channel1.Location = new System.Drawing.Point(16, 104);
			this.textBox_CountValue_Channel1.Name = "textBox_CountValue_Channel1";
			this.textBox_CountValue_Channel1.TabIndex = 3;
			this.textBox_CountValue_Channel1.Text = "";
			this.textBox_CountValue_Channel1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_CountValue_Channel0
			// 
			this.textBox_CountValue_Channel0.Location = new System.Drawing.Point(16, 72);
			this.textBox_CountValue_Channel0.Name = "textBox_CountValue_Channel0";
			this.textBox_CountValue_Channel0.TabIndex = 2;
			this.textBox_CountValue_Channel0.Text = "";
			this.textBox_CountValue_Channel0.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// radioButton_CountValue_Hex
			// 
			this.radioButton_CountValue_Hex.Location = new System.Drawing.Point(16, 40);
			this.radioButton_CountValue_Hex.Name = "radioButton_CountValue_Hex";
			this.radioButton_CountValue_Hex.TabIndex = 1;
			this.radioButton_CountValue_Hex.Text = "16進数";
			// 
			// radioButtonCountValue_Dec
			// 
			this.radioButtonCountValue_Dec.Checked = true;
			this.radioButtonCountValue_Dec.Location = new System.Drawing.Point(16, 16);
			this.radioButtonCountValue_Dec.Name = "radioButtonCountValue_Dec";
			this.radioButtonCountValue_Dec.TabIndex = 0;
			this.radioButtonCountValue_Dec.TabStop = true;
			this.radioButtonCountValue_Dec.Text = "10進数";
			// 
			// groupBox_Status
			// 
			this.groupBox_Status.Controls.AddRange(new System.Windows.Forms.Control[] {
																						  this.textBox_Status_Channel7,
																						  this.textBox_Status_Channel6,
																						  this.textBox_Status_Channel5,
																						  this.textBox_Status_Channel4,
																						  this.textBox_Status_Channel3,
																						  this.textBox_Status_Channel2,
																						  this.textBox_Status_Channel1,
																						  this.textBox_Status_Channel0});
			this.groupBox_Status.Location = new System.Drawing.Point(240, 56);
			this.groupBox_Status.Name = "groupBox_Status";
			this.groupBox_Status.Size = new System.Drawing.Size(120, 328);
			this.groupBox_Status.TabIndex = 15;
			this.groupBox_Status.TabStop = false;
			this.groupBox_Status.Text = "ステータス";
			// 
			// textBox_Status_Channel7
			// 
			this.textBox_Status_Channel7.Location = new System.Drawing.Point(14, 296);
			this.textBox_Status_Channel7.Name = "textBox_Status_Channel7";
			this.textBox_Status_Channel7.TabIndex = 9;
			this.textBox_Status_Channel7.Text = "";
			this.textBox_Status_Channel7.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_Status_Channel6
			// 
			this.textBox_Status_Channel6.Location = new System.Drawing.Point(14, 264);
			this.textBox_Status_Channel6.Name = "textBox_Status_Channel6";
			this.textBox_Status_Channel6.TabIndex = 8;
			this.textBox_Status_Channel6.Text = "";
			this.textBox_Status_Channel6.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_Status_Channel5
			// 
			this.textBox_Status_Channel5.Location = new System.Drawing.Point(14, 232);
			this.textBox_Status_Channel5.Name = "textBox_Status_Channel5";
			this.textBox_Status_Channel5.TabIndex = 7;
			this.textBox_Status_Channel5.Text = "";
			this.textBox_Status_Channel5.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_Status_Channel4
			// 
			this.textBox_Status_Channel4.Location = new System.Drawing.Point(14, 200);
			this.textBox_Status_Channel4.Name = "textBox_Status_Channel4";
			this.textBox_Status_Channel4.TabIndex = 6;
			this.textBox_Status_Channel4.Text = "";
			this.textBox_Status_Channel4.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_Status_Channel3
			// 
			this.textBox_Status_Channel3.Location = new System.Drawing.Point(14, 168);
			this.textBox_Status_Channel3.Name = "textBox_Status_Channel3";
			this.textBox_Status_Channel3.TabIndex = 5;
			this.textBox_Status_Channel3.Text = "";
			this.textBox_Status_Channel3.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_Status_Channel2
			// 
			this.textBox_Status_Channel2.Location = new System.Drawing.Point(14, 136);
			this.textBox_Status_Channel2.Name = "textBox_Status_Channel2";
			this.textBox_Status_Channel2.TabIndex = 4;
			this.textBox_Status_Channel2.Text = "";
			this.textBox_Status_Channel2.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_Status_Channel1
			// 
			this.textBox_Status_Channel1.Location = new System.Drawing.Point(16, 104);
			this.textBox_Status_Channel1.Name = "textBox_Status_Channel1";
			this.textBox_Status_Channel1.TabIndex = 3;
			this.textBox_Status_Channel1.Text = "";
			this.textBox_Status_Channel1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_Status_Channel0
			// 
			this.textBox_Status_Channel0.Location = new System.Drawing.Point(16, 72);
			this.textBox_Status_Channel0.Name = "textBox_Status_Channel0";
			this.textBox_Status_Channel0.TabIndex = 2;
			this.textBox_Status_Channel0.Text = "";
			this.textBox_Status_Channel0.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// groupBox_PresetValue
			// 
			this.groupBox_PresetValue.Controls.AddRange(new System.Windows.Forms.Control[] {
																							   this.textBox_PresetValue_Channel7,
																							   this.textBox_PresetValue_Channel6,
																							   this.textBox_PresetValue_Channel5,
																							   this.textBox_PresetValue_Channel4,
																							   this.textBox_PresetValue_Channel3,
																							   this.textBox_PresetValue_Channel2,
																							   this.textBox_PresetValue_Channel1,
																							   this.textBox_PresetValue_Channel0,
																							   this.radioButton_PresetValue_Hex,
																							   this.radioButton_PresetValue_Dec});
			this.groupBox_PresetValue.Location = new System.Drawing.Point(368, 56);
			this.groupBox_PresetValue.Name = "groupBox_PresetValue";
			this.groupBox_PresetValue.Size = new System.Drawing.Size(128, 328);
			this.groupBox_PresetValue.TabIndex = 16;
			this.groupBox_PresetValue.TabStop = false;
			this.groupBox_PresetValue.Text = "プリセット値";
			// 
			// textBox_PresetValue_Channel7
			// 
			this.textBox_PresetValue_Channel7.Location = new System.Drawing.Point(14, 296);
			this.textBox_PresetValue_Channel7.Name = "textBox_PresetValue_Channel7";
			this.textBox_PresetValue_Channel7.TabIndex = 9;
			this.textBox_PresetValue_Channel7.Text = "700";
			this.textBox_PresetValue_Channel7.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_PresetValue_Channel6
			// 
			this.textBox_PresetValue_Channel6.Location = new System.Drawing.Point(14, 264);
			this.textBox_PresetValue_Channel6.Name = "textBox_PresetValue_Channel6";
			this.textBox_PresetValue_Channel6.TabIndex = 8;
			this.textBox_PresetValue_Channel6.Text = "600";
			this.textBox_PresetValue_Channel6.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_PresetValue_Channel5
			// 
			this.textBox_PresetValue_Channel5.Location = new System.Drawing.Point(14, 232);
			this.textBox_PresetValue_Channel5.Name = "textBox_PresetValue_Channel5";
			this.textBox_PresetValue_Channel5.TabIndex = 7;
			this.textBox_PresetValue_Channel5.Text = "500";
			this.textBox_PresetValue_Channel5.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_PresetValue_Channel4
			// 
			this.textBox_PresetValue_Channel4.Location = new System.Drawing.Point(14, 200);
			this.textBox_PresetValue_Channel4.Name = "textBox_PresetValue_Channel4";
			this.textBox_PresetValue_Channel4.TabIndex = 6;
			this.textBox_PresetValue_Channel4.Text = "400";
			this.textBox_PresetValue_Channel4.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_PresetValue_Channel3
			// 
			this.textBox_PresetValue_Channel3.Location = new System.Drawing.Point(14, 168);
			this.textBox_PresetValue_Channel3.Name = "textBox_PresetValue_Channel3";
			this.textBox_PresetValue_Channel3.TabIndex = 5;
			this.textBox_PresetValue_Channel3.Text = "300";
			this.textBox_PresetValue_Channel3.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_PresetValue_Channel2
			// 
			this.textBox_PresetValue_Channel2.Location = new System.Drawing.Point(14, 136);
			this.textBox_PresetValue_Channel2.Name = "textBox_PresetValue_Channel2";
			this.textBox_PresetValue_Channel2.TabIndex = 4;
			this.textBox_PresetValue_Channel2.Text = "200";
			this.textBox_PresetValue_Channel2.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_PresetValue_Channel1
			// 
			this.textBox_PresetValue_Channel1.Location = new System.Drawing.Point(16, 104);
			this.textBox_PresetValue_Channel1.Name = "textBox_PresetValue_Channel1";
			this.textBox_PresetValue_Channel1.TabIndex = 3;
			this.textBox_PresetValue_Channel1.Text = "100";
			this.textBox_PresetValue_Channel1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_PresetValue_Channel0
			// 
			this.textBox_PresetValue_Channel0.Location = new System.Drawing.Point(16, 72);
			this.textBox_PresetValue_Channel0.Name = "textBox_PresetValue_Channel0";
			this.textBox_PresetValue_Channel0.TabIndex = 2;
			this.textBox_PresetValue_Channel0.Text = "0";
			this.textBox_PresetValue_Channel0.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// radioButton_PresetValue_Hex
			// 
			this.radioButton_PresetValue_Hex.Location = new System.Drawing.Point(16, 40);
			this.radioButton_PresetValue_Hex.Name = "radioButton_PresetValue_Hex";
			this.radioButton_PresetValue_Hex.TabIndex = 1;
			this.radioButton_PresetValue_Hex.Text = "16進数";
			this.radioButton_PresetValue_Hex.CheckedChanged += new System.EventHandler(this.radioButton_PresetValue_Hex_CheckedChanged);
			// 
			// radioButton_PresetValue_Dec
			// 
			this.radioButton_PresetValue_Dec.Checked = true;
			this.radioButton_PresetValue_Dec.Location = new System.Drawing.Point(16, 16);
			this.radioButton_PresetValue_Dec.Name = "radioButton_PresetValue_Dec";
			this.radioButton_PresetValue_Dec.TabIndex = 0;
			this.radioButton_PresetValue_Dec.TabStop = true;
			this.radioButton_PresetValue_Dec.Text = "10進数";
			this.radioButton_PresetValue_Dec.CheckedChanged += new System.EventHandler(this.radioButton_PresetValue_Dec_CheckedChanged);
			// 
			// button_CntInit
			// 
			this.button_CntInit.Location = new System.Drawing.Point(512, 16);
			this.button_CntInit.Name = "button_CntInit";
			this.button_CntInit.Size = new System.Drawing.Size(112, 24);
			this.button_CntInit.TabIndex = 17;
			this.button_CntInit.Text = "CntInit";
			this.button_CntInit.Click += new System.EventHandler(this.button_CntInit_Click);
			// 
			// button_ModeSet
			// 
			this.button_ModeSet.Location = new System.Drawing.Point(512, 64);
			this.button_ModeSet.Name = "button_ModeSet";
			this.button_ModeSet.Size = new System.Drawing.Size(112, 24);
			this.button_ModeSet.TabIndex = 18;
			this.button_ModeSet.Text = "モード設定...";
			this.button_ModeSet.Click += new System.EventHandler(this.button_ModeSet_Click);
			// 
			// button_ComparisonSet
			// 
			this.button_ComparisonSet.Location = new System.Drawing.Point(512, 104);
			this.button_ComparisonSet.Name = "button_ComparisonSet";
			this.button_ComparisonSet.Size = new System.Drawing.Size(112, 24);
			this.button_ComparisonSet.TabIndex = 19;
			this.button_ComparisonSet.Text = "比較設定...";
			this.button_ComparisonSet.Click += new System.EventHandler(this.button_ComparisonSet_Click);
			// 
			// button_CntStartCount
			// 
			this.button_CntStartCount.Location = new System.Drawing.Point(512, 160);
			this.button_CntStartCount.Name = "button_CntStartCount";
			this.button_CntStartCount.Size = new System.Drawing.Size(112, 24);
			this.button_CntStartCount.TabIndex = 20;
			this.button_CntStartCount.Text = "CntStartCount";
			this.button_CntStartCount.Click += new System.EventHandler(this.button_CntStartCount_Click);
			// 
			// button_CntPreset
			// 
			this.button_CntPreset.Location = new System.Drawing.Point(512, 200);
			this.button_CntPreset.Name = "button_CntPreset";
			this.button_CntPreset.Size = new System.Drawing.Size(112, 24);
			this.button_CntPreset.TabIndex = 21;
			this.button_CntPreset.Text = "CntPreset";
			this.button_CntPreset.Click += new System.EventHandler(this.button_CntPreset_Click);
			// 
			// button_CntStopCount
			// 
			this.button_CntStopCount.Location = new System.Drawing.Point(512, 240);
			this.button_CntStopCount.Name = "button_CntStopCount";
			this.button_CntStopCount.Size = new System.Drawing.Size(112, 24);
			this.button_CntStopCount.TabIndex = 22;
			this.button_CntStopCount.Text = "CntStopCount";
			this.button_CntStopCount.Click += new System.EventHandler(this.button_CntStopCount_Click);
			// 
			// button_CntExit
			// 
			this.button_CntExit.Location = new System.Drawing.Point(512, 392);
			this.button_CntExit.Name = "button_CntExit";
			this.button_CntExit.Size = new System.Drawing.Size(112, 24);
			this.button_CntExit.TabIndex = 23;
			this.button_CntExit.Text = "CntExit";
			this.button_CntExit.Click += new System.EventHandler(this.button_CntExit_Click);
			// 
			// button_Exit
			// 
			this.button_Exit.Location = new System.Drawing.Point(512, 432);
			this.button_Exit.Name = "button_Exit";
			this.button_Exit.Size = new System.Drawing.Size(112, 24);
			this.button_Exit.TabIndex = 24;
			this.button_Exit.Text = "Exit";
			this.button_Exit.Click += new System.EventHandler(this.button_Exit_Click);
			// 
			// textBox_Comparison_result
			// 
			this.textBox_Comparison_result.Location = new System.Drawing.Point(120, 400);
			this.textBox_Comparison_result.Name = "textBox_Comparison_result";
			this.textBox_Comparison_result.Size = new System.Drawing.Size(368, 19);
			this.textBox_Comparison_result.TabIndex = 25;
			this.textBox_Comparison_result.Text = "";
			// 
			// textBox_ReturnCode
			// 
			this.textBox_ReturnCode.Location = new System.Drawing.Point(120, 432);
			this.textBox_ReturnCode.Name = "textBox_ReturnCode";
			this.textBox_ReturnCode.Size = new System.Drawing.Size(368, 19);
			this.textBox_ReturnCode.TabIndex = 26;
			this.textBox_ReturnCode.Text = "";
			// 
			// timer1
			// 
			this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
			// 
			// Counter
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
			this.ClientSize = new System.Drawing.Size(640, 478);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.textBox_ReturnCode,
																		  this.textBox_Comparison_result,
																		  this.button_Exit,
																		  this.button_CntExit,
																		  this.button_CntStopCount,
																		  this.button_CntPreset,
																		  this.button_CntStartCount,
																		  this.button_ComparisonSet,
																		  this.button_ModeSet,
																		  this.button_CntInit,
																		  this.groupBox_PresetValue,
																		  this.groupBox_Status,
																		  this.groupBox_CountValue,
																		  this.textBox_DeviceName,
																		  this.label9,
																		  this.label8,
																		  this.label_Channel7,
																		  this.label_Channel6,
																		  this.label_Channel5,
																		  this.label_Channel4,
																		  this.label_Channel3,
																		  this.label_Channel2,
																		  this.label_Channel1,
																		  this.label_Channel0,
																		  this.label_DeviceName});
			this.Name = "Counter";
			this.Text = "カウンタサンプル";
			this.groupBox_CountValue.ResumeLayout(false);
			this.groupBox_Status.ResumeLayout(false);
			this.groupBox_PresetValue.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// アプリケーションのメイン エントリ ポイントです。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Counter());
		}

		private void radioButton_PresetValue_Dec_CheckedChanged(object sender, System.EventArgs e)
		{
			
			for (short ChNo = 0; ChNo < 8; ChNo++) 
			{
				m_Preset[ChNo].Text = System.Convert.ToString(PresetData[ChNo]);
			}
		}

		private void radioButton_PresetValue_Hex_CheckedChanged(object sender, System.EventArgs e)
		{
			for (short ChNo = 0; ChNo < 8; ChNo++) 
			{
				m_Preset[ChNo].Text = System.Convert.ToString(PresetData[ChNo], 16);
			}	
		}

		private void button_CntInit_Click(object sender, System.EventArgs e)
		{
			// 初期化処理
			int	Ret;

			Ret = cnt.Init(textBox_DeviceName.Text, out m_Id);

			string	ErrorString;
			cnt.GetErrorString(Ret, out ErrorString);
			textBox_ReturnCode.Text = "Ret = " + System.Convert.ToString(Ret) + " : " + ErrorString;
			if (Ret != 0)
			{
				return;
			}
			//-----------------------------
			// 総チャネル数を取得
			//-----------------------------
			Ret = cnt.GetMaxChannels(Counter.m_Id, out m_ChannelNum);
			
			cnt.GetErrorString(Ret, out ErrorString);
			textBox_ReturnCode.Text = "Ret = " + System.Convert.ToString(Ret) + " : " + ErrorString;
			if (Ret != 0)
			{
				m_ChannelNum = 0;
				return;
			}
			// このサンプルは8ポートを超えない
			if (m_ChannelNum > 8)
			{
				m_ChannelNum = 8;
			}
			//-----------------------------
			// カウンタ、ステータス、プリセット
			// 表示の無効化
			//-----------------------------
			for (short ChNo = m_ChannelNum; ChNo < 8; ChNo++) 
			{
				m_CH[ChNo].Enabled = false;	
				m_Status[ChNo].Enabled = false;
				m_Preset[ChNo].Enabled = false;
			}

			MatchCount = 0;
		}

		private void button_ModeSet_Click(object sender, System.EventArgs e)
		{
			//---------------------------------------------
			// モード設定 ダイアログを表示
			//---------------------------------------------
			Mode	ModeDlg = new Mode();
			ModeDlg.ShowDialog();
			ModeDlg.Dispose();
		}

		private void button_ComparisonSet_Click(object sender, System.EventArgs e)
		{
			//---------------------------------------------
			// 比較設定 ダイアログを表示
			//---------------------------------------------
			Comp	ComparisonSetDlg = new Comp();
			ComparisonSetDlg.ShowDialog();
			ComparisonSetDlg.Dispose();
		}

		private void button_CntStartCount_Click(object sender, System.EventArgs e)
		{
			short[] ChNoArray = new short[8];
			int Ret;
			string	ErrorString;

			//-----------------------------
			// パラメータの設定
			//-----------------------------
			for (short ChNo = 0; ChNo < m_ChannelNum; ChNo++) 
			{
				ChNoArray[ChNo] = ChNo;
			}
			//-----------------------------
			// カウンタスタート
			//-----------------------------
			Ret = cnt.StartCount(m_Id, ChNoArray, m_ChannelNum);
			//-----------------------------
			// エラー処理
			//-----------------------------
			cnt.GetErrorString(Ret, out ErrorString);
			textBox_ReturnCode.Text = "Ret = " + System.Convert.ToString(Ret) + " : " + ErrorString;
			if (Ret != (int)CcntConst.CNT_ERR_SUCCESS) 
			{
				return;
			}
			//-----------------------------
			// タイマを起動
			//-----------------------------
			timer1.Start();
		}

		private void button_CntPreset_Click(object sender, System.EventArgs e)
		{
			short[] ChNoArray = new short[8];
			int Ret;
			string	ErrorString;

			//-----------------------------
			// パラメータの設定
			//-----------------------------
			for (short ChNo = 0; ChNo < m_ChannelNum; ChNo++) 
			{
				ChNoArray[ChNo] = ChNo;
				
				try 
				{
					if (radioButton_PresetValue_Dec.Checked == true) 
					{
						PresetData[ChNo] = System.Convert.ToUInt32(m_Preset[ChNo].Text);
					} 
					else 
					{
						PresetData[ChNo] = System.Convert.ToUInt32(m_Preset[ChNo].Text, 16);
					}
				} 
				catch
				{
					PresetData[ChNo] = 0;
				}
			}
			//-----------------------------
			// プリセット
			//-----------------------------
			Ret = cnt.Preset(m_Id, ChNoArray, m_ChannelNum, PresetData);
			//-----------------------------
			// エラー処理
			//-----------------------------
			cnt.GetErrorString(Ret, out ErrorString);
			textBox_ReturnCode.Text = "Ret = " + System.Convert.ToString(Ret) + " : " + ErrorString;
			if (Ret != (int)CcntConst.CNT_ERR_SUCCESS) 
			{
				return;
			}
		}

		private void button_CntStopCount_Click(object sender, System.EventArgs e)
		{
			short[] ChNoArray = new short[8];
			int Ret;
			string	ErrorString;

			//-----------------------------
			// パラメータの設定
			//-----------------------------
			for (short ChNo = 0; ChNo < m_ChannelNum; ChNo++) 
			{
				ChNoArray[ChNo] = ChNo;
			}
			//-----------------------------
			// カウンタストップ
			//-----------------------------
			Ret = cnt.StopCount(m_Id, ChNoArray, m_ChannelNum);
			//-----------------------------
			// エラー処理
			//-----------------------------
			cnt.GetErrorString(Ret, out ErrorString);
			textBox_ReturnCode.Text = "Ret = " + System.Convert.ToString(Ret) + " : " + ErrorString;
			if (Ret != (int)CcntConst.CNT_ERR_SUCCESS) 
			{
				return;
			}
			//-----------------------------
			// タイマを停止
			//-----------------------------
			timer1.Stop();
		}

		private void button_CntExit_Click(object sender, System.EventArgs e)
		{
			
			int	Ret;
			string	ErrorString;

			Ret = cnt.Exit(m_Id);

			cnt.GetErrorString(Ret, out ErrorString);
			textBox_ReturnCode.Text = "Ret = " + System.Convert.ToString(Ret) + " : " + ErrorString;
		}

		private void button_Exit_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void timer1_Tick(object sender, System.EventArgs e)
		{
			short[] ChNoArray = new short[8];
			uint[] CountValue = new uint[8];
			int		Ret;
			short	Sts;

			//-----------------------------
			// パラメータを設定
			//-----------------------------
			for (short ChNo = 0; ChNo < m_ChannelNum; ChNo++) 
			{
				ChNoArray[ChNo] = ChNo;
			}
			//-----------------------------
			// カウント値を取得
			//-----------------------------
			Ret = cnt.ReadCount(m_Id, ChNoArray, m_ChannelNum, CountValue);
			if (Ret == (int)CcntConst.CNT_ERR_SUCCESS)
			{
				for (short ChNo = 0; ChNo < m_ChannelNum; ChNo++) 
				{
					if (radioButtonCountValue_Dec.Checked == true) 
					{
						m_CH[ChNo].Text = System.Convert.ToString(CountValue[ChNo]);
					} 
					else 
					{
						m_CH[ChNo].Text = System.Convert.ToString(CountValue[ChNo], 16);
					}
				}
			}
			//-----------------------------
			// ステータスを取得
			//-----------------------------
			for (short ChNo = 0; ChNo < m_ChannelNum; ChNo++) 
			{
				Ret = cnt.ReadStatus(m_Id, ChNo, out Sts);
				if (Ret == (int)CcntConst.CNT_ERR_SUCCESS)
				{
					m_Status[ChNo].Text = System.Convert.ToString(Sts, 16);
				}
			}
		}
		protected override void WndProc(ref Message m)
		{
			switch (m.Msg)
			{
				case((int)CcntConst.CNTM_COUNTUP_CH0):
				case((int)CcntConst.CNTM_COUNTUP_CH1):
				case((int)CcntConst.CNTM_COUNTUP_CH2):
				case((int)CcntConst.CNTM_COUNTUP_CH3):
				case((int)CcntConst.CNTM_COUNTUP_CH4):
				case((int)CcntConst.CNTM_COUNTUP_CH5):
				case((int)CcntConst.CNTM_COUNTUP_CH6):
				case((int)CcntConst.CNTM_COUNTUP_CH7):
					MatchCount++;
					if (((m.WParam.ToInt32() & 0x0ffff0000) >> 16) == (int)CcntConst.CNT_DIR_UP) 
					{
						textBox_Comparison_result.Text = 
							"カウント一致!! CH" + System.Convert.ToString(m.Msg & 0x07) + 
							" Value = " + Convert.ToUInt32(m.LParam.ToInt64() & 0x00000000ffffffff) +
							" UP Match Count = " + System.Convert.ToString(MatchCount);
					} 
					else 
					{
						textBox_Comparison_result.Text = 
							"カウント一致!! CH" + System.Convert.ToString(m.Msg & 0x07) + 
							" Value = " + Convert.ToUInt32(m.LParam.ToInt64() & 0x00000000ffffffff) +
							" DOWN Match Count = " + System.Convert.ToString(MatchCount);
					}
					break;
			}
			base.WndProc(ref m);
		}

	}
}
