﻿Option Strict Off
Option Explicit On 
Imports System.Text
Public Class Ctlio
	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 LDeviceName As System.Windows.Forms.Label
	Friend WithEvents txtDeviceName As System.Windows.Forms.TextBox
	Friend WithEvents cboTargetAxis As System.Windows.Forms.ComboBox
	Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
	Friend WithEvents Label2 As System.Windows.Forms.Label
	Friend WithEvents Label3 As System.Windows.Forms.Label
	Friend WithEvents Label4 As System.Windows.Forms.Label
	Friend WithEvents Label5 As System.Windows.Forms.Label
	Friend WithEvents Label6 As System.Windows.Forms.Label
	Friend WithEvents btnComOut1 As System.Windows.Forms.Button
	Friend WithEvents btnComOut2 As System.Windows.Forms.Button
	Friend WithEvents btnComOut3 As System.Windows.Forms.Button
	Friend WithEvents btnComHoldOff As System.Windows.Forms.Button
	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 btnComErcOut As System.Windows.Forms.Button
	Friend WithEvents btnComErcClear As System.Windows.Forms.Button
	Friend WithEvents btnComAlarmClear As System.Windows.Forms.Button
	Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
    Friend WithEvents btnComEnd As System.Windows.Forms.Button
    Friend WithEvents lblComment As System.Windows.Forms.Label
	Public WithEvents timer As System.Windows.Forms.Timer
	Friend WithEvents lblOUT1 As System.Windows.Forms.Label
	Friend WithEvents lblOUT2 As System.Windows.Forms.Label
	Friend WithEvents lblOUT3 As System.Windows.Forms.Label
	Friend WithEvents lblHoldOff As System.Windows.Forms.Label
	Friend WithEvents lblIN1 As System.Windows.Forms.Label
	Friend WithEvents lblIN2 As System.Windows.Forms.Label
	Friend WithEvents lblIN3 As System.Windows.Forms.Label
	Friend WithEvents lblIN4 As System.Windows.Forms.Label
	Friend WithEvents lblIN5 As System.Windows.Forms.Label
	Friend WithEvents lblIN6 As System.Windows.Forms.Label
	Friend WithEvents lblIN7 As System.Windows.Forms.Label
	Friend WithEvents Label1 As System.Windows.Forms.Label
	<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Me.LDeviceName = New System.Windows.Forms.Label()
        Me.txtDeviceName = New System.Windows.Forms.TextBox()
        Me.cboTargetAxis = New System.Windows.Forms.ComboBox()
        Me.GroupBox1 = New System.Windows.Forms.GroupBox()
        Me.lblIN7 = New System.Windows.Forms.Label()
        Me.lblIN6 = New System.Windows.Forms.Label()
        Me.lblIN5 = New System.Windows.Forms.Label()
        Me.lblIN4 = New System.Windows.Forms.Label()
        Me.lblIN3 = New System.Windows.Forms.Label()
        Me.lblIN2 = New System.Windows.Forms.Label()
        Me.lblIN1 = New System.Windows.Forms.Label()
        Me.lblHoldOff = New System.Windows.Forms.Label()
        Me.lblOUT3 = New System.Windows.Forms.Label()
        Me.lblOUT2 = New System.Windows.Forms.Label()
        Me.lblOUT1 = 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.Label9 = New System.Windows.Forms.Label()
        Me.Label8 = New System.Windows.Forms.Label()
        Me.Label7 = New System.Windows.Forms.Label()
        Me.btnComHoldOff = New System.Windows.Forms.Button()
        Me.btnComOut3 = New System.Windows.Forms.Button()
        Me.btnComOut2 = New System.Windows.Forms.Button()
        Me.btnComOut1 = New System.Windows.Forms.Button()
        Me.Label6 = New System.Windows.Forms.Label()
        Me.Label5 = New System.Windows.Forms.Label()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.btnComErcOut = New System.Windows.Forms.Button()
        Me.btnComErcClear = New System.Windows.Forms.Button()
        Me.btnComAlarmClear = New System.Windows.Forms.Button()
        Me.GroupBox2 = New System.Windows.Forms.GroupBox()
        Me.lblComment = New System.Windows.Forms.Label()
        Me.btnComEnd = New System.Windows.Forms.Button()
        Me.timer = New System.Windows.Forms.Timer(Me.components)
        Me.Label1 = New System.Windows.Forms.Label()
        Me.GroupBox1.SuspendLayout()
        Me.GroupBox2.SuspendLayout()
        Me.SuspendLayout()
        '
        'LDeviceName
        '
        Me.LDeviceName.AutoSize = True
        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(112, 16)
        Me.txtDeviceName.Name = "txtDeviceName"
        Me.txtDeviceName.Size = New System.Drawing.Size(80, 21)
        Me.txtDeviceName.TabIndex = 1
        Me.txtDeviceName.Text = "SMC000"
        '
        'cboTargetAxis
        '
        Me.cboTargetAxis.Location = New System.Drawing.Point(288, 16)
        Me.cboTargetAxis.Name = "cboTargetAxis"
        Me.cboTargetAxis.Size = New System.Drawing.Size(64, 23)
        Me.cboTargetAxis.TabIndex = 2
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblIN7, Me.lblIN6, Me.lblIN5, Me.lblIN4, Me.lblIN3, Me.lblIN2, Me.lblIN1, Me.lblHoldOff, Me.lblOUT3, Me.lblOUT2, Me.lblOUT1, Me.Label14, Me.Label13, Me.Label12, Me.Label11, Me.Label10, Me.Label9, Me.Label8, Me.Label7, Me.btnComHoldOff, Me.btnComOut3, Me.btnComOut2, Me.btnComOut1, Me.Label6, Me.Label5, Me.Label4, Me.Label3, Me.Label2})
        Me.GroupBox1.Location = New System.Drawing.Point(16, 48)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(448, 144)
        Me.GroupBox1.TabIndex = 3
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "Control I/O"
        '
        'lblIN7
        '
        Me.lblIN7.BackColor = System.Drawing.SystemColors.ScrollBar
        Me.lblIN7.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblIN7.Location = New System.Drawing.Point(392, 112)
        Me.lblIN7.Name = "lblIN7"
        Me.lblIN7.Size = New System.Drawing.Size(40, 16)
        Me.lblIN7.TabIndex = 31
        Me.lblIN7.TextAlign = System.Drawing.ContentAlignment.TopCenter
        '
        'lblIN6
        '
        Me.lblIN6.BackColor = System.Drawing.SystemColors.ScrollBar
        Me.lblIN6.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblIN6.Location = New System.Drawing.Point(344, 112)
        Me.lblIN6.Name = "lblIN6"
        Me.lblIN6.Size = New System.Drawing.Size(40, 16)
        Me.lblIN6.TabIndex = 30
        Me.lblIN6.TextAlign = System.Drawing.ContentAlignment.TopCenter
        '
        'lblIN5
        '
        Me.lblIN5.BackColor = System.Drawing.SystemColors.ScrollBar
        Me.lblIN5.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblIN5.Location = New System.Drawing.Point(296, 112)
        Me.lblIN5.Name = "lblIN5"
        Me.lblIN5.Size = New System.Drawing.Size(40, 16)
        Me.lblIN5.TabIndex = 29
        Me.lblIN5.TextAlign = System.Drawing.ContentAlignment.TopCenter
        '
        'lblIN4
        '
        Me.lblIN4.BackColor = System.Drawing.SystemColors.ScrollBar
        Me.lblIN4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblIN4.Location = New System.Drawing.Point(248, 112)
        Me.lblIN4.Name = "lblIN4"
        Me.lblIN4.Size = New System.Drawing.Size(40, 16)
        Me.lblIN4.TabIndex = 28
        Me.lblIN4.TextAlign = System.Drawing.ContentAlignment.TopCenter
        '
        'lblIN3
        '
        Me.lblIN3.BackColor = System.Drawing.SystemColors.ScrollBar
        Me.lblIN3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblIN3.Location = New System.Drawing.Point(200, 112)
        Me.lblIN3.Name = "lblIN3"
        Me.lblIN3.Size = New System.Drawing.Size(40, 16)
        Me.lblIN3.TabIndex = 27
        Me.lblIN3.TextAlign = System.Drawing.ContentAlignment.TopCenter
        '
        'lblIN2
        '
        Me.lblIN2.BackColor = System.Drawing.SystemColors.ScrollBar
        Me.lblIN2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblIN2.Location = New System.Drawing.Point(152, 112)
        Me.lblIN2.Name = "lblIN2"
        Me.lblIN2.Size = New System.Drawing.Size(40, 16)
        Me.lblIN2.TabIndex = 26
        Me.lblIN2.TextAlign = System.Drawing.ContentAlignment.TopCenter
        '
        'lblIN1
        '
        Me.lblIN1.BackColor = System.Drawing.SystemColors.ScrollBar
        Me.lblIN1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblIN1.Location = New System.Drawing.Point(104, 112)
        Me.lblIN1.Name = "lblIN1"
        Me.lblIN1.Size = New System.Drawing.Size(40, 16)
        Me.lblIN1.TabIndex = 25
        Me.lblIN1.TextAlign = System.Drawing.ContentAlignment.TopCenter
        '
        'lblHoldOff
        '
        Me.lblHoldOff.BackColor = System.Drawing.SystemColors.ScrollBar
        Me.lblHoldOff.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblHoldOff.Location = New System.Drawing.Point(280, 64)
        Me.lblHoldOff.Name = "lblHoldOff"
        Me.lblHoldOff.Size = New System.Drawing.Size(72, 16)
        Me.lblHoldOff.TabIndex = 24
        Me.lblHoldOff.TextAlign = System.Drawing.ContentAlignment.TopCenter
        '
        'lblOUT3
        '
        Me.lblOUT3.BackColor = System.Drawing.SystemColors.ScrollBar
        Me.lblOUT3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblOUT3.Location = New System.Drawing.Point(216, 64)
        Me.lblOUT3.Name = "lblOUT3"
        Me.lblOUT3.Size = New System.Drawing.Size(48, 16)
        Me.lblOUT3.TabIndex = 23
        Me.lblOUT3.TextAlign = System.Drawing.ContentAlignment.TopCenter
        '
        'lblOUT2
        '
        Me.lblOUT2.BackColor = System.Drawing.SystemColors.ScrollBar
        Me.lblOUT2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblOUT2.Location = New System.Drawing.Point(160, 64)
        Me.lblOUT2.Name = "lblOUT2"
        Me.lblOUT2.Size = New System.Drawing.Size(48, 16)
        Me.lblOUT2.TabIndex = 22
        Me.lblOUT2.TextAlign = System.Drawing.ContentAlignment.TopCenter
        '
        'lblOUT1
        '
        Me.lblOUT1.BackColor = System.Drawing.SystemColors.ScrollBar
        Me.lblOUT1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblOUT1.Location = New System.Drawing.Point(104, 64)
        Me.lblOUT1.Name = "lblOUT1"
        Me.lblOUT1.Size = New System.Drawing.Size(48, 16)
        Me.lblOUT1.TabIndex = 21
        Me.lblOUT1.TextAlign = System.Drawing.ContentAlignment.TopCenter
        '
        'Label14
        '
        Me.Label14.AutoSize = True
        Me.Label14.Location = New System.Drawing.Point(400, 88)
        Me.Label14.Name = "Label14"
        Me.Label14.Size = New System.Drawing.Size(24, 14)
        Me.Label14.TabIndex = 20
        Me.Label14.Text = "IN7"
        '
        'Label13
        '
        Me.Label13.AutoSize = True
        Me.Label13.Location = New System.Drawing.Point(352, 88)
        Me.Label13.Name = "Label13"
        Me.Label13.Size = New System.Drawing.Size(24, 14)
        Me.Label13.TabIndex = 19
        Me.Label13.Text = "IN6"
        '
        'Label12
        '
        Me.Label12.AutoSize = True
        Me.Label12.Location = New System.Drawing.Point(304, 88)
        Me.Label12.Name = "Label12"
        Me.Label12.Size = New System.Drawing.Size(24, 14)
        Me.Label12.TabIndex = 18
        Me.Label12.Text = "IN5"
        '
        'Label11
        '
        Me.Label11.AutoSize = True
        Me.Label11.Location = New System.Drawing.Point(256, 88)
        Me.Label11.Name = "Label11"
        Me.Label11.Size = New System.Drawing.Size(24, 14)
        Me.Label11.TabIndex = 17
        Me.Label11.Text = "IN4"
        '
        'Label10
        '
        Me.Label10.AutoSize = True
        Me.Label10.Location = New System.Drawing.Point(208, 88)
        Me.Label10.Name = "Label10"
        Me.Label10.Size = New System.Drawing.Size(24, 14)
        Me.Label10.TabIndex = 16
        Me.Label10.Text = "IN3"
        '
        'Label9
        '
        Me.Label9.AutoSize = True
        Me.Label9.Location = New System.Drawing.Point(160, 88)
        Me.Label9.Name = "Label9"
        Me.Label9.Size = New System.Drawing.Size(24, 14)
        Me.Label9.TabIndex = 15
        Me.Label9.Text = "IN2"
        '
        'Label8
        '
        Me.Label8.AutoSize = True
        Me.Label8.Location = New System.Drawing.Point(112, 88)
        Me.Label8.Name = "Label8"
        Me.Label8.Size = New System.Drawing.Size(24, 14)
        Me.Label8.TabIndex = 14
        Me.Label8.Text = "IN1"
        '
        'Label7
        '
        Me.Label7.AutoSize = True
        Me.Label7.Location = New System.Drawing.Point(16, 112)
        Me.Label7.Name = "Label7"
        Me.Label7.Size = New System.Drawing.Size(61, 14)
        Me.Label7.TabIndex = 13
        Me.Label7.Text = "Input Data"
        '
        'btnComHoldOff
        '
        Me.btnComHoldOff.Location = New System.Drawing.Point(280, 40)
        Me.btnComHoldOff.Name = "btnComHoldOff"
        Me.btnComHoldOff.Size = New System.Drawing.Size(48, 16)
        Me.btnComHoldOff.TabIndex = 8
        '
        'btnComOut3
        '
        Me.btnComOut3.Location = New System.Drawing.Point(216, 40)
        Me.btnComOut3.Name = "btnComOut3"
        Me.btnComOut3.Size = New System.Drawing.Size(48, 16)
        Me.btnComOut3.TabIndex = 7
        '
        'btnComOut2
        '
        Me.btnComOut2.Location = New System.Drawing.Point(160, 40)
        Me.btnComOut2.Name = "btnComOut2"
        Me.btnComOut2.Size = New System.Drawing.Size(48, 16)
        Me.btnComOut2.TabIndex = 6
        '
        'btnComOut1
        '
        Me.btnComOut1.Location = New System.Drawing.Point(104, 40)
        Me.btnComOut1.Name = "btnComOut1"
        Me.btnComOut1.Size = New System.Drawing.Size(48, 16)
        Me.btnComOut1.TabIndex = 5
        '
        'Label6
        '
        Me.Label6.AutoSize = True
        Me.Label6.Location = New System.Drawing.Point(280, 24)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(50, 14)
        Me.Label6.TabIndex = 4
        Me.Label6.Text = "Hold Off"
        '
        'Label5
        '
        Me.Label5.AutoSize = True
        Me.Label5.Location = New System.Drawing.Point(224, 24)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(37, 14)
        Me.Label5.TabIndex = 3
        Me.Label5.Text = "OUT3"
        '
        'Label4
        '
        Me.Label4.AutoSize = True
        Me.Label4.Location = New System.Drawing.Point(160, 24)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(37, 14)
        Me.Label4.TabIndex = 2
        Me.Label4.Text = "OUT2"
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.Location = New System.Drawing.Point(104, 24)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(37, 14)
        Me.Label3.TabIndex = 1
        Me.Label3.Text = "OUT1"
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(16, 40)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(71, 14)
        Me.Label2.TabIndex = 0
        Me.Label2.Text = "Output Data"
        '
        'btnComErcOut
        '
        Me.btnComErcOut.Location = New System.Drawing.Point(16, 208)
        Me.btnComErcOut.Name = "btnComErcOut"
        Me.btnComErcOut.Size = New System.Drawing.Size(88, 24)
        Me.btnComErcOut.TabIndex = 4
        Me.btnComErcOut.Text = "Erc OutPut"
        '
        'btnComErcClear
        '
        Me.btnComErcClear.Location = New System.Drawing.Point(136, 208)
        Me.btnComErcClear.Name = "btnComErcClear"
        Me.btnComErcClear.Size = New System.Drawing.Size(88, 24)
        Me.btnComErcClear.TabIndex = 5
        Me.btnComErcClear.Text = "Erc Reset"
        '
        'btnComAlarmClear
        '
        Me.btnComAlarmClear.Location = New System.Drawing.Point(256, 208)
        Me.btnComAlarmClear.Name = "btnComAlarmClear"
        Me.btnComAlarmClear.Size = New System.Drawing.Size(136, 24)
        Me.btnComAlarmClear.TabIndex = 6
        Me.btnComAlarmClear.Text = "Alm Clear OutPut"
        '
        'GroupBox2
        '
        Me.GroupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblComment})
        Me.GroupBox2.Location = New System.Drawing.Point(16, 248)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(448, 144)
        Me.GroupBox2.TabIndex = 7
        Me.GroupBox2.TabStop = False
        Me.GroupBox2.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(432, 112)
        Me.lblComment.TabIndex = 0
        '
        'btnComEnd
        '
        Me.btnComEnd.Location = New System.Drawing.Point(248, 408)
        Me.btnComEnd.Name = "btnComEnd"
        Me.btnComEnd.Size = New System.Drawing.Size(112, 24)
        Me.btnComEnd.TabIndex = 9
        Me.btnComEnd.Text = "E&XIT"
        '
        'timer
        '
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(232, 18)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(44, 14)
        Me.Label1.TabIndex = 10
        Me.Label1.Text = "AxisNo"
        '
        'Ctlio
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(480, 446)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label1, Me.LDeviceName, Me.btnComEnd, Me.GroupBox2, Me.btnComAlarmClear, Me.btnComErcClear, Me.btnComErcOut, Me.GroupBox1, Me.cboTargetAxis, 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 = "Ctlio"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "CONTROL I/O"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox2.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

	Dim dwRet As Integer
	Dim OutData As Short
	Dim InData As Short
	Dim szComment As String
	Dim Id As Short
	Dim AxisNo As Short
    Dim ErcOn As Short
    Dim ErrorString As New StringBuilder("", 256)  'Error String

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

        Dim HoldOff As Short

        dwRet = SmcWGetHoldOff(Id, AxisNo, HoldOff)
        If (HoldOff And CSMC_HOLDOFF) = CSMC_HOLDOFF Then
            dwRet = SmcWSetHoldOff(Id, AxisNo, CSMC_HOLD)
        Else
            dwRet = SmcWSetHoldOff(Id, AxisNo, CSMC_HOLDOFF)
        End If

    End Sub

    Private Sub btnComErcOut_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnComErcOut.Click

        ErcOn = 0
        dwRet = SmcWSetErcOut(Id, AxisNo, ErcOn)

    End Sub

    Private Sub btnComErcClear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnComErcClear.Click

        ErcOn = 1
        dwRet = SmcWSetErcOut(Id, AxisNo, ErcOn)

    End Sub

    Private Sub btnComAlarmClear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnComAlarmClear.Click

        dwRet = SmcWSetAlarmClear(Id, AxisNo)

    End Sub

    Private Sub btnComOut1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnComOut1.Click

        '-----------------------------------
        ' Set Ctrl Output Data to Driver
        '-----------------------------------
        dwRet = SmcWGetDigitalOut(Id, AxisNo, OutData)
        If (OutData And CSMC_OUT1) = CSMC_OUT1 Then
            dwRet = SmcWSetDigitalOut(Id, AxisNo, 0, CSMC_OUT1)
        Else
            dwRet = SmcWSetDigitalOut(Id, AxisNo, CSMC_OUT1, CSMC_OUT1)
        End If

    End Sub

    Private Sub btnComOut2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnComOut2.Click

        '-----------------------------------
        ' Set Ctrl Output Data to Driver
        '-----------------------------------
        dwRet = SmcWGetDigitalOut(Id, AxisNo, OutData)
        If (OutData And CSMC_OUT2) = CSMC_OUT2 Then
            dwRet = SmcWSetDigitalOut(Id, AxisNo, 0, CSMC_OUT2)
        Else
            dwRet = SmcWSetDigitalOut(Id, AxisNo, CSMC_OUT2, CSMC_OUT2)
        End If

    End Sub

    Private Sub btnComOut3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnComOut3.Click

        '-----------------------------------
        ' Set Ctrl Output Data to Driver
        '-----------------------------------
        dwRet = SmcWGetDigitalOut(Id, AxisNo, OutData)
        If (OutData And CSMC_OUT3) = CSMC_OUT3 Then
            dwRet = SmcWSetDigitalOut(Id, AxisNo, 0, CSMC_OUT3)
        Else
            dwRet = SmcWSetDigitalOut(Id, AxisNo, CSMC_OUT3, CSMC_OUT3)
        End If

    End Sub

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

        Dim n As Short

        ' Centering
        Me.Left = (Screen.PrimaryScreen.Bounds.Width - Me.Width) / 2
        Me.Top = (Screen.PrimaryScreen.Bounds.Height - Me.Height) / 2
        '-------------
        ' Initialize
        '-------------
        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

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

        ' ComboBox Initialise
        cboTargetAxis.SelectedIndex = AxisNo - 1

        timer.Enabled = True
        timer.Interval = 1

        lblComment.Text = "OK "
        
    End Sub

    Private Sub timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timer.Tick

        Dim HoldOff As Short

        '-------------------------------
        ' Get Ctrl Output Data from Driver
        '-------------------------------
        dwRet = SmcWGetDigitalOut(Id, AxisNo, OutData)
        If dwRet <> 0 Then
            SmcWGetErrorString(dwRet, ErrorString)
            lblComment.Text = "SmcWGetDigitalOut = " & dwRet & " : " & ErrorString.ToString
            Exit Sub
        End If

        If (OutData And CSMC_OUT1) = CSMC_OUT1 Then
            lblOUT1.Text = "ON"
        Else
            lblOUT1.Text = "OFF"
        End If
        If (OutData And CSMC_OUT2) = CSMC_OUT2 Then
            lblOUT2.Text = "ON"
        Else
            lblOUT2.Text = "OFF"
        End If
        If (OutData And CSMC_OUT3) = CSMC_OUT3 Then
            lblOUT3.Text = "ON"
        Else
            lblOUT3.Text = "OFF"
        End If

        '-------------------------------
        ' Get Ctrl Input Data from Driver
        '-------------------------------
        dwRet = SmcWGetDigitalIn(Id, AxisNo, InData)
        If (InData And CSMC_IN1) = CSMC_IN1 Then
            lblIN1.Text = "ON"
        Else
            lblIN1.Text = "OFF"
        End If
        If (InData And CSMC_IN2) = CSMC_IN2 Then
            lblIN2.Text = "ON"
        Else
            lblIN2.Text = "OFF"
        End If
        If (InData And CSMC_IN3) = CSMC_IN3 Then
            lblIN3.Text = "ON"
        Else
            lblIN3.Text = "OFF"
        End If
        If (InData And CSMC_IN4) = CSMC_IN4 Then
            lblIN4.Text = "ON"
        Else
            lblIN4.Text = "OFF"
        End If
        If (InData And CSMC_IN5) = CSMC_IN5 Then
            lblIN5.Text = "ON"
        Else
            lblIN5.Text = "OFF"
        End If
        If (InData And CSMC_IN6) = CSMC_IN6 Then
            lblIN6.Text = "ON"
        Else
            lblIN6.Text = "OFF"
        End If
        If (InData And CSMC_IN7) = CSMC_IN7 Then
            lblIN7.Text = "ON"
        Else
            lblIN7.Text = "OFF"
        End If

        dwRet = SmcWGetHoldOff(Id, AxisNo, HoldOff)
        If (HoldOff And CSMC_HOLDOFF) = CSMC_HOLDOFF Then
            lblHoldOff.Text = "HOLDOFF"
        Else
            lblHoldOff.Text = "HOLD"
        End If

        lblComment.Text = "OK "

    End Sub

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

        Dim n As Short

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

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

        ' ComboBox Initialise
        cboTargetAxis.SelectedIndex = AxisNo - 1

        timer.Enabled = True
        timer.Interval = 1

        lblComment.Text = "OK "

    End Sub
End Class
