Option Strict Off
Option Explicit On
Public Class frm_AO
    Inherits System.Windows.Forms.Form
    Dim wRtn As UInt16
    Public wTotalBoards As UInt16
    Public Const MAX_DATA_NUM As UInt32 = 512
    'Dim sGetCardInfo As IXUD_CARD_INFO
    'Dim sGetDevInfo As IXUD_DEVICE_INFO
    Dim sCardInfo(MAX_BOARD_NUMBER) As IXUD_CARD_INFO
    Dim sDevInfo(MAX_BOARD_NUMBER) As IXUD_DEVICE_INFO
    Dim dwDOBuf(MAX_DATA_NUM) As UInt32
    Dim wBoardNo As UInt16
    Public sModelName As New String(" "c, 20)

    Private Sub cbxBoardNo_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cbxBoardNo.SelectedIndexChanged
        Dim ChIndex As Short

        wBoardNo = CUShort(Me.cbxBoardNo.SelectedIndex)

        cbxPort.Items.Clear()

        Me.Text = Me.cbxBoardNo.Text & " Digital Output Cont. Sample Program"
        If sCardInfo(wBoardNo).wDIOPorts + sCardInfo(wBoardNo).wDOPorts > 0 Then
            For ChIndex = 0 To sCardInfo(wBoardNo).wDIOPorts + sCardInfo(wBoardNo).wDOPorts - 1
                Me.cbxPort.Items.Add("Port " & Str(ChIndex))
            Next ChIndex

            cbxPort.SelectedIndex = 0
            Me.Text = Me.cbxBoardNo.Text + " Digital Output Cont. Sample Program"
        Else
            MsgBox("None DO Channel")
            Ixud_DriverClose()
        End If
    End Sub

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

        Dim wIndex As UInt32

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

        If cmdActive.Text = "&ACTIVE" Then
            cmdActive.Text = "&STOP"
            '//Setting Analog Output Pattern
            For wIndex = 0 To MAX_DATA_NUM
                dwDOBuf(wIndex) = wIndex And &HFF
            Next

            '//Write Digital Output Pattern
            wRtn = Ixud_StartDO(wBoardNo, Me.cbxPort.SelectedIndex, 0, CSng(Me.tbxRate.Text) * 1000.0, MAX_DATA_NUM, 0, dwDOBuf)

        Else
            cmdActive.Text = "&ACTIVE"

            wRtn = Ixud_StopDO(wBoardNo, Me.cbxPort.SelectedIndex)

        End If


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


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

    End Sub

   
End Class