﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using CSmcCs;

namespace BankArc
{
	/// <summary>
	/// Summary description for BankArc.
	/// </summary>
	public class BankArc : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox txtDeviceName;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.ComboBox cboTargetAxis;
		private System.Windows.Forms.TextBox txtTargetAxis;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.RadioButton rdoDirCw;
		private System.Windows.Forms.RadioButton rdoDirCcw;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox txtArcSpeed;
		private System.Windows.Forms.Button btnComMove;
		private System.Windows.Forms.Button btnComStop;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.RadioButton rdoOptionSingle;
		private System.Windows.Forms.RadioButton rdoOptionLoop;
		private System.Windows.Forms.Button btnExit;
		private System.Windows.Forms.GroupBox COMMENT;
		private System.Windows.Forms.Label lblComment;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.ComboBox cboTargetBankNum;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		string		szDeviceName;
		short		ArcStartDir;
		short		MotionType;
		bool		bRet;
		short		Id;
		short		AxisNo;
		short		BankNum;

		short		InterAxis;
		short		InterType;
		short		AutoEndPointPull;
		short		BankNo;
		short		Reserved;
		double		ArcSpeed;
		short		Coordinates;
		int			Center_X;
		int			Center_Y;
		int			End_X;
		int			End_Y;

		CSmc		Smc	= new CSmc();

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

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

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.label1 = new System.Windows.Forms.Label();
			this.txtDeviceName = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.cboTargetAxis = new System.Windows.Forms.ComboBox();
			this.txtTargetAxis = new System.Windows.Forms.TextBox();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.btnComStop = new System.Windows.Forms.Button();
			this.btnComMove = new System.Windows.Forms.Button();
			this.txtArcSpeed = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.rdoDirCcw = new System.Windows.Forms.RadioButton();
			this.rdoDirCw = new System.Windows.Forms.RadioButton();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.rdoOptionLoop = new System.Windows.Forms.RadioButton();
			this.rdoOptionSingle = new System.Windows.Forms.RadioButton();
			this.btnExit = new System.Windows.Forms.Button();
			this.COMMENT = new System.Windows.Forms.GroupBox();
			this.lblComment = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.cboTargetBankNum = new System.Windows.Forms.ComboBox();
			this.groupBox1.SuspendLayout();
			this.groupBox2.SuspendLayout();
			this.COMMENT.SuspendLayout();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.AutoSize = true;
			this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label1.Location = new System.Drawing.Point(8, 21);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(79, 14);
			this.label1.TabIndex = 0;
			this.label1.Text = "DeviceName:";
			// 
			// txtDeviceName
			// 
			this.txtDeviceName.AutoSize = false;
			this.txtDeviceName.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtDeviceName.Location = new System.Drawing.Point(90, 16);
			this.txtDeviceName.Name = "txtDeviceName";
			this.txtDeviceName.ScrollBars = System.Windows.Forms.ScrollBars.Horizontal;
			this.txtDeviceName.Size = new System.Drawing.Size(78, 23);
			this.txtDeviceName.TabIndex = 1;
			this.txtDeviceName.Text = "";
			// 
			// label2
			// 
			this.label2.AutoSize = true;
			this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label2.Location = new System.Drawing.Point(184, 24);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(47, 14);
			this.label2.TabIndex = 2;
			this.label2.Text = "AxisNo:";
			// 
			// cboTargetAxis
			// 
			this.cboTargetAxis.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboTargetAxis.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.cboTargetAxis.Location = new System.Drawing.Point(232, 16);
			this.cboTargetAxis.Name = "cboTargetAxis";
			this.cboTargetAxis.Size = new System.Drawing.Size(48, 23);
			this.cboTargetAxis.Sorted = true;
			this.cboTargetAxis.TabIndex = 2;
			this.cboTargetAxis.SelectedIndexChanged += new System.EventHandler(this.cboTargetAxis_SelectedIndexChanged);
			// 
			// txtTargetAxis
			// 
			this.txtTargetAxis.AutoSize = false;
			this.txtTargetAxis.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtTargetAxis.Location = new System.Drawing.Point(288, 16);
			this.txtTargetAxis.Name = "txtTargetAxis";
			this.txtTargetAxis.ReadOnly = true;
			this.txtTargetAxis.ScrollBars = System.Windows.Forms.ScrollBars.Horizontal;
			this.txtTargetAxis.Size = new System.Drawing.Size(32, 23);
			this.txtTargetAxis.TabIndex = 3;
			this.txtTargetAxis.Text = "txtTargetAxis";
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.cboTargetBankNum,
																					this.label4,
																					this.btnComStop,
																					this.btnComMove,
																					this.txtArcSpeed,
																					this.label3,
																					this.rdoDirCcw,
																					this.rdoDirCw});
			this.groupBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.groupBox1.Location = new System.Drawing.Point(8, 56);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(200, 152);
			this.groupBox1.TabIndex = 4;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "MOTION";
			// 
			// btnComStop
			// 
			this.btnComStop.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnComStop.Location = new System.Drawing.Point(104, 112);
			this.btnComStop.Name = "btnComStop";
			this.btnComStop.Size = new System.Drawing.Size(88, 32);
			this.btnComStop.TabIndex = 8;
			this.btnComStop.Text = "STOP";
			this.btnComStop.Click += new System.EventHandler(this.btnComStop_Click);
			// 
			// btnComMove
			// 
			this.btnComMove.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnComMove.Location = new System.Drawing.Point(8, 112);
			this.btnComMove.Name = "btnComMove";
			this.btnComMove.Size = new System.Drawing.Size(88, 32);
			this.btnComMove.TabIndex = 7;
			this.btnComMove.Text = "START";
			this.btnComMove.Click += new System.EventHandler(this.btnComMove_Click);
			// 
			// txtArcSpeed
			// 
			this.txtArcSpeed.AutoSize = false;
			this.txtArcSpeed.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtArcSpeed.Location = new System.Drawing.Point(120, 32);
			this.txtArcSpeed.Name = "txtArcSpeed";
			this.txtArcSpeed.ScrollBars = System.Windows.Forms.ScrollBars.Horizontal;
			this.txtArcSpeed.Size = new System.Drawing.Size(64, 23);
			this.txtArcSpeed.TabIndex = 6;
			this.txtArcSpeed.Text = "";
			// 
			// label3
			// 
			this.label3.AutoSize = true;
			this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label3.Location = new System.Drawing.Point(72, 32);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(44, 14);
			this.label3.TabIndex = 2;
			this.label3.Text = "Speed:";
			// 
			// rdoDirCcw
			// 
			this.rdoDirCcw.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.rdoDirCcw.Location = new System.Drawing.Point(16, 56);
			this.rdoDirCcw.Name = "rdoDirCcw";
			this.rdoDirCcw.Size = new System.Drawing.Size(56, 16);
			this.rdoDirCcw.TabIndex = 5;
			this.rdoDirCcw.Text = "CCW";
			this.rdoDirCcw.CheckedChanged += new System.EventHandler(this.rdoDirCcw_CheckedChanged);
			// 
			// rdoDirCw
			// 
			this.rdoDirCw.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.rdoDirCw.Location = new System.Drawing.Point(16, 27);
			this.rdoDirCw.Name = "rdoDirCw";
			this.rdoDirCw.Size = new System.Drawing.Size(56, 16);
			this.rdoDirCw.TabIndex = 4;
			this.rdoDirCw.Text = "CW";
			this.rdoDirCw.CheckedChanged += new System.EventHandler(this.rdoDirCw_CheckedChanged);
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.rdoOptionLoop,
																					this.rdoOptionSingle});
			this.groupBox2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.groupBox2.Location = new System.Drawing.Point(220, 56);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(96, 88);
			this.groupBox2.TabIndex = 5;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "TYPE";
			// 
			// rdoOptionLoop
			// 
			this.rdoOptionLoop.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.rdoOptionLoop.Location = new System.Drawing.Point(16, 56);
			this.rdoOptionLoop.Name = "rdoOptionLoop";
			this.rdoOptionLoop.Size = new System.Drawing.Size(72, 24);
			this.rdoOptionLoop.TabIndex = 11;
			this.rdoOptionLoop.Text = "Loop";
			this.rdoOptionLoop.CheckedChanged += new System.EventHandler(this.rdoOptionLoop_CheckedChanged);
			// 
			// rdoOptionSingle
			// 
			this.rdoOptionSingle.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.rdoOptionSingle.Location = new System.Drawing.Point(16, 24);
			this.rdoOptionSingle.Name = "rdoOptionSingle";
			this.rdoOptionSingle.Size = new System.Drawing.Size(64, 24);
			this.rdoOptionSingle.TabIndex = 10;
			this.rdoOptionSingle.Text = "Single";
			this.rdoOptionSingle.CheckedChanged += new System.EventHandler(this.rdoOptionSingle_CheckedChanged);
			// 
			// btnExit
			// 
			this.btnExit.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnExit.Location = new System.Drawing.Point(220, 168);
			this.btnExit.Name = "btnExit";
			this.btnExit.Size = new System.Drawing.Size(88, 32);
			this.btnExit.TabIndex = 0;
			this.btnExit.Text = "EXIT";
			this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
			// 
			// COMMENT
			// 
			this.COMMENT.Controls.AddRange(new System.Windows.Forms.Control[] {
																				  this.lblComment});
			this.COMMENT.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.COMMENT.Location = new System.Drawing.Point(8, 216);
			this.COMMENT.Name = "COMMENT";
			this.COMMENT.Size = new System.Drawing.Size(320, 120);
			this.COMMENT.TabIndex = 8;
			this.COMMENT.TabStop = false;
			this.COMMENT.Text = "COMMENT";
			// 
			// lblComment
			// 
			this.lblComment.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.lblComment.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lblComment.Location = new System.Drawing.Point(8, 24);
			this.lblComment.Name = "lblComment";
			this.lblComment.Size = new System.Drawing.Size(304, 88);
			this.lblComment.TabIndex = 0;
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(17, 83);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(64, 16);
			this.label4.TabIndex = 9;
			this.label4.Text = "BankNum";
			// 
			// cboTargetBankNum
			// 
			this.cboTargetBankNum.Location = new System.Drawing.Point(88, 80);
			this.cboTargetBankNum.Name = "cboTargetBankNum";
			this.cboTargetBankNum.Size = new System.Drawing.Size(56, 23);
			this.cboTargetBankNum.TabIndex = 10;
			this.cboTargetBankNum.SelectedIndexChanged += new System.EventHandler(this.cboTargetBankNum_SelectedIndexChanged);
			// 
			// BankArc
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(338, 342);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.COMMENT,
																		  this.btnExit,
																		  this.groupBox2,
																		  this.groupBox1,
																		  this.txtTargetAxis,
																		  this.cboTargetAxis,
																		  this.label2,
																		  this.txtDeviceName,
																		  this.label1});
			this.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "BankArc";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "BANKARC";
			this.Load += new System.EventHandler(this.BankArc_Load);
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.COMMENT.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

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

		private void BankArc_Load(object sender, System.EventArgs e)
		{
			string	szErrorString;
			int		ret = 0;
			short	i = 0;
			string	tmp;

			lblComment.Text = "OK";
			
			//-------------
			// Initialize
			//-------------
			szDeviceName = "SMC000";
			txtDeviceName.Text = szDeviceName;
			AxisNo = 1;

			txtArcSpeed.Text = "10000";
			rdoOptionSingle.Checked = true;
			MotionType = (short)CSmcConst.CSMC_SINGLE;
			rdoDirCw.Checked = true;
			ArcStartDir = (short)CSmcConst.CSMC_CW;

			txtTargetAxis.Text = string.Format("{0:d}",AxisNo + 1);

			//AxisNo ComboBox
			cboTargetAxis.Items.Clear();
			for( i = 1; i <= 8; i++ )
			{
				cboTargetAxis.Items.Add(i);
			}    
			//ComboBox Initialise
			cboTargetAxis.SelectedIndex = AxisNo - 1;
   
			BankNum = 4;
			//BankNum ComboBox
			cboTargetBankNum.Items.Clear();
			for( i = 1; i <= 4; i++ )
			{
				cboTargetBankNum.Items.Add(i);
			}    
			//ComboBox Initialise
			cboTargetBankNum.SelectedIndex = BankNum - 1;

			ret = Smc.WInit(szDeviceName, out Id);
			if( ret != 0 )
			{
				Smc.WGetErrorString(ret, out tmp);
				szErrorString = string.Format("SmcWInit = {0:d} : {1}", ret, tmp);
				lblComment.Text = szErrorString;
			}


			
			InterAxis = 0;
			InterType = 0;
			AutoEndPointPull = 0;
			BankNo = 0;
			Reserved = 0;
			ArcSpeed = 0;
			Coordinates = 0;
			Center_X = 0;
			Center_Y = 0;
			End_X = 0;
			End_Y = 0;
		}

		private void btnExit_Click(object sender, System.EventArgs e)
		{
			Smc.WExit(Id);
			this.Close();
		}

		private void cboTargetAxis_SelectedIndexChanged(object sender, System.EventArgs e)
		{	
			AxisNo = (short)(cboTargetAxis.SelectedIndex + 1);
			txtTargetAxis.Text = string.Format("{0:d}", AxisNo + 1); 
		}

		private bool SetBankParam()
		{
			int		ret = 0;
			string	szErrorString;
			string	tmp;
    
			//----------------------------
			// Set Bank Number to Driver
			//----------------------------
			ret = Smc.WSetBankNumber(Id, AxisNo, BankNum);
			if( ret != 0 )
			{
				Smc.WGetErrorString(ret, out tmp);
				szErrorString = string.Format("SmcWSetBankNumber = {0:d} : {1}", ret, tmp);
				lblComment.Text = szErrorString;
				return false;	
			}

			//----------------------------
			// Set Interpolation to Driver
			//----------------------------
			int		cal1, cal2;
			cal1 = (int)Math.Pow(2, (AxisNo - 1));
			cal2 = (int)Math.Pow(2 , AxisNo);
			InterAxis = (short)(cal1 | cal2);
    
			//Circular arc interpolation
			InterType = 3;
    
			//Automatically enter an end point pull in operation at the end of arc interpolation operation.
			AutoEndPointPull = 1;
    
			for( BankNo = 1; BankNo <= BankNum; BankNo++ )
			{
				ret = Smc.WSetBankInterpolation(Id, AxisNo, BankNo, InterType, InterAxis, Reserved);
				if( ret != 0 )
				{
					Smc.WGetErrorString(ret, out tmp);
					szErrorString = string.Format("SmcWSetBankInterpolation = {0:d} : {1}", ret, tmp);
					lblComment.Text = szErrorString;
					return false;	
				}
				ret = Smc.WSetBankArcParam(Id, AxisNo, BankNo, ArcStartDir, AutoEndPointPull);
				if( ret != 0 )
				{
					Smc.WGetErrorString(ret, out tmp);
					szErrorString = string.Format("SmcWSetBankArcParam = {0:d} : {1}", ret, tmp);
					lblComment.Text = szErrorString;
					return false;	
				}
			}
    
			//----------------------------
			// Set Arc Point to Driver
			//----------------------------
			try
			{
				ArcSpeed = double.Parse(txtArcSpeed.Text);
			}
			catch (FormatException)
			{
				ArcSpeed = 0;
			}

			Coordinates = 5000;
    
			Center_X = Coordinates;
			Center_Y = 0;
			if( ArcStartDir == (short)CSmcConst.CSMC_CW )
			{
				End_X = Coordinates;
				End_Y = Coordinates;
			}
			else
			{
				End_X = Coordinates;
				End_Y = (-1) * Coordinates;
			}
			ret = Smc.WSetBankArcPoint(Id, AxisNo, 1, ArcSpeed, Center_X, Center_Y, End_X, End_Y);
			if( ret != 0 )
			{
				Smc.WGetErrorString(ret, out tmp);
				szErrorString = string.Format("SmcWSetBankArcPoint = {0:d} : {1}", ret, tmp);
				lblComment.Text = szErrorString;
				return false;	
			}
    
			if( ArcStartDir == (short)CSmcConst.CSMC_CW )
			{
				Center_X = 0;
				Center_Y = (-1) * Coordinates;
				End_X = Coordinates;
				End_Y = (-1) * Coordinates;
			}
			else
			{
				Center_X = 0;
				Center_Y = Coordinates;
				End_X = Coordinates;
				End_Y = Coordinates;
			}
			ret = Smc.WSetBankArcPoint(Id, AxisNo, 2, ArcSpeed, Center_X, Center_Y, End_X, End_Y);
			if( ret != 0 )
			{
				Smc.WGetErrorString(ret, out tmp);
				szErrorString = string.Format("SmcWSetBankArcPoint = {0:d} : {1}", ret, tmp);
				lblComment.Text = szErrorString;
				return false;	
			}
    
			Center_X = (-1) * Coordinates;
			Center_Y = 0;
			if( ArcStartDir == (short)CSmcConst.CSMC_CW )
			{
				End_X = (-1) * Coordinates;
				End_Y = (-1) * Coordinates;
			}
			else
			{
				End_X = (-1) * Coordinates;
				End_Y = Coordinates;
			}

			ret = Smc.WSetBankArcPoint(Id, AxisNo, 3, ArcSpeed, Center_X, Center_Y, End_X, End_Y);
			if( ret != 0 )
			{
				Smc.WGetErrorString(ret, out tmp);
				szErrorString = string.Format("SmcWSetBankArcPoint = {0:d} : {1}", ret, tmp);
				lblComment.Text = szErrorString;
				return false;	
			}
    
			if( ArcStartDir == (short)CSmcConst.CSMC_CW )
			{
				Center_X = 0;
				Center_Y = Coordinates;
				End_X = (-1) * Coordinates;
				End_Y = Coordinates;
			}
			else
			{
				Center_X = 0;
				Center_Y = (-1) * Coordinates;
				End_X = (-1) * Coordinates;
				End_Y = (-1) * Coordinates;
			}

			ret = Smc.WSetBankArcPoint(Id, AxisNo, 4, ArcSpeed, Center_X, Center_Y, End_X, End_Y);
			if( ret != 0 )
			{
				Smc.WGetErrorString(ret, out tmp);
				szErrorString = string.Format("SmcWSetBankArcPoint = {0:d} : {1}", ret, tmp);
				lblComment.Text = szErrorString;
				return false;	
			}
   
			return true;
		}

		private void rdoDirCw_CheckedChanged(object sender, System.EventArgs e)
		{
			ArcStartDir = (short)CSmcConst.CSMC_CW;
		}

		private void rdoDirCcw_CheckedChanged(object sender, System.EventArgs e)
		{
			ArcStartDir = (short)CSmcConst.CSMC_CCW;
		}

		private void rdoOptionSingle_CheckedChanged(object sender, System.EventArgs e)
		{
			MotionType = (short)CSmcConst.CSMC_SINGLE;
		}

		private void rdoOptionLoop_CheckedChanged(object sender, System.EventArgs e)
		{
			MotionType = (short)CSmcConst.CSMC_LOOP;
		}

		private void btnComMove_Click(object sender, System.EventArgs e)
		{
			int		ret;
			string	tmp;
			string	szErrorString;

			//----------------------------------
			// Set parameters to Driver
			//----------------------------------
			bRet = SetBankParam();
			if( bRet == false )
			{
				return;
			}
    
			//---------------
			// Ready motion
			//---------------
			ret = Smc.WSetBankReady(Id, AxisNo, MotionType);
			if( ret != 0 )
			{
				Smc.WGetErrorString(ret, out tmp);
				szErrorString = string.Format("SmcWSetBankReady = {0:d} : {1}", ret, tmp);
				lblComment.Text = szErrorString;
				return;	
			}

			ret = Smc.WGetBankArcPoint(Id, AxisNo, 1, out ArcSpeed, out Center_X, out Center_Y, out End_X, out End_Y);
			if( ret != 0 )
			{
				Smc.WGetErrorString(ret, out tmp);
				szErrorString = string.Format("SmcWGetBankArcPoint = {0:d} : {1}", ret, tmp);
				lblComment.Text = szErrorString;
				return;	
			}
			tmp = string.Format("{0:f1}", ArcSpeed);
			txtArcSpeed.Text = tmp;

			//---------------
			// Start Motion
			//---------------
			ret = Smc.WMotionStart(Id, AxisNo);
			if( ret != 0 )
			{
				Smc.WGetErrorString(ret, out tmp);
				szErrorString = string.Format("SmcWMotionStart = {0:d} : {1}", ret, tmp);
				lblComment.Text = szErrorString;
				return;
			}
			lblComment.Text = "OK";
		}

		private void btnComStop_Click(object sender, System.EventArgs e)
		{
			int		ret;
			string	tmp;
			string	szErrorString;
    
			ret = Smc.WMotionStop(Id, AxisNo);
			if( ret != 0 )
			{
				Smc.WGetErrorString(ret, out tmp);
				szErrorString = string.Format("SmcWMotionStop = {0:d} : {1}", ret, tmp);
				lblComment.Text = szErrorString;
				return;
			}
			lblComment.Text = "OK";
		}

		private void cboTargetBankNum_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			BankNum = (short)(cboTargetBankNum.SelectedIndex + 1);
		}
	}
}
