Option Strict Off
Option Explicit On 
Imports System.Text
Public Class Form1
    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.
    Public WithEvents CommandSetting As System.Windows.Forms.Button
    Public WithEvents TextDevice As System.Windows.Forms.TextBox
    Public WithEvents CommandInit As System.Windows.Forms.Button
    Public WithEvents CommandStart As System.Windows.Forms.Button
    Public WithEvents CommandInfo As System.Windows.Forms.Button
    Public WithEvents CommandStop As System.Windows.Forms.Button
    Public WithEvents CommandExit As System.Windows.Forms.Button
    Public WithEvents ListData As System.Windows.Forms.ListBox
    Public WithEvents TextInfo As System.Windows.Forms.TextBox
    Public WithEvents LabelCountJudge As System.Windows.Forms.Label
    Public WithEvents Label2 As System.Windows.Forms.Label
    Public WithEvents Label1 As System.Windows.Forms.Label
    Public WithEvents Label3 As System.Windows.Forms.Label
    Public WithEvents Label6 As System.Windows.Forms.Label
    Public WithEvents LabelStatus As System.Windows.Forms.Label
    Public WithEvents Label4 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.CommandSetting = New System.Windows.Forms.Button
        Me.TextDevice = New System.Windows.Forms.TextBox
        Me.CommandInit = New System.Windows.Forms.Button
        Me.CommandStart = New System.Windows.Forms.Button
        Me.CommandInfo = New System.Windows.Forms.Button
        Me.CommandStop = New System.Windows.Forms.Button
        Me.CommandExit = New System.Windows.Forms.Button
        Me.ListData = New System.Windows.Forms.ListBox
        Me.TextInfo = New System.Windows.Forms.TextBox
        Me.LabelCountJudge = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.Label6 = New System.Windows.Forms.Label
        Me.LabelStatus = New System.Windows.Forms.Label
        Me.Label4 = New System.Windows.Forms.Label
        Me.SuspendLayout()
        '
        'CommandSetting
        '
        Me.CommandSetting.BackColor = System.Drawing.SystemColors.Control
        Me.CommandSetting.Cursor = System.Windows.Forms.Cursors.Default
        Me.CommandSetting.ForeColor = System.Drawing.SystemColors.ControlText
        Me.CommandSetting.Location = New System.Drawing.Point(8, 99)
        Me.CommandSetting.Name = "CommandSetting"
        Me.CommandSetting.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.CommandSetting.Size = New System.Drawing.Size(96, 31)
        Me.CommandSetting.TabIndex = 2
        Me.CommandSetting.Text = "Set"
        Me.CommandSetting.UseVisualStyleBackColor = False
        '
        'TextDevice
        '
        Me.TextDevice.AcceptsReturn = True
        Me.TextDevice.BackColor = System.Drawing.SystemColors.Window
        Me.TextDevice.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.TextDevice.ForeColor = System.Drawing.SystemColors.WindowText
        Me.TextDevice.Location = New System.Drawing.Point(8, 26)
        Me.TextDevice.MaxLength = 0
        Me.TextDevice.Name = "TextDevice"
        Me.TextDevice.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.TextDevice.Size = New System.Drawing.Size(96, 23)
        Me.TextDevice.TabIndex = 0
        Me.TextDevice.Text = "DIG000"
        '
        'CommandInit
        '
        Me.CommandInit.BackColor = System.Drawing.SystemColors.Control
        Me.CommandInit.Cursor = System.Windows.Forms.Cursors.Default
        Me.CommandInit.ForeColor = System.Drawing.SystemColors.ControlText
        Me.CommandInit.Location = New System.Drawing.Point(8, 57)
        Me.CommandInit.Name = "CommandInit"
        Me.CommandInit.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.CommandInit.Size = New System.Drawing.Size(96, 32)
        Me.CommandInit.TabIndex = 1
        Me.CommandInit.Text = "Init"
        Me.CommandInit.UseVisualStyleBackColor = False
        '
        'CommandStart
        '
        Me.CommandStart.BackColor = System.Drawing.SystemColors.Control
        Me.CommandStart.Cursor = System.Windows.Forms.Cursors.Default
        Me.CommandStart.ForeColor = System.Drawing.SystemColors.ControlText
        Me.CommandStart.Location = New System.Drawing.Point(8, 140)
        Me.CommandStart.Name = "CommandStart"
        Me.CommandStart.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.CommandStart.Size = New System.Drawing.Size(96, 31)
        Me.CommandStart.TabIndex = 3
        Me.CommandStart.Text = "Start Judgment "
        Me.CommandStart.UseVisualStyleBackColor = False
        '
        'CommandInfo
        '
        Me.CommandInfo.BackColor = System.Drawing.SystemColors.Control
        Me.CommandInfo.Cursor = System.Windows.Forms.Cursors.Default
        Me.CommandInfo.ForeColor = System.Drawing.SystemColors.ControlText
        Me.CommandInfo.Location = New System.Drawing.Point(8, 181)
        Me.CommandInfo.Name = "CommandInfo"
        Me.CommandInfo.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.CommandInfo.Size = New System.Drawing.Size(96, 31)
        Me.CommandInfo.TabIndex = 4
        Me.CommandInfo.Text = "Get Status"
        Me.CommandInfo.UseVisualStyleBackColor = False
        '
        'CommandStop
        '
        Me.CommandStop.BackColor = System.Drawing.SystemColors.Control
        Me.CommandStop.Cursor = System.Windows.Forms.Cursors.Default
        Me.CommandStop.ForeColor = System.Drawing.SystemColors.ControlText
        Me.CommandStop.Location = New System.Drawing.Point(8, 222)
        Me.CommandStop.Name = "CommandStop"
        Me.CommandStop.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.CommandStop.Size = New System.Drawing.Size(96, 32)
        Me.CommandStop.TabIndex = 5
        Me.CommandStop.Text = "Stop Judgment"
        Me.CommandStop.UseVisualStyleBackColor = False
        '
        'CommandExit
        '
        Me.CommandExit.BackColor = System.Drawing.SystemColors.Control
        Me.CommandExit.Cursor = System.Windows.Forms.Cursors.Default
        Me.CommandExit.ForeColor = System.Drawing.SystemColors.ControlText
        Me.CommandExit.Location = New System.Drawing.Point(8, 263)
        Me.CommandExit.Name = "CommandExit"
        Me.CommandExit.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.CommandExit.Size = New System.Drawing.Size(96, 32)
        Me.CommandExit.TabIndex = 6
        Me.CommandExit.Text = "Exit"
        Me.CommandExit.UseVisualStyleBackColor = False
        '
        'ListData
        '
        Me.ListData.BackColor = System.Drawing.SystemColors.Window
        Me.ListData.Cursor = System.Windows.Forms.Cursors.Default
        Me.ListData.ForeColor = System.Drawing.SystemColors.WindowText
        Me.ListData.Location = New System.Drawing.Point(120, 43)
        Me.ListData.Name = "ListData"
        Me.ListData.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.ListData.Size = New System.Drawing.Size(336, 238)
        Me.ListData.TabIndex = 7
        '
        'TextInfo
        '
        Me.TextInfo.AcceptsReturn = True
        Me.TextInfo.BackColor = System.Drawing.SystemColors.Window
        Me.TextInfo.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.TextInfo.ForeColor = System.Drawing.SystemColors.WindowText
        Me.TextInfo.Location = New System.Drawing.Point(8, 329)
        Me.TextInfo.MaxLength = 0
        Me.TextInfo.Name = "TextInfo"
        Me.TextInfo.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.TextInfo.Size = New System.Drawing.Size(448, 33)
        Me.TextInfo.TabIndex = 8
        '
        'LabelCountJudge
        '
        Me.LabelCountJudge.BackColor = System.Drawing.SystemColors.Control
        Me.LabelCountJudge.Cursor = System.Windows.Forms.Cursors.Default
        Me.LabelCountJudge.ForeColor = System.Drawing.SystemColors.ControlText
        Me.LabelCountJudge.Location = New System.Drawing.Point(176, 312)
        Me.LabelCountJudge.Name = "LabelCountJudge"
        Me.LabelCountJudge.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.LabelCountJudge.Size = New System.Drawing.Size(40, 21)
        Me.LabelCountJudge.TabIndex = 28
        Me.LabelCountJudge.Text = "0"
        '
        'Label2
        '
        Me.Label2.BackColor = System.Drawing.SystemColors.Control
        Me.Label2.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label2.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label2.Location = New System.Drawing.Point(8, 312)
        Me.Label2.Name = "Label2"
        Me.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label2.Size = New System.Drawing.Size(152, 21)
        Me.Label2.TabIndex = 27
        Me.Label2.Text = "Judgment result of record "
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.SystemColors.Control
        Me.Label1.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label1.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label1.Location = New System.Drawing.Point(8, 9)
        Me.Label1.Name = "Label1"
        Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label1.Size = New System.Drawing.Size(96, 21)
        Me.Label1.TabIndex = 26
        Me.Label1.Text = "Device Name"
        '
        'Label3
        '
        Me.Label3.BackColor = System.Drawing.SystemColors.Control
        Me.Label3.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label3.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label3.Location = New System.Drawing.Point(120, 9)
        Me.Label3.Name = "Label3"
        Me.Label3.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label3.Size = New System.Drawing.Size(336, 17)
        Me.Label3.TabIndex = 25
        Me.Label3.Text = "Count        Data       Upper      Lower     Judgmen"
        '
        'Label6
        '
        Me.Label6.BackColor = System.Drawing.SystemColors.Control
        Me.Label6.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label6.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label6.Location = New System.Drawing.Point(248, 312)
        Me.Label6.Name = "Label6"
        Me.Label6.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label6.Size = New System.Drawing.Size(48, 21)
        Me.Label6.TabIndex = 24
        Me.Label6.Text = "Status"
        '
        'LabelStatus
        '
        Me.LabelStatus.BackColor = System.Drawing.SystemColors.Control
        Me.LabelStatus.Cursor = System.Windows.Forms.Cursors.Default
        Me.LabelStatus.ForeColor = System.Drawing.SystemColors.ControlText
        Me.LabelStatus.Location = New System.Drawing.Point(312, 312)
        Me.LabelStatus.Name = "LabelStatus"
        Me.LabelStatus.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.LabelStatus.Size = New System.Drawing.Size(57, 21)
        Me.LabelStatus.TabIndex = 23
        Me.LabelStatus.Text = "0H"
        '
        'Label4
        '
        Me.Label4.BackColor = System.Drawing.SystemColors.Control
        Me.Label4.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label4.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label4.Location = New System.Drawing.Point(120, 26)
        Me.Label4.Name = "Label4"
        Me.Label4.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label4.Size = New System.Drawing.Size(336, 17)
        Me.Label4.TabIndex = 25
        Me.Label4.Text = "                               bound      bound       result"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(464, 372)
        Me.Controls.Add(Me.CommandSetting)
        Me.Controls.Add(Me.TextDevice)
        Me.Controls.Add(Me.CommandInit)
        Me.Controls.Add(Me.CommandStart)
        Me.Controls.Add(Me.CommandInfo)
        Me.Controls.Add(Me.CommandStop)
        Me.Controls.Add(Me.CommandExit)
        Me.Controls.Add(Me.ListData)
        Me.Controls.Add(Me.TextInfo)
        Me.Controls.Add(Me.LabelCountJudge)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label6)
        Me.Controls.Add(Me.LabelStatus)
        Me.Controls.Add(Me.Label4)
        Me.MaximizeBox = False
        Me.Name = "Form1"
        Me.Text = "Waveform Judgment Instrument2"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Dim Id As Short ' Device ID
    Const MAX_SAMPLES As Short = 512 ' Number of the maximam samples
    Dim Data(MAX_SAMPLES) As Single  ' Array of retrieving data
    Dim Judge(MAX_SAMPLES) As Short  ' Result of waveform judgment
    Dim JudgeDetail(MAX_SAMPLES) As Short ' Details result of waveform
    Dim UpperData(MAX_SAMPLES) As Single ' Array which the upper bound data for waveform judgment are stored in
    Dim LowerData(MAX_SAMPLES) As Single ' Array which the lower bound data for waveform judgment are stored in
    Dim Records As Integer ' Number of retrieved record

    '==================================
    ' Init handling
    '==================================
    Private Sub CommandInit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CommandInit.Click
        Dim Ret As Integer  ' Return value
        Dim Ret2 As Integer ' Return value2
        Dim ErrorString As New StringBuilder("", 256)     ' Error string

        '----------------------------------
        ' Init handling
        '----------------------------------
        Ret = DigInit(TextDevice.Text, Id)
        If Ret <> 0 Then
            Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigInit = " & Ret & " : " & ErrorString.ToString()
            Exit Sub
        End If

        '----------------------------------
        ' Reset device
        '----------------------------------
        Ret = DigResetDevice(Id)
        If Ret <> 0 Then
            Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigResetDevice = " & Ret & " : " & ErrorString.ToString()
            Exit Sub
        End If

        TextInfo.Text = "Init : Normality completion"
    End Sub

    '==================================
    ' Set device
    '==================================
    Private Sub CommandSetting_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CommandSetting.Click
        Dim Ret As Integer     ' Return value
        Dim Ret2 As Integer    ' Return value2
        Dim ErrorString As New StringBuilder("", 256)     ' Error string

        '----------------------------------
        ' Set the operation mode : Waveform judgment instrument mode
        '----------------------------------
        Ret = DigSetDigitizerMode(Id, DIG_MODE_JUDGE)
        If Ret <> 0 Then
            Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetDigitizerMode = " & Ret & " : " & ErrorString.ToString()
            Exit Sub
        End If

        '----------------------------------
        ' Set sampling clock source : Crystal oscillator of board
        '----------------------------------
        Ret = DigSetClockSource(Id, DIG_ECU_SRC_CLOCK)
        If Ret <> 0 Then
            Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetClockSource = " & Ret & " : " & ErrorString.ToString()
            Exit Sub
        End If

        '----------------------------------
        ' Set sampling rate : 1MHz
        '----------------------------------
        Ret = DigSetSampleRate(Id, 1000000)
        If Ret <> 0 Then
            Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetSampleRate = " & Ret & " : " & ErrorString.ToString()
            Exit Sub
        End If

        '----------------------------------
        ' Set the length of record : 512
        '----------------------------------
        Ret = DigSetRecordLength(Id, MAX_SAMPLES)
        If Ret <> 0 Then
            Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetRecordLength = " & Ret & " : " & ErrorString.ToString()
            Exit Sub
        End If

        '----------------------------------
        ' Set the number of records : 1
        '----------------------------------
        Ret = DigSetRecordNumber(Id, 1)
        If Ret <> 0 Then
            Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetRecordNumber = " & Ret & " : " & ErrorString.ToString()
            Exit Sub
        End If

        '----------------------------------
        ' Set duty ratio : 50%
        '----------------------------------
        Ret = DigSetDutyCycle(Id, 50)
        If Ret <> 0 Then
            Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetDutyCycle = " & Ret & " : " & ErrorString.ToString()
            Exit Sub
        End If

        '----------------------------------
        ' Set channel : Enable channel0 only
        '----------------------------------
        ' Enable channel0
        Ret = DigSetChannel(Id, DIG_CHANNEL0, DIG_ENABLE)
        If Ret <> 0 Then
            Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetChannel = " & Ret & " : " & ErrorString.ToString()
            Exit Sub
        End If

        ' Disable channel1
        Ret = DigSetChannel(Id, DIG_CHANNEL1, DIG_DISABLE)
        If Ret <> 0 Then
            Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetChannel = " & Ret & " : " & ErrorString.ToString()
            Exit Sub
        End If

        '----------------------------------
        ' Set range : +/-20V
        '----------------------------------
        Ret = DigSetRange(Id, DIG_CHANNEL0, DIG_RANGE_40VPP)
        If Ret <> 0 Then
            Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetRange = " & Ret & " : " & ErrorString.ToString()
            Exit Sub
        End If

        '----------------------------------
        ' Set the type of pre-trigger : Auto
        '----------------------------------
        Ret = DigSetPreTriggerType(Id, DIG_TRIGGERTYPE_AUTO)
        If Ret <> 0 Then
            Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetPreTriggerType = " & Ret & " : " & ErrorString.ToString()
            Exit Sub
        End If

        '----------------------------------
        ' Set the type of post-trigger : Analog edge trigger
        '----------------------------------
        Ret = DigSetPostTriggerType(Id, DIG_TRIGGERTYPE_AIEDGE)
        If Ret <> 0 Then
            Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetPostTriggerType = " & Ret & " : " & ErrorString.ToString()
            Exit Sub
        End If

        '----------------------------------
        ' Detailed setting for the post-trigger : TriggerSource : channel0, Trigger level : 0V, Rising edge, 1
        '----------------------------------
        Ret = DigSetPostTriggerAiEdge(Id, DIG_CHANNEL0, 0, DIG_TRIGGER_SLOPE_RISE, 1)
        If Ret <> 0 Then
            Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetPostTriggerAiEdge = " & Ret & " : " & ErrorString.ToString()
            Exit Sub
        End If

        '----------------------------------
        ' Specify the channel to perform waveform judgment : Channel0
        '----------------------------------
        Ret = DigSetJudgeChannel(Id, DIG_CHANNEL0, DIG_ENABLE)
        If Ret <> 0 Then
            Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetJudgeChannel = " & Ret & " : " & ErrorString.ToString()
            Exit Sub
        End If

        '----------------------------------
        ' Set the upper bound value for counting the waveform judgment result : Count the FAIL records, The upper bound value of count times is 1
        '----------------------------------
        Ret = DigSetJudgeCountLimit(Id, DIG_CHANNEL0, DIG_JUDGE_NG, 1)
        If Ret <> 0 Then
            Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetJudgeCountLimit = " & Ret & " : " & ErrorString.ToString()
            Exit Sub
        End If

        '----------------------------------
        ' Set the data for waveform judgment : UpperData : +5V, LowerData : -5V
        '----------------------------------
        Dim i As Integer
        For i = 0 To MAX_SAMPLES - 1
            UpperData(i) = 5
            LowerData(i) = -5
        Next
        Ret = DigSetJudgeData(Id, DIG_CHANNEL0, MAX_SAMPLES, UpperData, LowerData)
        If Ret <> 0 Then
            Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetJudgeData = " & Ret & " : " & ErrorString.ToString()
            Exit Sub
        End If

        ' Retrieve the data for waveform judgment which has been set to digitizer
        Ret = DigGetJudgeData(Id, DIG_CHANNEL0, MAX_SAMPLES, UpperData, LowerData)
        If Ret <> 0 Then
            Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigGetJudgeData = " & Ret & " : " & ErrorString.ToString()
            Exit Sub
        End If

        TextInfo.Text = "Set device : Normality completion"
    End Sub


    '==================================
    ' Start Judgment
    '==================================
    Private Sub CommandStart_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CommandStart.Click
        Dim Ret As Integer     ' Return value
        Dim Ret2 As Integer    ' Return value2
        Dim ErrorString As New StringBuilder("", 256)     ' Error string

        '----------------------------------
        ' Initialize variable
        '----------------------------------
        Records = 0
        ListData.Items.Clear()

        '----------------------------------
        ' Operation start
        '----------------------------------
        Ret = DigStart(Id)
        If Ret <> 0 Then
            Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigStart = " & Ret & " : " & ErrorString.ToString()
            Exit Sub
        End If
        TextInfo.Text = "Start Judgment : Normality completion"

        '----------------------------------
        ' Polling until the operation status is changed to be OFF
        '----------------------------------
        Dim Status As Integer

        Do
            System.Windows.Forms.Application.DoEvents()    ' In order to enable the dialog operation
            '----------------------------------
            ' Get the opration status
            '----------------------------------
            Ret = DigGetStatus(Id, Status)
            If Ret <> 0 Then
                Ret2 = DigGetErrorString(Ret, ErrorString)
                TextInfo.Text = "DigGetStatus = " & Ret & " : " & ErrorString.ToString()
                Exit Sub
            End If
            LabelStatus.Text = Hex(Status) & "H"
        Loop While (Status And DIG_STATUS_BUSY) = DIG_STATUS_BUSY

        '----------------------------------
        ' After operation stop, get the number of samples which are being stored in driver memory
        '----------------------------------
        Ret = DigGetDriverMemoryRecords(Id, Records)
        If Ret <> 0 Then
            Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigGetDriverMemoryRecords = " & Ret & " : " & ErrorString.ToString()
            Exit Sub
        End If

        '----------------------------------
        ' Retrieve the acquisition data : Retrieve the data of 1 record from the new data
        '----------------------------------
        ' If there are not the data of acquistion records in driver memory, do not retrieve the data
        If Records <= 0 Then
            TextInfo.Text = "There are not acquistion data."
            Exit Sub
        End If

        Ret = DigReadLatestRecords(Id, DIG_RECORD_ALL, 1, Data, Judge, JudgeDetail)
        If Ret <> 0 Then
            Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigReadEarliestRecords = " & Ret & " : " & ErrorString.ToString()
            Exit Sub
        End If

        '----------------------------------
        ' Display the judge result
        '----------------------------------
        LabelCountJudge.Text = CStr(Judge(0))
        Dim i As Integer
        For i = 0 To MAX_SAMPLES - 1
            ListData.Items.Add(i + 1 & vbTab & String.Format("{0:F3}", Data(i)) & vbTab & String.Format("{0:F3}", UpperData(i)) & vbTab & String.Format("{0:F3}", LowerData(i)) & vbTab & JudgeDetail(i))
        Next i

    End Sub

    '==================================
    ' Get status
    '==================================
    Private Sub CommandInfo_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CommandInfo.Click
        Dim Ret As Integer     ' Return value
        Dim Ret2 As Integer    ' Return value2
        Dim ErrorString As New StringBuilder("", 256)     ' Error string
        Dim Status As Integer    ' Status

        '----------------------------------
        ' Get the operation status
        '----------------------------------
        Ret = DigGetStatus(Id, Status)
        If Ret <> 0 Then
            Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigGetStatus = " & Ret & " : " & ErrorString.ToString()
            Exit Sub
        End If
        LabelStatus.Text = Hex(Status) & "H"

		TextInfo.Text = "Get status : Normality completion"
    End Sub

    '==================================
    ' Stop Judgment
    '==================================
    Private Sub CommandStop_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CommandStop.Click
        Dim Ret As Integer     ' Return value
        Dim Ret2 As Integer    ' Return value2
        Dim ErrorString As New StringBuilder("", 256)     ' Error string

        Ret = DigStop(Id)
        If Ret <> 0 Then
            Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigExit = " & Ret & " : " & ErrorString.ToString()
            Exit Sub
        End If

        TextInfo.Text = "Stop Judgment : Normality completion"
    End Sub

    '==================================
    ' Exit handling
    '==================================
    Private Sub CommandExit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CommandExit.Click
        Dim Ret As Integer     ' Return value
        Dim Ret2 As Integer    ' Return value2
        Dim ErrorString As New StringBuilder("", 256)     ' Error string

        Ret = DigExit(Id)
        If Ret <> 0 Then
            Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigExit = " & Ret & " : " & ErrorString.ToString()
            Exit Sub
        End If

        TextInfo.Text = "Exit handling : Normality completion"
    End Sub

    '==================================
    ' Form unload
    '==================================
    Private Sub Form1_Closed(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Closed
        Dim Ret As Integer    ' Return value
        Ret = DigExit(Id)
    End Sub
End Class
