Option Strict Off
Option Explicit On 
Public Class SimpleIO
	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 GroupBox2 As System.Windows.Forms.GroupBox
	Friend WithEvents Label6 As System.Windows.Forms.Label
	Friend WithEvents Label7 As System.Windows.Forms.Label
	Friend WithEvents GroupBox3 As System.Windows.Forms.GroupBox
	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 Label5 As System.Windows.Forms.Label
	Friend WithEvents Label1 As System.Windows.Forms.Label
	Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
	Friend WithEvents Label4 As System.Windows.Forms.Label
	Friend WithEvents Label3 As System.Windows.Forms.Label
	Friend WithEvents Label2 As System.Windows.Forms.Label
	Friend WithEvents GroupBox4 As System.Windows.Forms.GroupBox
	Friend WithEvents Label12 As System.Windows.Forms.Label
	Friend WithEvents Label13 As System.Windows.Forms.Label
	Friend WithEvents txtReturnCode As System.Windows.Forms.TextBox
	Friend WithEvents btnInpBit As System.Windows.Forms.Button
	Friend WithEvents txtInpBitData As System.Windows.Forms.TextBox
	Friend WithEvents txtInpBitNo As System.Windows.Forms.TextBox
	Friend WithEvents btnEchoBackByte As System.Windows.Forms.Button
	Friend WithEvents btnOutByte As System.Windows.Forms.Button
	Friend WithEvents txtOutPortData As System.Windows.Forms.TextBox
	Friend WithEvents txtOutPortNo As System.Windows.Forms.TextBox
	Friend WithEvents btnDioInit As System.Windows.Forms.Button
	Friend WithEvents btnExit As System.Windows.Forms.Button
	Friend WithEvents btnDioExit As System.Windows.Forms.Button
	Friend WithEvents btnInpByte As System.Windows.Forms.Button
	Friend WithEvents txtInpPortData As System.Windows.Forms.TextBox
	Friend WithEvents txtInpPortNo As System.Windows.Forms.TextBox
	Friend WithEvents cboDeviceName As System.Windows.Forms.ComboBox
	Friend WithEvents btnEchoBackBit As System.Windows.Forms.Button
	Friend WithEvents btnOutBit As System.Windows.Forms.Button
	Friend WithEvents txtOutBitData As System.Windows.Forms.TextBox
	Friend WithEvents txtOutBitNo As System.Windows.Forms.TextBox
	<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
		Me.txtReturnCode = New System.Windows.Forms.TextBox()
		Me.GroupBox2 = New System.Windows.Forms.GroupBox()
		Me.btnInpBit = New System.Windows.Forms.Button()
		Me.txtInpBitData = New System.Windows.Forms.TextBox()
		Me.txtInpBitNo = New System.Windows.Forms.TextBox()
		Me.Label6 = New System.Windows.Forms.Label()
		Me.Label7 = New System.Windows.Forms.Label()
		Me.GroupBox3 = New System.Windows.Forms.GroupBox()
		Me.btnEchoBackByte = New System.Windows.Forms.Button()
		Me.btnOutByte = New System.Windows.Forms.Button()
		Me.txtOutPortData = New System.Windows.Forms.TextBox()
		Me.txtOutPortNo = New System.Windows.Forms.TextBox()
		Me.Label8 = New System.Windows.Forms.Label()
		Me.Label9 = New System.Windows.Forms.Label()
		Me.Label10 = New System.Windows.Forms.Label()
		Me.Label5 = New System.Windows.Forms.Label()
		Me.btnDioInit = New System.Windows.Forms.Button()
		Me.Label1 = New System.Windows.Forms.Label()
		Me.btnExit = New System.Windows.Forms.Button()
		Me.btnDioExit = New System.Windows.Forms.Button()
		Me.GroupBox1 = New System.Windows.Forms.GroupBox()
		Me.btnInpByte = New System.Windows.Forms.Button()
		Me.txtInpPortData = New System.Windows.Forms.TextBox()
		Me.txtInpPortNo = New System.Windows.Forms.TextBox()
		Me.Label4 = New System.Windows.Forms.Label()
		Me.Label3 = New System.Windows.Forms.Label()
		Me.Label2 = New System.Windows.Forms.Label()
		Me.cboDeviceName = New System.Windows.Forms.ComboBox()
		Me.GroupBox4 = New System.Windows.Forms.GroupBox()
		Me.btnEchoBackBit = New System.Windows.Forms.Button()
		Me.btnOutBit = New System.Windows.Forms.Button()
		Me.txtOutBitData = New System.Windows.Forms.TextBox()
		Me.txtOutBitNo = New System.Windows.Forms.TextBox()
		Me.Label12 = New System.Windows.Forms.Label()
		Me.Label13 = New System.Windows.Forms.Label()
		Me.GroupBox2.SuspendLayout()
		Me.GroupBox3.SuspendLayout()
		Me.GroupBox1.SuspendLayout()
		Me.GroupBox4.SuspendLayout()
		Me.SuspendLayout()
		'
		'txtReturnCode
		'
		Me.txtReturnCode.Location = New System.Drawing.Point(88, 388)
		Me.txtReturnCode.Name = "txtReturnCode"
		Me.txtReturnCode.Size = New System.Drawing.Size(264, 20)
		Me.txtReturnCode.TabIndex = 17
		Me.txtReturnCode.Text = ""
		'
		'GroupBox2
		'
		Me.GroupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnInpBit, Me.txtInpBitData, Me.txtInpBitNo, Me.Label6, Me.Label7})
		Me.GroupBox2.Location = New System.Drawing.Point(13, 131)
		Me.GroupBox2.Name = "GroupBox2"
		Me.GroupBox2.Size = New System.Drawing.Size(580, 70)
		Me.GroupBox2.TabIndex = 2
		Me.GroupBox2.TabStop = False
		Me.GroupBox2.Text = "1 Bit Input"
		'
		'btnInpBit
		'
		Me.btnInpBit.Location = New System.Drawing.Point(352, 24)
		Me.btnInpBit.Name = "btnInpBit"
		Me.btnInpBit.Size = New System.Drawing.Size(105, 25)
		Me.btnInpBit.TabIndex = 6
		Me.btnInpBit.Text = "DioInpBit"
		'
		'txtInpBitData
		'
		Me.txtInpBitData.Location = New System.Drawing.Point(236, 28)
		Me.txtInpBitData.Name = "txtInpBitData"
		Me.txtInpBitData.Size = New System.Drawing.Size(45, 20)
		Me.txtInpBitData.TabIndex = 5
		Me.txtInpBitData.Text = "TextBox2"
		'
		'txtInpBitNo
		'
		Me.txtInpBitNo.Location = New System.Drawing.Point(88, 28)
		Me.txtInpBitNo.Name = "txtInpBitNo"
		Me.txtInpBitNo.Size = New System.Drawing.Size(45, 20)
		Me.txtInpBitNo.TabIndex = 4
		Me.txtInpBitNo.Text = "TextBox1"
		'
		'Label6
		'
		Me.Label6.Location = New System.Drawing.Point(164, 31)
		Me.Label6.Name = "Label6"
		Me.Label6.Size = New System.Drawing.Size(62, 19)
		Me.Label6.TabIndex = 2
		Me.Label6.Text = "Input Data :"
		'
		'Label7
		'
		Me.Label7.Location = New System.Drawing.Point(10, 31)
		Me.Label7.Name = "Label7"
		Me.Label7.Size = New System.Drawing.Size(78, 19)
		Me.Label7.TabIndex = 1
		Me.Label7.Text = "Logic BitNo :"
		'
		'GroupBox3
		'
		Me.GroupBox3.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnEchoBackByte, Me.btnOutByte, Me.txtOutPortData, Me.txtOutPortNo, Me.Label8, Me.Label9, Me.Label10})
		Me.GroupBox3.Location = New System.Drawing.Point(13, 215)
		Me.GroupBox3.Name = "GroupBox3"
		Me.GroupBox3.Size = New System.Drawing.Size(580, 70)
		Me.GroupBox3.TabIndex = 3
		Me.GroupBox3.TabStop = False
		Me.GroupBox3.Text = "1 Port Output"
		'
		'btnEchoBackByte
		'
		Me.btnEchoBackByte.Location = New System.Drawing.Point(464, 24)
		Me.btnEchoBackByte.Name = "btnEchoBackByte"
		Me.btnEchoBackByte.Size = New System.Drawing.Size(105, 25)
		Me.btnEchoBackByte.TabIndex = 10
		Me.btnEchoBackByte.Text = "DioEchoBackByte"
		'
		'btnOutByte
		'
		Me.btnOutByte.Location = New System.Drawing.Point(352, 24)
		Me.btnOutByte.Name = "btnOutByte"
		Me.btnOutByte.Size = New System.Drawing.Size(105, 25)
		Me.btnOutByte.TabIndex = 9
		Me.btnOutByte.Text = "DioOutByte"
		'
		'txtOutPortData
		'
		Me.txtOutPortData.Location = New System.Drawing.Point(236, 28)
		Me.txtOutPortData.Name = "txtOutPortData"
		Me.txtOutPortData.Size = New System.Drawing.Size(45, 20)
		Me.txtOutPortData.TabIndex = 8
		Me.txtOutPortData.Text = "TextBox2"
		'
		'txtOutPortNo
		'
		Me.txtOutPortNo.Location = New System.Drawing.Point(88, 28)
		Me.txtOutPortNo.Name = "txtOutPortNo"
		Me.txtOutPortNo.Size = New System.Drawing.Size(45, 20)
		Me.txtOutPortNo.TabIndex = 7
		Me.txtOutPortNo.Text = "TextBox1"
		'
		'Label8
		'
		Me.Label8.Location = New System.Drawing.Point(290, 31)
		Me.Label8.Name = "Label8"
		Me.Label8.Size = New System.Drawing.Size(38, 19)
		Me.Label8.TabIndex = 3
		Me.Label8.Text = "(Hex)"
		'
		'Label9
		'
		Me.Label9.Location = New System.Drawing.Point(164, 31)
		Me.Label9.Name = "Label9"
		Me.Label9.Size = New System.Drawing.Size(78, 19)
		Me.Label9.TabIndex = 2
		Me.Label9.Text = "Output Data :"
		'
		'Label10
		'
		Me.Label10.Location = New System.Drawing.Point(10, 31)
		Me.Label10.Name = "Label10"
		Me.Label10.Size = New System.Drawing.Size(78, 19)
		Me.Label10.TabIndex = 1
		Me.Label10.Text = "Logic PortNo :"
		'
		'Label5
		'
		Me.Label5.Location = New System.Drawing.Point(13, 389)
		Me.Label5.Name = "Label5"
		Me.Label5.Size = New System.Drawing.Size(83, 18)
		Me.Label5.TabIndex = 27
		Me.Label5.Text = "Return Value :"
		'
		'btnDioInit
		'
		Me.btnDioInit.Location = New System.Drawing.Point(365, 10)
		Me.btnDioInit.Name = "btnDioInit"
		Me.btnDioInit.Size = New System.Drawing.Size(105, 25)
		Me.btnDioInit.TabIndex = 0
		Me.btnDioInit.Text = "DioInit"
		'
		'Label1
		'
		Me.Label1.Location = New System.Drawing.Point(13, 15)
		Me.Label1.Name = "Label1"
		Me.Label1.Size = New System.Drawing.Size(78, 19)
		Me.Label1.TabIndex = 20
		Me.Label1.Text = "Device Name :"
		'
		'btnExit
		'
		Me.btnExit.Location = New System.Drawing.Point(365, 420)
		Me.btnExit.Name = "btnExit"
		Me.btnExit.Size = New System.Drawing.Size(105, 25)
		Me.btnExit.TabIndex = 16
		Me.btnExit.Text = "Exit"
		'
		'btnDioExit
		'
		Me.btnDioExit.Location = New System.Drawing.Point(365, 383)
		Me.btnDioExit.Name = "btnDioExit"
		Me.btnDioExit.Size = New System.Drawing.Size(105, 25)
		Me.btnDioExit.TabIndex = 15
		Me.btnDioExit.Text = "DioExit"
		'
		'GroupBox1
		'
		Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnInpByte, Me.txtInpPortData, Me.txtInpPortNo, Me.Label4, Me.Label3, Me.Label2})
		Me.GroupBox1.Location = New System.Drawing.Point(13, 48)
		Me.GroupBox1.Name = "GroupBox1"
		Me.GroupBox1.Size = New System.Drawing.Size(580, 69)
		Me.GroupBox1.TabIndex = 1
		Me.GroupBox1.TabStop = False
		Me.GroupBox1.Text = "1 Port Input"
		'
		'btnInpByte
		'
		Me.btnInpByte.Location = New System.Drawing.Point(352, 24)
		Me.btnInpByte.Name = "btnInpByte"
		Me.btnInpByte.Size = New System.Drawing.Size(105, 25)
		Me.btnInpByte.TabIndex = 3
		Me.btnInpByte.Text = "DioInpByte"
		'
		'txtInpPortData
		'
		Me.txtInpPortData.Location = New System.Drawing.Point(236, 28)
		Me.txtInpPortData.Name = "txtInpPortData"
		Me.txtInpPortData.Size = New System.Drawing.Size(45, 20)
		Me.txtInpPortData.TabIndex = 2
		Me.txtInpPortData.Text = "TextBox2"
		'
		'txtInpPortNo
		'
		Me.txtInpPortNo.Location = New System.Drawing.Point(88, 28)
		Me.txtInpPortNo.Name = "txtInpPortNo"
		Me.txtInpPortNo.Size = New System.Drawing.Size(45, 20)
		Me.txtInpPortNo.TabIndex = 1
		Me.txtInpPortNo.Text = "TextBox1"
		'
		'Label4
		'
		Me.Label4.Location = New System.Drawing.Point(290, 31)
		Me.Label4.Name = "Label4"
		Me.Label4.Size = New System.Drawing.Size(38, 19)
		Me.Label4.TabIndex = 3
		Me.Label4.Text = "(Hex)"
		'
		'Label3
		'
		Me.Label3.Location = New System.Drawing.Point(164, 31)
		Me.Label3.Name = "Label3"
		Me.Label3.Size = New System.Drawing.Size(62, 19)
		Me.Label3.TabIndex = 2
		Me.Label3.Text = "Input Data :"
		'
		'Label2
		'
		Me.Label2.Location = New System.Drawing.Point(10, 31)
		Me.Label2.Name = "Label2"
		Me.Label2.Size = New System.Drawing.Size(78, 19)
		Me.Label2.TabIndex = 1
		Me.Label2.Text = "Logic PortNo :"
		'
		'cboDeviceName
		'
		Me.cboDeviceName.Location = New System.Drawing.Point(96, 10)
		Me.cboDeviceName.Name = "cboDeviceName"
		Me.cboDeviceName.Size = New System.Drawing.Size(200, 21)
		Me.cboDeviceName.TabIndex = 18
		'
		'GroupBox4
		'
		Me.GroupBox4.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnEchoBackBit, Me.btnOutBit, Me.txtOutBitData, Me.txtOutBitNo, Me.Label12, Me.Label13})
		Me.GroupBox4.Location = New System.Drawing.Point(13, 299)
		Me.GroupBox4.Name = "GroupBox4"
		Me.GroupBox4.Size = New System.Drawing.Size(580, 70)
		Me.GroupBox4.TabIndex = 4
		Me.GroupBox4.TabStop = False
		Me.GroupBox4.Text = "1 Bit Output"
		'
		'btnEchoBackBit
		'
		Me.btnEchoBackBit.Location = New System.Drawing.Point(464, 24)
		Me.btnEchoBackBit.Name = "btnEchoBackBit"
		Me.btnEchoBackBit.Size = New System.Drawing.Size(105, 25)
		Me.btnEchoBackBit.TabIndex = 14
		Me.btnEchoBackBit.Text = "DioEchoBackBit"
		'
		'btnOutBit
		'
		Me.btnOutBit.Location = New System.Drawing.Point(352, 24)
		Me.btnOutBit.Name = "btnOutBit"
		Me.btnOutBit.Size = New System.Drawing.Size(105, 25)
		Me.btnOutBit.TabIndex = 13
		Me.btnOutBit.Text = "DioOutBit"
		'
		'txtOutBitData
		'
		Me.txtOutBitData.Location = New System.Drawing.Point(236, 28)
		Me.txtOutBitData.Name = "txtOutBitData"
		Me.txtOutBitData.Size = New System.Drawing.Size(45, 20)
		Me.txtOutBitData.TabIndex = 12
		Me.txtOutBitData.Text = "TextBox2"
		'
		'txtOutBitNo
		'
		Me.txtOutBitNo.Location = New System.Drawing.Point(88, 28)
		Me.txtOutBitNo.Name = "txtOutBitNo"
		Me.txtOutBitNo.Size = New System.Drawing.Size(45, 20)
		Me.txtOutBitNo.TabIndex = 11
		Me.txtOutBitNo.Text = "TextBox1"
		'
		'Label12
		'
		Me.Label12.Location = New System.Drawing.Point(164, 31)
		Me.Label12.Name = "Label12"
		Me.Label12.Size = New System.Drawing.Size(72, 19)
		Me.Label12.TabIndex = 2
		Me.Label12.Text = "Output Data :"
		'
		'Label13
		'
		Me.Label13.Location = New System.Drawing.Point(10, 31)
		Me.Label13.Name = "Label13"
		Me.Label13.Size = New System.Drawing.Size(78, 19)
		Me.Label13.TabIndex = 1
		Me.Label13.Text = "Logic BitNo :"
		'
		'SimpleIO
		'
		Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
		Me.ClientSize = New System.Drawing.Size(606, 459)
		Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.txtReturnCode, Me.GroupBox2, Me.GroupBox3, Me.Label5, Me.btnDioInit, Me.Label1, Me.btnExit, Me.btnDioExit, Me.GroupBox1, Me.cboDeviceName, Me.GroupBox4})
		Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
		Me.MaximizeBox = False
		Me.MinimizeBox = False
		Me.Name = "SimpleIO"
		Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
		Me.Text = "Simple I/O"
		Me.GroupBox2.ResumeLayout(False)
		Me.GroupBox3.ResumeLayout(False)
		Me.GroupBox1.ResumeLayout(False)
		Me.GroupBox4.ResumeLayout(False)
		Me.ResumeLayout(False)

	End Sub

#End Region
	Dim Id As Short										' Device ID
	Dim Ret As Integer									' Return value
	Dim szError As New System.Text.StringBuilder(256)	' Error string
	Dim szText As New String("", 100)

	'---------------------------------------------------------
	'	Initialize dialog
	'---------------------------------------------------------
	Private Sub SimpleIO_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

		'-----------------------------------
		' Detect device
		'-----------------------------------
		Dim Index As Short
		Dim GroupID, UnitID, DeviceID As Short
		Dim DeviceName As New System.Text.StringBuilder(256)
		Dim Device As New System.Text.StringBuilder(256)
		Index = 0
		Do
			Ret = DioQueryDeviceName(Index, GroupID, UnitID, DeviceID, DeviceName, Device)
			If Ret <> DIO_ERR_SUCCESS Then
				Exit Do
			End If
			cboDeviceName.Items.Add(DeviceName.ToString())
			Index += 1
		Loop
		cboDeviceName.SelectedIndex = 0
		'-----------------------------------
		' Initialize screen items
		'-----------------------------------
		txtInpPortNo.Text = "0"
		txtInpBitNo.Text = "0"
		txtOutPortNo.Text = "0"
		txtOutBitNo.Text = "0"
		txtOutPortData.Text = "55"
		txtOutBitData.Text = "1"
		txtReturnCode.Text = ""
		txtInpPortData.Text = ""
		txtInpBitData.Text = ""

	End Sub

	'---------------------------------------------------------
	'	Initialization
	'---------------------------------------------------------
	Private Sub btnDioInit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDioInit.Click

		Dim szDeviceName As New String("", 100)
		'-----------------------------
		' Get device name from screen
		'-----------------------------
		szDeviceName = cboDeviceName.Text
		'-----------------------------
		' Initialize and get ID
		'-----------------------------
		Ret = DioInit(szDeviceName, Id)
		'-----------------------------
		' Process error
		'-----------------------------
		DioGetErrorString(Ret, szError)
		txtReturnCode.Text = "DioInit : " & szError.ToString()

	End Sub

	'---------------------------------------------------------
	'	1 port input
	'---------------------------------------------------------
	Private Sub btnInpByte_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInpByte.Click

		Dim InpPortNo As Short
		Dim InpPortData As Byte
		'-----------------------------
		' Get port No. from screen
		'-----------------------------
		InpPortNo = Val(txtInpPortNo.Text)
		'-----------------------------
		' Port input
		'-----------------------------
		Ret = DioInpByte(Id, InpPortNo, InpPortData)
		'-----------------------------
		' Process error
		'-----------------------------
		DioGetErrorString(Ret, szError)
		txtReturnCode.Text = "DioInpByte : " & szError.ToString()
		If Ret <> DIO_ERR_SUCCESS Then
			Exit Sub
		End If
		'-----------------------------
		' Display data
		'-----------------------------
		txtInpPortData.Text = String.Format("{0:X2}", InpPortData)

	End Sub

	'---------------------------------------------------------
	'	1 bit input
	'---------------------------------------------------------
	Private Sub btnInpBit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInpBit.Click

		Dim InpBitNo As Short
		Dim InpBitData As Byte
		'-----------------------------
		' Get bit No. from screen
		'-----------------------------
		InpBitNo = Val(txtInpBitNo.Text)
		'-----------------------------
		' Bit input
		'-----------------------------
		Ret = DioInpBit(Id, InpBitNo, InpBitData)
		'-----------------------------
		' Process error
		'-----------------------------
		DioGetErrorString(Ret, szError)
		txtReturnCode.Text = "DioInpBit : " & szError.ToString()
		If Ret <> DIO_ERR_SUCCESS Then
			Exit Sub
		End If
		'-----------------------------
		' Display data
		'-----------------------------
		txtInpBitData.Text = String.Format("{0:X}", InpBitData)

	End Sub

	'---------------------------------------------------------
	'	1 port output
	'---------------------------------------------------------
	Private Sub btnOutByte_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOutByte.Click

		Dim OutPortNo As Short
		Dim OutPortData As Byte
		'-----------------------------
		' Get the port No. and the output data from screen
		'-----------------------------
		szText = txtOutPortNo.Text
		OutPortNo = Val(szText)
		szText = txtOutPortData.Text
		OutPortData = Val("&H" & szText)
		'-----------------------------
		' Port output
		'-----------------------------
		Ret = DioOutByte(Id, OutPortNo, OutPortData)
		'-----------------------------
		' Process error
		'-----------------------------
		DioGetErrorString(Ret, szError)
		txtReturnCode.Text = "DioOutByte : " & szError.ToString()
		If Ret <> DIO_ERR_SUCCESS Then
			Exit Sub
		End If

	End Sub

	'---------------------------------------------------------
	'	1 bit output
	'---------------------------------------------------------
	Private Sub btnOutBit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOutBit.Click

		Dim OutBitNo As Short
		Dim OutBitData As Byte
		'-----------------------------
		' Get the bit No. and the output data from screen
		'-----------------------------
		szText = txtOutBitNo.Text
		OutBitNo = Val(szText)
		szText = txtOutBitData.Text
		OutBitData = Val("&H" & szText)
		'-----------------------------
		' Bit output
		'-----------------------------
		Ret = DioOutBit(Id, OutBitNo, OutBitData)
		'-----------------------------
		' Process error
		'-----------------------------
		DioGetErrorString(Ret, szError)
		txtReturnCode.Text = "DioOutBit : " & szError.ToString()
		If Ret <> DIO_ERR_SUCCESS Then
			Exit Sub
		End If

	End Sub

	'---------------------------------------------------------
	'	1 port EchoBack
	'---------------------------------------------------------
	Private Sub btnEchoBackByte_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEchoBackByte.Click

		Dim OutPortNo As Short
		Dim OutPortData As Byte
		'-----------------------------
		' Get port No. from screen
		'-----------------------------
		OutPortNo = Val(txtOutPortNo.Text)
		'-----------------------------
		' Port EchoBack
		'-----------------------------
		Ret = DioEchoBackByte(Id, OutPortNo, OutPortData)
		'-----------------------------
		' Process error
		'-----------------------------
		DioGetErrorString(Ret, szError)
		txtReturnCode.Text = "DioEchoBackByte : " & szError.ToString()
		If Ret <> DIO_ERR_SUCCESS Then
			Exit Sub
		End If
		'-----------------------------
		' Display data
		'-----------------------------
		txtOutPortData.Text = String.Format("{0:X2}", OutPortData)

	End Sub

	'---------------------------------------------------------
	'	1 Bit EchoBack
	'---------------------------------------------------------
	Private Sub btnEchoBackBit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEchoBackBit.Click

		Dim OutBitNo As Short
		Dim OutBitData As Byte
		'-----------------------------
		' Get bit No. from screen
		'-----------------------------
		OutBitNo = Val(txtOutBitNo.Text)
		'-----------------------------
		' Bit EchoBack
		'-----------------------------
		Ret = DioEchoBackBit(Id, OutBitNo, OutBitData)
		'-----------------------------
		' Process error
		'-----------------------------
		DioGetErrorString(Ret, szError)
		txtReturnCode.Text = "DioEchoBackBit : " & szError.ToString()
		If Ret <> DIO_ERR_SUCCESS Then
			Exit Sub
		End If
		'-----------------------------
		' Display data
		'-----------------------------
		txtOutBitData.Text = String.Format("{0:X}", OutBitData)

	End Sub

	'---------------------------------------------------------
	'	Termination
	'---------------------------------------------------------
	Private Sub btnDioExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDioExit.Click

		' Termination
		'-----------------------------
		Ret = DioExit(Id)
		'-----------------------------
		' Process error
		'-----------------------------
		DioGetErrorString(Ret, szError)
		txtReturnCode.Text = "DioExit : " & szError.ToString()

	End Sub

	'---------------------------------------------------------
	'	Exit dialog
	'---------------------------------------------------------
	Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

		'-----------------------------
		' Termination
		'-----------------------------
		Ret = DioExit(Id)
		'-----------------------------
		' Exit dialog
		'-----------------------------
		End

	End Sub

	Private Sub SimpleIO_Closed(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Closed

		' Termination
		Ret = DioExit(Id)

	End Sub
End Class
