using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using CdigCs;

namespace Sync
{
	/// <summary>
	/// Form1 ̊Tv̐łB
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		/// <summary>
		/// NXCdigCX^X쐬
		/// </summary>
		Cdig  dig = new Cdig();
		public const int	MAX_SAMPLES = 1000;				// őTv̐ݒ

		public short	m_Id1;								// foCX1ID
		public short	m_Id2;								// foCX2ID
		public float[]	m_Data1 = new float[MAX_SAMPLES];	// foCX1擾f[^̔z
		public float[]	m_Data2 = new float[MAX_SAMPLES];	// foCX2擾f[^̔z
		public int		m_Samples1;							// foCX1擾Tv
		public int		m_Samples2;							// foCX2擾Tv

		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Button buttonExit;
		private System.Windows.Forms.Button buttonStop;
		private System.Windows.Forms.Button buttonInfo;
		private System.Windows.Forms.Button buttonStart;
		private System.Windows.Forms.Button buttonInit;
		private System.Windows.Forms.ListBox listBoxData1;
		private System.Windows.Forms.TextBox textBoxInfo1;
		private System.Windows.Forms.Label labelStatus1;
		private System.Windows.Forms.Label labelCount1;
		private System.Windows.Forms.ComboBox comboBoxRange1;
		private System.Windows.Forms.TextBox textBoxDevice1;
		private System.Windows.Forms.ListBox listBoxData2;
		private System.Windows.Forms.TextBox textBoxInfo2;
		private System.Windows.Forms.Label labelStatus2;
		private System.Windows.Forms.Label labelCount2;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.ComboBox comboBoxRange2;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.TextBox textBoxDevice2;
		/// <summary>
		/// KvȃfUCiϐłB
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// 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.groupBox1 = new System.Windows.Forms.GroupBox();
			this.listBoxData1 = new System.Windows.Forms.ListBox();
			this.textBoxInfo1 = new System.Windows.Forms.TextBox();
			this.labelStatus1 = new System.Windows.Forms.Label();
			this.labelCount1 = new System.Windows.Forms.Label();
			this.label6 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.comboBoxRange1 = new System.Windows.Forms.ComboBox();
			this.label2 = new System.Windows.Forms.Label();
			this.buttonExit = new System.Windows.Forms.Button();
			this.buttonStop = new System.Windows.Forms.Button();
			this.buttonInfo = new System.Windows.Forms.Button();
			this.buttonStart = new System.Windows.Forms.Button();
			this.buttonInit = new System.Windows.Forms.Button();
			this.textBoxDevice1 = new System.Windows.Forms.TextBox();
			this.listBoxData2 = new System.Windows.Forms.ListBox();
			this.textBoxInfo2 = new System.Windows.Forms.TextBox();
			this.labelStatus2 = new System.Windows.Forms.Label();
			this.labelCount2 = new System.Windows.Forms.Label();
			this.label7 = new System.Windows.Forms.Label();
			this.label8 = new System.Windows.Forms.Label();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.comboBoxRange2 = new System.Windows.Forms.ComboBox();
			this.label9 = new System.Windows.Forms.Label();
			this.textBoxDevice2 = new System.Windows.Forms.TextBox();
			this.groupBox1.SuspendLayout();
			this.groupBox2.SuspendLayout();
			this.SuspendLayout();
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.comboBoxRange1,
																					this.label2,
																					this.textBoxDevice1});
			this.groupBox1.Location = new System.Drawing.Point(88, 16);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(176, 240);
			this.groupBox1.TabIndex = 0;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "foCX1";
			// 
			// listBoxData1
			// 
			this.listBoxData1.ItemHeight = 12;
			this.listBoxData1.Location = new System.Drawing.Point(96, 96);
			this.listBoxData1.Name = "listBoxData1";
			this.listBoxData1.Size = new System.Drawing.Size(160, 148);
			this.listBoxData1.TabIndex = 36;
			// 
			// textBoxInfo1
			// 
			this.textBoxInfo1.Location = new System.Drawing.Point(88, 304);
			this.textBoxInfo1.Multiline = true;
			this.textBoxInfo1.Name = "textBoxInfo1";
			this.textBoxInfo1.ReadOnly = true;
			this.textBoxInfo1.Size = new System.Drawing.Size(176, 40);
			this.textBoxInfo1.TabIndex = 35;
			this.textBoxInfo1.Text = "";
			// 
			// labelStatus1
			// 
			this.labelStatus1.Location = new System.Drawing.Point(168, 288);
			this.labelStatus1.Name = "labelStatus1";
			this.labelStatus1.Size = new System.Drawing.Size(72, 16);
			this.labelStatus1.TabIndex = 34;
			this.labelStatus1.Text = "0H";
			// 
			// labelCount1
			// 
			this.labelCount1.Location = new System.Drawing.Point(168, 264);
			this.labelCount1.Name = "labelCount1";
			this.labelCount1.Size = new System.Drawing.Size(72, 16);
			this.labelCount1.TabIndex = 33;
			this.labelCount1.Text = "0";
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(88, 288);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(64, 16);
			this.label6.TabIndex = 32;
			this.label6.Text = "Xe[^X";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(88, 264);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(80, 16);
			this.label5.TabIndex = 31;
			this.label5.Text = "TvO";
			// 
			// comboBoxRange1
			// 
			this.comboBoxRange1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.comboBoxRange1.Location = new System.Drawing.Point(8, 56);
			this.comboBoxRange1.Name = "comboBoxRange1";
			this.comboBoxRange1.Size = new System.Drawing.Size(160, 20);
			this.comboBoxRange1.TabIndex = 28;
			this.comboBoxRange1.SelectedIndexChanged += new System.EventHandler(this.comboBoxRange1_SelectedIndexChanged);
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(8, 40);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(64, 16);
			this.label2.TabIndex = 27;
			this.label2.Text = "W";
			// 
			// buttonExit
			// 
			this.buttonExit.Location = new System.Drawing.Point(8, 176);
			this.buttonExit.Name = "buttonExit";
			this.buttonExit.TabIndex = 26;
			this.buttonExit.Text = "I";
			this.buttonExit.Click += new System.EventHandler(this.buttonExit_Click);
			// 
			// buttonStop
			// 
			this.buttonStop.Location = new System.Drawing.Point(8, 144);
			this.buttonStop.Name = "buttonStop";
			this.buttonStop.TabIndex = 24;
			this.buttonStop.Text = "W~";
			this.buttonStop.Click += new System.EventHandler(this.buttonStop_Click);
			// 
			// buttonInfo
			// 
			this.buttonInfo.Location = new System.Drawing.Point(8, 112);
			this.buttonInfo.Name = "buttonInfo";
			this.buttonInfo.TabIndex = 23;
			this.buttonInfo.Text = "Ԏ擾";
			this.buttonInfo.Click += new System.EventHandler(this.buttonInfo_Click);
			// 
			// buttonStart
			// 
			this.buttonStart.Location = new System.Drawing.Point(8, 80);
			this.buttonStart.Name = "buttonStart";
			this.buttonStart.TabIndex = 22;
			this.buttonStart.Text = "WJn";
			this.buttonStart.Click += new System.EventHandler(this.buttonStart_Click);
			// 
			// buttonInit
			// 
			this.buttonInit.Location = new System.Drawing.Point(8, 48);
			this.buttonInit.Name = "buttonInit";
			this.buttonInit.TabIndex = 21;
			this.buttonInit.Text = "";
			this.buttonInit.Click += new System.EventHandler(this.buttonInit_Click);
			// 
			// textBoxDevice1
			// 
			this.textBoxDevice1.Location = new System.Drawing.Point(8, 16);
			this.textBoxDevice1.Name = "textBoxDevice1";
			this.textBoxDevice1.Size = new System.Drawing.Size(72, 19);
			this.textBoxDevice1.TabIndex = 20;
			this.textBoxDevice1.Text = "DIG000";
			// 
			// listBoxData2
			// 
			this.listBoxData2.ItemHeight = 12;
			this.listBoxData2.Location = new System.Drawing.Point(272, 96);
			this.listBoxData2.Name = "listBoxData2";
			this.listBoxData2.Size = new System.Drawing.Size(160, 148);
			this.listBoxData2.TabIndex = 43;
			// 
			// textBoxInfo2
			// 
			this.textBoxInfo2.Location = new System.Drawing.Point(264, 304);
			this.textBoxInfo2.Multiline = true;
			this.textBoxInfo2.Name = "textBoxInfo2";
			this.textBoxInfo2.ReadOnly = true;
			this.textBoxInfo2.Size = new System.Drawing.Size(176, 40);
			this.textBoxInfo2.TabIndex = 42;
			this.textBoxInfo2.Text = "";
			// 
			// labelStatus2
			// 
			this.labelStatus2.Location = new System.Drawing.Point(344, 288);
			this.labelStatus2.Name = "labelStatus2";
			this.labelStatus2.Size = new System.Drawing.Size(72, 16);
			this.labelStatus2.TabIndex = 41;
			this.labelStatus2.Text = "0H";
			// 
			// labelCount2
			// 
			this.labelCount2.Location = new System.Drawing.Point(344, 264);
			this.labelCount2.Name = "labelCount2";
			this.labelCount2.Size = new System.Drawing.Size(72, 16);
			this.labelCount2.TabIndex = 40;
			this.labelCount2.Text = "0";
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(264, 288);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(64, 16);
			this.label7.TabIndex = 39;
			this.label7.Text = "Xe[^X";
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(264, 264);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(80, 16);
			this.label8.TabIndex = 38;
			this.label8.Text = "TvO";
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.comboBoxRange2,
																					this.label9,
																					this.textBoxDevice2});
			this.groupBox2.Location = new System.Drawing.Point(264, 16);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(176, 240);
			this.groupBox2.TabIndex = 37;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "foCX2";
			// 
			// comboBoxRange2
			// 
			this.comboBoxRange2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.comboBoxRange2.Location = new System.Drawing.Point(8, 56);
			this.comboBoxRange2.Name = "comboBoxRange2";
			this.comboBoxRange2.Size = new System.Drawing.Size(160, 20);
			this.comboBoxRange2.TabIndex = 28;
			this.comboBoxRange2.SelectedIndexChanged += new System.EventHandler(this.comboBoxRange2_SelectedIndexChanged);
			// 
			// label9
			// 
			this.label9.Location = new System.Drawing.Point(8, 40);
			this.label9.Name = "label9";
			this.label9.Size = new System.Drawing.Size(64, 16);
			this.label9.TabIndex = 27;
			this.label9.Text = "W";
			// 
			// textBoxDevice2
			// 
			this.textBoxDevice2.Location = new System.Drawing.Point(8, 16);
			this.textBoxDevice2.Name = "textBoxDevice2";
			this.textBoxDevice2.Size = new System.Drawing.Size(72, 19);
			this.textBoxDevice2.TabIndex = 20;
			this.textBoxDevice2.Text = "DIG001";
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
			this.ClientSize = new System.Drawing.Size(448, 350);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.listBoxData2,
																		  this.textBoxInfo2,
																		  this.labelStatus2,
																		  this.labelCount2,
																		  this.label7,
																		  this.label8,
																		  this.groupBox2,
																		  this.listBoxData1,
																		  this.textBoxInfo1,
																		  this.labelStatus1,
																		  this.labelCount1,
																		  this.label6,
																		  this.label5,
																		  this.buttonExit,
																		  this.buttonStop,
																		  this.buttonInfo,
																		  this.buttonStart,
																		  this.buttonInit,
																		  this.groupBox1});
			this.MaximizeBox = false;
			this.Name = "Form1";
			this.Text = "2foCXpTvO";
			this.Load += new System.EventHandler(this.Form1_Load);
			this.Closed += new System.EventHandler(this.Form1_Closed);
			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 Form1());
		}
		/// <summary>
		/// tH[
		/// </summary>
		private void Form1_Load(object sender, System.EventArgs e)
		{
			// ̓WpR{{bNX̍쐬

			// foCX1
			comboBoxRange1.ResetText();
			comboBoxRange1.Items.AddRange(new object[]
				{
					"-20 - +20V",
					"-10 - +10V",
					"-5 - +5V",
					"-2 - +2V",
					"-1 - +1V",
					"-0.5 - +0.5V",
					"-0.2 - +0.2V",
					"-0.1 - +0.1V",
					"-0.05 - +0.05V",
					"-0.02 - +0.02V"}
				);

			// foCX2
			comboBoxRange2.ResetText();
			comboBoxRange2.Items.AddRange(new object[]
				{
					"-20 - +20V",
					"-10 - +10V",
					"-5 - +5V",
					"-2 - +2V",
					"-1 - +1V",
					"-0.5 - +0.5V",
					"-0.2 - +0.2V",
					"-0.1 - +0.1V",
					"-0.05 - +0.05V",
					"-0.02 - +0.02V"}
				);
		}

		/// <summary>
		/// 
		/// </summary>
		private void buttonInit_Click(object sender, System.EventArgs e)
		{
			int		Ret;
			string	ErrorString;

			//-------------------------------------
			// foCX1
			//-------------------------------------
			//--------------------------------
			// 
			//--------------------------------
			Ret = dig.Init(textBoxDevice1.Text, out m_Id1);
			if(Ret != 0)
			{
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo1.Text = "dig.Init = " + Ret.ToString() + " : " + ErrorString;
				return;
			}

			//--------------------------------
			// foCX̃Zbg
			//--------------------------------
			Ret = dig.ResetDevice(m_Id1);
			if(Ret != 0)
			{
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo1.Text = "dig.ResetDevice = " + Ret.ToString() + " : " + ErrorString;
				return;
			}

			textBoxInfo1.Text = " : I";

			//-------------------------------------
			// foCX2
			//-------------------------------------
			//--------------------------------
			// 
			//--------------------------------
			Ret = dig.Init(textBoxDevice2.Text, out m_Id2);
			if(Ret != 0)
			{
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo2.Text = "dig.Init = " + Ret.ToString() + " : " + ErrorString;
				return;
			}

			//--------------------------------
			// foCX̃Zbg
			//--------------------------------
			Ret = dig.ResetDevice(m_Id2);
			if(Ret != 0)
			{
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo2.Text = "dig.ResetDevice = " + Ret.ToString() + " : " + ErrorString;
				return;
			}

			textBoxInfo2.Text = " : I";
		}

		/// <summary>
		/// foCX1̓W̐ݒ
		/// </summary>
		private void comboBoxRange1_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			int		Index;		// R{{bNX̃CfbNX
			float	Range;		// ̓Wl
			Index = comboBoxRange1.SelectedIndex;
			switch(Index)
			{
				case 0:	Range = Cdig.DIG_RANGE_40VPP;	break;
				case 1:	Range = Cdig.DIG_RANGE_20VPP;	break;
				case 2:	Range = Cdig.DIG_RANGE_10VPP;	break;
				case 3:	Range = Cdig.DIG_RANGE_4VPP;	break;
				case 4:	Range = Cdig.DIG_RANGE_2VPP;	break;
				case 5:	Range = Cdig.DIG_RANGE_1VPP;	break;
				case 6:	Range = Cdig.DIG_RANGE_400MVPP;	break;
				case 7:	Range = Cdig.DIG_RANGE_200MVPP;	break;
				case 8:	Range = Cdig.DIG_RANGE_100MVPP;	break;
				case 9:	Range = Cdig.DIG_RANGE_40MVPP;	break;
				default:Range = 0;						break;
			}

			//--------------------------
			// ̓W̐ݒ
			//--------------------------
			int		Ret;
			Ret = dig.SetRange(m_Id1, Cdig.DIG_CHANNEL0, Range);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo1.Text = "dig.SetRange = " + Ret.ToString() + " : " + ErrorString;
				return;
			}

			textBoxInfo1.Text = "Wݒ : I";
		}

		/// <summary>
		/// foCX2̓W̐ݒ
		/// </summary>
		private void comboBoxRange2_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			int		Index;		// R{{bNX̃CfbNX
			float	Range;		// ̓Wl
			Index = comboBoxRange2.SelectedIndex;
			switch(Index)
			{
				case 0:	Range = Cdig.DIG_RANGE_40VPP;	break;
				case 1:	Range = Cdig.DIG_RANGE_20VPP;	break;
				case 2:	Range = Cdig.DIG_RANGE_10VPP;	break;
				case 3:	Range = Cdig.DIG_RANGE_4VPP;	break;
				case 4:	Range = Cdig.DIG_RANGE_2VPP;	break;
				case 5:	Range = Cdig.DIG_RANGE_1VPP;	break;
				case 6:	Range = Cdig.DIG_RANGE_400MVPP;	break;
				case 7:	Range = Cdig.DIG_RANGE_200MVPP;	break;
				case 8:	Range = Cdig.DIG_RANGE_100MVPP;	break;
				case 9:	Range = Cdig.DIG_RANGE_40MVPP;	break;
				default:Range = 0;						break;
			}

			//--------------------------
			// ̓W̐ݒ
			//--------------------------
			int		Ret;
			Ret = dig.SetRange(m_Id2, Cdig.DIG_CHANNEL0, Range);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo2.Text = "dig.SetRange = " + Ret.ToString() + " : " + ErrorString;
				return;
			}

			textBoxInfo2.Text = "Wݒ : I";
		}

		/// <summary>
		/// WJn
		/// </summary>
		private void buttonStart_Click(object sender, System.EventArgs e)
		{
			int		Ret;		// ߂l
			//---------------------------------
			// ϐ
			//---------------------------------
			m_Samples1 = 0;
			m_Samples2 = 0;
			listBoxData1.Items.Clear();
			listBoxData2.Items.Clear();

			//-------------------------------------------
			// foCX1
			//-------------------------------------------
			//---------------------------------
			// 샂[hݒFf[^K[[h
			//---------------------------------
			Ret = dig.SetDigitizerMode(m_Id1, Cdig.DIG_MODE_LOGGER);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo1.Text = "dig.SetDigitizerMode = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			//---------------------------------
			// CxgRg[jbgݒFoXM1 - vgK
			//---------------------------------
			Ret = dig.SetEcuSignal(m_Id1, Cdig.DIG_ECU_DEST_SYNC1, Cdig.DIG_ECU_SRC_PRETRG);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo1.Text = "dig.SetEcuSignal = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			//---------------------------------
			// TvONbN\[XݒF{[hU
			//---------------------------------
			Ret = dig.SetClockSource(m_Id1, Cdig.DIG_ECU_SRC_CLOCK);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo1.Text = "dig.SetClockSource = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			//---------------------------------
			// TvONbNݒF1000usec (ݒl * 10 + 10(nsec))
			//---------------------------------
			Ret = dig.SetSampleClock(m_Id1, 99999);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo1.Text = "dig.SetSampleClock = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			//---------------------------------
			// R[hW񐔐ݒF1
			//---------------------------------
			Ret = dig.SetRecordNumber(m_Id1, 1);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo1.Text = "dig.SetRecordNumber = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			//---------------------------------
			// vgKTvݒF1000Tv
			//---------------------------------
			Ret = dig.SetPreSampleTimes(m_Id1, MAX_SAMPLES);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo1.Text = "dig.SetPreSampleTimes = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			//---------------------------------
			// |XggKTvݒFȂ
			//---------------------------------
			Ret = dig.SetPostSampleTimes(m_Id1, 0);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo1.Text = "dig.SetPostSampleTimes = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			//---------------------------------
			// `lݒF0`l̂ݗL
			//---------------------------------
			// 0`lLɂ
			Ret = dig.SetChannel(m_Id1, Cdig.DIG_CHANNEL0, Cdig.DIG_ENABLE);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo1.Text = "dig.SetChannel = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			// 1`l𖳌ɂ
			Ret = dig.SetChannel(m_Id1, Cdig.DIG_CHANNEL1, Cdig.DIG_DISABLE);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo1.Text = "dig.SetChannel = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			//---------------------------------
			// vgKނ̐ݒF
			//---------------------------------
			Ret = dig.SetPreTriggerType(m_Id1, Cdig.DIG_TRIGGERTYPE_AUTO);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo1.Text = "dig.SetPreTriggerType = " + Ret.ToString() + " : " + ErrorString;
				return;
			}

			//-------------------------------------------
			// foCX2
			//-------------------------------------------
			//---------------------------------
			// 샂[hݒFf[^K[[h
			//---------------------------------
			Ret = dig.SetDigitizerMode(m_Id2, Cdig.DIG_MODE_LOGGER);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo2.Text = "dig.SetDigitizerMode = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			//---------------------------------
			// TvONbN\[XݒF{[hU
			//---------------------------------
			Ret = dig.SetClockSource(m_Id2, Cdig.DIG_ECU_SRC_CLOCK);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo2.Text = "dig.SetClockSource = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			//---------------------------------
			// TvONbNݒF1000usec (ݒl * 10 + 10(nsec))
			//---------------------------------
			Ret = dig.SetSampleClock(m_Id2, 99999);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo2.Text = "dig.SetSampleClock = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			//---------------------------------
			// R[hW񐔐ݒF1
			//---------------------------------
			Ret = dig.SetRecordNumber(m_Id2, 1);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo2.Text = "dig.SetRecordNumber = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			//---------------------------------
			// vgKTvݒF1000Tv
			//---------------------------------
			Ret = dig.SetPreSampleTimes(m_Id2, MAX_SAMPLES);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo2.Text = "dig.SetPreSampleTimes = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			//---------------------------------
			// |XggKTvݒFȂ
			//---------------------------------
			Ret = dig.SetPostSampleTimes(m_Id2, 0);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo2.Text = "dig.SetPostSampleTimes = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			//---------------------------------
			// `lݒF0`l̂ݗL
			//---------------------------------
			// 0`lLɂ
			Ret = dig.SetChannel(m_Id2, Cdig.DIG_CHANNEL0, Cdig.DIG_ENABLE);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo2.Text = "dig.SetChannel = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			// 1`l𖳌ɂ
			Ret = dig.SetChannel(m_Id2, Cdig.DIG_CHANNEL1, Cdig.DIG_DISABLE);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo2.Text = "dig.SetChannel = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			//---------------------------------
			// vgKނ̐ݒFfW^GbW
			//---------------------------------
			Ret = dig.SetPreTriggerType(m_Id2, Cdig.DIG_TRIGGERTYPE_DIEDGE);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo2.Text = "dig.SetPreTriggerType = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			//---------------------------------
			// vgK̐ݒFM=oX1, =, =1
			//---------------------------------
			Ret = dig.SetPreTriggerDiEdge(m_Id2, Cdig.DIG_ECU_SRC_SYNC1, 0, 1);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo2.Text = "dig.SetPreTriggerDiEdge = " + Ret.ToString() + " : " + ErrorString;
				return;
			}

			//---------------------------------
			// JnFfoCX2ɃX^[g܂B
			//---------------------------------
			Ret = dig.Start(m_Id2);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo2.Text = "dig.Start = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			textBoxInfo2.Text = "WJn : I";

			Ret = dig.Start(m_Id1);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo1.Text = "dig.Start = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			textBoxInfo1.Text = "WJn : I";

			//---------------------------------
			// 쒆Xe[^XOFFɂȂ܂Ń|[O
			//---------------------------------
			int Status1, Status2;

			do
			{
				//---------------------------------
				// _CAOLɂ邽߂̏
				//---------------------------------
				System.Windows.Forms.Application.DoEvents();
				//------------------------------------------------------------
				// foCX1
				//------------------------------------------------------------
				//---------------------------------
				// hCoɊi[ꂽTv擾
				//---------------------------------
				Ret = dig.GetDriverMemorySamples(m_Id1, out m_Samples1);
				if(Ret != 0)
				{
					string ErrorString;
					dig.GetErrorString(Ret, out ErrorString);
					textBoxInfo1.Text = "dig.GetDriverMemorySamples = " + Ret.ToString() + " : " + ErrorString;
					return;
				}
				labelCount1.Text = m_Samples1.ToString();
				//---------------------------------
				// Xe[^X̎擾
				//---------------------------------
				Ret = dig.GetStatus(m_Id1, out Status1);
				if(Ret != 0)
				{
					string ErrorString;
					dig.GetErrorString(Ret, out ErrorString);
					textBoxInfo1.Text = "dig.GetStatus = " + Ret.ToString() + " : " + ErrorString;
					return;
				}
				labelStatus1.Text = Status1.ToString("X") + "H";
				//------------------------------------------------------------
				// foCX2
				//------------------------------------------------------------
				//---------------------------------
				// hCoɊi[ꂽTv擾
				//---------------------------------
				Ret = dig.GetDriverMemorySamples(m_Id2, out m_Samples2);
				if(Ret != 0)
				{
					string ErrorString;
					dig.GetErrorString(Ret, out ErrorString);
					textBoxInfo2.Text = "dig.GetDriverMemorySamples = " + Ret.ToString() + " : " + ErrorString;
					return;
				}
				labelCount2.Text = m_Samples2.ToString();
				//---------------------------------
				// Xe[^X̎擾
				//---------------------------------
				Ret = dig.GetStatus(m_Id2, out Status2);
				if(Ret != 0)
				{
					string ErrorString;
					dig.GetErrorString(Ret, out ErrorString);
					textBoxInfo2.Text = "dig.GetStatus = " + Ret.ToString() + " : " + ErrorString;
					return;
				}
				labelStatus2.Text = Status2.ToString("X") + "H";
			}while(((Status1 | Status2) & Cdig.DIG_STATUS_BUSY) == Cdig.DIG_STATUS_BUSY);

			//------------------------------------------------------------
			// foCX1
			//------------------------------------------------------------
			//---------------------------------
			// ~ɃhCoɊi[ĂTv擾
			//---------------------------------
			Ret = dig.GetDriverMemorySamples(m_Id1, out m_Samples1);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo1.Text = "dig.GetDriverMemorySamples = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			labelCount1.Text = m_Samples1.ToString();
			//---------------------------------
			// Wf[^擾
			//---------------------------------
			int TriggerPoint1;			// |XggK̐擪f[^ʒu
			if(m_Samples1 > 0)
			{
				// 擾TvOf[^i[zTCYȂ悤
				if(m_Samples1 > MAX_SAMPLES)
				{
					m_Samples1 = MAX_SAMPLES;
				}
				Ret = dig.ReadSamples(m_Id1, ref m_Samples1, ref m_Data1, out TriggerPoint1);
				if(Ret != 0)
				{
					string ErrorString;
					dig.GetErrorString(Ret, out ErrorString);
					textBoxInfo1.Text = "dig.ReadSamples = " + Ret.ToString() + " : " + ErrorString;
					return;
				}
				//---------------------------------
				// 擾f[^\
				//---------------------------------
				for(int i = 0; i < m_Samples1; i++)
				{
					listBoxData1.Items.Add(String.Format("{0:D}\t{1:F3}", i+1, m_Data1[i])); 
				}
			}

			//------------------------------------------------------------
			// foCX2
			//------------------------------------------------------------
			//---------------------------------
			// ~ɃhCoɊi[ĂTv擾
			//---------------------------------
			Ret = dig.GetDriverMemorySamples(m_Id2, out m_Samples2);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo2.Text = "dig.GetDriverMemorySamples = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			labelCount2.Text = m_Samples2.ToString();
			//---------------------------------
			// Wf[^擾
			//---------------------------------
			int TriggerPoint2;			// |XggK̐擪f[^ʒu
			if(m_Samples2 > 0)
			{
				// 擾TvOf[^i[zTCYȂ悤
				if(m_Samples2 > MAX_SAMPLES)
				{
					m_Samples2 = MAX_SAMPLES;
				}
				Ret = dig.ReadSamples(m_Id2, ref m_Samples2, ref m_Data2, out TriggerPoint2);
				if(Ret != 0)
				{
					string ErrorString;
					dig.GetErrorString(Ret, out ErrorString);
					textBoxInfo2.Text = "dig.ReadSamples = " + Ret.ToString() + " : " + ErrorString;
					return;
				}
				//---------------------------------
				// 擾f[^\
				//---------------------------------
				for(int i = 0; i < m_Samples2; i++)
				{
					listBoxData2.Items.Add(String.Format("{0:D}\t{1:F3}", i+1, m_Data2[i])); 
				}
			}
		}

		/// <summary>
		/// Ԏ擾
		/// </summary>
		private void buttonInfo_Click(object sender, System.EventArgs e)
		{
			int		Ret;		// ߂l
			int		Status;		// Xe[^X
			int		Samples;	// Tv

			//------------------------------------------------------------
			// foCX1
			//------------------------------------------------------------
			//---------------------------------
			// hCoɊi[ꂽTv擾
			//---------------------------------
			Ret = dig.GetDriverMemorySamples(m_Id1, out Samples);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo1.Text = "dig.GetDriverMemorySamples = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			labelCount1.Text = Samples.ToString();
			//---------------------------------
			// Xe[^X̎擾
			//---------------------------------
			Ret = dig.GetStatus(m_Id1, out Status);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo1.Text = "dig.GetStatus = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			labelStatus1.Text = Status.ToString("X") + "H";
			textBoxInfo1.Text = "Ԏ擾 : I";

			//------------------------------------------------------------
			// foCX2
			//------------------------------------------------------------
			//---------------------------------
			// hCoɊi[ꂽTv擾
			//---------------------------------
			Ret = dig.GetDriverMemorySamples(m_Id2, out Samples);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo2.Text = "dig.GetDriverMemorySamples = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			labelCount2.Text = Samples.ToString();
			//---------------------------------
			// Xe[^X̎擾
			//---------------------------------
			Ret = dig.GetStatus(m_Id2, out Status);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo2.Text = "dig.GetStatus = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			labelStatus2.Text = Status.ToString("X") + "H";
			textBoxInfo2.Text = "Ԏ擾 : I";
		}

		/// <summary>
		/// W~
		/// </summary>
		private void buttonStop_Click(object sender, System.EventArgs e)
		{
			int		Ret;		// ߂l

			//------------------------------------------------------------
			// foCX1
			//------------------------------------------------------------
			Ret = dig.Stop(m_Id1);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo1.Text = "dig.Stop = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			textBoxInfo1.Text = "W~ : I";

			//------------------------------------------------------------
			// foCX2
			//------------------------------------------------------------
			Ret = dig.Stop(m_Id2);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo2.Text = "dig.Stop = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			textBoxInfo2.Text = "W~ : I";
		}

		/// <summary>
		/// I
		/// </summary>
		private void buttonExit_Click(object sender, System.EventArgs e)
		{
			int		Ret;	// ߂l

			//------------------------------------------------------------
			// foCX1
			//------------------------------------------------------------
			Ret = dig.Exit(m_Id1);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo1.Text = "dig.Exit = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			textBoxInfo1.Text = "I : I";
			//------------------------------------------------------------
			// foCX2
			//------------------------------------------------------------
			Ret = dig.Exit(m_Id2);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo2.Text = "dig.Exit = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			textBoxInfo2.Text = "I : I";
		}

		/// <summary>
		/// tH[I
		/// </summary>
		private void Form1_Closed(object sender, System.EventArgs e)
		{
			// I
			dig.Exit(m_Id1);
			dig.Exit(m_Id2);
		}
	}
}
