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 fFrequency As Single
        Dim wStatus As Integer

        ListBox1.Items.Clear()

        For wChannelIndex = 0 To 15
            '//Read Frequency
            wRtn = Ixud_ReadFrequency(wBoardNo, wChannelIndex, fFrequency, CLng(DelayMs.Text), wStatus) 'Read Frequency


            'If (wChannelIndex = 9) Then Me.Text1.Text = Format(fFrequency, "###000.00000") + "Hz" + "[" + Format(fFrequency - 200#, "###0.00000") + "]"

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

            ListBox1.Items.Add("Channel " + Format(wChannelIndex, "##00") + ";  " + Format(fFrequency, "###000.00000") + "Hz;  " + "[" + "Status=" + Str(wStatus) + "]")

            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
        Me.Mode.SelectedIndex = 0

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


    End Sub

    Private Sub Mode_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Mode.SelectedIndexChanged
        Dim wBoardIndex As Integer
        Dim wChannelIndex As Integer
        Dim wMode As Integer

        If Mode.SelectedIndex = 0 Then
            wMode = &H2
        Else
            wMode = &H12
        End If

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