Option Strict Off
Option Explicit On
Public Class form
    Inherits System.Windows.Forms.Form
    Dim wRtn As UInt16
    Public wTotalBoards As UInt16
    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_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxBoardNo.SelectedIndexChanged
        Dim i As Integer

        Me.Text = Me.cbxBoardNo.Text + "  Timer Counter"


        wBoardNo = Val(CStr(Me.cbxBoardNo.SelectedIndex))

        '//whether have timer counter
        If sCardInfo(wBoardNo).wCounterChannels = 0 Then
            MsgBox("Not support timer counter")
            cmdActive.Enabled = False
        Else

            cmdActive.Enabled = True

        End If

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

        Dim wChannelIndex As Integer
        Dim dwCounter As Long

        ListBox1.Items.Clear()

        For wChannelIndex = 0 To 15
            'Read Counter
            wRtn = Ixud_ReadCounter(wBoardNo, wChannelIndex, dwCounter) 'Read Counter

            If wRtn Then
                MsgBox("Error!" + Str(wRtn))
            End If

            ListBox1.Items.Add("Channel " + Format(wChannelIndex, "##00") + "  " + Format(dwCounter, "###00000"))

            Application.DoEvents()

        Next

    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 form_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
        Dim wBoardIndex As Short
        Dim wChannelIndex As Integer
        '//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


        '//Set total channel to Frequency Mode
        For wBoardIndex = 0 To wTotalBoards - 1
            For wChannelIndex = 0 To 15
                wRtn = Ixud_SetFCChannelMode(wBoardIndex, wChannelIndex, 3, 20) 'Read Counter Mode
            Next
        Next


    End Sub
End Class