﻿Option Strict Off
Option Explicit On 
Imports System.Text
Public Class SyncMove
	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 GroupBox1 As System.Windows.Forms.GroupBox
	Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
	Friend WithEvents GroupBox3 As System.Windows.Forms.GroupBox
	Friend WithEvents GroupBox4 As System.Windows.Forms.GroupBox
	Friend WithEvents LDeviceName As System.Windows.Forms.Label
	Friend WithEvents txtDeviceName As System.Windows.Forms.TextBox
	Friend WithEvents Label12 As System.Windows.Forms.Label
	Friend WithEvents cboTargetAxis As System.Windows.Forms.ComboBox
	Friend WithEvents chkAxis1 As System.Windows.Forms.CheckBox
	Friend WithEvents chkAxis2 As System.Windows.Forms.CheckBox
	Friend WithEvents chkAxis3 As System.Windows.Forms.CheckBox
	Friend WithEvents chkAxis4 As System.Windows.Forms.CheckBox
	Friend WithEvents chkAxis5 As System.Windows.Forms.CheckBox
	Friend WithEvents chkAxis6 As System.Windows.Forms.CheckBox
	Friend WithEvents chkAxis7 As System.Windows.Forms.CheckBox
	Friend WithEvents chkAxis8 As System.Windows.Forms.CheckBox
	Friend WithEvents chkChip As System.Windows.Forms.CheckBox
	Friend WithEvents chkBoardCN2 As System.Windows.Forms.CheckBox
	Friend WithEvents chkBoardCN3 As System.Windows.Forms.CheckBox
	Friend WithEvents btnComSetSync As System.Windows.Forms.Button
	Friend WithEvents btnComGetSync As System.Windows.Forms.Button
	Friend WithEvents txtSetSync As System.Windows.Forms.TextBox
	Friend WithEvents txtGetSync As System.Windows.Forms.TextBox
	Friend WithEvents btnComStartSync As System.Windows.Forms.Button
	Friend WithEvents lblComment As System.Windows.Forms.Label
    Friend WithEvents btnComEnd As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.LDeviceName = New System.Windows.Forms.Label()
        Me.txtDeviceName = New System.Windows.Forms.TextBox()
        Me.Label12 = New System.Windows.Forms.Label()
        Me.cboTargetAxis = New System.Windows.Forms.ComboBox()
        Me.GroupBox1 = New System.Windows.Forms.GroupBox()
        Me.btnComStartSync = New System.Windows.Forms.Button()
        Me.txtGetSync = New System.Windows.Forms.TextBox()
        Me.txtSetSync = New System.Windows.Forms.TextBox()
        Me.btnComGetSync = New System.Windows.Forms.Button()
        Me.btnComSetSync = New System.Windows.Forms.Button()
        Me.GroupBox3 = New System.Windows.Forms.GroupBox()
        Me.chkBoardCN3 = New System.Windows.Forms.CheckBox()
        Me.chkBoardCN2 = New System.Windows.Forms.CheckBox()
        Me.chkChip = New System.Windows.Forms.CheckBox()
        Me.GroupBox2 = New System.Windows.Forms.GroupBox()
        Me.chkAxis8 = New System.Windows.Forms.CheckBox()
        Me.chkAxis7 = New System.Windows.Forms.CheckBox()
        Me.chkAxis6 = New System.Windows.Forms.CheckBox()
        Me.chkAxis5 = New System.Windows.Forms.CheckBox()
        Me.chkAxis4 = New System.Windows.Forms.CheckBox()
        Me.chkAxis3 = New System.Windows.Forms.CheckBox()
        Me.chkAxis2 = New System.Windows.Forms.CheckBox()
        Me.chkAxis1 = New System.Windows.Forms.CheckBox()
        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.GroupBox3.SuspendLayout()
        Me.GroupBox2.SuspendLayout()
        Me.GroupBox4.SuspendLayout()
        Me.SuspendLayout()
        '
        'LDeviceName
        '
        Me.LDeviceName.AutoSize = True
        Me.LDeviceName.Location = New System.Drawing.Point(16, 16)
        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(104, 14)
        Me.txtDeviceName.Name = "txtDeviceName"
        Me.txtDeviceName.Size = New System.Drawing.Size(88, 21)
        Me.txtDeviceName.TabIndex = 1
        Me.txtDeviceName.Text = "SMC000"
        '
        'Label12
        '
        Me.Label12.AutoSize = True
        Me.Label12.Location = New System.Drawing.Point(208, 16)
        Me.Label12.Name = "Label12"
        Me.Label12.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label12.Size = New System.Drawing.Size(44, 14)
        Me.Label12.TabIndex = 2
        Me.Label12.Text = "AxisNo"
        '
        'cboTargetAxis
        '
        Me.cboTargetAxis.Location = New System.Drawing.Point(264, 14)
        Me.cboTargetAxis.Name = "cboTargetAxis"
        Me.cboTargetAxis.Size = New System.Drawing.Size(64, 23)
        Me.cboTargetAxis.TabIndex = 3
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnComStartSync, Me.txtGetSync, Me.txtSetSync, Me.btnComGetSync, Me.btnComSetSync, Me.GroupBox3, Me.chkChip, Me.GroupBox2})
        Me.GroupBox1.Location = New System.Drawing.Point(16, 48)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(352, 192)
        Me.GroupBox1.TabIndex = 4
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "SYNCHRONIZATION"
        '
        'btnComStartSync
        '
        Me.btnComStartSync.Location = New System.Drawing.Point(224, 128)
        Me.btnComStartSync.Name = "btnComStartSync"
        Me.btnComStartSync.Size = New System.Drawing.Size(104, 32)
        Me.btnComStartSync.TabIndex = 7
        Me.btnComStartSync.Text = "StartSync"
        '
        'txtGetSync
        '
        Me.txtGetSync.Enabled = False
        Me.txtGetSync.Location = New System.Drawing.Point(112, 152)
        Me.txtGetSync.Name = "txtGetSync"
        Me.txtGetSync.Size = New System.Drawing.Size(88, 21)
        Me.txtGetSync.TabIndex = 6
        Me.txtGetSync.Text = ""
        '
        'txtSetSync
        '
        Me.txtSetSync.Enabled = False
        Me.txtSetSync.Location = New System.Drawing.Point(112, 120)
        Me.txtSetSync.Name = "txtSetSync"
        Me.txtSetSync.Size = New System.Drawing.Size(88, 21)
        Me.txtSetSync.TabIndex = 5
        Me.txtSetSync.Text = ""
        '
        'btnComGetSync
        '
        Me.btnComGetSync.Location = New System.Drawing.Point(16, 152)
        Me.btnComGetSync.Name = "btnComGetSync"
        Me.btnComGetSync.Size = New System.Drawing.Size(80, 24)
        Me.btnComGetSync.TabIndex = 4
        Me.btnComGetSync.Text = "Get"
        '
        'btnComSetSync
        '
        Me.btnComSetSync.Location = New System.Drawing.Point(16, 118)
        Me.btnComSetSync.Name = "btnComSetSync"
        Me.btnComSetSync.Size = New System.Drawing.Size(80, 24)
        Me.btnComSetSync.TabIndex = 3
        Me.btnComSetSync.Text = "Set"
        '
        'GroupBox3
        '
        Me.GroupBox3.Controls.AddRange(New System.Windows.Forms.Control() {Me.chkBoardCN3, Me.chkBoardCN2})
        Me.GroupBox3.Location = New System.Drawing.Point(256, 24)
        Me.GroupBox3.Name = "GroupBox3"
        Me.GroupBox3.Size = New System.Drawing.Size(80, 80)
        Me.GroupBox3.TabIndex = 2
        Me.GroupBox3.TabStop = False
        Me.GroupBox3.Text = "Board"
        '
        'chkBoardCN3
        '
        Me.chkBoardCN3.Location = New System.Drawing.Point(16, 48)
        Me.chkBoardCN3.Name = "chkBoardCN3"
        Me.chkBoardCN3.Size = New System.Drawing.Size(56, 16)
        Me.chkBoardCN3.TabIndex = 1
        Me.chkBoardCN3.Text = "CN3"
        '
        'chkBoardCN2
        '
        Me.chkBoardCN2.Location = New System.Drawing.Point(16, 24)
        Me.chkBoardCN2.Name = "chkBoardCN2"
        Me.chkBoardCN2.Size = New System.Drawing.Size(56, 16)
        Me.chkBoardCN2.TabIndex = 0
        Me.chkBoardCN2.Text = "CN2"
        '
        'chkChip
        '
        Me.chkChip.Location = New System.Drawing.Point(192, 48)
        Me.chkChip.Name = "chkChip"
        Me.chkChip.Size = New System.Drawing.Size(56, 24)
        Me.chkChip.TabIndex = 1
        Me.chkChip.Text = "Chip"
        '
        'GroupBox2
        '
        Me.GroupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.chkAxis8, Me.chkAxis7, Me.chkAxis6, Me.chkAxis5, Me.chkAxis4, Me.chkAxis3, Me.chkAxis2, Me.chkAxis1})
        Me.GroupBox2.Location = New System.Drawing.Point(16, 24)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(168, 80)
        Me.GroupBox2.TabIndex = 0
        Me.GroupBox2.TabStop = False
        Me.GroupBox2.Text = "Axis"
        '
        'chkAxis8
        '
        Me.chkAxis8.Location = New System.Drawing.Point(128, 48)
        Me.chkAxis8.Name = "chkAxis8"
        Me.chkAxis8.Size = New System.Drawing.Size(32, 16)
        Me.chkAxis8.TabIndex = 7
        Me.chkAxis8.Text = "8"
        '
        'chkAxis7
        '
        Me.chkAxis7.Location = New System.Drawing.Point(88, 48)
        Me.chkAxis7.Name = "chkAxis7"
        Me.chkAxis7.Size = New System.Drawing.Size(32, 16)
        Me.chkAxis7.TabIndex = 6
        Me.chkAxis7.Text = "7"
        '
        'chkAxis6
        '
        Me.chkAxis6.Location = New System.Drawing.Point(48, 48)
        Me.chkAxis6.Name = "chkAxis6"
        Me.chkAxis6.Size = New System.Drawing.Size(32, 16)
        Me.chkAxis6.TabIndex = 5
        Me.chkAxis6.Text = "6"
        '
        'chkAxis5
        '
        Me.chkAxis5.Location = New System.Drawing.Point(16, 48)
        Me.chkAxis5.Name = "chkAxis5"
        Me.chkAxis5.Size = New System.Drawing.Size(32, 16)
        Me.chkAxis5.TabIndex = 4
        Me.chkAxis5.Text = "5"
        '
        'chkAxis4
        '
        Me.chkAxis4.Location = New System.Drawing.Point(128, 24)
        Me.chkAxis4.Name = "chkAxis4"
        Me.chkAxis4.Size = New System.Drawing.Size(32, 16)
        Me.chkAxis4.TabIndex = 3
        Me.chkAxis4.Text = "4"
        '
        'chkAxis3
        '
        Me.chkAxis3.Location = New System.Drawing.Point(88, 24)
        Me.chkAxis3.Name = "chkAxis3"
        Me.chkAxis3.Size = New System.Drawing.Size(32, 16)
        Me.chkAxis3.TabIndex = 2
        Me.chkAxis3.Text = "3"
        '
        'chkAxis2
        '
        Me.chkAxis2.Location = New System.Drawing.Point(48, 24)
        Me.chkAxis2.Name = "chkAxis2"
        Me.chkAxis2.Size = New System.Drawing.Size(32, 16)
        Me.chkAxis2.TabIndex = 1
        Me.chkAxis2.Text = "2"
        '
        'chkAxis1
        '
        Me.chkAxis1.Location = New System.Drawing.Point(16, 24)
        Me.chkAxis1.Name = "chkAxis1"
        Me.chkAxis1.Size = New System.Drawing.Size(32, 16)
        Me.chkAxis1.TabIndex = 0
        Me.chkAxis1.Text = "1"
        '
        'GroupBox4
        '
        Me.GroupBox4.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblComment})
        Me.GroupBox4.Location = New System.Drawing.Point(16, 256)
        Me.GroupBox4.Name = "GroupBox4"
        Me.GroupBox4.Size = New System.Drawing.Size(352, 112)
        Me.GroupBox4.TabIndex = 5
        Me.GroupBox4.TabStop = False
        Me.GroupBox4.Text = "COMMENT"
        '
        'lblComment
        '
        Me.lblComment.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblComment.Location = New System.Drawing.Point(16, 24)
        Me.lblComment.Name = "lblComment"
        Me.lblComment.Size = New System.Drawing.Size(320, 72)
        Me.lblComment.TabIndex = 0
        '
        'btnComEnd
        '
        Me.btnComEnd.Location = New System.Drawing.Point(208, 376)
        Me.btnComEnd.Name = "btnComEnd"
        Me.btnComEnd.Size = New System.Drawing.Size(88, 24)
        Me.btnComEnd.TabIndex = 7
        Me.btnComEnd.Text = "E&XIT"
        '
        'SyncMove
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(384, 414)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnComEnd, Me.GroupBox4, Me.GroupBox1, Me.cboTargetAxis, Me.Label12, 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 = "SyncMove"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "SYNCMOVE"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox3.ResumeLayout(False)
        Me.GroupBox2.ResumeLayout(False)
        Me.GroupBox4.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

	Dim dwRet As Integer
	Dim szComment As String
	Dim Id As Short
	Dim AxisNo As Short
	Dim SyncAxis As Short
	Dim SyncChip As Short
	Dim SyncBoard As Short
	Dim GetSyncAxis As Short
	Dim GetSyncChip As Short
	Dim GetSyncBoard As Short
    Dim ErrorString As New StringBuilder("", 256)  'Error String

	Private Sub chkAxis1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkAxis1.CheckedChanged

		If chkAxis1.Checked = True Then
			SyncAxis = SyncAxis Or &H1
		ElseIf chkAxis1.Checked = False Then
			SyncAxis = SyncAxis Xor &H1
		End If

		txtSetSync.Text = Hex(SyncAxis) + "H" & " " & Hex(SyncChip) + "H" & " " & Hex(SyncBoard) + "H"

	End Sub

	Private Sub chkAxis2_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkAxis2.CheckedChanged

		If chkAxis2.Checked = True Then
			SyncAxis = SyncAxis Or &H2
		ElseIf chkAxis2.Checked = False Then
			SyncAxis = SyncAxis Xor &H2
		End If

		txtSetSync.Text = Hex(SyncAxis) + "H" & " " & Hex(SyncChip) + "H" & " " & Hex(SyncBoard) + "H"

	End Sub

	Private Sub chkAxis3_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkAxis3.CheckedChanged

		If chkAxis3.Checked = True Then
			SyncAxis = SyncAxis Or &H4
		ElseIf chkAxis3.Checked = False Then
			SyncAxis = SyncAxis Xor &H4
		End If

		txtSetSync.Text = Hex(SyncAxis) + "H" & " " & Hex(SyncChip) + "H" & " " & Hex(SyncBoard) + "H"

	End Sub

	Private Sub chkAxis4_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkAxis4.CheckedChanged

		If chkAxis4.Checked = True Then
			SyncAxis = SyncAxis Or &H8
		ElseIf chkAxis4.Checked = False Then
			SyncAxis = SyncAxis Xor &H8
		End If

		txtSetSync.Text = Hex(SyncAxis) + "H" & " " & Hex(SyncChip) + "H" & " " & Hex(SyncBoard) + "H"

	End Sub

	Private Sub chkAxis5_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkAxis5.CheckedChanged

		If chkAxis5.Checked = True Then
			SyncAxis = SyncAxis Or &H10
		ElseIf chkAxis5.Checked = False Then
			SyncAxis = SyncAxis Xor &H10
		End If

		txtSetSync.Text = Hex(SyncAxis) + "H" & " " & Hex(SyncChip) + "H" & " " & Hex(SyncBoard) + "H"

	End Sub

	Private Sub chkAxis6_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkAxis6.CheckedChanged

		If chkAxis6.Checked = True Then
			SyncAxis = SyncAxis Or &H20
		ElseIf chkAxis6.Checked = False Then
			SyncAxis = SyncAxis Xor &H20
		End If

		txtSetSync.Text = Hex(SyncAxis) + "H" & " " & Hex(SyncChip) + "H" & " " & Hex(SyncBoard) + "H"

	End Sub

	Private Sub chkAxis7_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkAxis7.CheckedChanged

		If chkAxis7.Checked = True Then
			SyncAxis = SyncAxis Or &H40
		ElseIf chkAxis7.Checked = False Then
			SyncAxis = SyncAxis Xor &H40
		End If

		txtSetSync.Text = Hex(SyncAxis) + "H" & " " & Hex(SyncChip) + "H" & " " & Hex(SyncBoard) + "H"

	End Sub

	Private Sub chkAxis8_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkAxis8.CheckedChanged

		If chkAxis8.Checked = True Then
			SyncAxis = SyncAxis Or &H80
		ElseIf chkAxis8.Checked = False Then
			SyncAxis = SyncAxis Xor &H80
		End If

		txtSetSync.Text = Hex(SyncAxis) + "H" & " " & Hex(SyncChip) + "H" & " " & Hex(SyncBoard) + "H"

	End Sub

	Private Sub chkChip_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkChip.CheckedChanged

		If chkChip.Checked = True Then
			SyncChip = 1
		ElseIf chkChip.Checked = False Then
			SyncChip = 0
		End If

		txtSetSync.Text = Hex(SyncAxis) + "H" & " " & Hex(SyncChip) + "H" & " " & Hex(SyncBoard) + "H"

	End Sub

	Private Sub chkBoardCN2_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkBoardCN2.CheckedChanged

		If chkBoardCN2.Checked = True Then
			SyncBoard = SyncBoard Or &H1
		ElseIf chkBoardCN2.Checked = False Then
			SyncBoard = SyncBoard Xor &H1
		End If
		txtSetSync.Text = Hex(SyncAxis) + "H" & " " & Hex(SyncChip) + "H" & " " & Hex(SyncBoard) + "H"

	End Sub

	Private Sub chkBoardCN3_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkBoardCN3.CheckedChanged

		If chkBoardCN3.Checked = True Then
			SyncBoard = SyncBoard Or &H2
		ElseIf chkBoardCN3.Checked = False Then
			SyncBoard = SyncBoard Xor &H2
		End If
		txtSetSync.Text = Hex(SyncAxis) + "H" & " " & Hex(SyncChip) + "H" & " " & Hex(SyncBoard) + "H"

	End Sub

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

		AxisNo = cboTargetAxis.SelectedIndex + 1

	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 btnComGetSync_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnComGetSync.Click

		dwRet = SmcWGetSync(Id, GetSyncAxis, GetSyncChip, GetSyncBoard)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWSetSync = " & dwRet & " : " & ErrorString.ToString
            Exit Sub
        End If

        txtGetSync.Text = Hex(GetSyncAxis) + "H" & " " & Hex(GetSyncChip) + "H" & " " & Hex(GetSyncBoard) + "H"

        lblComment.Text = "OK "
        
    End Sub

    Private Sub btnComSetSync_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnComSetSync.Click

        dwRet = SmcWSetSync(Id, SyncAxis, SyncChip, SyncBoard)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWSetSync = " & dwRet & " : " & ErrorString.ToString
            Exit Sub
        End If

        lblComment.Text = "OK "
        
    End Sub

    Private Sub btnComStartSync_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnComStartSync.Click

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

        lblComment.Text = "OK "
        
    End Sub

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

        Dim BoardCN As Short
        Dim Axis As Short
        Dim n As Short
        ' Centering
        Me.Left = (Screen.PrimaryScreen.Bounds.Width - Me.Width) / 2
        Me.Top = (Screen.PrimaryScreen.Bounds.Height - Me.Height) / 2

        AxisNo = 1

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

        ' ComboBox Initialise
        cboTargetAxis.SelectedIndex = AxisNo - 1

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

        SyncAxis = 0
        txtSetSync.Text = Hex(SyncAxis)

        '------------------------
        ' Get synchronous setting
        '------------------------
        dwRet = SmcWGetSync(Id, SyncAxis, SyncChip, SyncBoard)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWSetSync = " & dwRet & " : " & ErrorString.ToString
            Exit Sub
        End If

        For n = 0 To 7
            Axis = (2 ^ n) And &HFF
            If (SyncAxis And Axis) = Axis Then
                Select Case n
                    Case 0
                        chkAxis1.Checked = True
                    Case 1
                        chkAxis2.Checked = True
                    Case 2
                        chkAxis3.Checked = True
                    Case 3
                        chkAxis4.Checked = True
                    Case 4
                        chkAxis5.Checked = True
                    Case 5
                        chkAxis6.Checked = True
                    Case 6
                        chkAxis7.Checked = True
                    Case 7
                        chkAxis8.Checked = True
                End Select
            End If
        Next

        If SyncChip = 1 Then
            chkChip.Checked = True
        End If

        For n = 0 To 2
            BoardCN = (2 ^ n) And &HFF
            If (SyncBoard And BoardCN) = BoardCN Then
                Select Case n
                    Case 0
                        chkBoardCN2.Checked = True
                    Case 1
                        chkBoardCN3.Checked = True
                End Select
            End If
        Next
        
        lblComment.Text = "OK "

    End Sub

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

        Dim BoardCN As Short
        Dim Axis As Short
        Dim n As Short

        If Id <> -1 Then
            SmcWExit(Id)
        End If

        chkAxis1.Checked = False
        chkAxis2.Checked = False
        chkAxis3.Checked = False
        chkAxis4.Checked = False
        chkAxis5.Checked = False
        chkAxis6.Checked = False
        chkAxis7.Checked = False
        chkAxis8.Checked = False
        chkChip.Checked = False
        chkBoardCN2.Checked = False
        chkBoardCN3.Checked = False

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

        '------------------------
        ' Get synchronous setting
        '------------------------
        dwRet = SmcWGetSync(Id, SyncAxis, SyncChip, SyncBoard)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWSetSync = " & dwRet & " : " & ErrorString.ToString
            Exit Sub
        End If

        For n = 0 To 7
            Axis = (2 ^ n) And &HFF
            If (SyncAxis And Axis) = Axis Then
                Select Case n
                    Case 0
                        chkAxis1.Checked = True
                    Case 1
                        chkAxis2.Checked = True
                    Case 2
                        chkAxis3.Checked = True
                    Case 3
                        chkAxis4.Checked = True
                    Case 4
                        chkAxis5.Checked = True
                    Case 5
                        chkAxis6.Checked = True
                    Case 6
                        chkAxis7.Checked = True
                    Case 7
                        chkAxis8.Checked = True
                End Select
            End If
        Next

        If SyncChip = 1 Then
            chkChip.Checked = True
        End If

        For n = 0 To 2
            BoardCN = (2 ^ n) And &HFF
            If (SyncBoard And BoardCN) = BoardCN Then
                Select Case n
                    Case 0
                        chkBoardCN2.Checked = True
                    Case 1
                        chkBoardCN3.Checked = True
                End Select
            End If
        Next

        lblComment.Text = "OK "

    End Sub

End Class
