using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using CgpibCs;
using System.IO;

namespace ConRec
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form_conrec : System.Windows.Forms.Form
	{
		public System.Windows.Forms.Button cmdExit;
		private System.Windows.Forms.SaveFileDialog dlgSaveCsv;
		public System.Windows.Forms.GroupBox Frame2;
		public System.Windows.Forms.ListBox lstRet;
		public System.Windows.Forms.GroupBox Frame6;
		public System.Windows.Forms.TextBox txtTimerInterval;
		public System.Windows.Forms.Button cmdSrqRecTrigger;
		public System.Windows.Forms.RadioButton optTimer;
		public System.Windows.Forms.RadioButton optMaxSpeed;
		public System.Windows.Forms.RadioButton optManual;
		public System.Windows.Forms.Label lblTimerUnit;
		public System.Windows.Forms.GroupBox Frame4;
		public System.Windows.Forms.Button cmdRec;
		public System.Windows.Forms.TextBox txtRec;
		public System.Windows.Forms.Button cmdSend;
		public System.Windows.Forms.TextBox txtSend;
		public System.Windows.Forms.Timer tmrTimerEventRec;
		public System.Windows.Forms.Button cmdDataDel;
		public System.Windows.Forms.Button cmdRetDel;
		public System.Windows.Forms.Button cmdInit;
		public System.Windows.Forms.GroupBox Frame3;
		public System.Windows.Forms.TextBox txtAddr;
		public System.Windows.Forms.Button cmdSearch;
		public System.Windows.Forms.ComboBox cboEoi;
		public System.Windows.Forms.ComboBox cboDelim;
		public System.Windows.Forms.ComboBox cboAddr;
		public System.Windows.Forms.Label Label5;
		public System.Windows.Forms.Label Label4;
		public System.Windows.Forms.Label Label3;
		public System.Windows.Forms.GroupBox Frame1;
		public System.Windows.Forms.TextBox txtMyAddr;
		public System.Windows.Forms.TextBox txtDevName;
		public System.Windows.Forms.Label Label2;
		public System.Windows.Forms.Label Label1;
		public System.Windows.Forms.GroupBox Frame5;
		public System.Windows.Forms.Button cmdSaveCsv;
		public System.Windows.Forms.Button cmdEventRecStop;
		public System.Windows.Forms.Button cmdEventRecStart;
		public System.Windows.Forms.ListBox lstEventRec;
		private System.ComponentModel.IContainer components;

		Cgpib	gpib = new Cgpib();
		short	m_Id;
		short[]	m_EqpId = new short[32];
		short	m_SelectEqpId;
		const long	GPIB_NOTIFY_MESSAGE = 0x15FF;

		public Form_conrec()
		{
			//
			// 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.components = new System.ComponentModel.Container();
			this.cmdExit = new System.Windows.Forms.Button();
			this.dlgSaveCsv = new System.Windows.Forms.SaveFileDialog();
			this.Frame2 = new System.Windows.Forms.GroupBox();
			this.lstRet = new System.Windows.Forms.ListBox();
			this.Frame6 = new System.Windows.Forms.GroupBox();
			this.txtTimerInterval = new System.Windows.Forms.TextBox();
			this.cmdSrqRecTrigger = new System.Windows.Forms.Button();
			this.optTimer = new System.Windows.Forms.RadioButton();
			this.optMaxSpeed = new System.Windows.Forms.RadioButton();
			this.optManual = new System.Windows.Forms.RadioButton();
			this.lblTimerUnit = new System.Windows.Forms.Label();
			this.Frame4 = new System.Windows.Forms.GroupBox();
			this.cmdRec = new System.Windows.Forms.Button();
			this.txtRec = new System.Windows.Forms.TextBox();
			this.cmdSend = new System.Windows.Forms.Button();
			this.txtSend = new System.Windows.Forms.TextBox();
			this.tmrTimerEventRec = new System.Windows.Forms.Timer(this.components);
			this.cmdDataDel = new System.Windows.Forms.Button();
			this.cmdRetDel = new System.Windows.Forms.Button();
			this.cmdInit = new System.Windows.Forms.Button();
			this.Frame3 = new System.Windows.Forms.GroupBox();
			this.txtAddr = new System.Windows.Forms.TextBox();
			this.cmdSearch = new System.Windows.Forms.Button();
			this.cboEoi = new System.Windows.Forms.ComboBox();
			this.cboDelim = new System.Windows.Forms.ComboBox();
			this.cboAddr = new System.Windows.Forms.ComboBox();
			this.Label5 = new System.Windows.Forms.Label();
			this.Label4 = new System.Windows.Forms.Label();
			this.Label3 = new System.Windows.Forms.Label();
			this.Frame1 = new System.Windows.Forms.GroupBox();
			this.txtMyAddr = new System.Windows.Forms.TextBox();
			this.txtDevName = new System.Windows.Forms.TextBox();
			this.Label2 = new System.Windows.Forms.Label();
			this.Label1 = new System.Windows.Forms.Label();
			this.Frame5 = new System.Windows.Forms.GroupBox();
			this.cmdSaveCsv = new System.Windows.Forms.Button();
			this.cmdEventRecStop = new System.Windows.Forms.Button();
			this.cmdEventRecStart = new System.Windows.Forms.Button();
			this.lstEventRec = new System.Windows.Forms.ListBox();
			this.Frame2.SuspendLayout();
			this.Frame6.SuspendLayout();
			this.Frame4.SuspendLayout();
			this.Frame3.SuspendLayout();
			this.Frame1.SuspendLayout();
			this.Frame5.SuspendLayout();
			this.SuspendLayout();
			// 
			// cmdExit
			// 
			this.cmdExit.BackColor = System.Drawing.SystemColors.Control;
			this.cmdExit.Cursor = System.Windows.Forms.Cursors.Default;
			this.cmdExit.ForeColor = System.Drawing.SystemColors.ControlText;
			this.cmdExit.Location = new System.Drawing.Point(448, 28);
			this.cmdExit.Name = "cmdExit";
			this.cmdExit.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cmdExit.Size = new System.Drawing.Size(113, 25);
			this.cmdExit.TabIndex = 57;
			this.cmdExit.Text = "Exit(&X)";
			this.cmdExit.Click += new System.EventHandler(this.cmdExit_Click);
			// 
			// dlgSaveCsv
			// 
			this.dlgSaveCsv.FileName = "doc1";
			// 
			// Frame2
			// 
			this.Frame2.BackColor = System.Drawing.SystemColors.Control;
			this.Frame2.Controls.AddRange(new System.Windows.Forms.Control[] {
																				 this.lstRet});
			this.Frame2.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Frame2.Location = new System.Drawing.Point(8, 479);
			this.Frame2.Name = "Frame2";
			this.Frame2.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Frame2.Size = new System.Drawing.Size(553, 104);
			this.Frame2.TabIndex = 58;
			this.Frame2.TabStop = false;
			this.Frame2.Text = "Return code";
			// 
			// lstRet
			// 
			this.lstRet.BackColor = System.Drawing.SystemColors.Window;
			this.lstRet.Cursor = System.Windows.Forms.Cursors.Default;
			this.lstRet.ForeColor = System.Drawing.SystemColors.WindowText;
			this.lstRet.Location = new System.Drawing.Point(8, 22);
			this.lstRet.Name = "lstRet";
			this.lstRet.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.lstRet.Size = new System.Drawing.Size(537, 69);
			this.lstRet.TabIndex = 35;
			// 
			// Frame6
			// 
			this.Frame6.BackColor = System.Drawing.SystemColors.Control;
			this.Frame6.Controls.AddRange(new System.Windows.Forms.Control[] {
																				 this.txtTimerInterval,
																				 this.cmdSrqRecTrigger,
																				 this.optTimer,
																				 this.optMaxSpeed,
																				 this.optManual,
																				 this.lblTimerUnit});
			this.Frame6.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Frame6.Location = new System.Drawing.Point(512, 324);
			this.Frame6.Name = "Frame6";
			this.Frame6.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Frame6.Size = new System.Drawing.Size(161, 144);
			this.Frame6.TabIndex = 62;
			this.Frame6.TabStop = false;
			this.Frame6.Text = "Start timing set";
			// 
			// txtTimerInterval
			// 
			this.txtTimerInterval.AcceptsReturn = true;
			this.txtTimerInterval.AutoSize = false;
			this.txtTimerInterval.BackColor = System.Drawing.SystemColors.Window;
			this.txtTimerInterval.Cursor = System.Windows.Forms.Cursors.IBeam;
			this.txtTimerInterval.ForeColor = System.Drawing.SystemColors.WindowText;
			this.txtTimerInterval.ImeMode = System.Windows.Forms.ImeMode.Disable;
			this.txtTimerInterval.Location = new System.Drawing.Point(72, 60);
			this.txtTimerInterval.MaxLength = 5;
			this.txtTimerInterval.Name = "txtTimerInterval";
			this.txtTimerInterval.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.txtTimerInterval.Size = new System.Drawing.Size(41, 25);
			this.txtTimerInterval.TabIndex = 31;
			this.txtTimerInterval.Text = "";
			// 
			// cmdSrqRecTrigger
			// 
			this.cmdSrqRecTrigger.BackColor = System.Drawing.SystemColors.Control;
			this.cmdSrqRecTrigger.Cursor = System.Windows.Forms.Cursors.Default;
			this.cmdSrqRecTrigger.ForeColor = System.Drawing.SystemColors.ControlText;
			this.cmdSrqRecTrigger.Location = new System.Drawing.Point(88, 16);
			this.cmdSrqRecTrigger.Name = "cmdSrqRecTrigger";
			this.cmdSrqRecTrigger.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cmdSrqRecTrigger.Size = new System.Drawing.Size(56, 25);
			this.cmdSrqRecTrigger.TabIndex = 30;
			this.cmdSrqRecTrigger.Text = "Trigger";
			this.cmdSrqRecTrigger.Click += new System.EventHandler(this.cmdSrqRecTrigger_Click);
			// 
			// optTimer
			// 
			this.optTimer.BackColor = System.Drawing.SystemColors.Control;
			this.optTimer.Cursor = System.Windows.Forms.Cursors.Default;
			this.optTimer.ForeColor = System.Drawing.SystemColors.ControlText;
			this.optTimer.Location = new System.Drawing.Point(8, 61);
			this.optTimer.Name = "optTimer";
			this.optTimer.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.optTimer.Size = new System.Drawing.Size(65, 23);
			this.optTimer.TabIndex = 29;
			this.optTimer.TabStop = true;
			this.optTimer.Text = "Timer";
			// 
			// optMaxSpeed
			// 
			this.optMaxSpeed.BackColor = System.Drawing.SystemColors.Control;
			this.optMaxSpeed.Cursor = System.Windows.Forms.Cursors.Default;
			this.optMaxSpeed.ForeColor = System.Drawing.SystemColors.ControlText;
			this.optMaxSpeed.Location = new System.Drawing.Point(8, 103);
			this.optMaxSpeed.Name = "optMaxSpeed";
			this.optMaxSpeed.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.optMaxSpeed.Size = new System.Drawing.Size(112, 23);
			this.optMaxSpeed.TabIndex = 28;
			this.optMaxSpeed.TabStop = true;
			this.optMaxSpeed.Text = "Maximum speed";
			// 
			// optManual
			// 
			this.optManual.BackColor = System.Drawing.SystemColors.Control;
			this.optManual.Checked = true;
			this.optManual.Cursor = System.Windows.Forms.Cursors.Default;
			this.optManual.ForeColor = System.Drawing.SystemColors.ControlText;
			this.optManual.Location = new System.Drawing.Point(8, 22);
			this.optManual.Name = "optManual";
			this.optManual.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.optManual.Size = new System.Drawing.Size(81, 20);
			this.optManual.TabIndex = 27;
			this.optManual.TabStop = true;
			this.optManual.Text = "Manaual";
			// 
			// lblTimerUnit
			// 
			this.lblTimerUnit.AutoSize = true;
			this.lblTimerUnit.BackColor = System.Drawing.SystemColors.Control;
			this.lblTimerUnit.Cursor = System.Windows.Forms.Cursors.Default;
			this.lblTimerUnit.ForeColor = System.Drawing.SystemColors.ControlText;
			this.lblTimerUnit.Location = new System.Drawing.Point(120, 66);
			this.lblTimerUnit.Name = "lblTimerUnit";
			this.lblTimerUnit.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.lblTimerUnit.Size = new System.Drawing.Size(33, 13);
			this.lblTimerUnit.TabIndex = 32;
			this.lblTimerUnit.Text = "mSec";
			// 
			// Frame4
			// 
			this.Frame4.BackColor = System.Drawing.SystemColors.Control;
			this.Frame4.Controls.AddRange(new System.Windows.Forms.Control[] {
																				 this.cmdRec,
																				 this.txtRec,
																				 this.cmdSend,
																				 this.txtSend});
			this.Frame4.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Frame4.Location = new System.Drawing.Point(8, 204);
			this.Frame4.Name = "Frame4";
			this.Frame4.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Frame4.Size = new System.Drawing.Size(553, 109);
			this.Frame4.TabIndex = 60;
			this.Frame4.TabStop = false;
			this.Frame4.Text = "Send / Receive data";
			// 
			// cmdRec
			// 
			this.cmdRec.BackColor = System.Drawing.SystemColors.Control;
			this.cmdRec.Cursor = System.Windows.Forms.Cursors.Default;
			this.cmdRec.ForeColor = System.Drawing.SystemColors.ControlText;
			this.cmdRec.Location = new System.Drawing.Point(432, 65);
			this.cmdRec.Name = "cmdRec";
			this.cmdRec.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cmdRec.Size = new System.Drawing.Size(113, 25);
			this.cmdRec.TabIndex = 22;
			this.cmdRec.Text = "Receive(&R)";
			this.cmdRec.Click += new System.EventHandler(this.cmdRec_Click);
			// 
			// txtRec
			// 
			this.txtRec.AcceptsReturn = true;
			this.txtRec.AutoSize = false;
			this.txtRec.BackColor = System.Drawing.SystemColors.Window;
			this.txtRec.Cursor = System.Windows.Forms.Cursors.IBeam;
			this.txtRec.ForeColor = System.Drawing.SystemColors.WindowText;
			this.txtRec.Location = new System.Drawing.Point(8, 65);
			this.txtRec.MaxLength = 0;
			this.txtRec.Name = "txtRec";
			this.txtRec.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.txtRec.Size = new System.Drawing.Size(417, 25);
			this.txtRec.TabIndex = 21;
			this.txtRec.Text = "";
			// 
			// cmdSend
			// 
			this.cmdSend.BackColor = System.Drawing.SystemColors.Control;
			this.cmdSend.Cursor = System.Windows.Forms.Cursors.Default;
			this.cmdSend.ForeColor = System.Drawing.SystemColors.ControlText;
			this.cmdSend.Location = new System.Drawing.Point(432, 22);
			this.cmdSend.Name = "cmdSend";
			this.cmdSend.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cmdSend.Size = new System.Drawing.Size(113, 25);
			this.cmdSend.TabIndex = 20;
			this.cmdSend.Text = "Send(&S)";
			this.cmdSend.Click += new System.EventHandler(this.cmdSend_Click);
			// 
			// txtSend
			// 
			this.txtSend.AcceptsReturn = true;
			this.txtSend.AutoSize = false;
			this.txtSend.BackColor = System.Drawing.SystemColors.Window;
			this.txtSend.Cursor = System.Windows.Forms.Cursors.IBeam;
			this.txtSend.ForeColor = System.Drawing.SystemColors.WindowText;
			this.txtSend.Location = new System.Drawing.Point(8, 22);
			this.txtSend.MaxLength = 0;
			this.txtSend.Name = "txtSend";
			this.txtSend.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.txtSend.Size = new System.Drawing.Size(417, 25);
			this.txtSend.TabIndex = 19;
			this.txtSend.Text = "";
			// 
			// tmrTimerEventRec
			// 
			this.tmrTimerEventRec.Interval = 1;
			this.tmrTimerEventRec.Tick += new System.EventHandler(this.tmrTimerEventRec_Tick);
			// 
			// cmdDataDel
			// 
			this.cmdDataDel.BackColor = System.Drawing.SystemColors.Control;
			this.cmdDataDel.Cursor = System.Windows.Forms.Cursors.Default;
			this.cmdDataDel.ForeColor = System.Drawing.SystemColors.ControlText;
			this.cmdDataDel.Location = new System.Drawing.Point(568, 227);
			this.cmdDataDel.Name = "cmdDataDel";
			this.cmdDataDel.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cmdDataDel.Size = new System.Drawing.Size(113, 25);
			this.cmdDataDel.TabIndex = 64;
			this.cmdDataDel.Text = "Clear data";
			this.cmdDataDel.Click += new System.EventHandler(this.cmdDataDel_Click);
			// 
			// cmdRetDel
			// 
			this.cmdRetDel.BackColor = System.Drawing.SystemColors.Control;
			this.cmdRetDel.Cursor = System.Windows.Forms.Cursors.Default;
			this.cmdRetDel.ForeColor = System.Drawing.SystemColors.ControlText;
			this.cmdRetDel.Location = new System.Drawing.Point(568, 520);
			this.cmdRetDel.Name = "cmdRetDel";
			this.cmdRetDel.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cmdRetDel.Size = new System.Drawing.Size(113, 25);
			this.cmdRetDel.TabIndex = 63;
			this.cmdRetDel.Text = "Clear return code";
			this.cmdRetDel.Click += new System.EventHandler(this.cmdRetDel_Click);
			// 
			// cmdInit
			// 
			this.cmdInit.BackColor = System.Drawing.SystemColors.Control;
			this.cmdInit.Cursor = System.Windows.Forms.Cursors.Default;
			this.cmdInit.ForeColor = System.Drawing.SystemColors.ControlText;
			this.cmdInit.Location = new System.Drawing.Point(328, 28);
			this.cmdInit.Name = "cmdInit";
			this.cmdInit.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cmdInit.Size = new System.Drawing.Size(113, 25);
			this.cmdInit.TabIndex = 0;
			this.cmdInit.Text = "Initialize(&I)";
			this.cmdInit.Click += new System.EventHandler(this.cmdInit_Click);
			// 
			// Frame3
			// 
			this.Frame3.BackColor = System.Drawing.SystemColors.Control;
			this.Frame3.Controls.AddRange(new System.Windows.Forms.Control[] {
																				 this.txtAddr,
																				 this.cmdSearch,
																				 this.cboEoi,
																				 this.cboDelim,
																				 this.cboAddr,
																				 this.Label5,
																				 this.Label4,
																				 this.Label3});
			this.Frame3.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Frame3.Location = new System.Drawing.Point(8, 83);
			this.Frame3.Name = "Frame3";
			this.Frame3.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Frame3.Size = new System.Drawing.Size(553, 110);
			this.Frame3.TabIndex = 59;
			this.Frame3.TabStop = false;
			this.Frame3.Text = "Target information";
			// 
			// txtAddr
			// 
			this.txtAddr.AcceptsReturn = true;
			this.txtAddr.AutoSize = false;
			this.txtAddr.BackColor = System.Drawing.SystemColors.Window;
			this.txtAddr.Cursor = System.Windows.Forms.Cursors.IBeam;
			this.txtAddr.ForeColor = System.Drawing.SystemColors.WindowText;
			this.txtAddr.Location = new System.Drawing.Point(96, 22);
			this.txtAddr.MaxLength = 0;
			this.txtAddr.Name = "txtAddr";
			this.txtAddr.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.txtAddr.Size = new System.Drawing.Size(73, 26);
			this.txtAddr.TabIndex = 36;
			this.txtAddr.Text = "Text1";
			// 
			// cmdSearch
			// 
			this.cmdSearch.BackColor = System.Drawing.SystemColors.Control;
			this.cmdSearch.Cursor = System.Windows.Forms.Cursors.Default;
			this.cmdSearch.ForeColor = System.Drawing.SystemColors.ControlText;
			this.cmdSearch.Location = new System.Drawing.Point(432, 59);
			this.cmdSearch.Name = "cmdSearch";
			this.cmdSearch.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cmdSearch.Size = new System.Drawing.Size(113, 25);
			this.cmdSearch.TabIndex = 15;
			this.cmdSearch.Text = "Find listener(&F)";
			this.cmdSearch.Click += new System.EventHandler(this.cmdSearch_Click);
			// 
			// cboEoi
			// 
			this.cboEoi.BackColor = System.Drawing.SystemColors.Window;
			this.cboEoi.Cursor = System.Windows.Forms.Cursors.Default;
			this.cboEoi.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboEoi.ForeColor = System.Drawing.SystemColors.WindowText;
			this.cboEoi.Items.AddRange(new object[] {
														"Not use",
														"Use"});
			this.cboEoi.Location = new System.Drawing.Point(272, 61);
			this.cboEoi.Name = "cboEoi";
			this.cboEoi.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cboEoi.Size = new System.Drawing.Size(113, 21);
			this.cboEoi.TabIndex = 14;
			// 
			// cboDelim
			// 
			this.cboDelim.BackColor = System.Drawing.SystemColors.Window;
			this.cboDelim.Cursor = System.Windows.Forms.Cursors.Default;
			this.cboDelim.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboDelim.ForeColor = System.Drawing.SystemColors.WindowText;
			this.cboDelim.Items.AddRange(new object[] {
														  "Not use",
														  "CR+LF",
														  "CR",
														  "LF"});
			this.cboDelim.Location = new System.Drawing.Point(96, 61);
			this.cboDelim.Name = "cboDelim";
			this.cboDelim.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cboDelim.Size = new System.Drawing.Size(113, 21);
			this.cboDelim.TabIndex = 13;
			// 
			// cboAddr
			// 
			this.cboAddr.BackColor = System.Drawing.SystemColors.Window;
			this.cboAddr.Cursor = System.Windows.Forms.Cursors.Default;
			this.cboAddr.ForeColor = System.Drawing.SystemColors.WindowText;
			this.cboAddr.Location = new System.Drawing.Point(176, 22);
			this.cboAddr.Name = "cboAddr";
			this.cboAddr.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cboAddr.Size = new System.Drawing.Size(369, 21);
			this.cboAddr.TabIndex = 12;
			// 
			// Label5
			// 
			this.Label5.AutoSize = true;
			this.Label5.BackColor = System.Drawing.SystemColors.Control;
			this.Label5.Cursor = System.Windows.Forms.Cursors.Default;
			this.Label5.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Label5.Location = new System.Drawing.Point(4, 27);
			this.Label5.Name = "Label5";
			this.Label5.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Label5.Size = new System.Drawing.Size(90, 13);
			this.Label5.TabIndex = 11;
			this.Label5.Text = "Target address =";
			// 
			// Label4
			// 
			this.Label4.AutoSize = true;
			this.Label4.BackColor = System.Drawing.SystemColors.Control;
			this.Label4.Cursor = System.Windows.Forms.Cursors.Default;
			this.Label4.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Label4.Location = new System.Drawing.Point(224, 65);
			this.Label4.Name = "Label4";
			this.Label4.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Label4.Size = new System.Drawing.Size(33, 13);
			this.Label4.TabIndex = 10;
			this.Label4.Text = "EOI =";
			// 
			// Label3
			// 
			this.Label3.AutoSize = true;
			this.Label3.BackColor = System.Drawing.SystemColors.Control;
			this.Label3.Cursor = System.Windows.Forms.Cursors.Default;
			this.Label3.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Label3.Location = new System.Drawing.Point(4, 65);
			this.Label3.Name = "Label3";
			this.Label3.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Label3.Size = new System.Drawing.Size(59, 13);
			this.Label3.TabIndex = 9;
			this.Label3.Text = "Delimiter =";
			// 
			// Frame1
			// 
			this.Frame1.BackColor = System.Drawing.SystemColors.Control;
			this.Frame1.Controls.AddRange(new System.Windows.Forms.Control[] {
																				 this.txtMyAddr,
																				 this.txtDevName,
																				 this.Label2,
																				 this.Label1});
			this.Frame1.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Frame1.Location = new System.Drawing.Point(8, 9);
			this.Frame1.Name = "Frame1";
			this.Frame1.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Frame1.Size = new System.Drawing.Size(313, 63);
			this.Frame1.TabIndex = 55;
			this.Frame1.TabStop = false;
			this.Frame1.Text = "Self information";
			// 
			// txtMyAddr
			// 
			this.txtMyAddr.AcceptsReturn = true;
			this.txtMyAddr.AutoSize = false;
			this.txtMyAddr.BackColor = System.Drawing.SystemColors.Window;
			this.txtMyAddr.Cursor = System.Windows.Forms.Cursors.IBeam;
			this.txtMyAddr.ForeColor = System.Drawing.SystemColors.WindowText;
			this.txtMyAddr.Location = new System.Drawing.Point(256, 22);
			this.txtMyAddr.MaxLength = 0;
			this.txtMyAddr.Name = "txtMyAddr";
			this.txtMyAddr.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.txtMyAddr.Size = new System.Drawing.Size(33, 25);
			this.txtMyAddr.TabIndex = 4;
			this.txtMyAddr.Text = "";
			// 
			// txtDevName
			// 
			this.txtDevName.AcceptsReturn = true;
			this.txtDevName.AutoSize = false;
			this.txtDevName.BackColor = System.Drawing.SystemColors.Window;
			this.txtDevName.Cursor = System.Windows.Forms.Cursors.IBeam;
			this.txtDevName.ForeColor = System.Drawing.SystemColors.WindowText;
			this.txtDevName.Location = new System.Drawing.Point(80, 22);
			this.txtDevName.MaxLength = 0;
			this.txtDevName.Name = "txtDevName";
			this.txtDevName.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.txtDevName.Size = new System.Drawing.Size(73, 25);
			this.txtDevName.TabIndex = 2;
			this.txtDevName.Text = "";
			// 
			// Label2
			// 
			this.Label2.AutoSize = true;
			this.Label2.BackColor = System.Drawing.SystemColors.Control;
			this.Label2.Cursor = System.Windows.Forms.Cursors.Default;
			this.Label2.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Label2.Location = new System.Drawing.Point(163, 28);
			this.Label2.Name = "Label2";
			this.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Label2.Size = new System.Drawing.Size(84, 13);
			this.Label2.TabIndex = 3;
			this.Label2.Text = "GPIB address =";
			// 
			// Label1
			// 
			this.Label1.AutoSize = true;
			this.Label1.BackColor = System.Drawing.SystemColors.Control;
			this.Label1.Cursor = System.Windows.Forms.Cursors.Default;
			this.Label1.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Label1.Location = new System.Drawing.Point(4, 28);
			this.Label1.Name = "Label1";
			this.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Label1.Size = new System.Drawing.Size(77, 13);
			this.Label1.TabIndex = 1;
			this.Label1.Text = "Device name=";
			// 
			// Frame5
			// 
			this.Frame5.BackColor = System.Drawing.SystemColors.Control;
			this.Frame5.Controls.AddRange(new System.Windows.Forms.Control[] {
																				 this.cmdSaveCsv,
																				 this.cmdEventRecStop,
																				 this.cmdEventRecStart,
																				 this.lstEventRec});
			this.Frame5.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Frame5.Location = new System.Drawing.Point(8, 324);
			this.Frame5.Name = "Frame5";
			this.Frame5.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Frame5.Size = new System.Drawing.Size(497, 144);
			this.Frame5.TabIndex = 61;
			this.Frame5.TabStop = false;
			this.Frame5.Text = "Receive data of SRQ event";
			// 
			// cmdSaveCsv
			// 
			this.cmdSaveCsv.BackColor = System.Drawing.SystemColors.Control;
			this.cmdSaveCsv.Cursor = System.Windows.Forms.Cursors.Default;
			this.cmdSaveCsv.ForeColor = System.Drawing.SystemColors.ControlText;
			this.cmdSaveCsv.Location = new System.Drawing.Point(352, 104);
			this.cmdSaveCsv.Name = "cmdSaveCsv";
			this.cmdSaveCsv.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cmdSaveCsv.Size = new System.Drawing.Size(120, 25);
			this.cmdSaveCsv.TabIndex = 26;
			this.cmdSaveCsv.Text = "Save received data";
			this.cmdSaveCsv.Click += new System.EventHandler(this.cmdSaveCsv_Click);
			// 
			// cmdEventRecStop
			// 
			this.cmdEventRecStop.BackColor = System.Drawing.SystemColors.Control;
			this.cmdEventRecStop.Cursor = System.Windows.Forms.Cursors.Default;
			this.cmdEventRecStop.Enabled = false;
			this.cmdEventRecStop.ForeColor = System.Drawing.SystemColors.ControlText;
			this.cmdEventRecStop.Location = new System.Drawing.Point(352, 63);
			this.cmdEventRecStop.Name = "cmdEventRecStop";
			this.cmdEventRecStop.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cmdEventRecStop.Size = new System.Drawing.Size(120, 25);
			this.cmdEventRecStop.TabIndex = 25;
			this.cmdEventRecStop.Text = "Stop receiving SRQ";
			this.cmdEventRecStop.Click += new System.EventHandler(this.cmdEventRecStop_Click);
			// 
			// cmdEventRecStart
			// 
			this.cmdEventRecStart.BackColor = System.Drawing.SystemColors.Control;
			this.cmdEventRecStart.Cursor = System.Windows.Forms.Cursors.Default;
			this.cmdEventRecStart.ForeColor = System.Drawing.SystemColors.ControlText;
			this.cmdEventRecStart.Location = new System.Drawing.Point(352, 22);
			this.cmdEventRecStart.Name = "cmdEventRecStart";
			this.cmdEventRecStart.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cmdEventRecStart.Size = new System.Drawing.Size(120, 25);
			this.cmdEventRecStart.TabIndex = 24;
			this.cmdEventRecStart.Text = "Start receiving SRQ";
			this.cmdEventRecStart.Click += new System.EventHandler(this.cmdEventRecStart_Click);
			// 
			// lstEventRec
			// 
			this.lstEventRec.BackColor = System.Drawing.SystemColors.Window;
			this.lstEventRec.Cursor = System.Windows.Forms.Cursors.Default;
			this.lstEventRec.ForeColor = System.Drawing.SystemColors.WindowText;
			this.lstEventRec.Location = new System.Drawing.Point(8, 22);
			this.lstEventRec.Name = "lstEventRec";
			this.lstEventRec.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.lstEventRec.Size = new System.Drawing.Size(329, 108);
			this.lstEventRec.TabIndex = 18;
			// 
			// Form_conrec
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(688, 594);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.Frame6,
																		  this.Frame4,
																		  this.cmdDataDel,
																		  this.cmdRetDel,
																		  this.cmdInit,
																		  this.Frame3,
																		  this.Frame1,
																		  this.Frame5,
																		  this.cmdExit,
																		  this.Frame2});
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "Form_conrec";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "ConRec";
			this.Load += new System.EventHandler(this.Form_conrec_Load);
			this.Frame2.ResumeLayout(false);
			this.Frame6.ResumeLayout(false);
			this.Frame4.ResumeLayout(false);
			this.Frame3.ResumeLayout(false);
			this.Frame1.ResumeLayout(false);
			this.Frame5.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

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

		//***************************************************************************
		//   Initializing
		//***************************************************************************
		private void Form_conrec_Load(object sender, System.EventArgs e)
		{
			txtDevName.Text			= "GPIB000";
			txtTimerInterval.Text	= "1000";	//1000mSec
			txtAddr.Text			= "0";
			txtSend.Text			= "CONTEC ConRec Sample";
			cboDelim.SelectedIndex	= 1;		//CR+LF
			cboEoi.SelectedIndex	= 1;		//Set "Use" as default
		}

		//**************************************************************************************************
		//   Display transmitted string to list box of "Return code"(sub routine)
		//**************************************************************************************************
		private void funcSetlstRet(string strRet)
		{
			//Add the item to the end of list box
			//Clear all of the items if the number of items more than 256
			if (lstRet.Items.Count >= 256)
			{
				lstRet.Items.RemoveAt(0);
				lstRet.Items.Add(strRet);
			}
			else
			{
				lstRet.Items.Add(strRet);
			}
			lstRet.SelectedIndex = lstRet.Items.Count - 1;
		}

		//**************************************************************************************************
		//   Display transmitted string to list box of received data(sub routine)
		//**************************************************************************************************
		private void funcSetlstSrqRecData(string strRet)
		{
			//Add the item to the end of list box
			//Clear all of the items if the number of items more than 256
			if (lstEventRec.Items.Count >= 256)
			{
				lstEventRec.Items.RemoveAt(0);
				lstEventRec.Items.Add(strRet);
			}
			else
			{
				lstEventRec.Items.Add(strRet);
			}
			lstRet.SelectedIndex = lstRet.Items.Count - 1;
		}

		//**************************************************************************************************
		//  Set the target (sub routine)
		//   Function: Set Equipment ID, Delimiter and EOI
		//   Return value: ture(normally), false(abnormally)
		//**************************************************************************************************
		private bool funcSetParam()
		{
			short	Delim;
			short	Eoi;
			short	Eos;
			short	PrmAddr;
			int		Ret;
			string	strRet;

			//If the other party equipment has been detected, the equipment that has been detected is specified. 
			if (cboAddr.Items.Count != 0) 
			{
				//Get Equipment ID of the device specified in combo box
				m_SelectEqpId = m_EqpId[cboAddr.SelectedIndex];
			} 
			else 
			{
				//Get Equipment ID of device address specified in edit box
				Delim	= (short)cboDelim.SelectedIndex;
				PrmAddr	= short.Parse(txtAddr.Text);
				Ret = gpib.SetEquipment(	m_Id,				//Device ID
											out m_SelectEqpId,	//Retrieved equipment ID
											PrmAddr,			//Primary address 
											0,					//Secondary address 
											Delim);				//Set delimiter
				if (Ret != 0) 
				{
					//error
					gpib.GetErrorString(Ret, out strRet);
					funcSetlstRet(strRet);		//Display in list
					return false;
				}
			}

			//Set delimiter code and EOI line
			Delim	= (short)cboDelim.SelectedIndex;
			Eoi		= (short)cboEoi.SelectedIndex;
			Eos		= 0;
			Ret	= gpib.SetDelim(	m_SelectEqpId,
				Delim,			//Set delimiter code
				Eoi,			//Set EOI line
				Eos);			//Set EOS(reserved)
			if (Ret != 0)
			{
				//error
				gpib.GetErrorString(Ret, out strRet);
				funcSetlstRet(strRet);			//Display in list
			}
			else
			{
				funcSetlstRet("[Partner apparatus setting] completed normally");	//Display in list
			}
			return true;
		}

		//***************************************************************************
		//   Initialize
		//   Function: Get device ID from device name
		//***************************************************************************
		private void cmdInit_Click(object sender, System.EventArgs e)
		{
			int		Ret;
			int		Data;
			string	strRet;

			Ret = gpib.Init(txtDevName.Text, out m_Id);
			if (Ret != 0) 
			{
				//error
				gpib.GetErrorString(Ret, out strRet);
				funcSetlstRet(strRet);			//Display in list
			} 
			else  
			{
				//If get device ID normally
				strRet = "GpibInit : DeviceID = " + m_Id;
				funcSetlstRet(strRet);	//Display in list
				//Get device address
				Ret = gpib.GetStatus(m_Id, 0x08, out Data);
				if (Ret == 0)
				{
					txtMyAddr.Text = Data.ToString();
				}
				//Confirm whether it is set to master
				Ret = gpib.GetStatus(m_Id, 0x0A, out Data);
				if ((Ret == 0) && (Data == 1)) 
				{
					MessageBox.Show("It is not a master. Please set it to master in property page.");
				} 
				else 
				{
					strRet = "[Initialize] completed normally";
					funcSetlstRet(strRet);	//Display in list
				}
			}
			
			gpib.SendIFC(m_Id, 1);	//Send IFC
		}

		//***************************************************************************
		//   Exit
		//   Function: Disable device ID
		//***************************************************************************
		private void cmdExit_Click(object sender, System.EventArgs e)
		{
			int		Ret;
			string	strRet;

			Ret = gpib.Exit(m_Id);
			if (Ret != 0) 
			{
				//error
				gpib.GetErrorString(Ret, out strRet);
				funcSetlstRet(strRet);	//Display in list
			}
			this.Close();
		}

		//***************************************************************************
		//   Detect partner apparatus
		//   FuntionF Detect partner apparatus from device ID and get equipment ID.
		//         Send the [*IDN?] command according with IEEE488.2 standard to partner apparatus with
		//         the equipment ID and get device ID(maker and module number etc.).
		//***************************************************************************
		private void cmdSearch_Click(object sender, System.EventArgs e)
		{
			short	PrmAddr;
			short	ScdAddr;
			short	ArraySize;
			short	ArrayCount;
			short[]	AddrArray = new short[32];
			int		Ret;
			int		SendLen;
			int		RecLen;	
			string	RecBuf;
			string	strRet;
			string	SendBuf;
			string	EqpInforBuf;

			PrmAddr		= -1;	//Search all primary address
			ScdAddr		= 0;	//Do not search secondary address
			ArraySize	= 32;	//Specify the number of devices to be detecte
			Ret = gpib.FindListener(m_Id, PrmAddr, ScdAddr, ref ArraySize, AddrArray);
			if (Ret != 0) 
			{
				//error
				gpib.GetErrorString(Ret, out strRet);
				funcSetlstRet(strRet);	//Display in list
				return;
			} 
			//Display detected partner apparatus when finishing detecting normally
			strRet = "GpibFindListener : the number of detected partner apparatus = " + ArraySize;
			funcSetlstRet(strRet);	//Display in list

			//Get device information of detected device
			cboAddr.ResetText();	//Initialize combo box items
			for (ArrayCount = 0; ArrayCount < ArraySize; ArrayCount++) 
			{
				//Get equipment ID
				Ret = gpib.SetEquipment(
					m_Id,							//Device ID
					out m_EqpId[ArrayCount],		//Retrieved equipment ID
					AddrArray[ArrayCount],			//Primary address
					0,								//Secondary address
					(short)cboDelim.SelectedIndex	//Set delimiter
					);
				if (Ret != 0)
				{
					//error
					gpib.GetErrorString(Ret, out strRet);
					funcSetlstRet(strRet);	//Display in list
					continue;
				}
		
				//Inquiry device information(data sending)
				SendBuf = "*IDN?";			//Data to be sent
				SendLen = SendBuf.Length;	//The number of sent data
				Ret = gpib.SendData(m_EqpId[ArrayCount], ref SendLen, SendBuf);
				if (Ret != 0) 
				{
					//error
					gpib.GetErrorString(Ret, out strRet);
					funcSetlstRet(strRet);	//Display in list
					continue;
				}

				//Inquiry device information(data receiving)
				RecLen = 256;	//Specify buffer size for receiving data
				Ret = gpib.RecData(m_EqpId[ArrayCount], ref RecLen, out RecBuf);
				if (Ret != 0) 
				{
					//error
					gpib.GetErrorString(Ret, out strRet);
					funcSetlstRet(strRet);	//Display in list
					continue;
				}

				//Confirm whether receiving data accords with IEEE488.2 standard
				if (RecBuf.IndexOf(",") != -1) 
				{
					//Combine with address information
					EqpInforBuf = "Address:" + AddrArray[ArrayCount] + RecBuf;
				} 
				else 
				{
					//Include only address information if receiving data does not accord with IEEE488.2 standard
					EqpInforBuf = "Address:" + AddrArray[ArrayCount];
				}
				//Add detected device to the list
				cboAddr.Items.Insert(ArrayCount, EqpInforBuf);
				cboAddr.SelectedIndex = ArrayCount;
			}

			//Reflect detected device to combo box and edit box
			if(cboAddr.SelectedIndex != -1)
			{
				txtAddr.Text = AddrArray[cboAddr.SelectedIndex].ToString();
			}
		}

		//***************************************************************************
		//   Send Data
		//   Function: Send data to slave device
		//***************************************************************************
		private void cmdSend_Click(object sender, System.EventArgs e)
		{
			int		SendLen;
			int		Ret;
			string	strRet;
			string	SendBuf;

			//Set equipment ID, delimiter and EOI
			if (funcSetParam() == false) return;

			//Get sending data from edit box
			SendBuf = txtSend.Text;
			SendLen = SendBuf.Length;
			if (SendLen == 0) 
			{
				strRet = "GpibSendData : sending data does not exist";
				funcSetlstRet(strRet);	//Display in list
				return;
			}

			funcSetlstRet("GpibSendData : sending data...");	//Display in list
			//Send data
			Ret = gpib.SendData(m_SelectEqpId, ref SendLen, SendBuf);
			if (Ret != 0) 
			{
				//error
				gpib.GetErrorString(Ret, out strRet);
				funcSetlstRet(strRet);	//Display in list
			} 
			else  
			{
				//Sent data normally
				strRet = "GpibSendData : the number of sent data = " + SendLen;
				funcSetlstRet(strRet);	//Display in list
				funcSetlstRet("[Send data] completed normally");	//Display in list
			}
		}

		//***************************************************************************
		//   Receive data
		//   Function: Receive data from slave device
		//***************************************************************************
		private void cmdRec_Click(object sender, System.EventArgs e)
		{
			int		RecLen;
			int		Ret;
			string	strRet;
			string	RecBuf;

			//Set equipment ID, delimiter and EOI
			if (funcSetParam() == false) return;

			RecLen = 256;	//Set recieving buffer size
			funcSetlstRet("GpibRecData : receiving data...");	//Display in list
			//Receive data
			Ret = gpib.RecData(m_SelectEqpId, ref RecLen, out RecBuf);
			if (Ret != 0) 
			{
				//error
				gpib.GetErrorString(Ret, out strRet);
				funcSetlstRet(strRet);	//Display in list
			} 
			else 
			{
				//Received data normally
				txtRec.Text = RecBuf.Substring(0,RecLen);
				strRet = "GpibRecData : the number of received data = " + RecLen;
				funcSetlstRet(strRet);	//Display in list
				strRet = "[Receive data] completed normally";
				funcSetlstRet(strRet);	//Display in list
			}
		}

		//**************************************************************************************************
		//   Clear send/receive text data
		//**************************************************************************************************
		private void cmdDataDel_Click(object sender, System.EventArgs e)
		{
			txtSend.Text	= "";
			txtRec.Text		= "";
			
			//Clear items of list box
			lstEventRec.Items.Clear();
		}

		//**************************************************************************************************
		//   Clear return code
		//**************************************************************************************************
		private void cmdRetDel_Click(object sender, System.EventArgs e)
		{
			//Clear items of list box
			lstRet.Items.Clear();		
		}

		//***************************************************************************
		//   Start manual timing
		//   Function: Send GET command
		//        When the GET command can not operate normally according to different
		//        partner apparatus,  please modify it according with device specification.
		//***************************************************************************
		private void cmdSrqRecTrigger_Click(object sender, System.EventArgs e)
		{
			int		Ret;
			string	strRet;

			if (funcSetParam() == false) return;

			//Perform transmitting function of GET command
			Ret = gpib.SendTrigger(m_SelectEqpId);
			if (Ret != 0) 
			{
				//error
				gpib.GetErrorString(Ret, out strRet);
				funcSetlstRet(strRet);	//Display in list
			} 
			else 
			{
				funcSetlstRet("[Send GET command] completed normally");	//Display in list
			}
		}

		//***************************************************************************
		//   Start SRQ event receiving
		//   Function: Receive data when SRQ is enabled
		//***************************************************************************
		private void cmdEventRecStart_Click(object sender, System.EventArgs e)
		{
			int		Ret;
			string	strRet;

			//Start timer if "timer" is selected
			if (optTimer.Checked == true) 
			{
				tmrTimerEventRec.Interval = short.Parse(txtTimerInterval.Text);
				tmrTimerEventRec.Enabled = true;
			}
			//Perform trigger if "Maximum Speed" is selected
			if (optMaxSpeed.Checked == true) 
			{
				cmdSrqRecTrigger_Click(cmdSrqRecTrigger, new System.EventArgs());
			}

			//Perform the function of event setting(enable SRQ event receiving)
			Ret = gpib.SetNotifySignal(m_Id, (uint)Handle, 0x0020);
			if (Ret != 0) 
			{
				//error
				gpib.GetErrorString(Ret, out strRet);
				funcSetlstRet(strRet);	//Display in list
			} 
			else 
			{
				cmdEventRecStart.Enabled	= false;
				cmdEventRecStop.Enabled		= true;
				funcSetlstRet("[Start SRQ event receiving] completed normally");	//Display in list
			}
		}

		//***************************************************************************
		//   Stop SRQ event receiving
		//   Function: Stop event receiving
		//***************************************************************************
		private void cmdEventRecStop_Click(object sender, System.EventArgs e)
		{
			int		Ret;
			string	strRet;

			//Stop timer if "timer" is selected
			if (optTimer.Checked == true) 
			{
				tmrTimerEventRec.Enabled = false;
			}
			//Perform the function of event setting(cancel SRQ event receiving)
			Ret = gpib.SetNotifySignal(m_Id, (uint)Handle, 0x0000);
			if (Ret != 0) 
			{
				//error
				gpib.GetErrorString(Ret, out strRet);
				funcSetlstRet(strRet);	//Display in list
			} 
			else 
			{
				cmdEventRecStart.Enabled	= true;
				cmdEventRecStop.Enabled		= false;
				funcSetlstRet("[Stop SRQ event receiving] completed normally");	//Display in list
			}
		}

		//***************************************************************************
		//   Save received data to CSV file
		//***************************************************************************
		private void cmdSaveCsv_Click(object sender, System.EventArgs e)
		{
			string			strFileDataBuf;
			short			i;
			FileStream		OutFile = null;
			StreamWriter	FileWriter = null; 

			dlgSaveCsv.FileName			= "ConRec.csv";		//Default file name
			dlgSaveCsv.DefaultExt		= "csv";
			dlgSaveCsv.Title			= "Save Received Data";	//dialog title
			//The folder that opens first is set to the application passing.
			dlgSaveCsv.InitialDirectory	= Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); 
			dlgSaveCsv.Filter			= "csv files(*.csv)|*.csv|All files (*.*)|*.*";

			//display dialog
			if (dlgSaveCsv.ShowDialog() != DialogResult.OK)
			{
				return;
			}

			OutFile		= new FileStream(dlgSaveCsv.FileName, FileMode.Create, FileAccess.Write);
			FileWriter	= new StreamWriter(OutFile, System.Text.Encoding.GetEncoding("Shift_JIS")); 
			
			//Write received data to ther file
			strFileDataBuf = "Received Times, Received Data\n";
			FileWriter.Write(strFileDataBuf);

			for(i = 0; i < lstEventRec.Items.Count; i++)
			{
				strFileDataBuf = i + "," + lstEventRec.Items[i] + "\n";
				FileWriter.Write(strFileDataBuf);
			}
			//Close file
			FileWriter.Close();
			OutFile.Close();
		}

		//***************************************************************************
		//   Start timer event
		//   Function: Perform trigger at fixed interval
		//***************************************************************************
		private void tmrTimerEventRec_Tick(object sender, System.EventArgs e)
		{
			cmdSrqRecTrigger_Click(cmdSrqRecTrigger, new System.EventArgs());
		}

		//***************************************************************************
		//   SRQ event receiving
		//   Function: Perform serial poll and receive data when SRQ line is enabled
		//***************************************************************************
		[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]
		protected override void WndProc(ref Message m)
		{
			short	Stb;
			short	Srq;
			int		RecLen;
			int		Ret;
			string	strRet;
			string	RecBuf;

			//----------------------------------------
			//   Process of SRQ receiving
			//----------------------------------------
			if (m.Msg == GPIB_NOTIFY_MESSAGE) 
			{
				if ((m.WParam.ToInt32() & 0x0020) != 0) 
				{
					//Set equipment ID, delimiter and EOI
					if (funcSetParam() == false) goto cmsNotifySignalEventEnd;
		
					funcSetlstRet("GpibSPoll : serial polling...");	//Display in list

					//Perform serial poll function
					Ret = gpib.SPoll(m_SelectEqpId, out Stb, out Srq);
					if (Ret != 0) 
					{
						//error
						gpib.GetErrorString(Ret, out strRet);
						funcSetlstRet(strRet);	//Display in list
						//Stop SRQ receiving when serial poll occurred error
						cmdEventRecStop_Click(cmdEventRecStop, new System.EventArgs());
						return;
					} 
					else 
					{
						strRet = string.Format("GpibSPoll : status byte = {0:X2}(H) SRQ line = {1:X2}(H)", Stb, Srq);
						funcSetlstRet(strRet);	//Display in list
						funcSetlstRet("[Serial poll] completed normally");	//Display in list
					}

					//Receive data
					RecLen = 256;	//Set recieving buffer size
					funcSetlstRet("GpibRecData : receiving data...");	//Display in list
					//Receive data
					Ret = gpib.RecData(m_SelectEqpId, ref RecLen, out RecBuf);
					if (Ret != 0) 
					{
						//error
						gpib.GetErrorString(Ret, out strRet);
						funcSetlstRet(strRet);	//Display in list
						//Stop SRQ receiving when error occurred in receiving data
						cmdEventRecStop_Click(cmdEventRecStop, new System.EventArgs());
						return;
					} 
					else 
					{
						//Finish receiving data normally
						RecBuf	= RecBuf.Substring(0,RecLen);
						funcSetlstSrqRecData(RecBuf);	//Display received data in list
						strRet	= "GpibRecData : the number of received data = " + RecLen;
						funcSetlstRet(strRet);	//Display in list
						funcSetlstRet("[Receive Data] completed normally");	//Display in list
					}

					//Perform trigger if "Maximum Speed" is selected
					if (optMaxSpeed.Checked == true) 
					{
						cmdSrqRecTrigger_Click(cmdSrqRecTrigger, new System.EventArgs());
					}
				}

			cmsNotifySignalEventEnd:
				//----------------------------------------
				//   Setting of waiting next event
				//----------------------------------------
				//Perform the function of event setting
				Ret = gpib.SetNotifySignal(m_Id, (uint)Handle, 0x0020);
				//Process of return code
				if (Ret != 0) 
				{
					//error
					gpib.GetErrorString(Ret, out strRet);
					funcSetlstRet(strRet);	//Display in list
				}
			}
			base.WndProc(ref m);
		}
	}
}
