
Public Class Form1
    Dim wRtn As UInt16
    Public wTotalBoards As UInt16
    Dim sGetCardInfo As IXUD_CARD_INFO
    Dim sGetDevInfo As IXUD_DEVICE_INFO
    Friend sCardInfo() As IXUD_CARD_INFO
    Friend sDevInfo() As IXUD_DEVICE_INFO
    Dim sSelDevInfo As IXUD_DEVICE_INFO 'vb6
    Dim sSelCardInfo As IXUD_CARD_INFO 'vb6
    Dim wBoardNo As UInt16
    Public szModelName As New String(" "c, 20)


    Dim wSetDioMode As UInt16
    Dim wDirectorDioMode As UInt32
    Dim wCounter As Integer, wMode As Integer


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim index As UInt16
        wRtn = Ixud_DriverInit(wTotalBoards)

        ReDim sCardInfo(wTotalBoards - 1)
        ReDim sDevInfo(wTotalBoards - 1)

        For index = 0 To CUShort(wTotalBoards - 1)
            wRtn = Ixud_GetCardInfo(index, sGetDevInfo, sGetCardInfo, szModelName)
            If szModelName <> "0" Then
                Me.cbxBoardNo.Items.Add(Str(index) + ": " + szModelName)
            Else
                Me.cbxBoardNo.Items.Add(Str(index) + ": Err Device")
            End If

            sDevInfo(index) = sGetDevInfo
            sCardInfo(index) = sGetCardInfo
        Next

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        'Exit buttom'
        wRtn = Ixud_DisableCounter(wBoardNo, 0) 'Stop Counter 0
        wRtn = Ixud_DisableCounter(wBoardNo, 1) 'Stop Counter 1

        Me.Text = "PWM Disable"
        'TMC12PWM.Caption = "PWM Disable"vb6
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnActive.Click
        'Active buttom'
        Dim CountVal As Long
        Dim DutyVal As Long
        Dim SourceCLK As Single

        wBoardNo = cbxBoardNo.SelectedIndex


        SourceCLK = 80000.0#  '//80 kHz

        wCounter = 0
        wMode = 3
        CountVal = CInt(SourceCLK / CSng(Me.tbxFrequency.Text)) 'Internal Clock is CLK2 = 80 kHz
        wRtn = Ixud_SetCounter(wBoardNo, wCounter, wMode, CountVal) 'Counter 1 Output Frequency

        wCounter = 1
        wMode = 1
        DutyVal = CountVal * (CSng(Me.tbxDuty.Text) * 0.01)
        wRtn = Ixud_SetCounter(wBoardNo, wCounter, wMode, DutyVal) 'Counter 2 Outupt Duty

        Me.Text = "PWM Enable " + "[" + CStr(SourceCLK / CSng(CountVal)) + " Hz," + CStr((CSng(DutyVal) / CSng(CountVal)) * 100.0#) + " %]"
    End Sub

    
    Private Sub cbxBoardNo_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxBoardNo.SelectedIndexChanged

        wBoardNo = cbxBoardNo.SelectedIndex
        'wBoardNo = cbxBoardNo.ListIndex vb6 


        sSelDevInfo = sDevInfo(wBoardNo)
        sSelCardInfo = sCardInfo(wBoardNo)

        Me.Text = Me.cbxBoardNo.Text + " PWM Output Sample Program"

    End Sub
End Class
