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 MultiAo
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class MultiAo : System.Windows.Forms.Form
	{
		internal System.Windows.Forms.Label Label7;
		internal System.Windows.Forms.TextBox txtAoVolt;
		internal System.Windows.Forms.TextBox txtAoChannel;
		internal System.Windows.Forms.Label Label5;
		internal System.Windows.Forms.Label Label4;
		internal System.Windows.Forms.Label Label3;
		internal System.Windows.Forms.Label Label2;
		internal System.Windows.Forms.Label Label1;
		internal System.Windows.Forms.Label lblErrorString;
		internal System.Windows.Forms.Label lblVolt;
		internal System.Windows.Forms.Label lblAoChannels;
		internal System.Windows.Forms.Button btnSet;
		internal System.Windows.Forms.Label lblCData1;
		internal System.Windows.Forms.Button btnAioExit;
		internal System.Windows.Forms.Button btnAioMultiAo;
		internal System.Windows.Forms.Button btnStop;
		internal System.Windows.Forms.Button btnStart;
		internal System.Windows.Forms.Button btnAioInit;
		internal System.Windows.Forms.Label lblCData2;
		internal System.Windows.Forms.Label lblErr;
		internal System.Windows.Forms.Label lblStart;
		internal System.Windows.Forms.ComboBox cboAioSetAoRange;
		internal System.Windows.Forms.ComboBox cboDeviceName;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		// Return value of function
		int				Ret;
		// ID
		short			Id;
		// Maximum number of channels
		short			MaxAoChannels;
		// The data of output voltage
		float[]			AoVolt = new float[256];
		// ErrorCode string
		StringBuilder	ErrorString = new StringBuilder(256);
		// Used to format string
		string			TextString;
		string			TextTemp;

		public MultiAo()
		{
			//
			// 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()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MultiAo));
			this.lblErrorString = new System.Windows.Forms.Label();
			this.lblVolt = new System.Windows.Forms.Label();
			this.lblAoChannels = new System.Windows.Forms.Label();
			this.btnSet = new System.Windows.Forms.Button();
			this.lblCData1 = new System.Windows.Forms.Label();
			this.Label7 = new System.Windows.Forms.Label();
			this.btnAioExit = new System.Windows.Forms.Button();
			this.btnAioMultiAo = new System.Windows.Forms.Button();
			this.btnStop = new System.Windows.Forms.Button();
			this.btnStart = new System.Windows.Forms.Button();
			this.btnAioInit = new System.Windows.Forms.Button();
			this.txtAoVolt = new System.Windows.Forms.TextBox();
			this.txtAoChannel = new System.Windows.Forms.TextBox();
			this.lblCData2 = new System.Windows.Forms.Label();
			this.Label5 = new System.Windows.Forms.Label();
			this.lblErr = new System.Windows.Forms.Label();
			this.lblStart = new System.Windows.Forms.Label();
			this.Label4 = new System.Windows.Forms.Label();
			this.Label3 = new System.Windows.Forms.Label();
			this.cboAioSetAoRange = new System.Windows.Forms.ComboBox();
			this.Label2 = new System.Windows.Forms.Label();
			this.cboDeviceName = new System.Windows.Forms.ComboBox();
			this.Label1 = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// lblErrorString
			// 
			this.lblErrorString.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.lblErrorString.Location = new System.Drawing.Point(12, 450);
			this.lblErrorString.Name = "lblErrorString";
			this.lblErrorString.Size = new System.Drawing.Size(298, 37);
			this.lblErrorString.TabIndex = 87;
			// 
			// lblVolt
			// 
			this.lblVolt.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.lblVolt.Location = new System.Drawing.Point(160, 214);
			this.lblVolt.Name = "lblVolt";
			this.lblVolt.Size = new System.Drawing.Size(64, 223);
			this.lblVolt.TabIndex = 86;
			// 
			// lblAoChannels
			// 
			this.lblAoChannels.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.lblAoChannels.Location = new System.Drawing.Point(101, 214);
			this.lblAoChannels.Name = "lblAoChannels";
			this.lblAoChannels.Size = new System.Drawing.Size(51, 223);
			this.lblAoChannels.TabIndex = 85;
			// 
			// btnSet
			// 
			this.btnSet.Location = new System.Drawing.Point(232, 158);
			this.btnSet.Name = "btnSet";
			this.btnSet.Size = new System.Drawing.Size(76, 25);
			this.btnSet.TabIndex = 71;
			this.btnSet.Text = "Set";
			this.btnSet.Click += new System.EventHandler(this.btnSet_Click);
			// 
			// lblCData1
			// 
			this.lblCData1.Location = new System.Drawing.Point(160, 195);
			this.lblCData1.Name = "lblCData1";
			this.lblCData1.Size = new System.Drawing.Size(64, 19);
			this.lblCData1.TabIndex = 84;
			this.lblCData1.Text = "Voltage";
			// 
			// Label7
			// 
			this.Label7.Location = new System.Drawing.Point(101, 195);
			this.Label7.Name = "Label7";
			this.Label7.Size = new System.Drawing.Size(64, 19);
			this.Label7.TabIndex = 83;
			this.Label7.Text = "Channel";
			// 
			// btnAioExit
			// 
			this.btnAioExit.Location = new System.Drawing.Point(12, 195);
			this.btnAioExit.Name = "btnAioExit";
			this.btnAioExit.Size = new System.Drawing.Size(76, 25);
			this.btnAioExit.TabIndex = 67;
			this.btnAioExit.Text = "AioExit";
			this.btnAioExit.Click += new System.EventHandler(this.btnAioExit_Click);
			// 
			// btnAioMultiAo
			// 
			this.btnAioMultiAo.Location = new System.Drawing.Point(12, 158);
			this.btnAioMultiAo.Name = "btnAioMultiAo";
			this.btnAioMultiAo.Size = new System.Drawing.Size(76, 25);
			this.btnAioMultiAo.TabIndex = 66;
			this.btnAioMultiAo.Text = "AioMultiAo";
			this.btnAioMultiAo.Click += new System.EventHandler(this.btnAioMultiAo_Click);
			// 
			// btnStop
			// 
			this.btnStop.Location = new System.Drawing.Point(12, 121);
			this.btnStop.Name = "btnStop";
			this.btnStop.Size = new System.Drawing.Size(76, 25);
			this.btnStop.TabIndex = 73;
			this.btnStop.Text = "Stop";
			this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
			// 
			// btnStart
			// 
			this.btnStart.Location = new System.Drawing.Point(12, 84);
			this.btnStart.Name = "btnStart";
			this.btnStart.Size = new System.Drawing.Size(76, 25);
			this.btnStart.TabIndex = 72;
			this.btnStart.Text = "Start";
			this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
			// 
			// btnAioInit
			// 
			this.btnAioInit.Location = new System.Drawing.Point(12, 47);
			this.btnAioInit.Name = "btnAioInit";
			this.btnAioInit.Size = new System.Drawing.Size(76, 25);
			this.btnAioInit.TabIndex = 65;
			this.btnAioInit.Text = "AioInit";
			this.btnAioInit.Click += new System.EventHandler(this.btnAioInit_Click);
			// 
			// txtAoVolt
			// 
			this.txtAoVolt.Location = new System.Drawing.Point(160, 163);
			this.txtAoVolt.Name = "txtAoVolt";
			this.txtAoVolt.Size = new System.Drawing.Size(64, 20);
			this.txtAoVolt.TabIndex = 70;
			this.txtAoVolt.Text = "";
			// 
			// txtAoChannel
			// 
			this.txtAoChannel.Location = new System.Drawing.Point(101, 163);
			this.txtAoChannel.Name = "txtAoChannel";
			this.txtAoChannel.Size = new System.Drawing.Size(51, 20);
			this.txtAoChannel.TabIndex = 68;
			this.txtAoChannel.Text = "";
			// 
			// lblCData2
			// 
			this.lblCData2.Location = new System.Drawing.Point(160, 144);
			this.lblCData2.Name = "lblCData2";
			this.lblCData2.Size = new System.Drawing.Size(64, 19);
			this.lblCData2.TabIndex = 82;
			this.lblCData2.Text = "Voltage";
			// 
			// Label5
			// 
			this.Label5.Location = new System.Drawing.Point(101, 144);
			this.Label5.Name = "Label5";
			this.Label5.Size = new System.Drawing.Size(64, 19);
			this.Label5.TabIndex = 81;
			this.Label5.Text = "Channel";
			// 
			// lblErr
			// 
			this.lblErr.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.lblErr.Location = new System.Drawing.Point(184, 114);
			this.lblErr.Name = "lblErr";
			this.lblErr.Size = new System.Drawing.Size(39, 17);
			this.lblErr.TabIndex = 80;
			// 
			// lblStart
			// 
			this.lblStart.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.lblStart.Location = new System.Drawing.Point(101, 114);
			this.lblStart.Name = "lblStart";
			this.lblStart.Size = new System.Drawing.Size(39, 17);
			this.lblStart.TabIndex = 79;
			// 
			// Label4
			// 
			this.Label4.Location = new System.Drawing.Point(184, 95);
			this.Label4.Name = "Label4";
			this.Label4.Size = new System.Drawing.Size(82, 19);
			this.Label4.TabIndex = 78;
			this.Label4.Text = "Error Register";
			// 
			// Label3
			// 
			this.Label3.Location = new System.Drawing.Point(101, 95);
			this.Label3.Name = "Label3";
			this.Label3.Size = new System.Drawing.Size(74, 19);
			this.Label3.TabIndex = 77;
			this.Label3.Text = "Start Register";
			// 
			// cboAioSetAoRange
			// 
			this.cboAioSetAoRange.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboAioSetAoRange.Location = new System.Drawing.Point(101, 64);
			this.cboAioSetAoRange.Name = "cboAioSetAoRange";
			this.cboAioSetAoRange.Size = new System.Drawing.Size(136, 21);
			this.cboAioSetAoRange.TabIndex = 69;
			this.cboAioSetAoRange.SelectionChangeCommitted += new System.EventHandler(this.cboAioSetAoRange_SelectionChangeCommitted);
			// 
			// Label2
			// 
			this.Label2.Location = new System.Drawing.Point(100, 44);
			this.Label2.Name = "Label2";
			this.Label2.Size = new System.Drawing.Size(64, 19);
			this.Label2.TabIndex = 76;
			this.Label2.Text = "Range";
			// 
			// cboDeviceName
			// 
			this.cboDeviceName.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboDeviceName.Location = new System.Drawing.Point(101, 10);
			this.cboDeviceName.Name = "cboDeviceName";
			this.cboDeviceName.Size = new System.Drawing.Size(203, 21);
			this.cboDeviceName.TabIndex = 74;
			// 
			// Label1
			// 
			this.Label1.Location = new System.Drawing.Point(12, 14);
			this.Label1.Name = "Label1";
			this.Label1.Size = new System.Drawing.Size(82, 19);
			this.Label1.TabIndex = 75;
			this.Label1.Text = "Device Name :";
			// 
			// MultiAo
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(322, 497);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.lblErrorString,
																		  this.lblVolt,
																		  this.lblAoChannels,
																		  this.btnSet,
																		  this.lblCData1,
																		  this.Label7,
																		  this.btnAioExit,
																		  this.btnAioMultiAo,
																		  this.btnStop,
																		  this.btnStart,
																		  this.btnAioInit,
																		  this.txtAoVolt,
																		  this.txtAoChannel,
																		  this.lblCData2,
																		  this.Label5,
																		  this.lblErr,
																		  this.lblStart,
																		  this.Label4,
																		  this.Label3,
																		  this.cboAioSetAoRange,
																		  this.Label2,
																		  this.cboDeviceName,
																		  this.Label1});
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MaximizeBox = false;
			this.Name = "MultiAo";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Analog output of plural channels once";
			this.Load += new System.EventHandler(this.MultiAo_Load);
			this.ResumeLayout(false);

		}
		#endregion

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

		//---------------------------------------------------------
		//	Initialize dialog
		//---------------------------------------------------------
		private void MultiAo_Load(object sender, System.EventArgs e)
		{
			//-----------------------------------
			// Detect device
			//-----------------------------------
			short	Index;
			short	GroupID, UnitID, DeviceID;
			StringBuilder	DeviceName = new StringBuilder(256);
			StringBuilder	Device = new StringBuilder(256);
			GroupID = 0;
			UnitID = 0;
			DeviceID = 0;
			for (Index=0; ; Index++) 
			{
				Ret = AIO.Ccapaio.AioQueryDeviceName(Index, ref GroupID, ref UnitID, ref DeviceID, DeviceName, Device);
				if (Ret != AIO.Ccapaio.AIO_ERR_SUCCESS) 
				{
					break;
				}
				cboDeviceName.Items.Add(DeviceName);
			}
			cboDeviceName.SelectedIndex = 0;

			//-----------------------------------
			// Create combobox for analog output range
			//-----------------------------------
			cboAioSetAoRange.Items.Add("-10 - +10V");
			cboAioSetAoRange.Items.Add("-5 - +5V");
			cboAioSetAoRange.Items.Add("0 - +10V");
			cboAioSetAoRange.Items.Add("0 - +5V");
			cboAioSetAoRange.Items.Add("0 - +20mA");

			txtAoChannel.Text = "0";
			//-----------------------------------
			// Initialize output data to 0
			//-----------------------------------
			short i;
			for(i = 0 ; i < 256 ; i++)
			{
				AoVolt[i] = 0;
			}
		}

		//--------------------------------------------------------------------------------------------------
		//	Initialize device
		//--------------------------------------------------------------------------------------------------
		private void btnAioInit_Click(object sender, System.EventArgs e)
		{
			//-----------------------------------
			// Initialization
			//-----------------------------------
			string	DeviceName = new string(' ', 100);
			DeviceName = cboDeviceName.Text;
			Ret = AIO.Ccapaio.AioInit(DeviceName, ref Id);
			//-----------------------------------
			// Process error
			//-----------------------------------
			AIO.Ccapaio.AioGetErrorString(Ret, ErrorString);
			TextString = "AioInit : " + ErrorString;
			lblErrorString.Text = TextString;
			if(Ret != 0)
			{
				return;
			}
			//-----------------------------------
			// Get and display range
			//-----------------------------------
			short	AoRange;
			short	Index;
			AoRange = 0;
			Index = 0;
			Ret = AIO.Ccapaio.AioGetAoRange(Id, 0, ref AoRange);
			if (Ret == AIO.Ccapaio.AIO_ERR_SUCCESS) 
			{
				switch(AoRange)
				{
					case AIO.Ccapaio.PM10:	Index = 0;	break;
					case AIO.Ccapaio.PM5:	Index = 1;	break;
					case AIO.Ccapaio.P10:	Index = 2;	break;
					case AIO.Ccapaio.P5:	Index = 3;	break;
					case AIO.Ccapaio.P20MA:	Index = 4;	break;
				}
				cboAioSetAoRange.SelectedIndex = Index;
				//-----------------------------------
				// Switch display
				//-----------------------------------
				if(AoRange == AIO.Ccapaio.P20MA)
				{
					lblCData1.Text = "Current";
					lblCData2.Text = "Current";
				}
				else
				{
					lblCData1.Text = "Voltage";
					lblCData2.Text = "Voltage";
				}
			}
			//-----------------------------------
			// Get maximum number of channels
			//-----------------------------------
			Ret = AIO.Ccapaio.AioGetAoMaxChannels(Id, ref MaxAoChannels);
			if(Ret != 0)
			{
				AIO.Ccapaio.AioGetErrorString(Ret, ErrorString);
				TextString = "AioGetAoMaxChannels : " + ErrorString;
				lblErrorString.Text = TextString;
			}
			//-----------------------------------
			// Display voltage
			//-----------------------------------
			short i;
			TextString = "";
			for(i = 0 ; i < MaxAoChannels ; i++)
			{
				TextTemp = string.Format("{0:d}\n", i);
				TextString += TextTemp;
				lblAoChannels.Text = TextString;
			}
			TextString = "";
			for(i = 0 ; i < MaxAoChannels ; i++)
			{
				TextTemp = string.Format("0.000\n");
				TextString += TextTemp;
				lblVolt.Text = TextString;
			}
			ShowRemoteStatus();
		}

		//--------------------------------------------------------------------------------------------------
		//	Start button
		//--------------------------------------------------------------------------------------------------
		private void btnStart_Click(object sender, System.EventArgs e)
		{
			//-----------------------------------
			// Start
			//-----------------------------------
			Ret = AIO.Ccapaio.AioStartIO(Id, 0x01);
			//-----------------------------------
			// Process error
			//-----------------------------------
			AIO.Ccapaio.AioGetErrorString(Ret, ErrorString);
			TextString = "AioStartIO : " + ErrorString;
			lblErrorString.Text = TextString;
			if(Ret != 0)
			{
				return;
			}
			ShowRemoteStatus();
		}

		//--------------------------------------------------------------------------------------------------
		//	Stop button
		//--------------------------------------------------------------------------------------------------
		private void btnStop_Click(object sender, System.EventArgs e)
		{
			//-----------------------------------
			// Stop
			//-----------------------------------
			Ret = AIO.Ccapaio.AioStartIO(Id, 0x00);
			//-----------------------------------
			// Process error
			//-----------------------------------
			AIO.Ccapaio.AioGetErrorString(Ret, ErrorString);
			TextString = "AioStartIO : " + ErrorString;
			lblErrorString.Text = TextString;
			if(Ret != 0)
			{
				return;
			}
			ShowRemoteStatus();
		}

		//--------------------------------------------------------------------------------------------------
		//	Analog output of plural channels once
		//--------------------------------------------------------------------------------------------------
		private void btnAioMultiAo_Click(object sender, System.EventArgs e)
		{
			GCHandle Pter = GCHandle.Alloc(AoVolt, GCHandleType.Pinned);
			//-----------------------------------
			// Analog output
			//-----------------------------------
			Ret = AIO.Ccapaio.AioMultiAoEx(Id, MaxAoChannels, AoVolt);
			Pter.Free();
			//-----------------------------------
			// Process error
			//-----------------------------------
			AIO.Ccapaio.AioGetErrorString(Ret, ErrorString);
			TextString = "AioMultiAoEx : " + ErrorString;
			lblErrorString.Text = TextString;
			if(Ret != 0)
			{
				return;
			}
		}

		//--------------------------------------------------------------------------------------------------
		//	Set analog output data
		//--------------------------------------------------------------------------------------------------
		private void btnSet_Click(object sender, System.EventArgs e)
		{
			string	szText = new string(' ', 100);
			short	AoChannel;
			float	AoVoltTmp;
			//-----------------------------------
			// Get data from screen
			//-----------------------------------
			szText = txtAoChannel.Text;
			try
			{
				AoChannel = Convert.ToInt16(szText);
			}
			catch (System.FormatException)
			{
				AoChannel = 0;
			}
			szText = txtAoVolt.Text;			
			try
			{
				AoVoltTmp = Convert.ToSingle(szText);			
			}
			catch (System.FormatException)
			{
				AoVoltTmp = 0;
			}

			if(AoChannel >= MaxAoChannels)
			{
				lblErrorString.Text = "Set output data : output channel is out of range";
				return;
			}
			//-----------------------------------
			// Update array and display data
			//-----------------------------------
			AoVolt[AoChannel] = AoVoltTmp;

			TextString = "";
			short i;
			for(i=0 ; i<MaxAoChannels; i++)
			{
				TextTemp = string.Format("{0:f3}\n", AoVolt[i]);
				TextString += TextTemp;
				lblVolt.Text = TextString;
			}
		}

		//--------------------------------------------------------------------------------------------------
		//	Terminate device
		//--------------------------------------------------------------------------------------------------
		private void btnAioExit_Click(object sender, System.EventArgs e)
		{
			//-----------------------------------
			// Terminate device
			//-----------------------------------
			Ret = AIO.Ccapaio.AioExit(Id);
			AIO.Ccapaio.AioGetErrorString(Ret, ErrorString);
			TextString = "AioExit : " + ErrorString;
			lblErrorString.Text = TextString;
		}

		private void MultiAo_Closed(object sender, System.EventArgs e)
		{
			//-----------------------------------
			// Terminate device
			//-----------------------------------
			Ret = AIO.Ccapaio.AioExit(Id);
		}

		//--------------------------------------------------------------------------------------------------
		//	Set analog output range
		//--------------------------------------------------------------------------------------------------
		private void cboAioSetAoRange_SelectionChangeCommitted(object sender, System.EventArgs e)
		{
			short	AoRange;
			short	Index;
			AoRange = 0;
			//-----------------------------------
			// Get screen content
			//-----------------------------------
			Index = (short)cboAioSetAoRange.SelectedIndex;
			switch(Index)
			{
				case 0:	AoRange = AIO.Ccapaio.PM10;		break;
				case 1:	AoRange = AIO.Ccapaio.PM5;		break;
				case 2:	AoRange = AIO.Ccapaio.P10;		break;
				case 3:	AoRange = AIO.Ccapaio.P5;		break;
				case 4:	AoRange = AIO.Ccapaio.P20MA;	break;
			}
			//-----------------------------------
			// Set output range
			//-----------------------------------
			Ret = AIO.Ccapaio.AioSetAoRangeAll(Id, AoRange);
			//-----------------------------------
			// Process error
			//-----------------------------------
			AIO.Ccapaio.AioGetErrorString(Ret, ErrorString);
			TextString = "AioSetAoRangeAll : " + ErrorString;
			lblErrorString.Text = TextString;
			if (Ret != 0) 
			{
				return;
			}
			//-----------------------------------
			// Switch display
			//-----------------------------------
			if(AoRange == AIO.Ccapaio.P20MA)
			{
				lblCData1.Text = "Current";
				lblCData2.Text = "Current";
			}
			else
			{
				lblCData1.Text = "Voltage";
				lblCData2.Text = "Voltage";
			}
		}

		//--------------------------------------------------------------------------------------------------
		//	Display remote status
		//--------------------------------------------------------------------------------------------------
		private void ShowRemoteStatus()
		{
			byte	Start, Err;
			string	szText = new string(' ', 100);
			Start = 0;
			Err = 0;
			//-----------------------------------
			// Input remote status
			//-----------------------------------
			Ret = AIO.Ccapaio.AioGetRemoteStatus(Id, ref Start, ref Err);
			//-----------------------------------
			// Process error
			//-----------------------------------
			if (Ret != AIO.Ccapaio.AIO_ERR_SUCCESS) 
			{
				AIO.Ccapaio.AioGetErrorString(Ret, ErrorString);
				TextString = "AioGetRemoteStatus : " + ErrorString;
				lblErrorString.Text = TextString;
				return;
			}
			//-----------------------------------
			// Display remote status
			//-----------------------------------
			szText = string.Format("{0:X2}", Start);
			lblStart.Text = szText;
			szText = string.Format("{0:X2}", Err);
			lblErr.Text = szText;
		}
	}
}