
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 sModelName 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 wApcCount0 As Long
    Public wApcCount1 As Long
    Public wApcCount2 As Long



    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, sModelName)
            If sModelName <> "0" Then
                Me.cbxSelectBoard.Items.Add(Str(index) + ": " + sModelName)
            Else
                Me.cbxSelectBoard.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
        wRtn = UniDAQ.Ixud_DriverClose()
        Me.Close()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim hEvent0 As Long
        Dim hEvent1 As Long
        Dim hEvent2 As Long
        Dim i As Integer

        If Button1.Text = "Active" Then
            Button1.Text = "Stop"
            btnExit.Enabled = False

            hEvent0 = 0
            hEvent1 = 0
            hEvent2 = 0
        Else
            Button1.Text = "Active"
            btnExit.Enabled = True
            Exit Sub
        End If

        wBoardNo = cbxSelectBoard.SelectedIndex

        wRtn = Ixud_SetDIOModes32(wBoardNo, 1) 'Set Port0 to Output Mode, Port 1,2 to Input Mode

        'Digital(Output)
        wRtn = Ixud_WriteDO(wBoardNo, 0, 0) 'Initial the Port 0 to Value 0

        'Register Callback function, Source = 1(INT_0) Event Type = High + Interrupt
        wRtn = Ixud_SetEventCallback(wBoardNo, IXUD_HARDWARE_INT Or IXUD_ACTIVE_HIGH, 1, hEvent0, AddressOf MyApcFunction0, 0)
        If wRtn <> 0 Then
            ListBox1.Items.Add("Register APC_0 Error!!" + CStr(wRtn))
            Button1.Text = "ACTIVE"
            Exit Sub
        End If
        'Register Callback function, Source = 2(INT_1) Event Type = Low + Interrupt
        wRtn = Ixud_SetEventCallback(wBoardNo, IXUD_HARDWARE_INT Or IXUD_ACTIVE_LOW, 2, hEvent1, AddressOf MyApcFunction1, 0)
        If wRtn <> 0 Then
            ListBox1.Items.Add("Register APC_1 Error!!" + CStr(wRtn))
            Button1.Text = "ACTIVE"
            Exit Sub
        End If
        'Register Callback function, Source = 3(INT_2) Event Type = High + Low + Interrupt
        wRtn = Ixud_SetEventCallback(wBoardNo, IXUD_HARDWARE_INT Or IXUD_ACTIVE_LOW Or IXUD_ACTIVE_HIGH, 3, hEvent2, AddressOf MyApcFunction2, 0)
        If wRtn <> 0 Then
            ListBox1.Items.Add("Register APC_2 Error!!" + CStr(wRtn))
            Button1.Text = "ACTIVE"
            Exit Sub
        End If

        wRtn = Ixud_InstallIrq(wBoardNo, &HF)
        If wRtn <> 0 Then
            ListBox1.Items.Add("Install Irq Error!!" + CStr(wRtn))
        End If

        For i = 0 To 9
            ListBox1.Items.Add("")
            System.Threading.Thread.Sleep(100)
            ListBox1.Items.Add("   Output 0x07 to Port-0")
            wRtn = Ixud_WriteDO(wBoardNo, 0, &H7) ' Output

            System.Threading.Thread.Sleep(100)
            ListBox1.Items.Add("   Output 0x00 to Port-0")
            wRtn = Ixud_WriteDO(wBoardNo, 0, &H0) ' Output

            Application.DoEvents()
        Next i

        wRtn = Ixud_RemoveIrq(wBoardNo)
        wRtn = Ixud_RemoveEventCallback(wBoardNo, 0) 'Remove Callback function

        ListBox1.Items.Add("")
        ListBox1.Items.Add("Event Count")
        ListBox1.Items.Add("INT_0 Count" + "  : " + CStr(wApcCount0))
        ListBox1.Items.Add("INT_1 Count" + "  : " + CStr(wApcCount1))
        ListBox1.Items.Add("INT_2 Count" + "  : " + CStr(wApcCount2))

        Button1.Text = "Active"
        btnExit.Enabled = True

    End Sub

    Sub MyApcFunction0(ByVal parm As UInteger)
        ' --------- Do you action in this function ------------
        wApcCount0 = wApcCount0 + 1

    End Sub

    Sub MyApcFunction1(ByVal parm As UInteger)
        ' --------- Do you action in this function ------------
        wApcCount1 = wApcCount1 + 1

    End Sub

    Sub MyApcFunction2(ByVal parm As UInteger)
        ' --------- Do you action in this function ------------
        wApcCount2 = wApcCount2 + 1

    End Sub

    Private Sub cbxSelectBoard_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxSelectBoard.SelectedIndexChanged
        Button1.Enabled = True
    End Sub
End Class




