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

namespace Slave
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Slave : System.Windows.Forms.Form
	{
		public System.Windows.Forms.Button cmdExit;
		public System.Windows.Forms.Button cmdInit;
		public System.Windows.Forms.GroupBox Frame4;
		public System.Windows.Forms.RadioButton optPPollResponseIst1;
		public System.Windows.Forms.Button cmdParallelpollSetting;
		public System.Windows.Forms.RadioButton optPPollResponseIst0;
		public System.Windows.Forms.RadioButton optPPollResponseSrq;
		public System.Windows.Forms.RadioButton optPPollResponseNot;
		public System.Windows.Forms.GroupBox Frame5;
		public System.Windows.Forms.RadioButton optSrqSend;
		public System.Windows.Forms.RadioButton optSrqNotSend;
		public System.Windows.Forms.TextBox txtSPollStb;
		public System.Windows.Forms.Button cmdSendSrq;
		public System.Windows.Forms.Label Label6;
		public System.Windows.Forms.Label Label5;
		public System.Windows.Forms.Button cmdDataDel;
		public System.Windows.Forms.GroupBox Frame1;
		public System.Windows.Forms.ComboBox cboEoi;
		public System.Windows.Forms.ComboBox cboDelim;
		public System.Windows.Forms.TextBox txtMyAddr;
		public System.Windows.Forms.TextBox txtDevName;
		public System.Windows.Forms.Label Label4;
		public System.Windows.Forms.Label Label3;
		public System.Windows.Forms.Label Label2;
		public System.Windows.Forms.Label Label1;
		public System.Windows.Forms.GroupBox Frame3;
		public System.Windows.Forms.ListBox lstRet;
		public System.Windows.Forms.Button cmdRetDel;
		public System.Windows.Forms.GroupBox Frame2;
		public System.Windows.Forms.Button cmdRec;
		public System.Windows.Forms.Button cmdSend;
		public System.Windows.Forms.TextBox txtRec;
		public System.Windows.Forms.TextBox txtSend;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		Cgpib	gpib = new Cgpib();
		short	m_Id;

		public Slave()
		{
			//
			// 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.cmdExit = new System.Windows.Forms.Button();
			this.cmdInit = new System.Windows.Forms.Button();
			this.Frame4 = new System.Windows.Forms.GroupBox();
			this.optPPollResponseIst1 = new System.Windows.Forms.RadioButton();
			this.cmdParallelpollSetting = new System.Windows.Forms.Button();
			this.optPPollResponseIst0 = new System.Windows.Forms.RadioButton();
			this.optPPollResponseSrq = new System.Windows.Forms.RadioButton();
			this.optPPollResponseNot = new System.Windows.Forms.RadioButton();
			this.Frame5 = new System.Windows.Forms.GroupBox();
			this.optSrqSend = new System.Windows.Forms.RadioButton();
			this.optSrqNotSend = new System.Windows.Forms.RadioButton();
			this.txtSPollStb = new System.Windows.Forms.TextBox();
			this.cmdSendSrq = new System.Windows.Forms.Button();
			this.Label6 = new System.Windows.Forms.Label();
			this.Label5 = new System.Windows.Forms.Label();
			this.cmdDataDel = new System.Windows.Forms.Button();
			this.Frame1 = new System.Windows.Forms.GroupBox();
			this.cboEoi = new System.Windows.Forms.ComboBox();
			this.cboDelim = new System.Windows.Forms.ComboBox();
			this.txtMyAddr = new System.Windows.Forms.TextBox();
			this.txtDevName = new System.Windows.Forms.TextBox();
			this.Label4 = new System.Windows.Forms.Label();
			this.Label3 = new System.Windows.Forms.Label();
			this.Label2 = new System.Windows.Forms.Label();
			this.Label1 = new System.Windows.Forms.Label();
			this.Frame3 = new System.Windows.Forms.GroupBox();
			this.lstRet = new System.Windows.Forms.ListBox();
			this.cmdRetDel = new System.Windows.Forms.Button();
			this.Frame2 = new System.Windows.Forms.GroupBox();
			this.cmdRec = new System.Windows.Forms.Button();
			this.cmdSend = new System.Windows.Forms.Button();
			this.txtRec = new System.Windows.Forms.TextBox();
			this.txtSend = new System.Windows.Forms.TextBox();
			this.Frame4.SuspendLayout();
			this.Frame5.SuspendLayout();
			this.Frame1.SuspendLayout();
			this.Frame3.SuspendLayout();
			this.Frame2.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(368, 56);
			this.cmdExit.Name = "cmdExit";
			this.cmdExit.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cmdExit.Size = new System.Drawing.Size(113, 29);
			this.cmdExit.TabIndex = 42;
			this.cmdExit.Text = "Exit(&X)";
			this.cmdExit.Click += new System.EventHandler(this.cmdExit_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(368, 8);
			this.cmdInit.Name = "cmdInit";
			this.cmdInit.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cmdInit.Size = new System.Drawing.Size(113, 29);
			this.cmdInit.TabIndex = 0;
			this.cmdInit.Text = "Initialize(&I)";
			this.cmdInit.Click += new System.EventHandler(this.cmdInit_Click);
			// 
			// Frame4
			// 
			this.Frame4.BackColor = System.Drawing.SystemColors.Control;
			this.Frame4.Controls.AddRange(new System.Windows.Forms.Control[] {
																				 this.optPPollResponseIst1,
																				 this.cmdParallelpollSetting,
																				 this.optPPollResponseIst0,
																				 this.optPPollResponseSrq,
																				 this.optPPollResponseNot});
			this.Frame4.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Frame4.Location = new System.Drawing.Point(560, 184);
			this.Frame4.Name = "Frame4";
			this.Frame4.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Frame4.Size = new System.Drawing.Size(168, 188);
			this.Frame4.TabIndex = 45;
			this.Frame4.TabStop = false;
			this.Frame4.Text = "Parallel poll response";
			// 
			// optPPollResponseIst1
			// 
			this.optPPollResponseIst1.BackColor = System.Drawing.SystemColors.Control;
			this.optPPollResponseIst1.Cursor = System.Windows.Forms.Cursors.Default;
			this.optPPollResponseIst1.ForeColor = System.Drawing.SystemColors.ControlText;
			this.optPPollResponseIst1.Location = new System.Drawing.Point(8, 81);
			this.optPPollResponseIst1.Name = "optPPollResponseIst1";
			this.optPPollResponseIst1.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.optPPollResponseIst1.Size = new System.Drawing.Size(152, 20);
			this.optPPollResponseIst1.TabIndex = 32;
			this.optPPollResponseIst1.TabStop = true;
			this.optPPollResponseIst1.Text = "ISTbit response(IST = 1) ";
			// 
			// cmdParallelpollSetting
			// 
			this.cmdParallelpollSetting.BackColor = System.Drawing.SystemColors.Control;
			this.cmdParallelpollSetting.Cursor = System.Windows.Forms.Cursors.Default;
			this.cmdParallelpollSetting.ForeColor = System.Drawing.SystemColors.ControlText;
			this.cmdParallelpollSetting.Location = new System.Drawing.Point(24, 140);
			this.cmdParallelpollSetting.Name = "cmdParallelpollSetting";
			this.cmdParallelpollSetting.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cmdParallelpollSetting.Size = new System.Drawing.Size(105, 29);
			this.cmdParallelpollSetting.TabIndex = 31;
			this.cmdParallelpollSetting.Text = "Reflect set value";
			this.cmdParallelpollSetting.Click += new System.EventHandler(this.cmdParallelpollSetting_Click);
			// 
			// optPPollResponseIst0
			// 
			this.optPPollResponseIst0.BackColor = System.Drawing.SystemColors.Control;
			this.optPPollResponseIst0.Cursor = System.Windows.Forms.Cursors.Default;
			this.optPPollResponseIst0.ForeColor = System.Drawing.SystemColors.ControlText;
			this.optPPollResponseIst0.Location = new System.Drawing.Point(8, 50);
			this.optPPollResponseIst0.Name = "optPPollResponseIst0";
			this.optPPollResponseIst0.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.optPPollResponseIst0.Size = new System.Drawing.Size(152, 20);
			this.optPPollResponseIst0.TabIndex = 18;
			this.optPPollResponseIst0.TabStop = true;
			this.optPPollResponseIst0.Text = "ISTbit response(IST = 0)";
			// 
			// optPPollResponseSrq
			// 
			this.optPPollResponseSrq.BackColor = System.Drawing.SystemColors.Control;
			this.optPPollResponseSrq.Cursor = System.Windows.Forms.Cursors.Default;
			this.optPPollResponseSrq.ForeColor = System.Drawing.SystemColors.ControlText;
			this.optPPollResponseSrq.Location = new System.Drawing.Point(8, 112);
			this.optPPollResponseSrq.Name = "optPPollResponseSrq";
			this.optPPollResponseSrq.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.optPPollResponseSrq.Size = new System.Drawing.Size(129, 18);
			this.optPPollResponseSrq.TabIndex = 17;
			this.optPPollResponseSrq.TabStop = true;
			this.optPPollResponseSrq.Text = "Response with SRQ";
			// 
			// optPPollResponseNot
			// 
			this.optPPollResponseNot.BackColor = System.Drawing.SystemColors.Control;
			this.optPPollResponseNot.Checked = true;
			this.optPPollResponseNot.Cursor = System.Windows.Forms.Cursors.Default;
			this.optPPollResponseNot.ForeColor = System.Drawing.SystemColors.ControlText;
			this.optPPollResponseNot.Location = new System.Drawing.Point(8, 19);
			this.optPPollResponseNot.Name = "optPPollResponseNot";
			this.optPPollResponseNot.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.optPPollResponseNot.Size = new System.Drawing.Size(89, 19);
			this.optPPollResponseNot.TabIndex = 16;
			this.optPPollResponseNot.TabStop = true;
			this.optPPollResponseNot.Text = "No response";
			// 
			// Frame5
			// 
			this.Frame5.BackColor = System.Drawing.SystemColors.Control;
			this.Frame5.Controls.AddRange(new System.Windows.Forms.Control[] {
																				 this.optSrqSend,
																				 this.optSrqNotSend,
																				 this.txtSPollStb,
																				 this.cmdSendSrq,
																				 this.Label6,
																				 this.Label5});
			this.Frame5.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Frame5.Location = new System.Drawing.Point(560, 8);
			this.Frame5.Name = "Frame5";
			this.Frame5.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Frame5.Size = new System.Drawing.Size(168, 150);
			this.Frame5.TabIndex = 48;
			this.Frame5.TabStop = false;
			this.Frame5.Text = "Serial poll response";
			// 
			// optSrqSend
			// 
			this.optSrqSend.BackColor = System.Drawing.SystemColors.Control;
			this.optSrqSend.Cursor = System.Windows.Forms.Cursors.Default;
			this.optSrqSend.ForeColor = System.Drawing.SystemColors.ControlText;
			this.optSrqSend.Location = new System.Drawing.Point(8, 47);
			this.optSrqSend.Name = "optSrqSend";
			this.optSrqSend.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.optSrqSend.Size = new System.Drawing.Size(113, 19);
			this.optSrqSend.TabIndex = 27;
			this.optSrqSend.TabStop = true;
			this.optSrqSend.Text = "Transmit SRQ";
			// 
			// optSrqNotSend
			// 
			this.optSrqNotSend.BackColor = System.Drawing.SystemColors.Control;
			this.optSrqNotSend.Checked = true;
			this.optSrqNotSend.Cursor = System.Windows.Forms.Cursors.Default;
			this.optSrqNotSend.ForeColor = System.Drawing.SystemColors.ControlText;
			this.optSrqNotSend.Location = new System.Drawing.Point(8, 19);
			this.optSrqNotSend.Name = "optSrqNotSend";
			this.optSrqNotSend.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.optSrqNotSend.Size = new System.Drawing.Size(113, 19);
			this.optSrqNotSend.TabIndex = 26;
			this.optSrqNotSend.TabStop = true;
			this.optSrqNotSend.Text = "Not transmit SRQ";
			// 
			// txtSPollStb
			// 
			this.txtSPollStb.AcceptsReturn = true;
			this.txtSPollStb.AutoSize = false;
			this.txtSPollStb.BackColor = System.Drawing.SystemColors.Window;
			this.txtSPollStb.Cursor = System.Windows.Forms.Cursors.IBeam;
			this.txtSPollStb.ForeColor = System.Drawing.SystemColors.WindowText;
			this.txtSPollStb.ImeMode = System.Windows.Forms.ImeMode.Off;
			this.txtSPollStb.Location = new System.Drawing.Point(104, 73);
			this.txtSPollStb.MaxLength = 3;
			this.txtSPollStb.Name = "txtSPollStb";
			this.txtSPollStb.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.txtSPollStb.Size = new System.Drawing.Size(48, 22);
			this.txtSPollStb.TabIndex = 24;
			this.txtSPollStb.Text = "0";
			// 
			// cmdSendSrq
			// 
			this.cmdSendSrq.BackColor = System.Drawing.SystemColors.Control;
			this.cmdSendSrq.Cursor = System.Windows.Forms.Cursors.Default;
			this.cmdSendSrq.ForeColor = System.Drawing.SystemColors.ControlText;
			this.cmdSendSrq.Location = new System.Drawing.Point(16, 112);
			this.cmdSendSrq.Name = "cmdSendSrq";
			this.cmdSendSrq.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cmdSendSrq.Size = new System.Drawing.Size(113, 29);
			this.cmdSendSrq.TabIndex = 22;
			this.cmdSendSrq.Text = "Reflect set value";
			this.cmdSendSrq.Click += new System.EventHandler(this.cmdSendSrq_Click);
			// 
			// Label6
			// 
			this.Label6.AutoSize = true;
			this.Label6.BackColor = System.Drawing.SystemColors.Control;
			this.Label6.Cursor = System.Windows.Forms.Cursors.Default;
			this.Label6.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Label6.Location = new System.Drawing.Point(8, 93);
			this.Label6.Name = "Label6";
			this.Label6.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Label6.Size = new System.Drawing.Size(98, 13);
			this.Label6.TabIndex = 25;
			this.Label6.Text = "(Set from 0 to 255)";
			// 
			// Label5
			// 
			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(8, 74);
			this.Label5.Name = "Label5";
			this.Label5.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Label5.Size = new System.Drawing.Size(97, 20);
			this.Label5.TabIndex = 23;
			this.Label5.Text = "Status byte =";
			// 
			// 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(16, 320);
			this.cmdDataDel.Name = "cmdDataDel";
			this.cmdDataDel.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cmdDataDel.Size = new System.Drawing.Size(113, 29);
			this.cmdDataDel.TabIndex = 46;
			this.cmdDataDel.Text = "Clear data";
			this.cmdDataDel.Click += new System.EventHandler(this.cmdDataDel_Click);
			// 
			// Frame1
			// 
			this.Frame1.BackColor = System.Drawing.SystemColors.Control;
			this.Frame1.Controls.AddRange(new System.Windows.Forms.Control[] {
																				 this.cboEoi,
																				 this.cboDelim,
																				 this.txtMyAddr,
																				 this.txtDevName,
																				 this.Label4,
																				 this.Label3,
																				 this.Label2,
																				 this.Label1});
			this.Frame1.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Frame1.Location = new System.Drawing.Point(8, 8);
			this.Frame1.Name = "Frame1";
			this.Frame1.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Frame1.Size = new System.Drawing.Size(353, 94);
			this.Frame1.TabIndex = 40;
			this.Frame1.TabStop = false;
			this.Frame1.Text = "Self information";
			// 
			// 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(256, 56);
			this.cboEoi.Name = "cboEoi";
			this.cboEoi.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cboEoi.Size = new System.Drawing.Size(89, 21);
			this.cboEoi.TabIndex = 8;
			// 
			// 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(88, 56);
			this.cboDelim.Name = "cboDelim";
			this.cboDelim.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cboDelim.Size = new System.Drawing.Size(73, 21);
			this.cboDelim.TabIndex = 6;
			// 
			// 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.Enabled = false;
			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(88, 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 = "";
			// 
			// 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(168, 56);
			this.Label4.Name = "Label4";
			this.Label4.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Label4.Size = new System.Drawing.Size(33, 13);
			this.Label4.TabIndex = 7;
			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(8, 56);
			this.Label3.Name = "Label3";
			this.Label3.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Label3.Size = new System.Drawing.Size(59, 13);
			this.Label3.TabIndex = 5;
			this.Label3.Text = "Delimiter =";
			// 
			// 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(168, 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(8, 28);
			this.Label1.Name = "Label1";
			this.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Label1.Size = new System.Drawing.Size(80, 13);
			this.Label1.TabIndex = 1;
			this.Label1.Text = "Device name =";
			// 
			// Frame3
			// 
			this.Frame3.BackColor = System.Drawing.SystemColors.Control;
			this.Frame3.Controls.AddRange(new System.Windows.Forms.Control[] {
																				 this.lstRet});
			this.Frame3.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Frame3.Location = new System.Drawing.Point(8, 216);
			this.Frame3.Name = "Frame3";
			this.Frame3.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Frame3.Size = new System.Drawing.Size(545, 95);
			this.Frame3.TabIndex = 44;
			this.Frame3.TabStop = false;
			this.Frame3.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, 19);
			this.lstRet.Name = "lstRet";
			this.lstRet.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.lstRet.Size = new System.Drawing.Size(529, 43);
			this.lstRet.TabIndex = 28;
			// 
			// 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(144, 320);
			this.cmdRetDel.Name = "cmdRetDel";
			this.cmdRetDel.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cmdRetDel.Size = new System.Drawing.Size(113, 29);
			this.cmdRetDel.TabIndex = 47;
			this.cmdRetDel.Text = "Clear return code";
			this.cmdRetDel.Click += new System.EventHandler(this.cmdRetDel_Click);
			// 
			// Frame2
			// 
			this.Frame2.BackColor = System.Drawing.SystemColors.Control;
			this.Frame2.Controls.AddRange(new System.Windows.Forms.Control[] {
																				 this.cmdRec,
																				 this.cmdSend,
																				 this.txtRec,
																				 this.txtSend});
			this.Frame2.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Frame2.Location = new System.Drawing.Point(8, 112);
			this.Frame2.Name = "Frame2";
			this.Frame2.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Frame2.Size = new System.Drawing.Size(545, 94);
			this.Frame2.TabIndex = 43;
			this.Frame2.TabStop = false;
			this.Frame2.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(424, 56);
			this.cmdRec.Name = "cmdRec";
			this.cmdRec.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cmdRec.Size = new System.Drawing.Size(105, 29);
			this.cmdRec.TabIndex = 30;
			this.cmdRec.Text = "Receive";
			this.cmdRec.Click += new System.EventHandler(this.cmdRec_Click);
			// 
			// 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(424, 19);
			this.cmdSend.Name = "cmdSend";
			this.cmdSend.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cmdSend.Size = new System.Drawing.Size(105, 29);
			this.cmdSend.TabIndex = 29;
			this.cmdSend.Text = "Send";
			this.cmdSend.Click += new System.EventHandler(this.cmdSend_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, 56);
			this.txtRec.MaxLength = 0;
			this.txtRec.Name = "txtRec";
			this.txtRec.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.txtRec.Size = new System.Drawing.Size(393, 29);
			this.txtRec.TabIndex = 13;
			this.txtRec.Text = "";
			// 
			// 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, 19);
			this.txtSend.MaxLength = 0;
			this.txtSend.Name = "txtSend";
			this.txtSend.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.txtSend.Size = new System.Drawing.Size(393, 29);
			this.txtSend.TabIndex = 12;
			this.txtSend.Text = "";
			// 
			// Slave
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(737, 374);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.cmdExit,
																		  this.cmdInit,
																		  this.Frame4,
																		  this.Frame5,
																		  this.cmdDataDel,
																		  this.Frame1,
																		  this.Frame3,
																		  this.cmdRetDel,
																		  this.Frame2});
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "Slave";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Slave";
			this.Load += new System.EventHandler(this.Slave_Load);
			this.Frame4.ResumeLayout(false);
			this.Frame5.ResumeLayout(false);
			this.Frame1.ResumeLayout(false);
			this.Frame3.ResumeLayout(false);
			this.Frame2.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

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

		//***************************************************************************
		//   Initializing
		//***************************************************************************
		private void Slave_Load(object sender, System.EventArgs e)
		{
			txtDevName.Text			= "GPIB000";
			cboDelim.SelectedIndex	= 1;						//Set "CR+LF" as default
			cboEoi.SelectedIndex	= 1;						//Set "Use" as default
			txtSend.Text			= "CONTEC Slave Sample";	//dafault send data
			txtSPollStb.Text		= "0";
		}
		//***************************************************************************
		//   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;
		}

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

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

			return true;
		}

		//***************************************************************************
		//   Initialization
		//   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 slave
				Ret = gpib.GetStatus(m_Id, 0x0A, out Data);
				if ((Ret == 0) && (Data == 0)) 
				{
					MessageBox.Show("It is not a slave. Please set it to slave in property page.");
				} 
				else 
				{
					funcSetlstRet("[Initialize] completed normally");	//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();
		}

		//***************************************************************************
		//   Send Data
		//   Function: Send data to master 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) 
			{
				funcSetlstRet("GpibSendData : sending data does not exist");	//Display in list
				return;
			}

			funcSetlstRet("GpibSendData : sending data...");		//Display in list
			//Transmit data
			Ret = gpib.SendData(m_Id, 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.ToString();
				funcSetlstRet(strRet);								//Display in list
				funcSetlstRet("[Send data] completed normally");	//Display in list
			}
		}

		//***************************************************************************
		//   Receive data
		//   Function: Receive data from master 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_Id, ref RecLen, out RecBuf);
			if (Ret != 0) 
			{
				//error
				gpib.GetErrorString(Ret, out strRet);
				funcSetlstRet(strRet);						//Display in list
			} 
			else 
			{
				//Finish receiving data normally
				txtRec.Text	= RecBuf.Substring(0, RecLen);
				strRet	= "GpibRecData : the number of received data = " + RecLen.ToString();
				funcSetlstRet(strRet);								//Display in list
				funcSetlstRet("[Receive data] completed normally");	//Display in list
			}
		}

		//***************************************************************************
		//  Set status byte
		//   Function: Transmit SRQ and set status byte
		//***************************************************************************
		private void cmdSendSrq_Click(object sender, System.EventArgs e)
		{
			int		Ret;
			string	strRet;
			short	intSrqSend;

			//The SRQ setting value is acquired. 
			if(optSrqNotSend.Checked == true)
			{
				intSrqSend = 0;
			}
			else
			{
				intSrqSend = 1;
			}
			//Transmit SRQ and perform the functin of seting status byte
			Ret = gpib.SendSRQ(m_Id, intSrqSend, short.Parse(txtSPollStb.Text));
			if (Ret != 0) 
			{
				//error
				gpib.GetErrorString(Ret, out strRet);
				funcSetlstRet(strRet);						//Display in list
			} 
			else 
			{
				funcSetlstRet("[Transmit SRQ ans set status byte] completed normally");	//Display in list
			}
		}

		//***************************************************************************
		//   Set parallel poll response
		//***************************************************************************
		private void cmdParallelpollSetting_Click(object sender, System.EventArgs e)
		{
			short	Response = 0;
			short	Ist = 0;
			int		Ret;
			string	strRet;

			if (optPPollResponseNot.Checked == true)
			{
				//No responsev
				Response	= 0;
			}
			else if(optPPollResponseIst0.Checked == true)
			{
				//[Response of ISTbit(IST=0)]
				Response	= 1;
				Ist			= 0;
			}
			else if (optPPollResponseIst1.Checked == true)
			{
				//[Response of ISTbit(IST=1)]
				Response	= 1;
				Ist			= 1;
			}
			else if (optPPollResponseSrq.Checked == true)
			{
				//[Response with SRQ]
				Response	= 2;
			}

			//Perform the function of setting parallel poll response
			Ret = gpib.SetPPollResponse(m_Id, Response);
			if (Ret != 0) 
			{
				//error
				gpib.GetErrorString(Ret, out strRet);
				funcSetlstRet(strRet);	//Display in list
			} 
			else 
			{
				funcSetlstRet("[Set parallel poll response] completed normally");	//Display in list
			}

			if (Response == 1) 
			{
				//Perform the function of settong ISTbit
				Ret = gpib.SetIst(m_Id, Ist);
				if (Ret != 0) 
				{
					//error
					gpib.GetErrorString(Ret, out strRet);
					funcSetlstRet(strRet);	//Display in list
				} 
				else 
				{
					funcSetlstRet("[Set IST of parallel poll response] completed normally");	//Display in list
				}
			}
		}

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

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