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

namespace WaveformJudgement1
{
	/// <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 = 512;					// R[h̐ݒ

		public short	m_Id;									// foCXID
		public int[]	m_Data = new int[MAX_SAMPLES];			// 擾f[^̔z
		public int[]	m_UpperData = new int[MAX_SAMPLES];		// f[^̔z
		public int[]	m_LowerData = new int[MAX_SAMPLES];		// f[^̔z
		public short[]	m_Judge = new short[1];					// R[hg`茋
		public short[]	m_JudgeDetail = new short[MAX_SAMPLES];	// g`茋ʏڍ
		public int		m_Records;								// 擾R[h
		public int		m_Resolution;							// foCX̕\
		public Bitmap	bmp;									// rbg}bv

		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox textBoxDevice;
		private System.Windows.Forms.Button buttonInit;
		private System.Windows.Forms.Button buttonSetting;
		private System.Windows.Forms.Button buttonStart;
		private System.Windows.Forms.Button buttonInfo;
		private System.Windows.Forms.Button buttonStop;
		private System.Windows.Forms.Button buttonExit;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label labelJudgeCount;
		private System.Windows.Forms.Label labelStatus;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.TextBox textBoxInfo;
		private System.Windows.Forms.PictureBox Graph;
		/// <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.label1 = new System.Windows.Forms.Label();
			this.textBoxDevice = new System.Windows.Forms.TextBox();
			this.buttonInit = new System.Windows.Forms.Button();
			this.buttonSetting = new System.Windows.Forms.Button();
			this.buttonStart = new System.Windows.Forms.Button();
			this.buttonInfo = new System.Windows.Forms.Button();
			this.buttonStop = new System.Windows.Forms.Button();
			this.buttonExit = new System.Windows.Forms.Button();
			this.Graph = new System.Windows.Forms.PictureBox();
			this.label2 = new System.Windows.Forms.Label();
			this.labelJudgeCount = new System.Windows.Forms.Label();
			this.labelStatus = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.textBoxInfo = new System.Windows.Forms.TextBox();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 8);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(64, 16);
			this.label1.TabIndex = 0;
			this.label1.Text = "foCX";
			// 
			// textBoxDevice
			// 
			this.textBoxDevice.Location = new System.Drawing.Point(8, 24);
			this.textBoxDevice.Name = "textBoxDevice";
			this.textBoxDevice.Size = new System.Drawing.Size(80, 19);
			this.textBoxDevice.TabIndex = 1;
			this.textBoxDevice.Text = "DIG000";
			// 
			// buttonInit
			// 
			this.buttonInit.Location = new System.Drawing.Point(8, 48);
			this.buttonInit.Name = "buttonInit";
			this.buttonInit.Size = new System.Drawing.Size(80, 23);
			this.buttonInit.TabIndex = 2;
			this.buttonInit.Text = "";
			this.buttonInit.Click += new System.EventHandler(this.buttonInit_Click);
			// 
			// buttonSetting
			// 
			this.buttonSetting.Location = new System.Drawing.Point(8, 80);
			this.buttonSetting.Name = "buttonSetting";
			this.buttonSetting.Size = new System.Drawing.Size(80, 23);
			this.buttonSetting.TabIndex = 3;
			this.buttonSetting.Text = "ݒ";
			this.buttonSetting.Click += new System.EventHandler(this.buttonSetting_Click);
			// 
			// buttonStart
			// 
			this.buttonStart.Location = new System.Drawing.Point(8, 112);
			this.buttonStart.Name = "buttonStart";
			this.buttonStart.Size = new System.Drawing.Size(80, 23);
			this.buttonStart.TabIndex = 4;
			this.buttonStart.Text = "Jn";
			this.buttonStart.Click += new System.EventHandler(this.buttonStart_Click);
			// 
			// buttonInfo
			// 
			this.buttonInfo.Location = new System.Drawing.Point(8, 144);
			this.buttonInfo.Name = "buttonInfo";
			this.buttonInfo.Size = new System.Drawing.Size(80, 23);
			this.buttonInfo.TabIndex = 5;
			this.buttonInfo.Text = "Ԏ擾";
			this.buttonInfo.Click += new System.EventHandler(this.buttonInfo_Click);
			// 
			// buttonStop
			// 
			this.buttonStop.Location = new System.Drawing.Point(8, 176);
			this.buttonStop.Name = "buttonStop";
			this.buttonStop.Size = new System.Drawing.Size(80, 23);
			this.buttonStop.TabIndex = 6;
			this.buttonStop.Text = "~";
			this.buttonStop.Click += new System.EventHandler(this.buttonStop_Click);
			// 
			// buttonExit
			// 
			this.buttonExit.Location = new System.Drawing.Point(8, 208);
			this.buttonExit.Name = "buttonExit";
			this.buttonExit.Size = new System.Drawing.Size(80, 23);
			this.buttonExit.TabIndex = 7;
			this.buttonExit.Text = "I";
			this.buttonExit.Click += new System.EventHandler(this.buttonExit_Click);
			// 
			// Graph
			// 
			this.Graph.BackColor = System.Drawing.Color.White;
			this.Graph.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.Graph.Location = new System.Drawing.Point(96, 8);
			this.Graph.Name = "Graph";
			this.Graph.Size = new System.Drawing.Size(312, 224);
			this.Graph.TabIndex = 8;
			this.Graph.TabStop = false;
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(8, 240);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(56, 16);
			this.label2.TabIndex = 9;
			this.label2.Text = "NG";
			// 
			// labelJudgeCount
			// 
			this.labelJudgeCount.Location = new System.Drawing.Point(64, 240);
			this.labelJudgeCount.Name = "labelJudgeCount";
			this.labelJudgeCount.Size = new System.Drawing.Size(96, 16);
			this.labelJudgeCount.TabIndex = 10;
			this.labelJudgeCount.Text = "0";
			// 
			// labelStatus
			// 
			this.labelStatus.Location = new System.Drawing.Point(256, 240);
			this.labelStatus.Name = "labelStatus";
			this.labelStatus.Size = new System.Drawing.Size(96, 16);
			this.labelStatus.TabIndex = 12;
			this.labelStatus.Text = "0H";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(192, 240);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(56, 16);
			this.label4.TabIndex = 11;
			this.label4.Text = "Xe[^X";
			// 
			// textBoxInfo
			// 
			this.textBoxInfo.Location = new System.Drawing.Point(8, 264);
			this.textBoxInfo.Name = "textBoxInfo";
			this.textBoxInfo.ReadOnly = true;
			this.textBoxInfo.Size = new System.Drawing.Size(400, 19);
			this.textBoxInfo.TabIndex = 13;
			this.textBoxInfo.Text = "";
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
			this.ClientSize = new System.Drawing.Size(416, 294);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.textBoxInfo,
																		  this.labelStatus,
																		  this.label4,
																		  this.labelJudgeCount,
																		  this.label2,
																		  this.Graph,
																		  this.buttonExit,
																		  this.buttonStop,
																		  this.buttonInfo,
																		  this.buttonStart,
																		  this.buttonSetting,
																		  this.buttonInit,
																		  this.textBoxDevice,
																		  this.label1});
			this.MaximizeBox = false;
			this.Name = "Form1";
			this.Text = "g`@1(p}XNf[^)";
			this.Closed += new System.EventHandler(this.Form1_Closed);
			this.Load += new System.EventHandler(this.Form1_Load);
			this.ResumeLayout(false);

		}
		#endregion

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

		private void Form1_Load(object sender, EventArgs e)
		{
			bmp = new Bitmap(Graph.Size.Width, Graph.Size.Height);	// OtƓTCỸrbg}bv𐶐
		}

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

			//--------------------------------
			// 
			//--------------------------------
			Ret = dig.Init(textBoxDevice.Text, out m_Id);
			if(Ret != 0)
			{
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo.Text = "dig.Init = " + Ret.ToString() + " : " + ErrorString;
				return;
			}

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

			textBoxInfo.Text = " : I";
		}

		/// <summary>
		/// foCXݒ
		/// </summary>
		private void buttonSetting_Click(object sender, System.EventArgs e)
		{
			int		Ret;

			//----------------------------------
			// ϐ
			//----------------------------------
			m_Records = 0;
			m_Resolution = 1024;   // DIG-100M1002-PCIpAŒݒ

			//---------------------------------
			// 샂[hݒFg`@[h
			//---------------------------------
			Ret = dig.SetDigitizerMode(m_Id, Cdig.DIG_MODE_JUDGE);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo.Text = "dig.SetDigitizerMode = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			//---------------------------------
			// ~vݒFTvONbNG[Ag`JEgvA
			//      foCXI[o[t[
			//---------------------------------
			Ret = dig.SetHaltCondition(m_Id, Cdig.DIG_HALT_CLOCK_ERROR | Cdig.DIG_HALT_JUDGE_COUNT | Cdig.DIG_HALT_DEVMEM_OVERFLOW);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo.Text = "dig.SetHaltCondition = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			//---------------------------------
			// TvONbN\[XݒF{[hU
			//---------------------------------
			Ret = dig.SetClockSource(m_Id, Cdig.DIG_ECU_SRC_CLOCK);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo.Text = "dig.SetClockSource = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			//---------------------------------
			// TvO[gݒF1MHz
			//---------------------------------
			Ret = dig.SetSampleRate(m_Id, 1000000);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo.Text = "dig.SetSampleRate = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			//---------------------------------
			// R[hݒF512Tv
			//---------------------------------
			Ret = dig.SetRecordLength(m_Id, MAX_SAMPLES);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo.Text = "dig.SetRecordLength = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			//---------------------------------
			// R[hW񐔐ݒF
			//---------------------------------
			Ret = dig.SetRecordNumber(m_Id, 0);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo.Text = "dig.SetRecordNumber = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			//---------------------------------
			// f[eBݒF50%
			//---------------------------------
			Ret = dig.SetDutyCycle(m_Id, 50.0f);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo.Text = "dig.SetDutyCycle = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			//---------------------------------
			// `lݒF0`l̂ݗL
			//---------------------------------
			// 0`lLɂ
			Ret = dig.SetChannel(m_Id, Cdig.DIG_CHANNEL0, Cdig.DIG_ENABLE);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo.Text = "dig.SetChannel = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			// 1`l𖳌ɂ
			Ret = dig.SetChannel(m_Id, Cdig.DIG_CHANNEL1, Cdig.DIG_DISABLE);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo.Text = "dig.SetChannel = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			//---------------------------------
			// WݒF}20V
			//---------------------------------
			Ret = dig.SetRange(m_Id, Cdig.DIG_CHANNEL0, Cdig.DIG_RANGE_40VPP);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo.Text = "dig.SetRange = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			//---------------------------------
			// vgKނ̐ݒF
			//---------------------------------
			Ret = dig.SetPreTriggerType(m_Id, Cdig.DIG_TRIGGERTYPE_AUTO);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo.Text = "dig.SetPreTriggerType = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			//---------------------------------
			// |XggKނ̐ݒFAiOGbW
			//---------------------------------
			Ret = dig.SetPostTriggerType(m_Id, Cdig.DIG_TRIGGERTYPE_AIEDGE);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo.Text = "dig.SetPostTriggerType = " + Ret.ToString() + " : " + ErrorString;
				return;
			}			
			//---------------------------------
			// |XggK̏ڍאݒFgKM0`lAgKx0VAGbWA1
			//---------------------------------
			Ret = dig.SetPostTriggerAiEdge(m_Id, Cdig.DIG_CHANNEL0, 0.0f, Cdig.DIG_TRIGGER_SLOPE_RISE, 1);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo.Text = "dig.SetPostTriggerAiEdge = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			//---------------------------------
			// g``lݒF0`l
			//---------------------------------
			Ret = dig.SetJudgeChannel(m_Id, Cdig.DIG_CHANNEL0, Cdig.DIG_ENABLE);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo.Text = "dig.SetJudgeChannel = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			//---------------------------------
			// g`茋ʃJEgݒFs񐔂JEgAJEg1
			//---------------------------------
			Ret = dig.SetJudgeCountLimit(m_Id, Cdig.DIG_CHANNEL0, Cdig.DIG_JUDGE_NG, 1);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo.Text = "dig.SetJudgeCountLimit = " + Ret.ToString() + " : " + ErrorString;
				return;
			}

			//----------------------------------
			// g`pf[^ݒF}[W}10f[^A}[W}50f[^AVK쐬
			//----------------------------------
			Ret = dig.SetAutoMask(m_Id, Cdig.DIG_CHANNEL0, 10, 50, Cdig.DIG_AUTOMASK_NEW);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo.Text = "dig.SetAutoMask = " + Ret.ToString() + " : " + ErrorString;
				return;
			}

			// ۂɐݒ肳ꂽf[^擾
			Ret = dig.GetJudgeData32(m_Id, Cdig.DIG_CHANNEL0, MAX_SAMPLES, ref m_UpperData, ref m_LowerData);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo.Text = "dig.GetJudgeData = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			textBoxInfo.Text = "foCXݒ : I";
		}

		/// <summary>
		/// g`Jn
		/// </summary>
		private void buttonStart_Click(object sender, System.EventArgs e)
		{
			int		Ret;		// ߂l
			//---------------------------------
			// ϐ
			//---------------------------------
			m_Records = 0;

			//---------------------------------
			// Jn
			//---------------------------------
			Ret = dig.Start(m_Id);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo.Text = "dig.Start = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			textBoxInfo.Text = "Jn : I";

			//---------------------------------
			// 쒆Xe[^XOFFɂȂ܂Ń|[O
			//---------------------------------
			int Status;
			int NgCount;

			do
			{
				//---------------------------------
				// _CAOLɂ邽߂̏
				//---------------------------------
				System.Windows.Forms.Application.DoEvents();
				//---------------------------------
				//hCoɊi[Ă郌R[h擾
				//---------------------------------
				Ret = dig.GetDriverMemoryRecords(m_Id, out m_Records);
				if(Ret != 0)
				{
					string ErrorString;
					dig.GetErrorString(Ret, out ErrorString);
					textBoxInfo.Text = "dig.GetDriverMemoryRecords = " + Ret.ToString() + " : " + ErrorString;
					return;
				}
				//---------------------------------
				// Wf[^擾FŐV1R[h̃f[^擾
				//---------------------------------
				if(m_Records > 0 || m_Records == -1)
				{
					Ret = dig.ReadLatestRecords32(m_Id, Cdig.DIG_RECORD_ALL, 1, ref m_Data, ref m_Judge, ref m_JudgeDetail);
					if(Ret != 0)
					{
						string ErrorString;
						dig.GetErrorString(Ret, out ErrorString);
						textBoxInfo.Text = "dig.ReadEarliestRecords = " + Ret.ToString() + " : " + ErrorString;
						return;
					}
					DrawGraph();
				}
				//---------------------------------
				// g`̎s񐔂擾
				//---------------------------------
				Ret = dig.GetJudgeCount(m_Id, out NgCount);
				if(Ret != 0)
				{
					string ErrorString;
					dig.GetErrorString(Ret, out ErrorString);
					textBoxInfo.Text = "dig.GetJudgeCount = " + Ret.ToString() + " : " + ErrorString;
					return;
				}
				labelJudgeCount.Text = NgCount.ToString();
				//---------------------------------
				// Xe[^X̎擾
				//---------------------------------
				Ret = dig.GetStatus(m_Id, out Status);
				if(Ret != 0)
				{
					string ErrorString;
					dig.GetErrorString(Ret, out ErrorString);
					textBoxInfo.Text = "dig.GetStatus = " + Ret.ToString() + " : " + ErrorString;
					return;
				}
				labelStatus.Text = Status.ToString("X") + "H";
			}while((Status & Cdig.DIG_STATUS_BUSY) == Cdig.DIG_STATUS_BUSY);
			//---------------------------------
			// g`̎s񐔂擾
			//---------------------------------
			Ret = dig.GetJudgeCount(m_Id, out NgCount);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo.Text = "dig.GetJudgeCount = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			labelJudgeCount.Text = NgCount.ToString();
			//---------------------------------
			// ~ɃhCoɊi[Ă郌R[h擾
			//---------------------------------
			Ret = dig.GetDriverMemoryRecords(m_Id, out m_Records);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo.Text = "dig.GetDriverMemoryRecords = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			//---------------------------------
			// Wf[^擾FŐV1R[h̃f[^擾
			//---------------------------------
			if(m_Records > 0 || m_Records == -1)
			{
				Ret = dig.ReadLatestRecords32(m_Id, Cdig.DIG_RECORD_ALL, 1, ref m_Data, ref m_Judge, ref m_JudgeDetail);
				if(Ret != 0)
				{
					string ErrorString;
					dig.GetErrorString(Ret, out ErrorString);
					textBoxInfo.Text = "dig.ReadEarliestRecords = " + Ret.ToString() + " : " + ErrorString;
					return;
				}
				DrawGraph();
			}
		}

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

			//---------------------------------
			// Xe[^X̎擾
			//---------------------------------
			Ret = dig.GetStatus(m_Id, out Status);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo.Text = "dig.GetStatus = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			labelStatus.Text = Status.ToString("X") + "H";
			textBoxInfo.Text = "Ԏ擾 : I";
		}

		/// <summary>
		/// ~
		/// </summary>
		private void buttonStop_Click(object sender, System.EventArgs e)
		{
			int		Ret;		// ߂l
			Ret = dig.Stop(m_Id);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo.Text = "dig.Stop = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			textBoxInfo.Text = "~ : I";
		}

		/// <summary>
		/// I
		/// </summary>
		private void buttonExit_Click(object sender, System.EventArgs e)
		{
			int		Ret;	// ߂l
			Ret = dig.Exit(m_Id);
			if(Ret != 0)
			{
				string ErrorString;
				dig.GetErrorString(Ret, out ErrorString);
				textBoxInfo.Text = "dig.Exit = " + Ret.ToString() + " : " + ErrorString;
				return;
			}
			textBoxInfo.Text = "I : I";
		}

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

		/// <summary>
		/// Ot`
		/// </summary>
		private void DrawGraph()
		{
			float XUnit;	// X`C^[o
			float PosX;		// X`ʒu
			float PosY;		// Y`ʒu
			float OldX;		// XWޔp
			float OldY;		// YWޔp

			//----------------------------------------------------
			// ݂̃f[^Otɕ`悵܂B
			//----------------------------------------------------
			Pen pen = new Pen(System.Drawing.Color.Red, 1);					// ԐFy̍쐬
			Graph.Image = bmp;
			Graphics grp = Graphics.FromImage(Graph.Image);					// rbg}bv`ΏۃIuWFNg𐶐
			grp.Clear(Graph.BackColor);										// OtNA
			XUnit = Graph.Size.Width / (float)(MAX_SAMPLES);				// 1f[^̉ړsNZ

			for(int i = 0; i < 3; i++)
			{
				OldX = 0;
				switch(i)
				{
					// f[^̕`ʒu_ݒ
					case 0:
						OldY = Graph.Height * (m_Resolution - m_UpperData[0]) / (float)m_Resolution;	// Y̍WvZ
						break;
					// f[^̕`ʒu_ݒ
					case 1:
						OldY = Graph.Height * (m_Resolution - m_LowerData[0]) / (float)m_Resolution;	// Y̍WvZ
						break;
					// Wf[^̕`ʒu_ݒ
					default:
						OldY = Graph.Height * (m_Resolution - m_Data[0]) / (float)m_Resolution;		// Y̍WvZ
						break;
				}
				// Y̍W`̈𒴂ꍇ
				if(OldY >= Graph.Height)
				{
					OldY = Graph.Height - 1;			// `ʒȕC
				}
				// Y̍W`̈ꍇ
				else if(OldY < 0)
				{
					OldY = 0;							// `ʒȕC
				}
				//----------------------------------------------------
				// Wf[^A`揈JԂ܂B
				//----------------------------------------------------
				for(int j = 1; j < MAX_SAMPLES; j++)
				{
					PosX = OldX + XUnit;	// X̍WvZ
					switch(i)
					{
						// f[^̕`ʒuݒ
						case 0:
							PosY = Graph.Height * (m_Resolution - m_UpperData[j]) / (float)m_Resolution;	// Y̍WvZ
							break;
						// f[^̕`ʒuݒ
						case 1:
							PosY = Graph.Height * (m_Resolution - m_LowerData[j]) / (float)m_Resolution;	// Y̍WvZ
							break;
						// Wf[^̕`ʒuݒ
						default:
							PosY = Graph.Height * (m_Resolution - m_Data[j]) / (float)m_Resolution;		// Y̍WvZ
							break;
					}
					// Y̍W`̈𒴂ꍇ
					if(PosY >= Graph.Height)
					{
						PosY = Graph.Height - 1;		// `ʒȕC
					}
						// Y̍W`̈ꍇ
					else if(PosY < 0)
					{
						PosY = 0;								// `ʒȕC
					}
					grp.DrawLine(pen, OldX, OldY, PosX, PosY);	// `

					OldX = PosX;			// X̍W`pɕێ
					OldY = PosY;			// Y̍W`pɕێ
				}
			}

			pen.Dispose();	// \[X̉
			grp.Dispose();	// \[X̉
		}
	}
}
