﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using CdioCs;

namespace Trigger
{
	/// <summary>
	/// Summary description for Trigger.
	/// </summary>
	public class Trigger : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label_DeviceName;
		private System.Windows.Forms.TextBox textBox_DeviceName;
		private System.Windows.Forms.GroupBox groupBox_Trigger;
		private System.Windows.Forms.Label label_Upcount;
		private System.Windows.Forms.Label label_Downcount;
		private System.Windows.Forms.Label label_Valid_Invalid;
		private System.Windows.Forms.Label label_Trigger_0;
		private System.Windows.Forms.Label label_Trigger_1;
		private System.Windows.Forms.Label label_Trigger_2;
		private System.Windows.Forms.Label label_Trigger_3;
		private System.Windows.Forms.Label label_Trigger_4;
		private System.Windows.Forms.Label label_Trigger_5;
		private System.Windows.Forms.Label label_Trigger_6;
		private System.Windows.Forms.Label label_Trigger_7;	
		private System.Windows.Forms.TextBox textBox_UpCount_0;
		private System.Windows.Forms.TextBox textBox_UpCount_1;
		private System.Windows.Forms.TextBox textBox_UpCount_2;
		private System.Windows.Forms.TextBox textBox_UpCount_3;
		private System.Windows.Forms.TextBox textBox_UpCount_4;
		private System.Windows.Forms.TextBox textBox_UpCount_5;
		private System.Windows.Forms.TextBox textBox_UpCount_6;
		private System.Windows.Forms.TextBox textBox_UpCount_7;
		private System.Windows.Forms.TextBox textBox_DownCount_0;
		private System.Windows.Forms.TextBox textBox_DownCount_1;
		private System.Windows.Forms.TextBox textBox_DownCount_2;
		private System.Windows.Forms.TextBox textBox_DownCount_3;
		private System.Windows.Forms.TextBox textBox_DownCount_4;
		private System.Windows.Forms.TextBox textBox_DownCount_5;
		private System.Windows.Forms.TextBox textBox_DownCount_6;
		private System.Windows.Forms.TextBox textBox_DownCount_7;
		private System.Windows.Forms.CheckBox checkBox_Trigger_0;
		private System.Windows.Forms.CheckBox checkBox_Trigger_1;
		private System.Windows.Forms.CheckBox checkBox_Trigger_2;
		private System.Windows.Forms.CheckBox checkBox_Trigger_3;
		private System.Windows.Forms.CheckBox checkBox_Trigger_4;
		private System.Windows.Forms.CheckBox checkBox_Trigger_5;
		private System.Windows.Forms.CheckBox checkBox_Trigger_6;
		private System.Windows.Forms.CheckBox checkBox_Trigger_7;
		private System.Windows.Forms.TextBox textBox_ReturnCode;
		private System.Windows.Forms.Label label_ReturnCode;
		private System.Windows.Forms.Button button_Trigger_Start;
		private System.Windows.Forms.Button button_DioInit;
		private System.Windows.Forms.Button button_DioExit;
		private System.Windows.Forms.Button button_Exit;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		private System.Windows.Forms.TextBox[] m_UpCountText = new System.Windows.Forms.TextBox[8];
		private System.Windows.Forms.TextBox[] m_DownCountText = new System.Windows.Forms.TextBox[8];
		private System.Windows.Forms.CheckBox[] m_TriggerCheck = new System.Windows.Forms.CheckBox[8];

		/// <summary>
		/// Create instance Cdio class
		/// </summary>
		Cdio  dio = new Cdio();

		public short	m_Id;
		public int[] m_UpCount = new int[8];
		public int[] m_DownCount =  new int[8];

		public Trigger()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
			m_UpCountText[0] = textBox_UpCount_0;
			m_UpCountText[1] = textBox_UpCount_1;
			m_UpCountText[2] = textBox_UpCount_2;
			m_UpCountText[3] = textBox_UpCount_3;
			m_UpCountText[4] = textBox_UpCount_4;
			m_UpCountText[5] = textBox_UpCount_5;
			m_UpCountText[6] = textBox_UpCount_6;
			m_UpCountText[7] = textBox_UpCount_7;

			m_DownCountText[0] = textBox_DownCount_0;
			m_DownCountText[1] = textBox_DownCount_1;
			m_DownCountText[2] = textBox_DownCount_2;
			m_DownCountText[3] = textBox_DownCount_3;
			m_DownCountText[4] = textBox_DownCount_4;
			m_DownCountText[5] = textBox_DownCount_5;
			m_DownCountText[6] = textBox_DownCount_6;
			m_DownCountText[7] = textBox_DownCount_7;

			m_TriggerCheck[0] = checkBox_Trigger_0;
			m_TriggerCheck[1] = checkBox_Trigger_1;
			m_TriggerCheck[2] = checkBox_Trigger_2;
			m_TriggerCheck[3] = checkBox_Trigger_3;
			m_TriggerCheck[4] = checkBox_Trigger_4;
			m_TriggerCheck[5] = checkBox_Trigger_5;
			m_TriggerCheck[6] = checkBox_Trigger_6;
			m_TriggerCheck[7] = checkBox_Trigger_7;

			short i;
			for ( i = 0;i < 8; i++)
				m_TriggerCheck[i].Checked  = true;

			textBox_ReturnCode.Text  = "";
		}

		/// <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>
		/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
		/// コード エディタで変更しないでください。
		/// </summary>
		private void InitializeComponent()
		{
			this.label_DeviceName = new System.Windows.Forms.Label();
			this.textBox_DeviceName = new System.Windows.Forms.TextBox();
			this.groupBox_Trigger = new System.Windows.Forms.GroupBox();
			this.button_Trigger_Start = new System.Windows.Forms.Button();
			this.checkBox_Trigger_7 = new System.Windows.Forms.CheckBox();
			this.checkBox_Trigger_6 = new System.Windows.Forms.CheckBox();
			this.checkBox_Trigger_5 = new System.Windows.Forms.CheckBox();
			this.checkBox_Trigger_4 = new System.Windows.Forms.CheckBox();
			this.checkBox_Trigger_3 = new System.Windows.Forms.CheckBox();
			this.checkBox_Trigger_2 = new System.Windows.Forms.CheckBox();
			this.checkBox_Trigger_1 = new System.Windows.Forms.CheckBox();
			this.checkBox_Trigger_0 = new System.Windows.Forms.CheckBox();
			this.textBox_DownCount_7 = new System.Windows.Forms.TextBox();
			this.textBox_DownCount_6 = new System.Windows.Forms.TextBox();
			this.textBox_DownCount_5 = new System.Windows.Forms.TextBox();
			this.textBox_DownCount_4 = new System.Windows.Forms.TextBox();
			this.textBox_DownCount_3 = new System.Windows.Forms.TextBox();
			this.textBox_DownCount_2 = new System.Windows.Forms.TextBox();
			this.textBox_DownCount_1 = new System.Windows.Forms.TextBox();
			this.textBox_DownCount_0 = new System.Windows.Forms.TextBox();
			this.textBox_UpCount_7 = new System.Windows.Forms.TextBox();
			this.textBox_UpCount_6 = new System.Windows.Forms.TextBox();
			this.textBox_UpCount_5 = new System.Windows.Forms.TextBox();
			this.textBox_UpCount_4 = new System.Windows.Forms.TextBox();
			this.textBox_UpCount_3 = new System.Windows.Forms.TextBox();
			this.textBox_UpCount_2 = new System.Windows.Forms.TextBox();
			this.textBox_UpCount_1 = new System.Windows.Forms.TextBox();
			this.textBox_UpCount_0 = new System.Windows.Forms.TextBox();
			this.label_Trigger_7 = new System.Windows.Forms.Label();
			this.label_Trigger_6 = new System.Windows.Forms.Label();
			this.label_Trigger_5 = new System.Windows.Forms.Label();
			this.label_Trigger_4 = new System.Windows.Forms.Label();
			this.label_Trigger_3 = new System.Windows.Forms.Label();
			this.label_Trigger_2 = new System.Windows.Forms.Label();
			this.label_Trigger_1 = new System.Windows.Forms.Label();
			this.label_Trigger_0 = new System.Windows.Forms.Label();
			this.label_Valid_Invalid = new System.Windows.Forms.Label();
			this.label_Downcount = new System.Windows.Forms.Label();
			this.label_Upcount = new System.Windows.Forms.Label();
			this.textBox_ReturnCode = new System.Windows.Forms.TextBox();
			this.label_ReturnCode = new System.Windows.Forms.Label();
			this.button_DioInit = new System.Windows.Forms.Button();
			this.button_DioExit = new System.Windows.Forms.Button();
			this.button_Exit = new System.Windows.Forms.Button();
			this.groupBox_Trigger.SuspendLayout();
			this.SuspendLayout();
			// 
			// label_DeviceName
			// 
			this.label_DeviceName.Location = new System.Drawing.Point(16, 16);
			this.label_DeviceName.Name = "label_DeviceName";
			this.label_DeviceName.TabIndex = 0;
			this.label_DeviceName.Text = "Device Name:";
			// 
			// textBox_DeviceName
			// 
			this.textBox_DeviceName.Location = new System.Drawing.Point(120, 16);
			this.textBox_DeviceName.Name = "textBox_DeviceName";
			this.textBox_DeviceName.TabIndex = 1;
			this.textBox_DeviceName.Text = "DIO000";
			// 
			// groupBox_Trigger
			// 
			this.groupBox_Trigger.Controls.AddRange(new System.Windows.Forms.Control[] {
																						   this.button_Trigger_Start,
																						   this.checkBox_Trigger_7,
																						   this.checkBox_Trigger_6,
																						   this.checkBox_Trigger_5,
																						   this.checkBox_Trigger_4,
																						   this.checkBox_Trigger_3,
																						   this.checkBox_Trigger_2,
																						   this.checkBox_Trigger_1,
																						   this.checkBox_Trigger_0,
																						   this.textBox_DownCount_7,
																						   this.textBox_DownCount_6,
																						   this.textBox_DownCount_5,
																						   this.textBox_DownCount_4,
																						   this.textBox_DownCount_3,
																						   this.textBox_DownCount_2,
																						   this.textBox_DownCount_1,
																						   this.textBox_DownCount_0,
																						   this.textBox_UpCount_7,
																						   this.textBox_UpCount_6,
																						   this.textBox_UpCount_5,
																						   this.textBox_UpCount_4,
																						   this.textBox_UpCount_3,
																						   this.textBox_UpCount_2,
																						   this.textBox_UpCount_1,
																						   this.textBox_UpCount_0,
																						   this.label_Trigger_7,
																						   this.label_Trigger_6,
																						   this.label_Trigger_5,
																						   this.label_Trigger_4,
																						   this.label_Trigger_3,
																						   this.label_Trigger_2,
																						   this.label_Trigger_1,
																						   this.label_Trigger_0,
																						   this.label_Valid_Invalid,
																						   this.label_Downcount,
																						   this.label_Upcount});
			this.groupBox_Trigger.Location = new System.Drawing.Point(16, 48);
			this.groupBox_Trigger.Name = "groupBox_Trigger";
			this.groupBox_Trigger.Size = new System.Drawing.Size(512, 168);
			this.groupBox_Trigger.TabIndex = 2;
			this.groupBox_Trigger.TabStop = false;
			this.groupBox_Trigger.Text = "Trigger";
			// 
			// button_Trigger_Start
			// 
			this.button_Trigger_Start.Location = new System.Drawing.Point(408, 136);
			this.button_Trigger_Start.Name = "button_Trigger_Start";
			this.button_Trigger_Start.Size = new System.Drawing.Size(88, 23);
			this.button_Trigger_Start.TabIndex = 36;
			this.button_Trigger_Start.Text = "Trigger Start";
			this.button_Trigger_Start.Click += new System.EventHandler(this.button_Trigger_Start_Click);
			// 
			// checkBox_Trigger_7
			// 
			this.checkBox_Trigger_7.Location = new System.Drawing.Point(472, 104);
			this.checkBox_Trigger_7.Name = "checkBox_Trigger_7";
			this.checkBox_Trigger_7.Size = new System.Drawing.Size(16, 24);
			this.checkBox_Trigger_7.TabIndex = 35;
			this.checkBox_Trigger_7.CheckedChanged += new System.EventHandler(this.checkBox_Trigger_7_CheckedChanged);
			// 
			// checkBox_Trigger_6
			// 
			this.checkBox_Trigger_6.Location = new System.Drawing.Point(424, 104);
			this.checkBox_Trigger_6.Name = "checkBox_Trigger_6";
			this.checkBox_Trigger_6.Size = new System.Drawing.Size(16, 24);
			this.checkBox_Trigger_6.TabIndex = 34;
			this.checkBox_Trigger_6.CheckedChanged += new System.EventHandler(this.checkBox_Trigger_6_CheckedChanged);
			// 
			// checkBox_Trigger_5
			// 
			this.checkBox_Trigger_5.Location = new System.Drawing.Point(376, 104);
			this.checkBox_Trigger_5.Name = "checkBox_Trigger_5";
			this.checkBox_Trigger_5.Size = new System.Drawing.Size(16, 24);
			this.checkBox_Trigger_5.TabIndex = 33;
			this.checkBox_Trigger_5.CheckedChanged += new System.EventHandler(this.checkBox_Trigger_5_CheckedChanged);
			// 
			// checkBox_Trigger_4
			// 
			this.checkBox_Trigger_4.Location = new System.Drawing.Point(328, 104);
			this.checkBox_Trigger_4.Name = "checkBox_Trigger_4";
			this.checkBox_Trigger_4.Size = new System.Drawing.Size(16, 24);
			this.checkBox_Trigger_4.TabIndex = 32;
			this.checkBox_Trigger_4.CheckedChanged += new System.EventHandler(this.checkBox_Trigger_4_CheckedChanged);
			// 
			// checkBox_Trigger_3
			// 
			this.checkBox_Trigger_3.Location = new System.Drawing.Point(280, 104);
			this.checkBox_Trigger_3.Name = "checkBox_Trigger_3";
			this.checkBox_Trigger_3.Size = new System.Drawing.Size(16, 24);
			this.checkBox_Trigger_3.TabIndex = 31;
			this.checkBox_Trigger_3.CheckedChanged += new System.EventHandler(this.checkBox_Trigger_3_CheckedChanged);
			// 
			// checkBox_Trigger_2
			// 
			this.checkBox_Trigger_2.Location = new System.Drawing.Point(232, 104);
			this.checkBox_Trigger_2.Name = "checkBox_Trigger_2";
			this.checkBox_Trigger_2.Size = new System.Drawing.Size(16, 24);
			this.checkBox_Trigger_2.TabIndex = 30;
			this.checkBox_Trigger_2.CheckedChanged += new System.EventHandler(this.checkBox_Trigger_2_CheckedChanged);
			// 
			// checkBox_Trigger_1
			// 
			this.checkBox_Trigger_1.Location = new System.Drawing.Point(184, 104);
			this.checkBox_Trigger_1.Name = "checkBox_Trigger_1";
			this.checkBox_Trigger_1.Size = new System.Drawing.Size(16, 24);
			this.checkBox_Trigger_1.TabIndex = 29;
			this.checkBox_Trigger_1.CheckedChanged += new System.EventHandler(this.checkBox_Trigger_1_CheckedChanged);
			// 
			// checkBox_Trigger_0
			// 
			this.checkBox_Trigger_0.Location = new System.Drawing.Point(136, 104);
			this.checkBox_Trigger_0.Name = "checkBox_Trigger_0";
			this.checkBox_Trigger_0.Size = new System.Drawing.Size(16, 24);
			this.checkBox_Trigger_0.TabIndex = 28;
			this.checkBox_Trigger_0.CheckedChanged += new System.EventHandler(this.checkBox_Trigger_0_CheckedChanged);
			// 
			// textBox_DownCount_7
			// 
			this.textBox_DownCount_7.Location = new System.Drawing.Point(456, 80);
			this.textBox_DownCount_7.Name = "textBox_DownCount_7";
			this.textBox_DownCount_7.Size = new System.Drawing.Size(46, 19);
			this.textBox_DownCount_7.TabIndex = 27;
			this.textBox_DownCount_7.Text = "";
			this.textBox_DownCount_7.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_DownCount_6
			// 
			this.textBox_DownCount_6.Location = new System.Drawing.Point(408, 80);
			this.textBox_DownCount_6.Name = "textBox_DownCount_6";
			this.textBox_DownCount_6.Size = new System.Drawing.Size(46, 19);
			this.textBox_DownCount_6.TabIndex = 26;
			this.textBox_DownCount_6.Text = "";
			this.textBox_DownCount_6.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_DownCount_5
			// 
			this.textBox_DownCount_5.Location = new System.Drawing.Point(360, 80);
			this.textBox_DownCount_5.Name = "textBox_DownCount_5";
			this.textBox_DownCount_5.Size = new System.Drawing.Size(46, 19);
			this.textBox_DownCount_5.TabIndex = 25;
			this.textBox_DownCount_5.Text = "";
			this.textBox_DownCount_5.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_DownCount_4
			// 
			this.textBox_DownCount_4.Location = new System.Drawing.Point(312, 80);
			this.textBox_DownCount_4.Name = "textBox_DownCount_4";
			this.textBox_DownCount_4.Size = new System.Drawing.Size(46, 19);
			this.textBox_DownCount_4.TabIndex = 24;
			this.textBox_DownCount_4.Text = "";
			this.textBox_DownCount_4.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_DownCount_3
			// 
			this.textBox_DownCount_3.Location = new System.Drawing.Point(264, 80);
			this.textBox_DownCount_3.Name = "textBox_DownCount_3";
			this.textBox_DownCount_3.Size = new System.Drawing.Size(46, 19);
			this.textBox_DownCount_3.TabIndex = 23;
			this.textBox_DownCount_3.Text = "";
			this.textBox_DownCount_3.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_DownCount_2
			// 
			this.textBox_DownCount_2.Location = new System.Drawing.Point(216, 80);
			this.textBox_DownCount_2.Name = "textBox_DownCount_2";
			this.textBox_DownCount_2.Size = new System.Drawing.Size(46, 19);
			this.textBox_DownCount_2.TabIndex = 22;
			this.textBox_DownCount_2.Text = "";
			this.textBox_DownCount_2.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_DownCount_1
			// 
			this.textBox_DownCount_1.Location = new System.Drawing.Point(168, 80);
			this.textBox_DownCount_1.Name = "textBox_DownCount_1";
			this.textBox_DownCount_1.Size = new System.Drawing.Size(46, 19);
			this.textBox_DownCount_1.TabIndex = 21;
			this.textBox_DownCount_1.Text = "";
			this.textBox_DownCount_1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_DownCount_0
			// 
			this.textBox_DownCount_0.Location = new System.Drawing.Point(120, 80);
			this.textBox_DownCount_0.Name = "textBox_DownCount_0";
			this.textBox_DownCount_0.Size = new System.Drawing.Size(46, 19);
			this.textBox_DownCount_0.TabIndex = 20;
			this.textBox_DownCount_0.Text = "";
			this.textBox_DownCount_0.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_UpCount_7
			// 
			this.textBox_UpCount_7.Location = new System.Drawing.Point(456, 48);
			this.textBox_UpCount_7.Name = "textBox_UpCount_7";
			this.textBox_UpCount_7.Size = new System.Drawing.Size(46, 19);
			this.textBox_UpCount_7.TabIndex = 19;
			this.textBox_UpCount_7.Text = "";
			this.textBox_UpCount_7.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_UpCount_6
			// 
			this.textBox_UpCount_6.Location = new System.Drawing.Point(408, 48);
			this.textBox_UpCount_6.Name = "textBox_UpCount_6";
			this.textBox_UpCount_6.Size = new System.Drawing.Size(46, 19);
			this.textBox_UpCount_6.TabIndex = 18;
			this.textBox_UpCount_6.Text = "";
			this.textBox_UpCount_6.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_UpCount_5
			// 
			this.textBox_UpCount_5.Location = new System.Drawing.Point(360, 48);
			this.textBox_UpCount_5.Name = "textBox_UpCount_5";
			this.textBox_UpCount_5.Size = new System.Drawing.Size(46, 19);
			this.textBox_UpCount_5.TabIndex = 17;
			this.textBox_UpCount_5.Text = "";
			this.textBox_UpCount_5.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_UpCount_4
			// 
			this.textBox_UpCount_4.Location = new System.Drawing.Point(312, 48);
			this.textBox_UpCount_4.Name = "textBox_UpCount_4";
			this.textBox_UpCount_4.Size = new System.Drawing.Size(46, 19);
			this.textBox_UpCount_4.TabIndex = 16;
			this.textBox_UpCount_4.Text = "";
			this.textBox_UpCount_4.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_UpCount_3
			// 
			this.textBox_UpCount_3.Location = new System.Drawing.Point(264, 48);
			this.textBox_UpCount_3.Name = "textBox_UpCount_3";
			this.textBox_UpCount_3.Size = new System.Drawing.Size(46, 19);
			this.textBox_UpCount_3.TabIndex = 15;
			this.textBox_UpCount_3.Text = "";
			this.textBox_UpCount_3.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_UpCount_2
			// 
			this.textBox_UpCount_2.Location = new System.Drawing.Point(216, 48);
			this.textBox_UpCount_2.Name = "textBox_UpCount_2";
			this.textBox_UpCount_2.Size = new System.Drawing.Size(46, 19);
			this.textBox_UpCount_2.TabIndex = 14;
			this.textBox_UpCount_2.Text = "";
			this.textBox_UpCount_2.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_UpCount_1
			// 
			this.textBox_UpCount_1.Location = new System.Drawing.Point(168, 48);
			this.textBox_UpCount_1.Name = "textBox_UpCount_1";
			this.textBox_UpCount_1.Size = new System.Drawing.Size(46, 19);
			this.textBox_UpCount_1.TabIndex = 13;
			this.textBox_UpCount_1.Text = "";
			this.textBox_UpCount_1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox_UpCount_0
			// 
			this.textBox_UpCount_0.Location = new System.Drawing.Point(120, 48);
			this.textBox_UpCount_0.Name = "textBox_UpCount_0";
			this.textBox_UpCount_0.Size = new System.Drawing.Size(46, 19);
			this.textBox_UpCount_0.TabIndex = 12;
			this.textBox_UpCount_0.Text = "";
			this.textBox_UpCount_0.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// label_Trigger_7
			// 
			this.label_Trigger_7.Location = new System.Drawing.Point(472, 24);
			this.label_Trigger_7.Name = "label_Trigger_7";
			this.label_Trigger_7.Size = new System.Drawing.Size(16, 23);
			this.label_Trigger_7.TabIndex = 11;
			this.label_Trigger_7.Text = "7";
			// 
			// label_Trigger_6
			// 
			this.label_Trigger_6.Location = new System.Drawing.Point(416, 24);
			this.label_Trigger_6.Name = "label_Trigger_6";
			this.label_Trigger_6.Size = new System.Drawing.Size(16, 23);
			this.label_Trigger_6.TabIndex = 10;
			this.label_Trigger_6.Text = "6";
			// 
			// label_Trigger_5
			// 
			this.label_Trigger_5.Location = new System.Drawing.Point(376, 24);
			this.label_Trigger_5.Name = "label_Trigger_5";
			this.label_Trigger_5.Size = new System.Drawing.Size(16, 23);
			this.label_Trigger_5.TabIndex = 9;
			this.label_Trigger_5.Text = "5";
			// 
			// label_Trigger_4
			// 
			this.label_Trigger_4.Location = new System.Drawing.Point(328, 24);
			this.label_Trigger_4.Name = "label_Trigger_4";
			this.label_Trigger_4.Size = new System.Drawing.Size(16, 23);
			this.label_Trigger_4.TabIndex = 8;
			this.label_Trigger_4.Text = "4";
			// 
			// label_Trigger_3
			// 
			this.label_Trigger_3.Location = new System.Drawing.Point(280, 24);
			this.label_Trigger_3.Name = "label_Trigger_3";
			this.label_Trigger_3.Size = new System.Drawing.Size(16, 23);
			this.label_Trigger_3.TabIndex = 7;
			this.label_Trigger_3.Text = "3";
			// 
			// label_Trigger_2
			// 
			this.label_Trigger_2.Location = new System.Drawing.Point(232, 24);
			this.label_Trigger_2.Name = "label_Trigger_2";
			this.label_Trigger_2.Size = new System.Drawing.Size(16, 23);
			this.label_Trigger_2.TabIndex = 6;
			this.label_Trigger_2.Text = "2";
			// 
			// label_Trigger_1
			// 
			this.label_Trigger_1.Location = new System.Drawing.Point(184, 24);
			this.label_Trigger_1.Name = "label_Trigger_1";
			this.label_Trigger_1.Size = new System.Drawing.Size(16, 23);
			this.label_Trigger_1.TabIndex = 5;
			this.label_Trigger_1.Text = "1";
			// 
			// label_Trigger_0
			// 
			this.label_Trigger_0.Location = new System.Drawing.Point(136, 24);
			this.label_Trigger_0.Name = "label_Trigger_0";
			this.label_Trigger_0.Size = new System.Drawing.Size(16, 23);
			this.label_Trigger_0.TabIndex = 4;
			this.label_Trigger_0.Text = "0";
			// 
			// label_Valid_Invalid
			// 
			this.label_Valid_Invalid.Location = new System.Drawing.Point(16, 104);
			this.label_Valid_Invalid.Name = "label_Valid_Invalid";
			this.label_Valid_Invalid.TabIndex = 3;
			this.label_Valid_Invalid.Text = "Valid / Invalid:";
			// 
			// label_Downcount
			// 
			this.label_Downcount.Location = new System.Drawing.Point(16, 80);
			this.label_Downcount.Name = "label_Downcount";
			this.label_Downcount.TabIndex = 2;
			this.label_Downcount.Text = "Down-count:";
			// 
			// label_Upcount
			// 
			this.label_Upcount.Location = new System.Drawing.Point(16, 56);
			this.label_Upcount.Name = "label_Upcount";
			this.label_Upcount.TabIndex = 1;
			this.label_Upcount.Text = "Up-count:";
			// 
			// textBox_ReturnCode
			// 
			this.textBox_ReturnCode.Location = new System.Drawing.Point(120, 224);
			this.textBox_ReturnCode.Name = "textBox_ReturnCode";
			this.textBox_ReturnCode.Size = new System.Drawing.Size(288, 19);
			this.textBox_ReturnCode.TabIndex = 4;
			this.textBox_ReturnCode.Text = "";
			// 
			// label_ReturnCode
			// 
			this.label_ReturnCode.Location = new System.Drawing.Point(16, 224);
			this.label_ReturnCode.Name = "label_ReturnCode";
			this.label_ReturnCode.TabIndex = 3;
			this.label_ReturnCode.Text = "Return Code:";
			// 
			// button_DioInit
			// 
			this.button_DioInit.Location = new System.Drawing.Point(424, 16);
			this.button_DioInit.Name = "button_DioInit";
			this.button_DioInit.Size = new System.Drawing.Size(88, 23);
			this.button_DioInit.TabIndex = 37;
			this.button_DioInit.Text = "DioInit";
			this.button_DioInit.Click += new System.EventHandler(this.button_DioInit_Click);
			// 
			// button_DioExit
			// 
			this.button_DioExit.Location = new System.Drawing.Point(424, 224);
			this.button_DioExit.Name = "button_DioExit";
			this.button_DioExit.Size = new System.Drawing.Size(88, 23);
			this.button_DioExit.TabIndex = 38;
			this.button_DioExit.Text = "DioExit";
			this.button_DioExit.Click += new System.EventHandler(this.button_DioExit_Click);
			// 
			// button_Exit
			// 
			this.button_Exit.Location = new System.Drawing.Point(424, 256);
			this.button_Exit.Name = "button_Exit";
			this.button_Exit.Size = new System.Drawing.Size(88, 23);
			this.button_Exit.TabIndex = 39;
			this.button_Exit.Text = "Exit";
			this.button_Exit.Click += new System.EventHandler(this.button_Exit_Click);
			// 
			// Trigger
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
			this.ClientSize = new System.Drawing.Size(544, 294);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.button_Exit,
																		  this.button_DioExit,
																		  this.button_DioInit,
																		  this.textBox_ReturnCode,
																		  this.label_ReturnCode,
																		  this.groupBox_Trigger,
																		  this.textBox_DeviceName,
																		  this.label_DeviceName});
			this.Name = "Trigger";
			this.Text = "Trigger";
			this.groupBox_Trigger.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Trigger());
		}

		private void button_DioInit_Click(object sender, System.EventArgs e)
		{
			// Initialization handling
			int	Ret;
			Ret = dio.Init(textBox_DeviceName.Text, out m_Id);

			string	ErrorString;
			dio.GetErrorString(Ret, out ErrorString);
			textBox_ReturnCode.Text = "Ret = " + System.Convert.ToString(Ret) + " : " + ErrorString;
			if (Ret != (int)CdioConst.DIO_ERR_SUCCESS) 
			{
				return;
			}
		}

		private void button_Trigger_Start_Click(object sender, System.EventArgs e)
		{
			int		Ret = 0;
			short	TrgBit;
			short	TrgKind;
			int		Tim;
			//-----------------------------
			// Parameters initialization
			//-----------------------------
			for (TrgBit = 0; TrgBit < 8; TrgBit++) 
			{
				m_UpCount[TrgBit] = 0;		// Up counter
				m_DownCount[TrgBit] = 0;	// Down counter
			}
			//-----------------------------
			// Witch check
			//-----------------------------
			Tim = 100;																// Observe in cycle 100ms
			TrgKind = (short)CdioConst.DIO_TRG_RISE | (short)CdioConst.DIO_TRG_FALL;	// Observe both of Up/Down
			for (TrgBit = 0; TrgBit < 8; TrgBit++) 
			{
				//-----------------------------
				// Trigger start
				//-----------------------------
				if (m_TriggerCheck[TrgBit].Checked == true) 
				{
					Ret = dio.NotifyTrg(m_Id, TrgBit, TrgKind, Tim, this.Handle);
					if (Ret != (int)CdioConst.DIO_ERR_SUCCESS) 
					{
						break;
					}
				}
				//-----------------------------
				// Tigger stop
				//-----------------------------
				else 
				{
					Ret = dio.StopNotifyTrg(m_Id, TrgBit);
					if (Ret != (int)CdioConst.DIO_ERR_SUCCESS) 
					{
						break;
					}
				}
			}
			//-----------------------------
			// Error process
			//-----------------------------
			string	ErrorString;
			dio.GetErrorString(Ret, out ErrorString);
			textBox_ReturnCode.Text = "Ret = " + System.Convert.ToString(Ret) + " : " + ErrorString;
		}

		private void button_DioExit_Click(object sender, System.EventArgs e)
		{
			// Exit handling of device
			int	Ret;
			Ret = dio.Exit(m_Id);
			//-----------------------------
			// Error process
			//-----------------------------
			string	ErrorString;
			dio.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();
		}

		protected override void WndProc(ref Message m)
		{
			switch (m.Msg)
			{
				case((int)CdioConst.DIOM_TRIGGER):
					int TrgBit = m.LParam.ToInt32() & 0x0000ffff;
					int TrgKind = (int)((m.LParam.ToInt32() & 0x0ffff0000) >> 16);
					if ((TrgKind & (int)CdioConst.DIO_TRG_RISE) == (int)CdioConst.DIO_TRG_RISE)
					{
						m_UpCount[TrgBit]++;
					}
					if ((TrgKind & (int)CdioConst.DIO_TRG_FALL) == (int)CdioConst.DIO_TRG_FALL)
					{
						m_DownCount[TrgBit]++;
					}
					m_UpCountText[TrgBit].Text = System.Convert.ToString(m_UpCount[TrgBit]);
					m_DownCountText[TrgBit].Text = System.Convert.ToString(m_DownCount[TrgBit]);
					break;
			}
			base.WndProc(ref m);
		}
	
		private void CheckProcess(short BitNo)
		{
			int Ret = 0;
			int Tim ;                 // 100ms周期で監視
			short Kind;               // アップダウン両方を監視

			Tim = 100;
			Kind = (short)CdioConst.DIO_TRG_RISE | (short)CdioConst.DIO_TRG_FALL;

			// トリガ開始
			if (m_TriggerCheck[BitNo].Checked == true)
				Ret = dio.NotifyTrg(m_Id, BitNo, Kind, Tim, this.Handle);

				//またはトリガ停止
			else
				Ret = dio.StopNotifyTrg (m_Id, BitNo);
       

			//エラー処理
			string ErrorString;
			dio.GetErrorString(Ret, out ErrorString);
			textBox_ReturnCode.Text = "Ret = " + System.Convert.ToString(Ret) + " : " + ErrorString;
		}

		private void checkBox_Trigger_0_CheckedChanged(object sender, System.EventArgs e)
		{
			CheckProcess(0);
		}

		private void checkBox_Trigger_1_CheckedChanged(object sender, System.EventArgs e)
		{
			CheckProcess(1);
		}

		private void checkBox_Trigger_2_CheckedChanged(object sender, System.EventArgs e)
		{
			CheckProcess(2);
		}

		private void checkBox_Trigger_3_CheckedChanged(object sender, System.EventArgs e)
		{
			CheckProcess(3);
		}

		private void checkBox_Trigger_4_CheckedChanged(object sender, System.EventArgs e)
		{
			CheckProcess(4);
		}

		private void checkBox_Trigger_5_CheckedChanged(object sender, System.EventArgs e)
		{
			CheckProcess(5);
		}

		private void checkBox_Trigger_6_CheckedChanged(object sender, System.EventArgs e)
		{
			CheckProcess(6);
		}

		private void checkBox_Trigger_7_CheckedChanged(object sender, System.EventArgs e)
		{
			CheckProcess(7);
		}
		
	
	
	}
}
