using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;
using CgpibCs;
using CSubFuncCs;

namespace Oscillo2
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class TDS3000 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.GroupBox groupBox3;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.GroupBox groupBox4;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.GroupBox groupBox5;
		private System.Windows.Forms.ComboBox cboDevice;
		private System.Windows.Forms.Button btnAutoset;
		private System.Windows.Forms.TextBox txtSec;
		private System.Windows.Forms.TextBox txtVolts;
		private System.Windows.Forms.Button btnSetWaveform;
		private System.Windows.Forms.Button btnChgWaveform;
		private System.Windows.Forms.Button btnEnd;
		private System.Windows.Forms.ComboBox cboDelimBox;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		Cgpib		gpib = new Cgpib();
		CSubFunc	SubFunc = new CSubFunc();

		int 		i;
		int 		Ret, Ret2;
		uint 		MyAddr;
		uint		Delim, Eoi;
		uint[] 		Fstb = new uint[32];
		string		MsgText, ErrText;
		GCHandle    gChCmd;                 				// GCHandle for cmd array
    	GCHandle    gChFstb;             					// GCHandle for Pstb array
    	IntPtr     	pFstb;                   				// IntPtr for Pstb array

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

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <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>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.label1 = new System.Windows.Forms.Label();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.cboDevice = new System.Windows.Forms.ComboBox();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.btnAutoset = new System.Windows.Forms.Button();
			this.txtSec = new System.Windows.Forms.TextBox();
			this.txtVolts = new System.Windows.Forms.TextBox();
			this.label5 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.label6 = new System.Windows.Forms.Label();
			this.groupBox3 = new System.Windows.Forms.GroupBox();
			this.btnSetWaveform = new System.Windows.Forms.Button();
			this.label7 = new System.Windows.Forms.Label();
			this.label8 = new System.Windows.Forms.Label();
			this.groupBox4 = new System.Windows.Forms.GroupBox();
			this.btnChgWaveform = new System.Windows.Forms.Button();
			this.label9 = new System.Windows.Forms.Label();
			this.groupBox5 = new System.Windows.Forms.GroupBox();
			this.cboDelimBox = new System.Windows.Forms.ComboBox();
			this.btnEnd = new System.Windows.Forms.Button();
			this.groupBox1.SuspendLayout();
			this.groupBox2.SuspendLayout();
			this.groupBox3.SuspendLayout();
			this.groupBox4.SuspendLayout();
			this.groupBox5.SuspendLayout();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(24, 8);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(144, 16);
			this.label1.TabIndex = 0;
			this.label1.Text = "Tektronix TDS3000";
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.cboDevice,
																					this.label2});
			this.groupBox1.Location = new System.Drawing.Point(13, 32);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(179, 56);
			this.groupBox1.TabIndex = 1;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Device";
			// 
			// cboDevice
			// 
			this.cboDevice.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboDevice.Location = new System.Drawing.Point(104, 22);
			this.cboDevice.Name = "cboDevice";
			this.cboDevice.Size = new System.Drawing.Size(64, 21);
			this.cboDevice.TabIndex = 1;
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(16, 24);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(56, 16);
			this.label2.TabIndex = 0;
			this.label2.Text = "Address =";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(13, 104);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(144, 16);
			this.label3.TabIndex = 2;
			this.label3.Text = "<<< Autoset >>>";
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.btnAutoset,
																					this.txtSec,
																					this.txtVolts,
																					this.label5,
																					this.label4});
			this.groupBox2.Location = new System.Drawing.Point(13, 119);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(390, 64);
			this.groupBox2.TabIndex = 3;
			this.groupBox2.TabStop = false;
			// 
			// btnAutoset
			// 
			this.btnAutoset.Location = new System.Drawing.Point(257, 14);
			this.btnAutoset.Name = "btnAutoset";
			this.btnAutoset.Size = new System.Drawing.Size(120, 40);
			this.btnAutoset.TabIndex = 5;
			this.btnAutoset.Text = "Autoset(&A)";
			this.btnAutoset.Click += new System.EventHandler(this.btnAutoset_Click);
			// 
			// txtSec
			// 
			this.txtSec.Location = new System.Drawing.Point(124, 34);
			this.txtSec.Name = "txtSec";
			this.txtSec.Size = new System.Drawing.Size(80, 20);
			this.txtSec.TabIndex = 4;
			this.txtSec.Text = "";
			// 
			// txtVolts
			// 
			this.txtVolts.Location = new System.Drawing.Point(24, 34);
			this.txtVolts.Name = "txtVolts";
			this.txtVolts.Size = new System.Drawing.Size(80, 20);
			this.txtVolts.TabIndex = 3;
			this.txtVolts.Text = "";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(124, 16);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(64, 16);
			this.label5.TabIndex = 2;
			this.label5.Text = "SEC/DIV";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(24, 16);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(64, 16);
			this.label4.TabIndex = 1;
			this.label4.Text = "VOLTS/DIV";
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(13, 198);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(200, 16);
			this.label6.TabIndex = 4;
			this.label6.Text = "<<< Waveform data are acquired >>>";
			// 
			// groupBox3
			// 
			this.groupBox3.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.btnSetWaveform,
																					this.label7});
			this.groupBox3.Location = new System.Drawing.Point(13, 214);
			this.groupBox3.Name = "groupBox3";
			this.groupBox3.Size = new System.Drawing.Size(390, 64);
			this.groupBox3.TabIndex = 5;
			this.groupBox3.TabStop = false;
			// 
			// btnSetWaveform
			// 
			this.btnSetWaveform.Location = new System.Drawing.Point(257, 16);
			this.btnSetWaveform.Name = "btnSetWaveform";
			this.btnSetWaveform.Size = new System.Drawing.Size(120, 40);
			this.btnSetWaveform.TabIndex = 6;
			this.btnSetWaveform.Text = "Acquired(&G)";
			this.btnSetWaveform.Click += new System.EventHandler(this.btnSetWaveform_Click);
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(8, 24);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(200, 32);
			this.label7.TabIndex = 0;
			this.label7.Text = "Waveform data(WFM_DATA.csv) are recorded in the current path.";
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(13, 294);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(200, 16);
			this.label8.TabIndex = 6;
			this.label8.Text = "<<< Amplitude is set on the display>>>";
			// 
			// groupBox4
			// 
			this.groupBox4.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.btnChgWaveform,
																					this.label9});
			this.groupBox4.Location = new System.Drawing.Point(13, 309);
			this.groupBox4.Name = "groupBox4";
			this.groupBox4.Size = new System.Drawing.Size(390, 64);
			this.groupBox4.TabIndex = 7;
			this.groupBox4.TabStop = false;
			// 
			// btnChgWaveform
			// 
			this.btnChgWaveform.Location = new System.Drawing.Point(257, 16);
			this.btnChgWaveform.Name = "btnChgWaveform";
			this.btnChgWaveform.Size = new System.Drawing.Size(120, 40);
			this.btnChgWaveform.TabIndex = 6;
			this.btnChgWaveform.Text = "Start(&S)";
			this.btnChgWaveform.Click += new System.EventHandler(this.btnChgWaveform_Click);
			// 
			// label9
			// 
			this.label9.Location = new System.Drawing.Point(8, 24);
			this.label9.Name = "label9";
			this.label9.Size = new System.Drawing.Size(200, 32);
			this.label9.TabIndex = 0;
			this.label9.Text = "It is made to indicate amplitude in the display of oscilloscope.";
			// 
			// groupBox5
			// 
			this.groupBox5.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.cboDelimBox});
			this.groupBox5.Location = new System.Drawing.Point(190, 32);
			this.groupBox5.Name = "groupBox5";
			this.groupBox5.Size = new System.Drawing.Size(213, 56);
			this.groupBox5.TabIndex = 8;
			this.groupBox5.TabStop = false;
			this.groupBox5.Text = "Delimiter";
			// 
			// cboDelimBox
			// 
			this.cboDelimBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboDelimBox.Items.AddRange(new object[] {
															 "Not Use",
															 "CR+LF",
															 "CR",
															 "LF"});
			this.cboDelimBox.Location = new System.Drawing.Point(8, 22);
			this.cboDelimBox.Name = "cboDelimBox";
			this.cboDelimBox.Size = new System.Drawing.Size(192, 21);
			this.cboDelimBox.TabIndex = 0;
			this.cboDelimBox.SelectedIndexChanged += new System.EventHandler(this.cboDelimBox_SelectedIndexChanged);
			// 
			// btnEnd
			// 
			this.btnEnd.Location = new System.Drawing.Point(13, 384);
			this.btnEnd.Name = "btnEnd";
			this.btnEnd.Size = new System.Drawing.Size(390, 40);
			this.btnEnd.TabIndex = 9;
			this.btnEnd.Text = "Exit(&X)";
			this.btnEnd.Click += new System.EventHandler(this.btnEnd_Click);
			// 
			// TDS3000
			// 
			this.ClientSize = new System.Drawing.Size(414, 432);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.btnEnd,
																		  this.groupBox5,
																		  this.groupBox4,
																		  this.label8,
																		  this.groupBox3,
																		  this.label6,
																		  this.groupBox2,
																		  this.label3,
																		  this.groupBox1,
																		  this.label1});
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "TDS3000";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "TDS3000";
			this.Load += new System.EventHandler(this.TDS3000_Load);
			this.Closed += new System.EventHandler(this.TDS3000_Closed);
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.groupBox3.ResumeLayout(false);
			this.groupBox4.ResumeLayout(false);
			this.groupBox5.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

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

		private void TDS3000_Load(object sender, System.EventArgs e)
		{
			string	Addr = new string(' ', 8);
			uint	Loop;

			// Specify Pinned handle to Cmd
			if (gChCmd.IsAllocated == false) {
				gChCmd = GCHandle.Alloc(SubFunc.Cmd, GCHandleType.Pinned);
			}
			// Specify Pinned handle to Fstb
			if (gChFstb.IsAllocated == false) {
				gChFstb = GCHandle.Alloc(Fstb, GCHandleType.Pinned);
			}
			// Get address object by Pinned handle
			SubFunc.pCmd = gChCmd.AddrOfPinnedObject();
			pFstb = gChFstb.AddrOfPinnedObject();

			Ret = SubFunc.GpibInit(out MsgText);
			if (Ret > 3)
			{
				Ret2 = SubFunc.CheckRet("GpinInit", (uint)Ret, out ErrText);
				MessageBox.Show(ErrText, null, MessageBoxButtons.OK);
			}

			// GpDelim(X, Y); X -> 0:Non/1:CR+LF/2:CR/3:LF , Y -> 0:Non/1:Use
			Ret = (int)gpib.Delim(3, 1);
			Ret = (int)gpib.DevFind(pFstb);
			Ret = (int)gpib.Boardsts(0x08, out MyAddr);

			for (Loop = 0; 30 >= Loop; Loop++)
			{
				if (MyAddr != Loop)
				{
					Addr = string.Format("{0:d}", Loop);
					cboDevice.Items.Add(Addr);
				}
			}

			if (Fstb[0] == 0xFF)
			{
				cboDevice.SelectedIndex = 0;
			}
			else
			{
				cboDevice.Text = Fstb[0].ToString();
			}

			cboDelimBox.SelectedIndex = 1;

			cboDelimBox_SelectedIndexChanged(cboDelimBox, new System.EventArgs());
		}

		private void TDS3000_Closed(object sender, System.EventArgs e)
		{
			SubFunc.GpibExit();

			// GCHandle free
			if (gChCmd.IsAllocated == true) {
				gChCmd.Free();
			}
			if (gChFstb.IsAllocated == true) {
				gChFstb.Free();
			}
		}

		private void btnAutoset_Click(object sender, System.EventArgs e)
		{
			StringBuilder	ReadVolts = new StringBuilder(10000);
			StringBuilder	ReadHoriz = new StringBuilder(10000);
			//string		GetStr = "";
			uint			Device;

			Device = Convert.ToUInt32(cboDevice.Text);
			if (Device != Fstb[0])
			{
				Fstb[0] = Device;
			}

			Ret = SubFunc.GpibPrint(Fstb[0], "CLEARMENU");
			if (Ret == 1)
			{
				return;
			}
			Ret = SubFunc.GpibPrint(Fstb[0], "FACTORY");
			if (Ret == 1)
			{
				return;
			}
			Ret = SubFunc.GpibPrint(Fstb[0], "LOCK ALL");
			if (Ret == 1)
			{
				return;
			}
			MessageBox.Show("WaveForm of the channel 1 was set up automatically. ", "Run", MessageBoxButtons.OK);

			SubFunc.WaitOPC(Fstb[0]);

			Ret = SubFunc.GpibPrint(Fstb[0], "HEADER 0");
			if (Ret == 1)
			{
				return;
			}

			Ret = SubFunc.GpibPrint(Fstb[0], "AUTOSET EXECUTE");
			if (Ret == 1)
			{
				return;
			}
			MessageBox.Show("It is carried out. ","TDS3000 -> Run", MessageBoxButtons.OK);

			Ret = SubFunc.GpibPrint(Fstb[0], "CH1:SCALE?");
			if (Ret == 1)
			{
				return;
			}
			Ret = SubFunc.GpibInput(Fstb[0], ReadVolts);
			if (Ret == 1)
			{
				return;
			}
			Ret = SubFunc.GpibPrint(Fstb[0], "HORIZONTAL:MAIN:SCALE?");
			if (Ret == 1)
			{
				return;
			}
			Ret = SubFunc.GpibInput(Fstb[0], ReadHoriz);
			if (Ret == 1)
			{
				return;
			}

			txtVolts.Text = ReadVolts.ToString();
			txtSec.Text = ReadHoriz.ToString();
			Ret = SubFunc.GpibPrint(Fstb[0], "UNLOCK ALL");
			if (Ret == 1)
			{
				return;
			}
		}

		private void btnSetWaveform_Click(object sender, System.EventArgs e)
		{
			string			DATSRC = "", StrData = "";
			StringBuilder	RD = new StringBuilder(10000);
			string			SendData = "";
			StringBuilder	YUNIT = new StringBuilder(10000);
			StringBuilder	XUNIT = new StringBuilder(10000);
			string			FileName = "", WfmData = ""/*, Kannma = ","*/;
			string			zeroStr = new String('0', 1024);
			StringBuilder	RecvData = new StringBuilder(zeroStr, 0, 1024, 1024);
			int[]			IntData = new int[1024];
			int				DataMax, DSTART, DSTOP;
			float[]			TIMEARR = new float[1024];
			float[]			VOLTARR = new float[1024];
			float			YOFF, YMULT, PtOff, XINCR;
			TextWriter		m_repFile;
			
			Fstb[0] = uint.Parse(cboDevice.Text);

			//	Ret = SubFunc.GpibInit(out ErrText);
			//	Ret = gpib.Delim(3, 1);
			Ret = SubFunc.GpibPrint(Fstb[0], "HEADER OFF");
			if (Ret == 1)
			{
				return;
			}

			DATSRC = "CH1";
			SendData = "DATA:SOURCE " + DATSRC;
			Ret = SubFunc.GpibPrint(Fstb[0], SendData);
			if (Ret == 1)
			{
				return;
			}
			Ret = SubFunc.GpibPrint(Fstb[0], "DATA:ENCDG RIBINARY;WIDTH 1");
			if (Ret == 1)
			{
				return;
			}
			DataMax = 500;

			SendData = "HORIZONTAL:RECORDLENGTH " + DataMax.ToString();
			Ret = SubFunc.GpibPrint(Fstb[0], SendData);
			if (Ret == 1)
			{
				return;
			}

			DSTART = 1; DSTOP = DataMax;

			StrData = "DATA:START " + DSTART.ToString();
			Ret = SubFunc.GpibPrint(Fstb[0], StrData);
			if (Ret == 1)
			{
				return;
			}

			StrData = "DATA:STOP " + DSTOP.ToString();
			Ret = SubFunc.GpibPrint(Fstb[0], StrData);
			if (Ret == 1)
			{
				return;
			}

			StrData = "HEADER OFF";
			Ret = SubFunc.GpibPrint(Fstb[0], StrData);
			if (Ret == 1)
			{
				return;
			}

			Ret = SubFunc.GpibPrint(Fstb[0], "ACQUIRE:STATE RUN");
			if (Ret == 1)
			{
				return;
			}
			SubFunc.WaitOPC(Fstb[0]);
			Ret = SubFunc.GpibPrint(Fstb[0], "CURVE?");
			if (Ret == 1)
			{
				return;
			}

			Ret = SubFunc.GpibInputB(Fstb[0], RecvData);
			if (Ret == 1)
			{
				return;
			}

			for (i = 0; DataMax >= i; i++)
			{
				IntData[i] = (int)RecvData[i];
				if (IntData[i] > 128)
				{
					IntData[i] = -(256 - IntData[i]);
				}
			}

			StrData = "WFMPRE:" + DATSRC + ":YOFF?";
			Ret = SubFunc.GpibPrint(Fstb[0], StrData);
			if (Ret == 1)
			{
				return;
			}
			Ret = SubFunc.GpibInput(Fstb[0], RD);
			if (Ret == 1)
			{
				return;
			}
			try
			{
				YOFF = float.Parse(RD.ToString());
			}
			catch (System.FormatException)
			{
				YOFF = 0;
			}

			StrData = "WFMPRE:" + DATSRC + ":YMULT?";
			Ret = SubFunc.GpibPrint(Fstb[0], StrData);
			if (Ret == 1)
			{
				return;
			}
			Ret = SubFunc.GpibInput(Fstb[0], RD);
			if (Ret == 1)
			{
				return;
			}
			try
			{
				YMULT = float.Parse(RD.ToString());
			}
			catch (System.FormatException)
			{
				YMULT = 0;
			}

			StrData = "WFMPRE:" + DATSRC + ":YUNIT?";
			Ret = SubFunc.GpibPrint(Fstb[0], StrData);
			if (Ret == 1)
			{
				return;
			}
			Ret = SubFunc.GpibInput(Fstb[0], YUNIT);
			if (Ret == 1)
			{	
				return;
			}

			StrData = "WFMPRE:" + DATSRC + ":PT_Off?";
			Ret = SubFunc.GpibPrint(Fstb[0], StrData);
			if (Ret == 1)
			{
				return;
			}
			Ret = SubFunc.GpibInput(Fstb[0], RD);
			if (Ret == 1)
			{
				return;
			}
			try
			{
				PtOff = float.Parse(RD.ToString());
			}
			catch (System.FormatException)
			{
				PtOff = 0;
			}

			StrData = "WFMPRE:" + DATSRC + ":XINCR?";
			Ret = SubFunc.GpibPrint(Fstb[0], StrData);
			if (Ret == 1)
			{
				return;
			}
			Ret = SubFunc.GpibInput(Fstb[0], RD);
			if (Ret == 1)
			{
				return;
			}
			try
			{
				XINCR = float.Parse(RD.ToString());
			}
			catch (System.FormatException)
			{
				XINCR = 0;
			}

			StrData = "WFMPRE:" + DATSRC + ":XUNIT?";
			Ret = SubFunc.GpibPrint(Fstb[0], StrData);
			if (Ret == 1)
			{
				return;
			}
			Ret = SubFunc.GpibInput(Fstb[0], XUNIT);
			if (Ret == 1)
			{
				return;
			}

			FileName = ".\\WFM_DATA.csv";
			
			try
			{
				m_repFile = File.CreateText(FileName);
			}
			catch (System.IO.IOException)
			{
				MessageBox.Show("A file is opened. ", "File open failure", MessageBoxButtons.OK);
				return;
			}

			for (i = 0; (DataMax - 1) >= i; i++)
			{
				TIMEARR[i] = (i - PtOff) * XINCR;
				VOLTARR[i] = (IntData[i] - YOFF) * YMULT;
				WfmData = string.Format("{0:f6},{1:f6}", TIMEARR[i], VOLTARR[i]);
				m_repFile.WriteLine(WfmData);
			}
			m_repFile.Close();
			MessageBox.Show("It was kept in the current drive. ", "finish", MessageBoxButtons.OK);
		}

		private void btnChgWaveform_Click(object sender, System.EventArgs e)
		{
			string	SendData = "";
			string	MEASSRC = "CH1", MEASTYPE = "AMPLITUDE";

			Fstb[0] = uint.Parse(cboDevice.Text);

			MessageBox.Show(" The signal connected to probe of the channel 1 is checked. ", "Check probe", MessageBoxButtons.OK);

			Ret = SubFunc.GpibPrint(Fstb[0], "HEADER OFF");
			if (Ret == 1)
			{
				return;
			}

			SendData = ":CH1:VOLTS 2E-1;POSITION 0;OFFSET 0;COUPLING AC";
			Ret = SubFunc.GpibPrint(Fstb[0], SendData);
			if (Ret == 1)
			{
				return;
			}
			SendData = ":CH1:IMPEDANCE MEG;BANDWIDTH FULL";
			Ret = SubFunc.GpibPrint(Fstb[0], SendData);
			if (Ret == 1)
			{
				return;
			}
			SendData = ":HORIZONTAL:MAIN:SCALE 2E-2";
			Ret = SubFunc.GpibPrint(Fstb[0], SendData);
			if (Ret == 1)
			{
				return;
			}
			SendData = ":SELECT:CH1 1";
			Ret = SubFunc.GpibPrint(Fstb[0], SendData);
			if (Ret == 1)
			{
				return;
			}

			SendData = ":MEASUREMENT:MEAS1:SOURCE1 " + MEASSRC + ";TYPE " + MEASTYPE + ";STATE 1";
			Ret = SubFunc.GpibPrint(Fstb[0], SendData);
			if (Ret == 1)
			{
				return;
			}

			SubFunc.WaitOPC(Fstb[0]);

			MessageBox.Show("It was made to indicate amplitude in the display of oscilloscope. ", "Message", MessageBoxButtons.OK);

			Ret = SubFunc.GpibPrint(Fstb[0], "UNLOCK ALL");
			if (Ret == 1)
			{
				return;
			}
		}

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

		///////////////////////////////////// Change Delimiter ///
		private void cboDelimBox_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			Eoi = 1;										// EOI : USE
			Delim = (uint)cboDelimBox.SelectedIndex;
			Ret = (int)gpib.Delim(Delim, Eoi);
		}
	}
}
