
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 wBoardNo As UInt16
    Public szModelName As New String(" "c, 20)

    Dim mpbo() As PictureBox    'Output PictureBox Control's Array
    Dim mpbof(31) As Boolean
    Dim mpbi() As PictureBox    'Input PictureBox Control's Array

    Dim mrbSetDio() As RadioButton

    Dim wSetDioMode As UInt16
    Dim wDirectorDioMode As UInt32

    Public wApcCount As Integer 'VB6 module2
    Public Sub MyApcFunction(ByVal parm As UInteger)
        'Sleep 1000
        ' --------- Do you action in this function ------------
        wApcCount = wApcCount + 1
        If wApcCount = 10000 Then
            wApcCount = 0
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '/////////////////////////////////////'
        'Dim wBoardIndex As Integer
        ''Dim szModelName As String * 20

        ''//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 wTotalBoards - 1

        ' wRtn = Ixud_GetCardInfo(wBoardIndex, sDevInfo(wBoardIndex), sCardInfo(wBoardIndex), szModelName)
        ' 'MsgBox("Get Card Information Err")
        ' If (wRtn) Then
        'MsgBox("Get Card Information Err")
        ' End If

        'Me.cbxBoardNo.Items.Add(Str(wBoardIndex) + " " + szModelName)

        ' Next

        ' Me.cbxBoardNo.SelectedIndex = 0
        ' Me.cbxTrigger.SelectedIndex = 0
        '//////////////
        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
        Me.cbxBoardNo.SelectedIndex = 0
        Me.cbxTrigger.SelectedIndex = 0
    End Sub


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        wRtn = UniDAQ.Ixud_DriverClose()
        Me.Close()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdActive.Click
        Dim hEvent As Long
        'Dim i As Integer
        'Dim ApcReg As Long
        Dim wTriggerMode As Integer

        If cmdActive.Text = "&ACTIVE" Then

            wBoardNo = Val(Me.cbxBoardNo.SelectedIndex)
            'wBoardNo = Val(Me.cbxBoardNo.ListIndex)

            hEvent = 0 '//Initial hEvent


            wApcCount = 0 '//Callback function count for Int Source 0

            cmdActive.Text = "&STOP"

            Select Case Me.cbxTrigger.SelectedIndex

                Case 0
                    wTriggerMode = IXUD_HARDWARE_INT Or IXUD_ACTIVE_LOW

                Case 1
                    wTriggerMode = IXUD_HARDWARE_INT Or IXUD_ACTIVE_HIGH

                Case 2

                    wTriggerMode = IXUD_HARDWARE_INT Or IXUD_ACTIVE_LOW Or IXUD_ACTIVE_HIGH
            End Select



            '//Register Callback function, Source = 1(INT_0)
            wRtn = Ixud_SetEventCallback(wBoardNo, wTriggerMode, 1, 0, AddressOf MyApcFunction, 0) '//Register APC

            If wRtn <> 0 Then
                lstMsg.Items.Add("Register APC Error!!")
            Else
                lstMsg.Items.Add(" Register APC OK!!!")
            End If


            '//Install IRQ number
            wRtn = Ixud_InstallIrq(wBoardNo, &H1)
            If wRtn Then
                lstMsg.Items.Add("Install IRQ Error")
            Else
                lstMsg.Items.Add("Install IRQ Success!!!")
            End If


            '//Set Count 3 to Mode 3 Generate 80000/40000 = 2Hz Clock
            wRtn = Ixud_SetCounter(wBoardNo, 2, 3, 40000)
        Else
            cmdActive.Text = "&ACTIVE"
            lstMsg.Items.Add(" Stop Counter Trigger")
            '//Stop Counter
            wRtn = Ixud_SetCounter(wBoardNo, 2, 2, 1)
            '// Revmove the Interrupt
            wRtn = Ixud_RemoveIrq(wBoardNo)
            lstMsg.Items.Add("Stop Interrupt!!")

            wRtn = Ixud_RemoveEventCallback(wBoardNo, 0) '//Remove APC
            lstMsg.Items.Add("Remove APC!!")

            lstMsg.Items.Add("Event Count" + Str(wApcCount))

        End If


        While Me.cmdActive.Text = "&STOP"


            Me.tbxAPCCount.Text = CStr(wApcCount)

            Application.DoEvents()
            System.Threading.Thread.Sleep(1)
            'DoEvents()

        End While



    End Sub

    





End Class
