﻿Public Class SimpleInput_SingleChannel_Button
    '================================================================================
    ' DncDaq Setting button click event
    '================================================================================
    Private Sub Button_DaqProperty_Click(sender As Object, e As EventArgs) Handles Button_DaqProperty.Click
        '----------------------------------------
        ' Displays DncDaq settings screen
        '----------------------------------------
        DncDaq1.ShowProperty()
    End Sub

    '================================================================================
    ' Exit button click event
    '================================================================================
    Private Sub Button_Exit_Click(sender As Object, e As EventArgs) Handles Button_Exit.Click
        '----------------------------------------
        ' Exit the dialog
        '----------------------------------------
        End
    End Sub

    '================================================================================
    ' DncDaqInit event
    '================================================================================
    Private Sub DncDaq1_OnInit(sender As Object, e As EventArgs) Handles DncDaq1.OnInit
        '----------------------------------------
        ' Clear Error Details
        '----------------------------------------
        TextBox_ErrorDetail.Text = ""
        '----------------------------------------
        ' Check if device settings exist in DncDaq
        '----------------------------------------
        If (DncDaq1.DaqProperty.Device.Count <= 0) Then
            TextBox_ErrorDetail.Text = "There is no device setting."
            Return
        End If
        '----------------------------------------
        ' Check if input task settings exist in DncDaq
        '----------------------------------------
        If (DncDaq1.DaqProperty.InputTask.Count <= 0) Then
            TextBox_ErrorDetail.Text = "There is no input task setting."
            Return
        End If
        '----------------------------------------
        ' The ch setting used in the input task setting is reflected in the label.
        '----------------------------------------
        Label_Channel.Text = "ch." + DncDaq1.DaqProperty.InputTask(0).AccessTypeInputValue
    End Sub

    '================================================================================
    ' DncDaq error event
    '================================================================================
    Private Sub DncDaq1_OnError(sender As Object, DeviceNo As Short, e As dnc.common.DncErrorEventArgs) Handles DncDaq1.OnError
        Dim ret As Integer            ' Variable for getting return value
        Dim error_string As String    ' Error string

        '------------------------------------
        ' Get the error string from the error No. in the event argument
        '------------------------------------
        error_string = ""
        ret = DncDaq1.DaqErrorString(DeviceNo, e.Error, error_string)
        '------------------------------------
        ' When failed to get the error string, initialize the error string
        '------------------------------------
        If (ret <> 0) Then
            error_string = ""
        End If
        '----------------------------------------
        ' Displays the obtained error string and the status information in the event argument on the label
        ' Check if Invoke is required because the error event may be executed in another thread,
        ' and if necessary, access the form control with Invoke.
        '----------------------------------------
        If (InvokeRequired = True) Then
            '------------------------------------
            ' Displays the error parameters in the text box
            ' The method called by Invoke is described by the lambda expression
            '------------------------------------
            Invoke(New Action(Sub() TextBox_ErrorDetail.Text = "Device No.: " + DeviceNo.ToString() + vbCrLf +
                                                               "Error type: " + e.ErrorType.ToString() + vbCrLf +
                                                               "Error code(value): " + e.Error.ToString() + vbCrLf +
                                                               "Error code(character string): " + error_string + vbCrLf +
                                                               "Error parameter: " + e.Param.ToString()
                                                               ))
        Else
            '------------------------------------
            ' Displays the error parameters in the text box
            '------------------------------------
            TextBox_ErrorDetail.Text = "Device No.: " + DeviceNo.ToString() + vbCrLf +
                                       "Error type: " + e.ErrorType.ToString() + vbCrLf +
                                       "Error code(value): " + e.Error.ToString() + vbCrLf +
                                       "Error code(character string): " + error_string + vbCrLf +
                                       "Error parameter: " + e.Param.ToString()
        End If
    End Sub
End Class
