Option Strict Off
Option Explicit On
Public Class frm_AO
    Inherits System.Windows.Forms.Form
    Dim wRtn As UInt16
    Public wTotalBoards As UInt16
    'Dim sGetCardInfo As IXUD_CARD_INFO
    'Dim sGetDevInfo As IXUD_DEVICE_INFO
    Dim sCardInfo(32) As IXUD_CARD_INFO
    Dim sDevInfo(32) As IXUD_DEVICE_INFO
    Dim wBoardNo As UInt16
    Public sModelName As New String(" "c, 20)

    'UPGRADE_WARNING: Event cbxBoardNo.SelectedIndexChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
    Private Sub cbxBoardNo_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cbxBoardNo.SelectedIndexChanged
        Dim ChIndex As Short

        wBoardNo = CUShort(Me.cbxBoardNo.SelectedIndex)

        cbxAOCh.Items.Clear()

        Me.Text = Me.cbxBoardNo.Text & " Analog Output"
        If sCardInfo(wBoardNo).wAOChannels > 0 Then
            For ChIndex = 0 To sCardInfo(wBoardNo).wAOChannels - 1
                Me.cbxAOCh.Items.Add("Channel " & Str(ChIndex))
            Next ChIndex

            cbxAOCh.SelectedIndex = 0
            Me.Text = Me.cbxBoardNo.Text + " Analog Output Demo"
        Else
            MsgBox("None AO Channel")
            Ixud_DriverClose()
        End If
    End Sub

    Private Sub cmdActive_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdActive.Click

        wBoardNo = Val(CStr(Me.cbxBoardNo.SelectedIndex))
        '//Set AO Config
        wRtn = Ixud_ConfigAO(wBoardNo, Me.cbxAOCh.SelectedIndex, Me.cbxAOCfg.SelectedIndex + 16)
        '//Write Analog Output Value
        wRtn = Ixud_WriteAOCurrent(wBoardNo, Me.cbxAOCh.SelectedIndex, CSng(Me.tbxAOVal.Text))
        'wRtn = Ixud_WriteAOCurrentH(wBoardNo, Me.cbxAOCh.ListIndex, &HFFF)

    End Sub

    Private Sub cmdExit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdExit.Click
        '//Driver Close
        Call Ixud_DriverClose()
        End
    End Sub

    Private Sub frm_AO_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
        Dim wBoardIndex As Short


        '//Driver Initial
        wRtn = Ixud_DriverInit(wTotalBoards)
        If (wRtn) Then
            MsgBox("Driver Initial Error!!Error Code:" & Str(wRtn))
            End
        End If

        '//Get Card Information
        For wBoardIndex = 0 To CUShort(wTotalBoards - 1)

            wRtn = Ixud_GetCardInfo(wBoardIndex, sDevInfo(wBoardIndex), sCardInfo(wBoardIndex), sModelName)

            If (wRtn) Then
                MsgBox("Get Card Information Err")
            End If

            Me.cbxBoardNo.Items.Add(Str(wBoardIndex) & " " & sModelName)

        Next


        Me.cbxBoardNo.SelectedIndex = 0

    End Sub

    Private Sub OutputHex_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OutputHex.Click
        wRtn = Ixud_WriteAOCurrentH(wBoardNo, Me.cbxAOCh.SelectedIndex, CLng("&h" + Me.tbxAOValH.Text))
    End Sub
End Class