⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aosyncform.vb

📁 使用研华DAQ和VB.net实现研华数据采集卡的多种功能.包括数据输入输出。内含多个源码
💻 VB
📖 第 1 页 / 共 3 页
字号:
        Me.Frame1.ResumeLayout(False)
        Me.Frame2.ResumeLayout(False)
        Me.frmOutputKind.ResumeLayout(False)
        CType(Me.DAQAO1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub chkSyncAOEnable_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles chkSyncAOEnable.CheckStateChanged
        If IsInitializing Then
            Exit Sub
        End If
        If chkSyncAOEnable.CheckState = System.Windows.Forms.CheckState.Checked Then
            DAQAO1.SetSynchronous(True)
        Else
            DAQAO1.SetSynchronous(False)
        End If
    End Sub

    Private Sub cmdExit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdExit.Click
        Me.Close()
        End
    End Sub

    Private Sub cmdOutputStart_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdOutputStart.Click
        'Open Device
        If DAQAO1.OpenDevice Then
            MsgBox(DAQAO1.ErrorMessage, MsgBoxStyle.OKOnly)
            Exit Sub
        End If

        'Set Outputtype & initialize output value
        If optVoltageOut.Checked = True Then
            OutputValue(0) = 0.0#
            OutputValue(1) = 1.25
            OutputValue(2) = 2.5
            OutputValue(3) = 5.0#

            DAQAO1.OutputType = DAQAOLib.OUTPUT_TYPE.adVoltage
        End If
        If optCurrentOut0.Checked = True Then
            OutputValue(0) = 0.0#
            OutputValue(1) = 5.0#
            OutputValue(2) = 10.0#
            OutputValue(3) = 20.0#

            DAQAO1.OutputType = DAQAOLib.OUTPUT_TYPE.adCurrent
        End If
        If optCurrentOut4.Checked = True Then
            OutputValue(0) = 4.0#
            OutputValue(1) = 10.0#
            OutputValue(2) = 15.0#
            OutputValue(3) = 20.0#

            DAQAO1.OutputType = DAQAOLib.OUTPUT_TYPE.adCurrent
        End If

        'Reset button state
        cmdOutputStart.Enabled = False
        cmdOutputStop.Enabled = True
        cmdExit.Enabled = False
        cmdSelectDevice.Enabled = False

        'Enable ScanTimer
        ScanTimer.Enabled = True



    End Sub

    Private Sub cmdOutputStop_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdOutputStop.Click
        'Disable ScanTimer
        ScanTimer.Enabled = False

        'Close Device
        If DAQAO1.CloseDevice Then
            MsgBox(DAQAO1.ErrorMessage, MsgBoxStyle.OKOnly)
            Exit Sub
        End If

        cmdOutputStart.Enabled = True
        cmdOutputStop.Enabled = False
        cmdExit.Enabled = True
        cmdSelectDevice.Enabled = True
    End Sub

    Private Sub cmdSelectDevice_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSelectDevice.Click
        Dim chkSyncEnable As Object
        Dim i As Short
        Dim j As Short
        Dim bRet As Boolean

        DAQAO1.SelectDevice()
        txtDeviceNum.Text = CStr(DAQAO1.DeviceNumber)
        txtDeviceName.Text = DAQAO1.DeviceName

        ' Open device
        If DAQAO1.OpenDevice Then
            MsgBox(DAQAO1.ErrorMessage, MsgBoxStyle.OKOnly)
            Exit Sub
        End If

        If DAQAO1.MaxChannel = 0 Then
            MsgBox("Function Not Supported")
            DAQAO1.CloseDevice()
            Exit Sub
            
        End If
        chkListBox.Items.Clear()

        For i = 0 To DAQAO1.MaxChannel - 1
            chkListBox.Items.Add("Chan " & i & " ")
        Next i
        Dim width As Integer = CInt(chkListBox.CreateGraphics().MeasureString(chkListBox.Items(0).ToString(), _
    chkListBox.Font).Width + 30)
        '  Set the column width based on the width of each item in the list.
        chkListBox.ColumnWidth = width

        'Set SyncAo enable
        DAQAO1.SetSynchronous(True)

        'Close Device
        If DAQAO1.CloseDevice Then
            MsgBox(DAQAO1.ErrorMessage, MsgBoxStyle.OKOnly)
            Exit Sub
        End If
    End Sub

    Private Sub frmSyncAo_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
        ' Select default device
        Call cmdSelectDevice_Click(cmdSelectDevice, New System.EventArgs)
        ' Setting initial value
        txtDeviceNum.Text = CStr(DAQAO1.DeviceNumber)
        txtDeviceName.Text = DAQAO1.DeviceName

    End Sub



    Private Sub ScanTimer_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles ScanTimer.Tick
        Dim chkSyncEnable As Object
        Dim i As Object

        'Output value
        For i = 0 To DAQAO1.MaxChannel - 1
            If chkListBox.GetItemChecked(i) Then
                DAQAO1.Channel = i
                If DAQAO1.RealOutput(OutputValue(Index)) Then
                    ScanTimer.Enabled = False

                    MsgBox(DAQAO1.ErrorMessage, MsgBoxStyle.OKOnly)
                    Exit Sub
                End If
            End If
        Next i

        ' Start SyncAO
        If DAQAO1.SynchronousOutput Then
            ScanTimer.Enabled = False
            MsgBox(DAQAO1.ErrorMessage, MsgBoxStyle.OKOnly)
            Exit Sub
        End If

        'Update text output value
        txtOutputValue.Text = Str(OutputValue(Index))

        Index = Index + 1
        If Index > 3 Then
            Index = 0
        End If

    End Sub

    Private Sub txtDeviceNum_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtDeviceNum.TextChanged

        Dim i As Integer
        If IsInitializing Then
            Exit Sub
        End If
        DAQAO1.DeviceNumber = Val(txtDeviceNum.Text)
        txtDeviceName.Text = DAQAO1.DeviceName
        ' Open device
        If DAQAO1.OpenDevice Then
            MsgBox(DAQAO1.ErrorMessage, MsgBoxStyle.OKOnly)
            Exit Sub
        End If

        If DAQAO1.MaxChannel = 0 Then
            '       MsgBox("Function Not Supported")
            DAQAO1.CloseDevice()
            Exit Sub
        End If
        chkListBox.Items.Clear()

        For i = 0 To DAQAO1.MaxChannel - 1
            chkListBox.Items.Add("Chan " & i & " ")
        Next i
        Dim width As Integer = CInt(chkListBox.CreateGraphics().MeasureString(chkListBox.Items(0).ToString(), _
    chkListBox.Font).Width + 30)
        '  Set the column width based on the width of each item in the list.
        chkListBox.ColumnWidth = width

        'Set SyncAo enable
        DAQAO1.SetSynchronous(True)

        'Close Device
        If DAQAO1.CloseDevice Then
            MsgBox(DAQAO1.ErrorMessage, MsgBoxStyle.OKOnly)
            Exit Sub
        End If
    End Sub

    Private Sub txtScanTime_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtScanTime.TextChanged
        If IsInitializing Then
            Exit Sub
        End If
        If (Val(txtScanTime.Text) > 0) Then
            ScanTimer.Interval = Val(txtScanTime.Text)
        End If
    End Sub

    Private Sub optCurrentOut0_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optCurrentOut0.CheckedChanged

    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -