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 TextInfo As System.Windows.Forms.TextBox
    Public WithEvents ListData As System.Windows.Forms.ListBox
    Public WithEvents ComboRange As System.Windows.Forms.ComboBox
    Public WithEvents CommandExit As System.Windows.Forms.Button
    Public WithEvents CommandSave As System.Windows.Forms.Button
    Public WithEvents CommandStop As System.Windows.Forms.Button
    Public WithEvents CommandInfo As System.Windows.Forms.Button
    Public WithEvents CommandStart As System.Windows.Forms.Button
    Public WithEvents CommandInit As System.Windows.Forms.Button
    Public WithEvents TextDevice As System.Windows.Forms.TextBox
    Public WithEvents LabelStatus As System.Windows.Forms.Label
    Public WithEvents Label6 As System.Windows.Forms.Label
    Public WithEvents LabelCount As System.Windows.Forms.Label
    Public WithEvents Label5 As System.Windows.Forms.Label
    Public WithEvents Label4 As System.Windows.Forms.Label
    Public WithEvents Label3 As System.Windows.Forms.Label
    Public WithEvents Label2 As System.Windows.Forms.Label
    Public WithEvents Label1 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.TextInfo = New System.Windows.Forms.TextBox()
        Me.ListData = New System.Windows.Forms.ListBox()
        Me.ComboRange = New System.Windows.Forms.ComboBox()
        Me.CommandExit = New System.Windows.Forms.Button()
        Me.CommandSave = New System.Windows.Forms.Button()
        Me.CommandStop = New System.Windows.Forms.Button()
        Me.CommandInfo = New System.Windows.Forms.Button()
        Me.CommandStart = New System.Windows.Forms.Button()
        Me.CommandInit = New System.Windows.Forms.Button()
        Me.TextDevice = New System.Windows.Forms.TextBox()
        Me.LabelStatus = New System.Windows.Forms.Label()
        Me.Label6 = New System.Windows.Forms.Label()
        Me.LabelCount = 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.Label1 = New System.Windows.Forms.Label()
        Me.SuspendLayout()
        '
        'TextInfo
        '
        Me.TextInfo.AcceptsReturn = True
        Me.TextInfo.AutoSize = False
        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(10, 297)
        Me.TextInfo.MaxLength = 0
        Me.TextInfo.Name = "TextInfo"
        Me.TextInfo.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.TextInfo.Size = New System.Drawing.Size(294, 29)
        Me.TextInfo.TabIndex = 9
        Me.TextInfo.Text = ""
        '
        '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(118, 73)
        Me.ListData.Name = "ListData"
        Me.ListData.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.ListData.Size = New System.Drawing.Size(185, 199)
        Me.ListData.TabIndex = 8
        '
        'ComboRange
        '
        Me.ComboRange.BackColor = System.Drawing.SystemColors.Window
        Me.ComboRange.Cursor = System.Windows.Forms.Cursors.Default
        Me.ComboRange.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.ComboRange.ForeColor = System.Drawing.SystemColors.WindowText
        Me.ComboRange.Location = New System.Drawing.Point(118, 25)
        Me.ComboRange.Name = "ComboRange"
        Me.ComboRange.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.ComboRange.Size = New System.Drawing.Size(185, 21)
        Me.ComboRange.TabIndex = 1
        '
        '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(10, 239)
        Me.CommandExit.Name = "CommandExit"
        Me.CommandExit.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.CommandExit.Size = New System.Drawing.Size(100, 29)
        Me.CommandExit.TabIndex = 7
        Me.CommandExit.Text = "Exit"
        '
        'CommandSave
        '
        Me.CommandSave.BackColor = System.Drawing.SystemColors.Control
        Me.CommandSave.Cursor = System.Windows.Forms.Cursors.Default
        Me.CommandSave.ForeColor = System.Drawing.SystemColors.ControlText
        Me.CommandSave.Location = New System.Drawing.Point(10, 202)
        Me.CommandSave.Name = "CommandSave"
        Me.CommandSave.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.CommandSave.Size = New System.Drawing.Size(100, 29)
        Me.CommandSave.TabIndex = 6
        Me.CommandSave.Text = "Save File"
        '
        '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(10, 165)
        Me.CommandStop.Name = "CommandStop"
        Me.CommandStop.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.CommandStop.Size = New System.Drawing.Size(100, 29)
        Me.CommandStop.TabIndex = 5
        Me.CommandStop.Text = "Stop Acquisition"
        '
        '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(10, 128)
        Me.CommandInfo.Name = "CommandInfo"
        Me.CommandInfo.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.CommandInfo.Size = New System.Drawing.Size(100, 29)
        Me.CommandInfo.TabIndex = 4
        Me.CommandInfo.Text = "Get Status "
        '
        '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(10, 91)
        Me.CommandStart.Name = "CommandStart"
        Me.CommandStart.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.CommandStart.Size = New System.Drawing.Size(100, 29)
        Me.CommandStart.TabIndex = 3
        Me.CommandStart.Text = "Start Acquisition "
        '
        '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(10, 54)
        Me.CommandInit.Name = "CommandInit"
        Me.CommandInit.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.CommandInit.Size = New System.Drawing.Size(100, 29)
        Me.CommandInit.TabIndex = 2
        Me.CommandInit.Text = "Init"
        '
        'TextDevice
        '
        Me.TextDevice.AcceptsReturn = True
        Me.TextDevice.AutoSize = False
        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(10, 25)
        Me.TextDevice.MaxLength = 0
        Me.TextDevice.Name = "TextDevice"
        Me.TextDevice.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.TextDevice.Size = New System.Drawing.Size(100, 21)
        Me.TextDevice.TabIndex = 0
        Me.TextDevice.Text = "DIG000"
        '
        '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(248, 281)
        Me.LabelStatus.Name = "LabelStatus"
        Me.LabelStatus.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.LabelStatus.Size = New System.Drawing.Size(40, 20)
        Me.LabelStatus.TabIndex = 34
        Me.LabelStatus.Text = "0H"
        '
        '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(200, 281)
        Me.Label6.Name = "Label6"
        Me.Label6.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label6.Size = New System.Drawing.Size(40, 20)
        Me.Label6.TabIndex = 33
        Me.Label6.Text = "Status"
        '
        'LabelCount
        '
        Me.LabelCount.BackColor = System.Drawing.SystemColors.Control
        Me.LabelCount.Cursor = System.Windows.Forms.Cursors.Default
        Me.LabelCount.ForeColor = System.Drawing.SystemColors.ControlText
        Me.LabelCount.Location = New System.Drawing.Point(144, 281)
        Me.LabelCount.Name = "LabelCount"
        Me.LabelCount.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.LabelCount.Size = New System.Drawing.Size(36, 20)
        Me.LabelCount.TabIndex = 32
        Me.LabelCount.Text = "0"
        '
        'Label5
        '
        Me.Label5.BackColor = System.Drawing.SystemColors.Control
        Me.Label5.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label5.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label5.Location = New System.Drawing.Point(10, 281)
        Me.Label5.Name = "Label5"
        Me.Label5.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label5.Size = New System.Drawing.Size(126, 20)
        Me.Label5.TabIndex = 31
        Me.Label5.Text = "Number of samplings"
        '
        '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(190, 57)
        Me.Label4.Name = "Label4"
        Me.Label4.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label4.Size = New System.Drawing.Size(65, 20)
        Me.Label4.TabIndex = 30
        Me.Label4.Text = "Voltage"
        '
        '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(118, 57)
        Me.Label3.Name = "Label3"
        Me.Label3.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label3.Size = New System.Drawing.Size(57, 20)
        Me.Label3.TabIndex = 29
        Me.Label3.Text = "Count"
        '
        '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(118, 9)
        Me.Label2.Name = "Label2"
        Me.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label2.Size = New System.Drawing.Size(97, 20)
        Me.Label2.TabIndex = 26
        Me.Label2.Text = "Range"
        '
        '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(10, 9)
        Me.Label1.Name = "Label1"
        Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label1.Size = New System.Drawing.Size(84, 20)
        Me.Label1.TabIndex = 18
        Me.Label1.Text = "Device Name"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(312, 334)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextInfo, Me.ListData, Me.ComboRange, Me.CommandExit, Me.CommandSave, Me.CommandStop, Me.CommandInfo, Me.CommandStart, Me.CommandInit, Me.TextDevice, Me.LabelStatus, Me.Label6, Me.LabelCount, Me.Label5, Me.Label4, Me.Label3, Me.Label2, Me.Label1})
        Me.MaximizeBox = False
        Me.Name = "Form1"
        Me.Text = "DataLogger"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Dim Id As Short ' Device ID
    Const MAX_SAMPLES As Integer = 1000 ' Number of  the maximal samples
    Dim Data(MAX_SAMPLES) As Single ' Array for acquire data
    Dim Samples As Integer ' Number of retrieved samples

    '==================================
    ' Form load
    '==================================
    Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
        '----------------------------------
        ' Initialize the input range
        '----------------------------------
        ComboRange.Items.Add(("-20.0 - +20.0V"))
        ComboRange.Items.Add(("-10.0 - +10.0V"))
        ComboRange.Items.Add(("-5.0 - +5.0V"))
        ComboRange.Items.Add(("-2.0 - +2.0V"))
        ComboRange.Items.Add(("-1.0 - +1.0V"))
        ComboRange.Items.Add(("-0.5 - + 0.5V"))
        ComboRange.Items.Add(("-0.2 - +0.2V"))
        ComboRange.Items.Add(("-0.1 - +0.1V"))
        ComboRange.Items.Add(("-0.05 - +0.05V"))
        ComboRange.Items.Add(("-0.02 - +0.02V"))

        Samples = 0
    End Sub

    '==================================
    ' 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 input range
    '==================================
    Private Sub ComboRange_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles ComboRange.SelectedIndexChanged
        Dim Range As Single
        Dim Index As Short
        Index = ComboRange.SelectedIndex
        Select Case Index
            Case 0 : Range = DIG_RANGE_40VPP
            Case 1 : Range = DIG_RANGE_20VPP
            Case 2 : Range = DIG_RANGE_10VPP
            Case 3 : Range = DIG_RANGE_4VPP
            Case 4 : Range = DIG_RANGE_2VPP
            Case 5 : Range = DIG_RANGE_1VPP
            Case 6 : Range = DIG_RANGE_400MVPP
            Case 7 : Range = DIG_RANGE_200MVPP
            Case 8 : Range = DIG_RANGE_100MVPP
            Case 9 : Range = DIG_RANGE_40MVPP
        End Select

        '----------------------------------
        ' Set input range of channel0
        '----------------------------------
        Dim Ret As Integer    ' Return value
        Dim Ret2 As Integer   ' Return value2
        Dim ErrorString As New StringBuilder("", 256)     ' Error string

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

		TextInfo.Text = "Set input range : Normality completion"
    End Sub

    '==================================
    ' Start acquisition
    '==================================
    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
        '----------------------------------
        Samples = 0
        ListData.Items.Clear()

        '----------------------------------
        ' Set operation mode : Data logger mode
        '----------------------------------
        Ret = DigSetDigitizerMode(Id, DIG_MODE_LOGGER)
        If Ret <> 0 Then
            Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetDigitizerMode = " & Ret & " : " & ErrorString.ToString()
            Exit Sub
        End If

        '----------------------------------
        ' Set sampling clock source : Digitizer crystal oscillator
        '----------------------------------
        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 clock : 1000usec (set value * 10 + 10 (nsec))
        '----------------------------------
        Ret = DigSetSampleClock(Id, 99999)
        If Ret <> 0 Then
            Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetSampleClock = " & Ret & " : " & ErrorString.ToString()
            Exit Sub
        End If

        '----------------------------------
        ' Set the number of acquiring 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 the number of pre-trigger samples : 1000
        '----------------------------------
        Ret = DigSetPreSampleTimes(Id, MAX_SAMPLES)
        If Ret <> 0 Then
            Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetPreSampleTimes = " & Ret & " : " & ErrorString.ToString()
            Exit Sub
        End If

        '----------------------------------
        ' Set the number of post-trigger samples : 0
        '----------------------------------
        Ret = DigSetPostSampleTimes(Id, 0)
        If Ret <> 0 Then
            Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetPostSampleTimes = " & 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 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

        '----------------------------------
        ' 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 acquisition : 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 number of samples stored in driver memory
            '----------------------------------
            Ret = DigGetDriverMemorySamples(Id, Samples)
            If Ret <> 0 Then
                Ret2 = DigGetErrorString(Ret, ErrorString)
                TextInfo.Text = "DigGetDriverMemorySamples = " & Ret & " : " & ErrorString.ToString()
                Exit Sub
            End If
            LabelCount.Text = CStr(Samples)

            '----------------------------------
            ' 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"
        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 = DigGetDriverMemorySamples(Id, Samples)
        If Ret <> 0 Then
            Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigGetDriverMemorySamples = " & Ret & " : " & ErrorString.ToString()
            Exit Sub
        End If

        '----------------------------------
        ' Retrieve the acquisition data
        '----------------------------------
        Dim TriggerPoint As Integer    ' Position of the first data after the establishment of the post-trigger
        If Samples > 0 Then
            ' Adjust to prevent the retrieved number of sampling from exceeding the size of array for storing data
            If Samples > MAX_SAMPLES Then
                Samples = MAX_SAMPLES
            End If
            Ret = DigReadSamples(Id, Samples, Data, TriggerPoint)
            If Ret <> 0 Then
                Ret2 = DigGetErrorString(Ret, ErrorString)
                TextInfo.Text = "DigReadSamples = " & Ret & " : " & ErrorString.ToString()
                Exit Sub
            End If
        End If
        '----------------------------------
        ' Display the acquisition data
        '----------------------------------
        Dim i As Integer
        For i = 0 To Samples - 1
            ListData.Items.Add(i + 1 & "           " & String.Format("{0:F3}", Data(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 Count As Integer    ' Number of samples
        Dim Status As Integer   ' Status

        '----------------------------------
        ' Get the number of samples in the driver memory
        '----------------------------------
        Ret = DigGetDriverMemorySamples(Id, Count)
        If Ret <> 0 Then
            Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigGetDriverMemorySamples = " & Ret & " : " & ErrorString.ToString()
            Exit Sub
        End If
        LabelCount.Text = CStr(Count)

        '----------------------------------
        ' 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 acquisition
    '==================================
    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 acquisition : Normality completion"
    End Sub

    '==================================
    ' Save file
    '==================================
    Private Sub CommandSave_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CommandSave.Click
        ' When there is no data error is returned
        If Samples = 0 Then
            TextInfo.Text = "There are no acquisition data"
            Exit Sub
        End If

        '----------------------------------
        ' Save file
        '----------------------------------
        Dim FileName As String   ' File name string
        FileName = "DataLogger.csv"    ' Set the file name

        ' When finish the file,
        ' words on the "Shift-JIS" is written on the file
        Dim sw As New System.IO.StreamWriter(FileName, False, System.Text.Encoding.GetEncoding(932))
        Try
            Dim i As Integer
            For i = 0 To Samples - 1
                ' Write data on the file
                sw.WriteLine(String.Format("{0:F3}", Data(i)))
            Next i
        Finally
            ' Close the file
            sw.Close()
        End Try

        TextInfo.Text = "Save file : Completed normally"
    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 : 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
