﻿Option Strict Off
Option Explicit On 
Imports System.Text
Public Class BaseMove
	Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

	Public Sub New()
		MyBase.New()

		'This call is required by the Windows Form Designer.
		InitializeComponent()

		'Add any initialization after the InitializeComponent() call

	End Sub

	'Form overrides dispose to clean up the component list.
	Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
		If disposing Then
			If Not (components Is Nothing) Then
				components.Dispose()
			End If
		End If
		MyBase.Dispose(disposing)
	End Sub

	'Required by the Windows Form Designer
	Private components As System.ComponentModel.IContainer

	'NOTE: The following procedure is required by the Windows Form Designer
	'It can be modified using the Windows Form Designer.  
	'Do not modify it using the code editor.
	Friend WithEvents Label2 As System.Windows.Forms.Label
	Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
	Friend WithEvents Label3 As System.Windows.Forms.Label
	Friend WithEvents Label5 As System.Windows.Forms.Label
	Friend WithEvents Label6 As System.Windows.Forms.Label
	Friend WithEvents Label7 As System.Windows.Forms.Label
	Friend WithEvents Label8 As System.Windows.Forms.Label
	Friend WithEvents Label9 As System.Windows.Forms.Label
	Friend WithEvents Label10 As System.Windows.Forms.Label
	Friend WithEvents Label11 As System.Windows.Forms.Label
	Friend WithEvents Label12 As System.Windows.Forms.Label
	Friend WithEvents Label13 As System.Windows.Forms.Label
	Friend WithEvents Label14 As System.Windows.Forms.Label
	Friend WithEvents Label15 As System.Windows.Forms.Label
	Friend WithEvents Label16 As System.Windows.Forms.Label
	Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
	Friend WithEvents LDeviceName As System.Windows.Forms.Label
	Friend WithEvents txtDeviceName As System.Windows.Forms.TextBox
	Friend WithEvents cboTargetAxis As System.Windows.Forms.ComboBox
	Friend WithEvents Label_StartSpeed As System.Windows.Forms.Label
	Friend WithEvents rdoOptionPtp As System.Windows.Forms.RadioButton
	Friend WithEvents btnComCW As System.Windows.Forms.Button
	Friend WithEvents btnComCCW As System.Windows.Forms.Button
	Friend WithEvents rdoOptionJog As System.Windows.Forms.RadioButton
	Friend WithEvents rdoOptionOrg As System.Windows.Forms.RadioButton
	Friend WithEvents btnComStop As System.Windows.Forms.Button
	Friend WithEvents btnComSDStop As System.Windows.Forms.Button
	Friend WithEvents Label17 As System.Windows.Forms.Label
	Friend WithEvents cboCoordinate As System.Windows.Forms.ComboBox
	Friend WithEvents GroupBox3 As System.Windows.Forms.GroupBox
	Friend WithEvents cboChange As System.Windows.Forms.ComboBox
	Friend WithEvents btnComChange As System.Windows.Forms.Button
	Friend WithEvents GroupBox4 As System.Windows.Forms.GroupBox
	Friend WithEvents lblComment As System.Windows.Forms.Label
    Friend WithEvents btnComEnd As System.Windows.Forms.Button
    Friend WithEvents txtAccelTime As System.Windows.Forms.TextBox
	Friend WithEvents txtStartSpeed As System.Windows.Forms.TextBox
	Friend WithEvents txtResolution As System.Windows.Forms.TextBox
	Friend WithEvents txtDistance As System.Windows.Forms.TextBox
	Friend WithEvents txtTargetSpeed As System.Windows.Forms.TextBox
	Friend WithEvents txtSSpeed As System.Windows.Forms.TextBox
	Friend WithEvents txtDecelTime As System.Windows.Forms.TextBox
	<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.LDeviceName = New System.Windows.Forms.Label()
        Me.txtDeviceName = New System.Windows.Forms.TextBox()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.cboTargetAxis = New System.Windows.Forms.ComboBox()
        Me.GroupBox1 = New System.Windows.Forms.GroupBox()
        Me.Label16 = New System.Windows.Forms.Label()
        Me.Label15 = New System.Windows.Forms.Label()
        Me.Label14 = New System.Windows.Forms.Label()
        Me.Label13 = New System.Windows.Forms.Label()
        Me.Label12 = New System.Windows.Forms.Label()
        Me.Label11 = New System.Windows.Forms.Label()
        Me.Label10 = New System.Windows.Forms.Label()
        Me.txtDistance = New System.Windows.Forms.TextBox()
        Me.txtSSpeed = New System.Windows.Forms.TextBox()
        Me.txtDecelTime = New System.Windows.Forms.TextBox()
        Me.txtAccelTime = New System.Windows.Forms.TextBox()
        Me.txtTargetSpeed = New System.Windows.Forms.TextBox()
        Me.txtStartSpeed = New System.Windows.Forms.TextBox()
        Me.Label9 = New System.Windows.Forms.Label()
        Me.Label8 = New System.Windows.Forms.Label()
        Me.Label7 = New System.Windows.Forms.Label()
        Me.Label6 = New System.Windows.Forms.Label()
        Me.Label5 = New System.Windows.Forms.Label()
        Me.Label_StartSpeed = New System.Windows.Forms.Label()
        Me.txtResolution = New System.Windows.Forms.TextBox()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.GroupBox2 = New System.Windows.Forms.GroupBox()
        Me.cboCoordinate = New System.Windows.Forms.ComboBox()
        Me.Label17 = New System.Windows.Forms.Label()
        Me.btnComSDStop = New System.Windows.Forms.Button()
        Me.btnComStop = New System.Windows.Forms.Button()
        Me.rdoOptionOrg = New System.Windows.Forms.RadioButton()
        Me.rdoOptionJog = New System.Windows.Forms.RadioButton()
        Me.btnComCCW = New System.Windows.Forms.Button()
        Me.btnComCW = New System.Windows.Forms.Button()
        Me.rdoOptionPtp = New System.Windows.Forms.RadioButton()
        Me.GroupBox3 = New System.Windows.Forms.GroupBox()
        Me.btnComChange = New System.Windows.Forms.Button()
        Me.cboChange = New System.Windows.Forms.ComboBox()
        Me.GroupBox4 = New System.Windows.Forms.GroupBox()
        Me.lblComment = New System.Windows.Forms.Label()
        Me.btnComEnd = New System.Windows.Forms.Button()
        Me.GroupBox1.SuspendLayout()
        Me.GroupBox2.SuspendLayout()
        Me.GroupBox3.SuspendLayout()
        Me.GroupBox4.SuspendLayout()
        Me.SuspendLayout()
        '
        'LDeviceName
        '
        Me.LDeviceName.AutoSize = True
        Me.LDeviceName.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.LDeviceName.Location = New System.Drawing.Point(24, 18)
        Me.LDeviceName.Name = "LDeviceName"
        Me.LDeviceName.Size = New System.Drawing.Size(79, 14)
        Me.LDeviceName.TabIndex = 0
        Me.LDeviceName.Text = "Device Name"
        '
        'txtDeviceName
        '
        Me.txtDeviceName.Location = New System.Drawing.Point(128, 16)
        Me.txtDeviceName.Name = "txtDeviceName"
        Me.txtDeviceName.Size = New System.Drawing.Size(104, 21)
        Me.txtDeviceName.TabIndex = 1
        Me.txtDeviceName.Text = "SMC000"
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(328, 20)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(44, 14)
        Me.Label2.TabIndex = 2
        Me.Label2.Text = "AxisNo"
        '
        'cboTargetAxis
        '
        Me.cboTargetAxis.Location = New System.Drawing.Point(392, 16)
        Me.cboTargetAxis.Name = "cboTargetAxis"
        Me.cboTargetAxis.Size = New System.Drawing.Size(72, 23)
        Me.cboTargetAxis.TabIndex = 3
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label16, Me.Label15, Me.Label14, Me.Label13, Me.Label12, Me.Label11, Me.Label10, Me.txtDistance, Me.txtSSpeed, Me.txtDecelTime, Me.txtAccelTime, Me.txtTargetSpeed, Me.txtStartSpeed, Me.Label9, Me.Label8, Me.Label7, Me.Label6, Me.Label5, Me.Label_StartSpeed, Me.txtResolution, Me.Label3})
        Me.GroupBox1.Location = New System.Drawing.Point(16, 56)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(288, 256)
        Me.GroupBox1.TabIndex = 4
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "PARAMETERS"
        '
        'Label16
        '
        Me.Label16.AutoSize = True
        Me.Label16.Location = New System.Drawing.Point(232, 224)
        Me.Label16.Name = "Label16"
        Me.Label16.Size = New System.Drawing.Size(41, 14)
        Me.Label16.TabIndex = 20
        Me.Label16.Text = "[pulse]"
        '
        'Label15
        '
        Me.Label15.AutoSize = True
        Me.Label15.Location = New System.Drawing.Point(232, 192)
        Me.Label15.Name = "Label15"
        Me.Label15.Size = New System.Drawing.Size(31, 14)
        Me.Label15.TabIndex = 19
        Me.Label15.Text = "[pps]"
        '
        'Label14
        '
        Me.Label14.AutoSize = True
        Me.Label14.Location = New System.Drawing.Point(232, 160)
        Me.Label14.Name = "Label14"
        Me.Label14.Size = New System.Drawing.Size(28, 14)
        Me.Label14.TabIndex = 18
        Me.Label14.Text = "[ms]"
        '
        'Label13
        '
        Me.Label13.AutoSize = True
        Me.Label13.Location = New System.Drawing.Point(232, 128)
        Me.Label13.Name = "Label13"
        Me.Label13.Size = New System.Drawing.Size(28, 14)
        Me.Label13.TabIndex = 17
        Me.Label13.Text = "[ms]"
        '
        'Label12
        '
        Me.Label12.AutoSize = True
        Me.Label12.Location = New System.Drawing.Point(232, 96)
        Me.Label12.Name = "Label12"
        Me.Label12.Size = New System.Drawing.Size(31, 14)
        Me.Label12.TabIndex = 16
        Me.Label12.Text = "[pps]"
        '
        'Label11
        '
        Me.Label11.AutoSize = True
        Me.Label11.Location = New System.Drawing.Point(232, 64)
        Me.Label11.Name = "Label11"
        Me.Label11.Size = New System.Drawing.Size(31, 14)
        Me.Label11.TabIndex = 15
        Me.Label11.Text = "[pps]"
        '
        'Label10
        '
        Me.Label10.AutoSize = True
        Me.Label10.Location = New System.Drawing.Point(232, 32)
        Me.Label10.Name = "Label10"
        Me.Label10.Size = New System.Drawing.Size(31, 14)
        Me.Label10.TabIndex = 14
        Me.Label10.Text = "[pps]"
        '
        'txtDistance
        '
        Me.txtDistance.Location = New System.Drawing.Point(112, 216)
        Me.txtDistance.Name = "txtDistance"
        Me.txtDistance.Size = New System.Drawing.Size(104, 21)
        Me.txtDistance.TabIndex = 13
        Me.txtDistance.Text = ""
        Me.txtDistance.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'txtSSpeed
        '
        Me.txtSSpeed.Location = New System.Drawing.Point(112, 184)
        Me.txtSSpeed.Name = "txtSSpeed"
        Me.txtSSpeed.Size = New System.Drawing.Size(104, 21)
        Me.txtSSpeed.TabIndex = 12
        Me.txtSSpeed.Text = ""
        Me.txtSSpeed.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'txtDecelTime
        '
        Me.txtDecelTime.Location = New System.Drawing.Point(112, 152)
        Me.txtDecelTime.Name = "txtDecelTime"
        Me.txtDecelTime.Size = New System.Drawing.Size(104, 21)
        Me.txtDecelTime.TabIndex = 11
        Me.txtDecelTime.Text = ""
        Me.txtDecelTime.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'txtAccelTime
        '
        Me.txtAccelTime.Location = New System.Drawing.Point(112, 120)
        Me.txtAccelTime.Name = "txtAccelTime"
        Me.txtAccelTime.Size = New System.Drawing.Size(104, 21)
        Me.txtAccelTime.TabIndex = 10
        Me.txtAccelTime.Text = ""
        Me.txtAccelTime.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'txtTargetSpeed
        '
        Me.txtTargetSpeed.Location = New System.Drawing.Point(112, 88)
        Me.txtTargetSpeed.Name = "txtTargetSpeed"
        Me.txtTargetSpeed.Size = New System.Drawing.Size(104, 21)
        Me.txtTargetSpeed.TabIndex = 9
        Me.txtTargetSpeed.Text = ""
        Me.txtTargetSpeed.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'txtStartSpeed
        '
        Me.txtStartSpeed.Location = New System.Drawing.Point(112, 56)
        Me.txtStartSpeed.Name = "txtStartSpeed"
        Me.txtStartSpeed.Size = New System.Drawing.Size(104, 21)
        Me.txtStartSpeed.TabIndex = 8
        Me.txtStartSpeed.Text = ""
        Me.txtStartSpeed.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'Label9
        '
        Me.Label9.AutoSize = True
        Me.Label9.Location = New System.Drawing.Point(16, 218)
        Me.Label9.Name = "Label9"
        Me.Label9.Size = New System.Drawing.Size(53, 14)
        Me.Label9.TabIndex = 7
        Me.Label9.Text = "Distance"
        '
        'Label8
        '
        Me.Label8.AutoSize = True
        Me.Label8.Location = New System.Drawing.Point(16, 187)
        Me.Label8.Name = "Label8"
        Me.Label8.Size = New System.Drawing.Size(52, 14)
        Me.Label8.TabIndex = 6
        Me.Label8.Text = "S Speed"
        '
        'Label7
        '
        Me.Label7.AutoSize = True
        Me.Label7.Location = New System.Drawing.Point(16, 156)
        Me.Label7.Name = "Label7"
        Me.Label7.Size = New System.Drawing.Size(67, 14)
        Me.Label7.TabIndex = 5
        Me.Label7.Text = "Decel Time"
        '
        'Label6
        '
        Me.Label6.AutoSize = True
        Me.Label6.Location = New System.Drawing.Point(16, 94)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(79, 14)
        Me.Label6.TabIndex = 4
        Me.Label6.Text = "Target Speed"
        '
        'Label5
        '
        Me.Label5.AutoSize = True
        Me.Label5.Location = New System.Drawing.Point(16, 125)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(66, 14)
        Me.Label5.TabIndex = 3
        Me.Label5.Text = "Accel Time"
        '
        'Label_StartSpeed
        '
        Me.Label_StartSpeed.AutoSize = True
        Me.Label_StartSpeed.Location = New System.Drawing.Point(16, 63)
        Me.Label_StartSpeed.Name = "Label_StartSpeed"
        Me.Label_StartSpeed.Size = New System.Drawing.Size(70, 14)
        Me.Label_StartSpeed.TabIndex = 2
        Me.Label_StartSpeed.Text = "Start Speed"
        '
        'txtResolution
        '
        Me.txtResolution.Location = New System.Drawing.Point(112, 32)
        Me.txtResolution.Name = "txtResolution"
        Me.txtResolution.Size = New System.Drawing.Size(104, 21)
        Me.txtResolution.TabIndex = 1
        Me.txtResolution.Text = ""
        Me.txtResolution.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.Location = New System.Drawing.Point(16, 32)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(63, 14)
        Me.Label3.TabIndex = 0
        Me.Label3.Text = "Resolution"
        '
        'GroupBox2
        '
        Me.GroupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.cboCoordinate, Me.Label17, Me.btnComSDStop, Me.btnComStop, Me.rdoOptionOrg, Me.rdoOptionJog, Me.btnComCCW, Me.btnComCW, Me.rdoOptionPtp})
        Me.GroupBox2.Location = New System.Drawing.Point(320, 56)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(264, 176)
        Me.GroupBox2.TabIndex = 5
        Me.GroupBox2.TabStop = False
        Me.GroupBox2.Text = "MOTION"
        '
        'cboCoordinate
        '
        Me.cboCoordinate.Location = New System.Drawing.Point(104, 136)
        Me.cboCoordinate.Name = "cboCoordinate"
        Me.cboCoordinate.Size = New System.Drawing.Size(136, 23)
        Me.cboCoordinate.TabIndex = 8
        '
        'Label17
        '
        Me.Label17.AutoSize = True
        Me.Label17.Location = New System.Drawing.Point(16, 138)
        Me.Label17.Name = "Label17"
        Me.Label17.Size = New System.Drawing.Size(68, 14)
        Me.Label17.TabIndex = 7
        Me.Label17.Text = "INC or ABS"
        '
        'btnComSDStop
        '
        Me.btnComSDStop.Location = New System.Drawing.Point(104, 96)
        Me.btnComSDStop.Name = "btnComSDStop"
        Me.btnComSDStop.Size = New System.Drawing.Size(136, 24)
        Me.btnComSDStop.TabIndex = 6
        Me.btnComSDStop.Text = "SDStop"
        '
        'btnComStop
        '
        Me.btnComStop.Location = New System.Drawing.Point(104, 64)
        Me.btnComStop.Name = "btnComStop"
        Me.btnComStop.Size = New System.Drawing.Size(136, 24)
        Me.btnComStop.TabIndex = 5
        Me.btnComStop.Text = "STOP"
        '
        'rdoOptionOrg
        '
        Me.rdoOptionOrg.Location = New System.Drawing.Point(16, 104)
        Me.rdoOptionOrg.Name = "rdoOptionOrg"
        Me.rdoOptionOrg.Size = New System.Drawing.Size(56, 16)
        Me.rdoOptionOrg.TabIndex = 4
        Me.rdoOptionOrg.Text = "ORG"
        '
        'rdoOptionJog
        '
        Me.rdoOptionJog.Location = New System.Drawing.Point(16, 64)
        Me.rdoOptionJog.Name = "rdoOptionJog"
        Me.rdoOptionJog.Size = New System.Drawing.Size(56, 24)
        Me.rdoOptionJog.TabIndex = 3
        Me.rdoOptionJog.Text = "JOG"
        '
        'btnComCCW
        '
        Me.btnComCCW.Location = New System.Drawing.Point(176, 24)
        Me.btnComCCW.Name = "btnComCCW"
        Me.btnComCCW.Size = New System.Drawing.Size(64, 24)
        Me.btnComCCW.TabIndex = 2
        Me.btnComCCW.Text = "CCW"
        '
        'btnComCW
        '
        Me.btnComCW.Location = New System.Drawing.Point(104, 24)
        Me.btnComCW.Name = "btnComCW"
        Me.btnComCW.Size = New System.Drawing.Size(64, 24)
        Me.btnComCW.TabIndex = 1
        Me.btnComCW.Text = "CW"
        '
        'rdoOptionPtp
        '
        Me.rdoOptionPtp.Location = New System.Drawing.Point(16, 28)
        Me.rdoOptionPtp.Name = "rdoOptionPtp"
        Me.rdoOptionPtp.Size = New System.Drawing.Size(48, 16)
        Me.rdoOptionPtp.TabIndex = 0
        Me.rdoOptionPtp.Text = "PTP"
        '
        'GroupBox3
        '
        Me.GroupBox3.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnComChange, Me.cboChange})
        Me.GroupBox3.Location = New System.Drawing.Point(320, 248)
        Me.GroupBox3.Name = "GroupBox3"
        Me.GroupBox3.Size = New System.Drawing.Size(264, 64)
        Me.GroupBox3.TabIndex = 6
        Me.GroupBox3.TabStop = False
        Me.GroupBox3.Text = "MOTION CHANGE"
        '
        'btnComChange
        '
        Me.btnComChange.Location = New System.Drawing.Point(160, 24)
        Me.btnComChange.Name = "btnComChange"
        Me.btnComChange.Size = New System.Drawing.Size(80, 24)
        Me.btnComChange.TabIndex = 2
        Me.btnComChange.Text = "Change"
        '
        'cboChange
        '
        Me.cboChange.Location = New System.Drawing.Point(16, 24)
        Me.cboChange.Name = "cboChange"
        Me.cboChange.Size = New System.Drawing.Size(120, 23)
        Me.cboChange.TabIndex = 1
        '
        'GroupBox4
        '
        Me.GroupBox4.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblComment})
        Me.GroupBox4.Location = New System.Drawing.Point(16, 328)
        Me.GroupBox4.Name = "GroupBox4"
        Me.GroupBox4.Size = New System.Drawing.Size(456, 136)
        Me.GroupBox4.TabIndex = 7
        Me.GroupBox4.TabStop = False
        Me.GroupBox4.Text = "COMMENT"
        '
        'lblComment
        '
        Me.lblComment.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblComment.Location = New System.Drawing.Point(8, 24)
        Me.lblComment.Name = "lblComment"
        Me.lblComment.Size = New System.Drawing.Size(440, 104)
        Me.lblComment.TabIndex = 0
        '
        'btnComEnd
        '
        Me.btnComEnd.Location = New System.Drawing.Point(496, 416)
        Me.btnComEnd.Name = "btnComEnd"
        Me.btnComEnd.Size = New System.Drawing.Size(80, 24)
        Me.btnComEnd.TabIndex = 9
        Me.btnComEnd.Text = "E&XIT"
        '
        'BaseMove
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(600, 478)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnComEnd, Me.GroupBox4, Me.GroupBox3, Me.GroupBox2, Me.GroupBox1, Me.cboTargetAxis, Me.Label2, Me.LDeviceName, Me.txtDeviceName})
        Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "BaseMove"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "BASEMOVE"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox2.ResumeLayout(False)
        Me.GroupBox3.ResumeLayout(False)
        Me.GroupBox4.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

	Dim dwRet As Integer
	Dim MotionType As Short
	Dim dblResolveSpeed As Double
	Dim dblStartSpeed As Double
	Dim dblTargetSpeed As Double
	Dim dblAccelTime As Double
	Dim dblDecelTime As Double
	Dim dblSSpeed As Double
	Dim lDistance As Integer
	Dim szComment As String
	Dim StartDir As Short
	Dim bRet As Boolean
	Dim Id As Short
	Dim AxisNo As Short
	Dim bCoordinate As Short
	Dim Change As Short
    Dim ErrorString As New StringBuilder("", 256)  'Error String

	Private Sub cboChange_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboChange.SelectedIndexChanged

		Change = cboChange.SelectedIndex

	End Sub

	Private Sub cboCoordinate_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboCoordinate.SelectedIndexChanged

		If cboCoordinate.SelectedIndex = 0 Then
			bCoordinate = CSMC_ABS
		Else
			bCoordinate = CSMC_INC
		End If

	End Sub

	Private Sub cboTargetAxis_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboTargetAxis.SelectedIndexChanged

		AxisNo = cboTargetAxis.SelectedIndex + 1

        '------------------------
        ' Set lDistance to 1000
        '------------------------
        lDistance = 1000
        dwRet = SmcWSetStopPosition(Id, AxisNo, bCoordinate, lDistance)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWSetStopPosition = " & dwRet & " : " & ErrorString.ToString
            Exit Sub
        End If

        '---------------------------
        ' Get parameters of Driver
        '---------------------------
        bRet = GetMoveParam()
        If bRet = False Then
            Exit Sub
        End If

        lblComment.Text = "OK "

	End Sub

	Private Sub btnComCCW_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnComCCW.Click

		StartDir = CSMC_CCW
		'----------------------------------
		' Set parameters to Driver
		'----------------------------------
		bRet = SetMoveParam()
		If bRet = False Then
			Exit Sub
		End If

		'---------------
		' Ready motion
		'---------------
		dwRet = SmcWSetReady(Id, AxisNo, MotionType, StartDir)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWSetReady = " & dwRet & " : " & ErrorString.ToString
            Exit Sub
        End If

        '---------------
        ' Start Motion
        '---------------
        dwRet = SmcWMotionStart(Id, AxisNo)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWMotionStart = " & dwRet & " : " & ErrorString.ToString
            Exit Sub
        End If

        '-------------------------------------
        ' Get setting parameters from Driver
        '-------------------------------------
        bRet = GetMoveParam()
        If bRet = False Then
            Exit Sub
        End If

        lblComment.Text = "OK "
        
	End Sub

	Private Sub btnComCW_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnComCW.Click

		StartDir = CSMC_CW
		'----------------------------------
		' Set parameters to Driver
		'----------------------------------
		bRet = SetMoveParam()
		If bRet = False Then
			Exit Sub
		End If

		'---------------
		' Ready motion
		'---------------
		dwRet = SmcWSetReady(Id, AxisNo, MotionType, StartDir)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWSetReady = " & dwRet & " : " & ErrorString.ToString
            Exit Sub
        End If

        '---------------
        ' Start Motion
        '---------------
        dwRet = SmcWMotionStart(Id, AxisNo)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWMotionStart = " & dwRet & " : " & ErrorString.ToString
            Exit Sub
        End If

        '-------------------------------------
        ' Get setting parameters from Driver
        '-------------------------------------
        bRet = GetMoveParam()
        If bRet = False Then
            Exit Sub
        End If

        lblComment.Text = "OK "
        
	End Sub

	Private Sub btnComEnd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnComEnd.Click

		SmcWExit(Id)
		End

	End Sub



    Private Sub btnComChange_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnComChange.Click

        If Change = 4 Then
            '----------------------------------
            ' Set TargetSpeed to Driver
            '----------------------------------
            Try
                dblTargetSpeed = Val(txtTargetSpeed.Text)
            Catch ex As Exception
                dblTargetSpeed = 0
            End Try
            dwRet = SmcWSetTargetSpeed(Id, AxisNo, dblTargetSpeed)
            If dwRet <> 0 Then
                SmcWGetErrorString(dwRet, ErrorString)
                lblComment.Text = "SmcWSetTargetSpeed = " & dwRet & " : " & ErrorString.ToString
                Exit Sub
            End If

            '----------------------------------
            ' Set AccelTime to Driver
            '----------------------------------
            Try
                dblAccelTime = Val(txtAccelTime.Text)
            Catch ex As Exception
                dblAccelTime = 0
            End Try
            dwRet = SmcWSetAccelTime(Id, AxisNo, dblAccelTime)
            If dwRet <> 0 Then
                SmcWGetErrorString(dwRet, ErrorString)
                lblComment.Text = "SmcWSetAccelTime = " & dwRet & " : " & ErrorString.ToString
                Exit Sub
            End If

            '----------------------------------
            ' Set DecelTime to Driver
            '----------------------------------
            Try
                dblDecelTime = Val(txtDecelTime.Text)
            Catch ex As Exception
                dblDecelTime = 0
            End Try
            dwRet = SmcWSetDecelTime(Id, AxisNo, dblDecelTime)
            If dwRet <> 0 Then
                SmcWGetErrorString(dwRet, ErrorString)
                lblComment.Text = "SmcWSetDecelTime = " & dwRet & " : " & ErrorString.ToString
                Exit Sub
            End If

        End If

        If Change = 5 Or Change = 6 Then
            '-------------------------
            ' Set Distance to Driver
            '-------------------------
            Try
                lDistance = Val(txtDistance.Text)
            Catch ex As Exception
                lDistance = 0
            End Try
            If MotionType = CSMC_PTP And bCoordinate = CSMC_INC Then
                lDistance = System.Math.Abs(lDistance)
                If StartDir = CSMC_CCW Then
                    lDistance = -(lDistance)
                End If
            End If

            dwRet = SmcWSetStopPosition(Id, AxisNo, bCoordinate, lDistance)
            If dwRet <> 0 Then
                SmcWGetErrorString(dwRet, ErrorString)
                lblComment.Text = "SmcWSetStopPosition = " & dwRet & " : " & ErrorString.ToString
                Exit Sub
            End If

        End If

        '--------------------
        ' Set Change Motion
        '--------------------
        dwRet = SmcWSetMotionChangeReady(Id, AxisNo, Change)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWSetMotionChangeReady = " & dwRet & " : " & ErrorString.ToString
            Exit Sub
        End If

        '----------------
        ' Change Motion
        '----------------
        dwRet = SmcWMotionChange(Id, AxisNo)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWMotionChange = " & dwRet & " : " & ErrorString.ToString
            Exit Sub
        End If

        '-------------------------------------
        ' Get setting parameters from Driver
        '-------------------------------------
        bRet = GetMoveParam()
        If bRet = False Then
            Exit Sub
        End If

        lblComment.Text = "OK "
        
    End Sub

    Private Sub btnComSDStop_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnComSDStop.Click

        dwRet = SmcWMotionDecStop(Id, AxisNo)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWMotionDecStop = " & dwRet & " : " & ErrorString.ToString
            Exit Sub
        End If

        lblComment.Text = "OK "
        
    End Sub

    Private Sub btnComStop_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnComStop.Click

        dwRet = SmcWMotionStop(Id, AxisNo)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWMotionStop = " & dwRet & " : " & ErrorString.ToString
            Exit Sub
        End If

        lblComment.Text = "OK "
        
    End Sub

    Private Sub BaseMove_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim n As Short
        AxisNo = 1

        ' AxisNo ComboBox
        cboTargetAxis.Items.Clear()
        For n = 1 To 8
            cboTargetAxis.Items.Add(Str(n))
        Next

        ' ComboBox Initialise
        cboTargetAxis.SelectedIndex = AxisNo - 1

        ' Coordinate ComboBox
        cboCoordinate.Items.Clear()
        cboCoordinate.Items.Add("ABS")
        cboCoordinate.Items.Add("INC")
        cboCoordinate.SelectedIndex = CSMC_INC

        ' Coordinate ComboBox
        cboChange.Items.Clear()
        cboChange.Items.Add("At once FL")
        cboChange.Items.Add("At once FH")
        cboChange.Items.Add("Decel FL")
        cboChange.Items.Add("Accel FH")
        cboChange.Items.Add("Motion Change")
        cboChange.Items.Add("Position Change1")
        cboChange.Items.Add("Position Change2")
        cboChange.SelectedIndex = 4

        '------------
        ' Initialize
        '------------
        dwRet = SmcWInit(txtDeviceName.Text, Id)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWInit = " & dwRet & " : " & ErrorString.ToString
            Exit Sub
        End If

        ' Initialize
        dblResolveSpeed = 0
        dblStartSpeed = 0
        dblTargetSpeed = 0
        dblAccelTime = 0
        dblDecelTime = 0
        dblSSpeed = 0
        lDistance = 0
        rdoOptionPtp.Checked = True

        ' Centering
        Me.Left = (Screen.PrimaryScreen.Bounds.Width - Me.Width) / 2
        Me.Top = (Screen.PrimaryScreen.Bounds.Height - Me.Height) / 2

        '------------------------
        ' Set lDistance to 1000
        '------------------------
        lDistance = 1000
        dwRet = SmcWSetStopPosition(Id, AxisNo, bCoordinate, lDistance)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWSetStopPosition = " & dwRet & " : " & ErrorString.ToString
            Exit Sub
        End If

        '---------------------------
        ' Get parameters of Driver
        '---------------------------
        bRet = GetMoveParam()
        If bRet = False Then
            Exit Sub
        End If

        lblComment.Text = "OK "
        
    End Sub

    Private Sub rdoOptionJog_Checkedchanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rdoOptionJog.CheckedChanged

        MotionType = CSMC_JOG

    End Sub

    Private Sub rdoOptionOrg_Checkedchanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rdoOptionOrg.CheckedChanged

        MotionType = CSMC_ORG

    End Sub

    Private Sub rdoOptionPtp_Checkedchanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rdoOptionPtp.CheckedChanged

        MotionType = CSMC_PTP

    End Sub

    Function SetMoveParam() As Boolean

        '----------------------------------
        ' Set Resolution to Driver
        '----------------------------------
        Try
            dblResolveSpeed = Val(txtResolution.Text)
        Catch ex As Exception
            dblResolveSpeed = 0
        End Try
        dwRet = SmcWSetResolveSpeed(Id, AxisNo, dblResolveSpeed)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWSetResolveSpeed = " & dwRet & " : " & ErrorString.ToString
            SetMoveParam = False
            Exit Function
        End If

        '----------------------------------
        ' Set StartSpeed to Driver
        '----------------------------------
        Try
            dblStartSpeed = Val(txtStartSpeed.Text)
        Catch ex As Exception
            dblStartSpeed = 0
        End Try
        dwRet = SmcWSetStartSpeed(Id, AxisNo, dblStartSpeed)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWSetStartSpeed = " & dwRet & " : " & ErrorString.ToString
            SetMoveParam = False
            Exit Function
        End If

        '----------------------------------
        ' Set TargetSpeed to Driver
        '----------------------------------
        Try
            dblTargetSpeed = Val(txtTargetSpeed.Text)
        Catch ex As Exception
            dblTargetSpeed = 0
        End Try
        dwRet = SmcWSetTargetSpeed(Id, AxisNo, dblTargetSpeed)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWSetTargetSpeed = " & dwRet & " : " & ErrorString.ToString
            SetMoveParam = False
            Exit Function
        End If

        '----------------------------------
        ' Set AccelTime to Driver
        '----------------------------------
        Try
            dblAccelTime = Val(txtAccelTime.Text)
        Catch ex As Exception
            dblAccelTime = 0
        End Try
        dwRet = SmcWSetAccelTime(Id, AxisNo, dblAccelTime)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWSetAccelTime = " & dwRet & " : " & ErrorString.ToString
            SetMoveParam = False
            Exit Function
        End If

        '----------------------------------
        ' Set DecelTime to Driver
        '----------------------------------
        Try
            dblDecelTime = Val(txtDecelTime.Text)
        Catch ex As Exception
            dblDecelTime = 0
        End Try
        dwRet = SmcWSetDecelTime(Id, AxisNo, dblDecelTime)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWSetDecelTime = " & dwRet & " : " & ErrorString.ToString
            SetMoveParam = False
            Exit Function
        End If

        '-----------------------------
        ' Set SSpeed to Driver
        '-----------------------------
        Try
            dblSSpeed = Val(txtSSpeed.Text)
        Catch ex As Exception
            dblSSpeed = 0
        End Try
        dwRet = SmcWSetSSpeed(Id, AxisNo, dblSSpeed)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWSetSSpeed = " & dwRet & " : " & ErrorString.ToString
            SetMoveParam = False
            Exit Function
        End If

        '-------------------------
        ' Set Distance to Driver
        '-------------------------
        If MotionType <> CSMC_PTP Then
            SetMoveParam = True
            Exit Function
        End If

        Try
            lDistance = Val(txtDistance.Text)
        Catch ex As Exception
            lDistance = 0
        End Try
        If bCoordinate = CSMC_INC Then
            lDistance = System.Math.Abs(lDistance)
            If StartDir = CSMC_CCW Then
                lDistance = -(lDistance)
            End If
        End If

        dwRet = SmcWSetStopPosition(Id, AxisNo, bCoordinate, lDistance)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWSetStopPosition = " & dwRet & " : " & ErrorString.ToString
            SetMoveParam = False
            Exit Function
        End If

        SetMoveParam = True

    End Function

    Function GetMoveParam() As Boolean

        '----------------------------------
        ' Set default value of Resolution
        '----------------------------------
        dwRet = SmcWGetResolveSpeed(Id, AxisNo, dblResolveSpeed)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWGetResolveSpeed = " & dwRet & " : " & ErrorString.ToString
            GetMoveParam = False
            Exit Function
        End If

        txtResolution.Text = Str(dblResolveSpeed)

        '----------------------------------
        ' Set default value of StartSpeed
        '----------------------------------
        dwRet = SmcWGetStartSpeed(Id, AxisNo, dblStartSpeed)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWGetStartSpeed = " & dwRet & " : " & ErrorString.ToString
            GetMoveParam = False
            Exit Function
        End If

        txtStartSpeed.Text = Str(dblStartSpeed)

        '----------------------------------
        ' Set default value of TargetSpeed
        '----------------------------------
        dwRet = SmcWGetTargetSpeed(Id, AxisNo, dblTargetSpeed)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWGetTargetSpeed = " & dwRet & " : " & ErrorString.ToString
            GetMoveParam = False
            Exit Function
        End If

        txtTargetSpeed.Text = Str(dblTargetSpeed)

        '----------------------------------
        ' Set default value of AccelTime
        '----------------------------------
        dwRet = SmcWGetAccelTime(Id, AxisNo, dblAccelTime)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWGetAccelTime = " & dwRet & " : " & ErrorString.ToString
            GetMoveParam = False
            Exit Function
        End If

        txtAccelTime.Text = Str(dblAccelTime)

        '----------------------------------
        ' Set default value of DecelTime
        '----------------------------------
        dwRet = SmcWGetDecelTime(Id, AxisNo, dblDecelTime)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWGetDecelTime = " & dwRet & " : " & ErrorString.ToString
            GetMoveParam = False
            Exit Function
        End If

        txtDecelTime.Text = Str(dblDecelTime)

        '-----------------------------
        ' Set default value of SSpeed
        '-----------------------------
        dwRet = SmcWGetSSpeed(Id, AxisNo, dblSSpeed)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWGetSSpeed = " & dwRet & " : " & ErrorString.ToString
            GetMoveParam = False
            Exit Function
        End If

        txtSSpeed.Text = Str(dblSSpeed)

        '----------------------------------
        ' Set default value of lDistance
        '----------------------------------
        dwRet = SmcWGetStopPosition(Id, AxisNo, bCoordinate, lDistance)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWGetStopPosition = " & dwRet & " : " & ErrorString.ToString
            GetMoveParam = False
            Exit Function
        End If

        txtDistance.Text = Str(lDistance)

        GetMoveParam = True

    End Function

    Private Sub txtDeviceName_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtDeviceName.TextChanged

        dwRet = SmcWInit(txtDeviceName.Text, Id)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWInit = " & dwRet & " : " & ErrorString.ToString
            Exit Sub
        End If

        rdoOptionPtp.Checked = True

        MotionType = CSMC_PTP
        '------------------------
        ' Set lDistance to 1000
        '------------------------
        lDistance = 1000
        dwRet = SmcWSetStopPosition(Id, AxisNo, bCoordinate, lDistance)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWSetStopPosition = " & dwRet & " : " & ErrorString.ToString
            Exit Sub
        End If
        '---------------------------
        ' Get parameters of Driver
        '---------------------------
        bRet = GetMoveParam()
        If bRet = False Then
            Exit Sub
        End If

        lblComment.Text = "OK "

    End Sub

End Class
