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

namespace Pti4
{
	/// <summary>
	/// Form1 ̊Tv̐łB
	/// </summary>
	public class Pti4 : 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 lblStart;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.Label label10;
		private System.Windows.Forms.Label label11;
		private System.Windows.Forms.Label label12;
		private System.Windows.Forms.GroupBox groupBox3;
		private System.Windows.Forms.Label label13;
		private System.Windows.Forms.Label label14;
		private System.Windows.Forms.Label label16;
		private System.Windows.Forms.Label label15;
		private System.Windows.Forms.Label label17;
		private System.Windows.Forms.Label label18;
		private System.Windows.Forms.Label label19;
		private System.Windows.Forms.ComboBox cboDevice;
		private System.Windows.Forms.Label lblErr;
		private System.Windows.Forms.TextBox txtCh0;
		private System.Windows.Forms.TextBox txtCh1;
		private System.Windows.Forms.TextBox txtStsDc;
		private System.Windows.Forms.TextBox txtStsUAlarm;
		private System.Windows.Forms.TextBox txtStsLAlarm;
		private System.Windows.Forms.TextBox txtRet;
		private System.Windows.Forms.Button btnInit;
		private System.Windows.Forms.Button btnMSet;
		private System.Windows.Forms.Button btnASet;
		private System.Windows.Forms.Button btnStart;
		private System.Windows.Forms.Button btnStop;
		private System.Windows.Forms.Button btnInput;
		private System.Windows.Forms.Button btnStatus;
		private System.Windows.Forms.Button btnExit;
		private System.Windows.Forms.Button btnOK;
		/// <summary>
		/// KvȃfUCiϐłB
		/// </summary>
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.TextBox txtCh3;
		private System.Windows.Forms.TextBox txtCh2;
		short	m_Id;		// ID

		public Pti4()
		{
			//
			// Windows tH[ fUCi T|[gɕKvłB
			//
			InitializeComponent();

			//
			// TODO: InitializeComponent ĂяǒɁARXgN^ R[hǉĂB
			//
		}

		/// <summary>
		/// gpĂ郊\[XɌ㏈s܂B
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// fUCi T|[gɕKvȃ\bhłB̃\bh̓e
		/// R[h GfB^ŕύXȂłB
		/// </summary>
		private void InitializeComponent()
		{
			this.label1 = new System.Windows.Forms.Label();
			this.cboDevice = new System.Windows.Forms.ComboBox();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.lblErr = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.lblStart = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.label12 = new System.Windows.Forms.Label();
			this.label11 = new System.Windows.Forms.Label();
			this.label10 = new System.Windows.Forms.Label();
			this.label9 = new System.Windows.Forms.Label();
			this.label8 = new System.Windows.Forms.Label();
			this.label7 = new System.Windows.Forms.Label();
			this.label6 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.txtCh3 = new System.Windows.Forms.TextBox();
			this.txtCh2 = new System.Windows.Forms.TextBox();
			this.txtCh1 = new System.Windows.Forms.TextBox();
			this.txtCh0 = new System.Windows.Forms.TextBox();
			this.groupBox3 = new System.Windows.Forms.GroupBox();
			this.label18 = new System.Windows.Forms.Label();
			this.label17 = new System.Windows.Forms.Label();
			this.label15 = new System.Windows.Forms.Label();
			this.label16 = new System.Windows.Forms.Label();
			this.label14 = new System.Windows.Forms.Label();
			this.txtStsLAlarm = new System.Windows.Forms.TextBox();
			this.txtStsUAlarm = new System.Windows.Forms.TextBox();
			this.txtStsDc = new System.Windows.Forms.TextBox();
			this.label13 = new System.Windows.Forms.Label();
			this.label19 = new System.Windows.Forms.Label();
			this.txtRet = new System.Windows.Forms.TextBox();
			this.btnInit = new System.Windows.Forms.Button();
			this.btnMSet = new System.Windows.Forms.Button();
			this.btnASet = new System.Windows.Forms.Button();
			this.btnStart = new System.Windows.Forms.Button();
			this.btnStop = new System.Windows.Forms.Button();
			this.btnInput = new System.Windows.Forms.Button();
			this.btnStatus = new System.Windows.Forms.Button();
			this.btnExit = new System.Windows.Forms.Button();
			this.btnOK = new System.Windows.Forms.Button();
			this.groupBox1.SuspendLayout();
			this.groupBox2.SuspendLayout();
			this.groupBox3.SuspendLayout();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 14);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(56, 16);
			this.label1.TabIndex = 0;
			this.label1.Text = "foCX";
			// 
			// cboDevice
			// 
			this.cboDevice.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboDevice.Location = new System.Drawing.Point(88, 10);
			this.cboDevice.Name = "cboDevice";
			this.cboDevice.Size = new System.Drawing.Size(240, 20);
			this.cboDevice.TabIndex = 1;
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.lblErr,
																					this.label4,
																					this.lblStart,
																					this.label2});
			this.groupBox1.Location = new System.Drawing.Point(16, 40);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(312, 48);
			this.groupBox1.TabIndex = 2;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "NAG[WX^";
			// 
			// lblErr
			// 
			this.lblErr.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.lblErr.Location = new System.Drawing.Point(235, 22);
			this.lblErr.Name = "lblErr";
			this.lblErr.Size = new System.Drawing.Size(40, 18);
			this.lblErr.TabIndex = 3;
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(152, 24);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(80, 16);
			this.label4.TabIndex = 2;
			this.label4.Text = "NWX^F";
			// 
			// lblStart
			// 
			this.lblStart.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.lblStart.Location = new System.Drawing.Point(99, 22);
			this.lblStart.Name = "lblStart";
			this.lblStart.Size = new System.Drawing.Size(40, 18);
			this.lblStart.TabIndex = 1;
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(16, 24);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(80, 16);
			this.label2.TabIndex = 0;
			this.label2.Text = "NWX^F";
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.label12,
																					this.label11,
																					this.label10,
																					this.label9,
																					this.label8,
																					this.label7,
																					this.label6,
																					this.label5,
																					this.txtCh3,
																					this.txtCh2,
																					this.txtCh1,
																					this.txtCh0});
			this.groupBox2.Location = new System.Drawing.Point(16, 95);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(312, 121);
			this.groupBox2.TabIndex = 3;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "͒l";
			// 
			// label12
			// 
			this.label12.Location = new System.Drawing.Point(220, 96);
			this.label12.Name = "label12";
			this.label12.Size = new System.Drawing.Size(40, 16);
			this.label12.TabIndex = 11;
			this.label12.Text = "";
			this.label12.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// label11
			// 
			this.label11.Location = new System.Drawing.Point(220, 72);
			this.label11.Name = "label11";
			this.label11.Size = new System.Drawing.Size(40, 16);
			this.label11.TabIndex = 10;
			this.label11.Text = "";
			this.label11.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// label10
			// 
			this.label10.Location = new System.Drawing.Point(220, 48);
			this.label10.Name = "label10";
			this.label10.Size = new System.Drawing.Size(40, 16);
			this.label10.TabIndex = 9;
			this.label10.Text = "";
			this.label10.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// label9
			// 
			this.label9.Location = new System.Drawing.Point(220, 24);
			this.label9.Name = "label9";
			this.label9.Size = new System.Drawing.Size(40, 16);
			this.label9.TabIndex = 8;
			this.label9.Text = "";
			this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(32, 92);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(64, 16);
			this.label8.TabIndex = 7;
			this.label8.Text = "`l3F";
			this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(32, 69);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(64, 16);
			this.label7.TabIndex = 6;
			this.label7.Text = "`l2F";
			this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(32, 46);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(64, 16);
			this.label6.TabIndex = 5;
			this.label6.Text = "`l1F";
			this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(32, 23);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(64, 16);
			this.label5.TabIndex = 4;
			this.label5.Text = "`l0F";
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// txtCh3
			// 
			this.txtCh3.Location = new System.Drawing.Point(99, 92);
			this.txtCh3.Name = "txtCh3";
			this.txtCh3.Size = new System.Drawing.Size(112, 19);
			this.txtCh3.TabIndex = 3;
			this.txtCh3.Text = "";
			// 
			// txtCh2
			// 
			this.txtCh2.Location = new System.Drawing.Point(99, 68);
			this.txtCh2.Name = "txtCh2";
			this.txtCh2.Size = new System.Drawing.Size(112, 19);
			this.txtCh2.TabIndex = 2;
			this.txtCh2.Text = "";
			// 
			// txtCh1
			// 
			this.txtCh1.Location = new System.Drawing.Point(99, 44);
			this.txtCh1.Name = "txtCh1";
			this.txtCh1.Size = new System.Drawing.Size(112, 19);
			this.txtCh1.TabIndex = 1;
			this.txtCh1.Text = "";
			// 
			// txtCh0
			// 
			this.txtCh0.Location = new System.Drawing.Point(99, 20);
			this.txtCh0.Name = "txtCh0";
			this.txtCh0.Size = new System.Drawing.Size(112, 19);
			this.txtCh0.TabIndex = 0;
			this.txtCh0.Text = "";
			// 
			// groupBox3
			// 
			this.groupBox3.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.label18,
																					this.label17,
																					this.label15,
																					this.label16,
																					this.label14,
																					this.txtStsLAlarm,
																					this.txtStsUAlarm,
																					this.txtStsDc,
																					this.label13});
			this.groupBox3.Location = new System.Drawing.Point(16, 224);
			this.groupBox3.Name = "groupBox3";
			this.groupBox3.Size = new System.Drawing.Size(312, 136);
			this.groupBox3.TabIndex = 4;
			this.groupBox3.TabStop = false;
			this.groupBox3.Text = "Xe[^X";
			// 
			// label18
			// 
			this.label18.Location = new System.Drawing.Point(220, 70);
			this.label18.Name = "label18";
			this.label18.Size = new System.Drawing.Size(40, 16);
			this.label18.TabIndex = 11;
			this.label18.Text = "Hex";
			this.label18.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// label17
			// 
			this.label17.Location = new System.Drawing.Point(220, 44);
			this.label17.Name = "label17";
			this.label17.Size = new System.Drawing.Size(40, 16);
			this.label17.TabIndex = 10;
			this.label17.Text = "Hex";
			this.label17.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// label15
			// 
			this.label15.Location = new System.Drawing.Point(220, 20);
			this.label15.Name = "label15";
			this.label15.Size = new System.Drawing.Size(40, 16);
			this.label15.TabIndex = 9;
			this.label15.Text = "Hex";
			this.label15.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// label16
			// 
			this.label16.Location = new System.Drawing.Point(16, 70);
			this.label16.Name = "label16";
			this.label16.Size = new System.Drawing.Size(80, 16);
			this.label16.TabIndex = 6;
			this.label16.Text = "A[F";
			this.label16.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label14
			// 
			this.label14.Location = new System.Drawing.Point(16, 44);
			this.label14.Name = "label14";
			this.label14.Size = new System.Drawing.Size(80, 16);
			this.label14.TabIndex = 4;
			this.label14.Text = "A[F";
			this.label14.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// txtStsLAlarm
			// 
			this.txtStsLAlarm.Location = new System.Drawing.Point(99, 69);
			this.txtStsLAlarm.Name = "txtStsLAlarm";
			this.txtStsLAlarm.Size = new System.Drawing.Size(112, 19);
			this.txtStsLAlarm.TabIndex = 3;
			this.txtStsLAlarm.Text = "";
			// 
			// txtStsUAlarm
			// 
			this.txtStsUAlarm.Location = new System.Drawing.Point(99, 44);
			this.txtStsUAlarm.Name = "txtStsUAlarm";
			this.txtStsUAlarm.Size = new System.Drawing.Size(112, 19);
			this.txtStsUAlarm.TabIndex = 2;
			this.txtStsUAlarm.Text = "";
			// 
			// txtStsDc
			// 
			this.txtStsDc.Location = new System.Drawing.Point(99, 19);
			this.txtStsDc.Name = "txtStsDc";
			this.txtStsDc.Size = new System.Drawing.Size(112, 19);
			this.txtStsDc.TabIndex = 1;
			this.txtStsDc.Text = "";
			// 
			// label13
			// 
			this.label13.Location = new System.Drawing.Point(48, 20);
			this.label13.Name = "label13";
			this.label13.Size = new System.Drawing.Size(48, 16);
			this.label13.TabIndex = 0;
			this.label13.Text = "fF";
			this.label13.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label19
			// 
			this.label19.Location = new System.Drawing.Point(13, 380);
			this.label19.Name = "label19";
			this.label19.Size = new System.Drawing.Size(48, 16);
			this.label19.TabIndex = 5;
			this.label19.Text = "߂lF";
			// 
			// txtRet
			// 
			this.txtRet.Location = new System.Drawing.Point(56, 376);
			this.txtRet.Name = "txtRet";
			this.txtRet.Size = new System.Drawing.Size(408, 19);
			this.txtRet.TabIndex = 6;
			this.txtRet.Text = "";
			// 
			// btnInit
			// 
			this.btnInit.Location = new System.Drawing.Point(344, 7);
			this.btnInit.Name = "btnInit";
			this.btnInit.Size = new System.Drawing.Size(120, 24);
			this.btnInit.TabIndex = 7;
			this.btnInit.Text = "";
			this.btnInit.Click += new System.EventHandler(this.btnInit_Click);
			// 
			// btnMSet
			// 
			this.btnMSet.Location = new System.Drawing.Point(344, 48);
			this.btnMSet.Name = "btnMSet";
			this.btnMSet.Size = new System.Drawing.Size(120, 24);
			this.btnMSet.TabIndex = 8;
			this.btnMSet.Text = "vݒ...";
			this.btnMSet.Click += new System.EventHandler(this.btnMSet_Click);
			// 
			// btnASet
			// 
			this.btnASet.Location = new System.Drawing.Point(344, 80);
			this.btnASet.Name = "btnASet";
			this.btnASet.Size = new System.Drawing.Size(120, 24);
			this.btnASet.TabIndex = 9;
			this.btnASet.Text = "A[ݒ...";
			this.btnASet.Click += new System.EventHandler(this.btnASet_Click);
			// 
			// btnStart
			// 
			this.btnStart.Location = new System.Drawing.Point(344, 128);
			this.btnStart.Name = "btnStart";
			this.btnStart.Size = new System.Drawing.Size(120, 24);
			this.btnStart.TabIndex = 10;
			this.btnStart.Text = "N";
			this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
			// 
			// btnStop
			// 
			this.btnStop.Location = new System.Drawing.Point(344, 160);
			this.btnStop.Name = "btnStop";
			this.btnStop.Size = new System.Drawing.Size(120, 24);
			this.btnStop.TabIndex = 11;
			this.btnStop.Text = "~";
			this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
			// 
			// btnInput
			// 
			this.btnInput.Location = new System.Drawing.Point(344, 208);
			this.btnInput.Name = "btnInput";
			this.btnInput.Size = new System.Drawing.Size(120, 24);
			this.btnInput.TabIndex = 12;
			this.btnInput.Text = "͒l";
			this.btnInput.Click += new System.EventHandler(this.btnInput_Click);
			// 
			// btnStatus
			// 
			this.btnStatus.Location = new System.Drawing.Point(344, 240);
			this.btnStatus.Name = "btnStatus";
			this.btnStatus.Size = new System.Drawing.Size(120, 24);
			this.btnStatus.TabIndex = 13;
			this.btnStatus.Text = "Xe[^X";
			this.btnStatus.Click += new System.EventHandler(this.btnStatus_Click);
			// 
			// btnExit
			// 
			this.btnExit.Location = new System.Drawing.Point(344, 288);
			this.btnExit.Name = "btnExit";
			this.btnExit.Size = new System.Drawing.Size(120, 24);
			this.btnExit.TabIndex = 14;
			this.btnExit.Text = "I";
			this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
			// 
			// btnOK
			// 
			this.btnOK.Location = new System.Drawing.Point(344, 336);
			this.btnOK.Name = "btnOK";
			this.btnOK.Size = new System.Drawing.Size(120, 24);
			this.btnOK.TabIndex = 15;
			this.btnOK.Text = "I";
			this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
			// 
			// Pti4
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
			this.ClientSize = new System.Drawing.Size(480, 405);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.btnOK,
																		  this.btnExit,
																		  this.btnStatus,
																		  this.btnInput,
																		  this.btnStop,
																		  this.btnStart,
																		  this.btnASet,
																		  this.btnMSet,
																		  this.btnInit,
																		  this.txtRet,
																		  this.label19,
																		  this.groupBox3,
																		  this.groupBox2,
																		  this.groupBox1,
																		  this.cboDevice,
																		  this.label1});
			this.Font = new System.Drawing.Font("lr oSVbN", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128)));
			this.Name = "Pti4";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "x^RlvTvvO";
			this.Load += new System.EventHandler(this.Pti4_Load);
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.groupBox3.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

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

		//	_CAȌ
		private void Pti4_Load(object sender, System.EventArgs e)
		{
			// o^ĂfoCXꗗ擾	
			int	ret;
			StringBuilder	device = new StringBuilder(50);
			StringBuilder	devicename = new StringBuilder(50);
			string	str = new string(' ', 100);
			short	index = 0;
			short	group_id, unit_id, device_id;
			group_id = 0;
			unit_id = 0;
			device_id = 0;
			do 
			{
				ret = Ccappt.PtQueryDeviceName(index, ref group_id, ref unit_id, ref device_id, devicename, device);
				if (ret == 0)
				{
					str = string.Format("{0} [{1}]", devicename, device);
					cboDevice.Items.Add(str);
					index++;
					cboDevice.SelectedIndex = 0;
				}
			} while (ret == 0);

			txtCh0.Text = "0";
			txtCh1.Text = "0";
			txtCh2.Text = "0";
			txtCh3.Text = "0";

		}

		//	[]{^NbN
		private void btnInit_Click(object sender, System.EventArgs e)
		{
			int	ret;
			StringBuilder	devicename = new StringBuilder(50);
			StringBuilder	tmp = new StringBuilder(50);
			short	index;
			short	group_id, unit_id, device_id;
			// foCX̌
			index = (short)cboDevice.SelectedIndex;
			group_id = 0;
			unit_id = 0;
			device_id = 0;
			ret = Ccappt.PtQueryDeviceName(index, ref group_id, ref unit_id, ref device_id, devicename, tmp);
			if (ret != 0)
			{
				ErrorHandling("PtQueryDeviceName", ret);
				return;
			}

			// 
			ret = Ccappt.PtInit(devicename, ref m_Id);
			if (ret != 0)
			{
				ErrorHandling("PtInit", ret);
				return;
			}

			txtRet.Text = "FI";
			ShowRemoteStatus();
		}

		//	[vݒ]{^NbN
		private void btnMSet_Click(object sender, System.EventArgs e)
		{
			Measure	MeasureDlg = new Measure();

			// vݒ_CAON
			MeasureDlg.SetId(m_Id);
			MeasureDlg.ShowDialog();
			MeasureDlg.Dispose();
		}

		//	[A[ݒ]{^NbN
		private void btnASet_Click(object sender, System.EventArgs e)
		{
			Alarm	AlarmDlg = new Alarm();

			// A[ݒ_CAON
			AlarmDlg.SetId(m_Id);
			AlarmDlg.ShowDialog();
			AlarmDlg.Dispose();	
		}

		//	[N]{^NbN
		private void btnStart_Click(object sender, System.EventArgs e)
		{
			//-----------------------------------
			// N
			//-----------------------------------
			int	ret;
			ret = Ccappt.PtStartIO(m_Id, 0x01);
			//-----------------------------------
			// G[
			//-----------------------------------
			if (ret != 0)
			{
				ErrorHandling("PtStartIO", ret);
				return;
			}
			txtRet.Text = "NFI";
			ShowRemoteStatus();
		}

		//	[~]{^NbN
		private void btnStop_Click(object sender, System.EventArgs e)
		{
			//-----------------------------------
			// ~
			//-----------------------------------
			int	ret;
			ret = Ccappt.PtStartIO(m_Id, 0x00);
			//-----------------------------------
			// G[
			//-----------------------------------
			if (ret != 0)
			{
				ErrorHandling("PtStartIO", ret);
				return;
			}
			txtRet.Text = "~FI";
			ShowRemoteStatus();
		}

		//	[͒l]{^NbN
		private void btnInput_Click(object sender, System.EventArgs e)
		{
			int	ret;
			float[]	data = new float[4];

			// 4`l̉x܂͒Rl
			GCHandle Pter = GCHandle.Alloc(data, GCHandleType.Pinned);
			ret = Ccappt.PtMultiInputEx(m_Id, 4, data);
			Pter.Free();
			if (ret != 0)
			{
				ErrorHandling("PtMultiInputEx", ret);
				if (ret != 20102)
				{
					return;
				}
			}

			txtCh0.Text = string.Format("{0:f}", data[0]);
			txtCh1.Text = string.Format("{0:f}", data[1]);
			txtCh2.Text = string.Format("{0:f}", data[2]);
			txtCh3.Text = string.Format("{0:f}", data[3]);
			//{0:f}
			txtRet.Text = "͏FI";
		}

		//	[Xe[^X]{^NbN
		private void btnStatus_Click(object sender, System.EventArgs e)
		{
			int	ret;
			int	disconnectstatus, upperstatus, lowerstatus;
			string	str = new string(' ', 32);

			// fԂ擾
			disconnectstatus = 0;
			upperstatus = 0;
			lowerstatus = 0;
			ret = Ccappt.PtGetDisconnectStatus(m_Id, ref disconnectstatus);
			if (ret != 0)
			{
				ErrorHandling("PtGetDisconnectStatus", ret);
				return;
			}

			// A[Ԃ擾
			ret = Ccappt.PtGetCurrentAlarmStatus(m_Id, ref upperstatus, ref lowerstatus);
			if (ret != 0)
			{
				ErrorHandling("PtGetCurrentAlarmStatus", ret);
				return;
			}

			str = string.Format("{0:X}", disconnectstatus);
			txtStsDc.Text = str;
			str = string.Format("{0:X}", upperstatus);
			txtStsUAlarm.Text = str;
			str = string.Format("{0:X}", lowerstatus);
			txtStsLAlarm.Text = str;

			txtRet.Text = "Xe[^X擾FI";
		}

		//	[I]{^NbN
		private void btnExit_Click(object sender, System.EventArgs e)
		{
			int	ret;

			// I
			ret = Ccappt.PtExit(m_Id);	
			if (ret != 0)
			{
				ErrorHandling("PtExit", ret);
				return;
			}

			txtRet.Text = "IFI";
		}

		//	_CAOI
		private void btnOK_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		// G[
		private void ErrorHandling(string Dfunction, int ret)
		{
			StringBuilder	errstr = new StringBuilder(256);
			string	str = new string(' ', 256);

			Ccappt.PtGetErrorString(ret, errstr);
			str = string.Format("[{0}] {1}", Dfunction, errstr);
			txtRet.Text = str;
		}

		// [gXe[^X̕\
		private void ShowRemoteStatus()
		{
			byte	Start, Err;
			string	szText = new string(' ', 100);
			int	ret;

			// [gXe[^X
			Start = 0;
			Err = 0;
			ret = Ccappt.PtGetRemoteStatus(m_Id, ref Start, ref Err);
			// G[
			if (ret != 0)
			{
				ErrorHandling("PtGetRemoteStatus", ret);
				return;
			}
			// [gXe[^X\
			szText = string.Format("{0:X2}", Start);
			lblStart.Text = szText;
			szText = string.Format("{0:X2}", Err);
			lblErr.Text = szText;
		}

		private void Pti4_Closed(object sender, System.EventArgs e)
		{
			int	ret;

			// I
			ret = Ccappt.PtExit(m_Id);	
		}
	}
}
