Measurement Computing   Easy to Use | Easy to Integrate | Easy to Support catalog banner

DaqCOM Programming Tool - controlling the DaqBook2000

Expand / Collapse
 

DaqCOM Programming Tool - controlling the DaqBook2000


Below is a listing of a sample program that controls a DaqBook2000 series device. The program will also work with the DaqLab2000 and DaqScan2000 series because they are based on the same design.

Program control is via the IOtech DaqCOM Programming Tool here after referred to by DaqCOM. It is a 32-bit DLL and because of this, program need to compile against x86 (32-bit) not x64. At the bottom of this article you'll find the DaqCOM installation and the example project, which is written in Visual BASIC (Visual Studio 2008). Access to DaqCOM is via a reference in the project. 


Below is the code listing
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Diagnostics
Imports System.Data
Imports System.Windows.Forms.Application
Imports DAQCOMLib
Imports DAQCOMLib.DeviceType
Imports DAQCOMLib.AnalogInputType
Imports DAQCOMLib.DeviceBaseAddress
Imports DAQCOMLib.DeviceBaseChannel
Imports DAQCOMLib.DeviceModulePosition
Imports DAQCOMLib.StopType
Imports DAQCOMLib.StartType
Imports DAQCOMLib.DigitalIOType

Public Class Form1

    Inherits System.Windows.Forms.Form
    Dim pSys As DaqSystem
    Dim pAcq As Acq
    Dim pSysDevices As AvailableDevices
    Dim pDevs As Devices
    Dim pDev As Device

    Dim pConfig As Config
    Dim pScanList As ScanList
    Dim pAnalogInput As AnalogInput
    Dim pAnalogInputs As AnalogInputs
    Dim pAI As Daq2000DirectAI

    Dim DEV As Boolean
    Dim pDIO As DigitalIO
    Dim pPort As Port


#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        Dim i, count As Long
        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Create DaqCOM objects
        pSys = New DaqSystem()

        pAcq = pSys.Add()
        pConfig = pAcq.Config

        pScanList = pConfig.ScanList
        pSysDevices = pAcq.AvailableDevices()
        DEV = False
        pAcq.DataStore.AutoSizeBuffers = False
        pAcq.DataStore.BufferSizeInScans = 100000
        pAcq.DataStore.IgnoreDataStoreOverruns = True


        count = pSysDevices.Count
        For i = 1 To count
            DevicesCombo.Items.Add(pSysDevices(i).Name)
        Next
        DevicesCombo.SelectedIndex = 0


    End Sub
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Private Sub SelectDevice_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectDevice.Click
        Dim i As Long
        Dim pRange As Range
        Dim pRanges As Ranges
        Try

            i = DevicesCombo.SelectedIndex
            pDev = pSysDevices.CreateFromIndex(i + 1)

            pDev.Open()
            pAnalogInputs = pDev.AnalogInputs

            DEV = True
            Dim pDirect As Daq2000DirectAIChannel
            pAnalogInput = pAnalogInputs.Add(aitDirect, dbcDaqChannel0)
            pDirect = pAnalogInput.Channels(1)
            pDirect.DifferentialMode = False
            pDirect.AddToScanList()

            pAnalogInput = pAnalogInputs.Add(aitDirect, dbcDaqChannel1)
            pDirect = pAnalogInput.Channels(1)
            pDirect.DifferentialMode = False
            pDirect.AddToScanList()

            pAnalogInput = pAnalogInputs.Add(aitDirect, dbcDaqChannel2)
            pDirect = pAnalogInput.Channels(1)
            pDirect.DifferentialMode = False
            pDirect.AddToScanList()

            pAnalogInput = pAnalogInputs.Add(aitDirect, dbcDaqChannel3)
            pDirect = pAnalogInput.Channels(1)
            pDirect.DifferentialMode = False
            pDirect.AddToScanList()


            'load up combo box with ranges settings for this device
            pRanges = pDirect.Ranges
            For i = 1 To pRanges.Count
                pRange = pRanges.Item(i)
                DirectRanges.Items.Add(pRange.Name)
            Next
            DirectRanges.SelectedIndex = 0

            'add a PortB on P2 to the scan list
            'pDIO contains three ports which are available to use
            pDIO = pDev.DigitalIOs.Add(diotDirectP2, dbaP2Address0, dmpPosition0)
            pDIO.Ports(2).AddToScanList()

            List.View = View.Details
            Init.Enabled = True
            SelectDevice.Enabled = False
        Catch
            MsgBox(Err.Description, MsgBoxStyle.Critical, "Device Selection")

            End
        End Try
    End Sub
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Private Sub Init_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Init.Click
        Dim pRange As Range
        Try

            'Set Direct channel ranges based on combo box selection
            pRange = pAnalogInputs(1).Channels(1).Ranges.Item(DirectRanges.SelectedIndex + 1)
            pAnalogInputs(1).Channels(1).SelectedRange() = pRange
            pAnalogInputs(2).Channels(1).SelectedRange() = pRange
            pAnalogInputs(3).Channels(1).SelectedRange() = pRange
            pAnalogInputs(4).Channels(1).SelectedRange() = pRange

            ' Clear output port - port C
            pPort = pDIO.Ports(3)
            pPort.Write(0)

            'Set the number of scans to collect
            pConfig.ScanCount = Val(TextBox1.Text)

            'Set the rate a which to collect the above scans
            pConfig.ScanRate = Val(TextBox2.Text) 'Hz

            'Now let's set up the start/stop condition for the channels in the scan list.
            pAcq.Starts.ItemByType(sttManual).UseAsAcqStart()
            pAcq.Stops.ItemByType(sptManual).UseAsAcqStop()

            'This function sets up the List Control.
            'MakeDisplayChannels()
            Status.Text() = "System configured...Ready to Arm!"
            Init.Enabled = False
            Arm.Enabled = True
        Catch
            MsgBox(Err.Description, vbCritical, "ProgramSystem")
            DaqExit()
        End Try
    End Sub


    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Private Sub Arm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Arm.Click
        Try
            'clear the display
            List.Items.Clear()

            TextBox2.Text = pConfig.ScanRate 'update text box with actual rate
            Status.Text() = "System Armed...Ready to Start!"

            'config the list box
            MakeDisplayChannels()

            Arm.Enabled = False
            DaqStart.Enabled = True

            'arm the acquisition
            pAcq.Arm()
        Catch
            MsgBox(Err.Description, vbCritical, "ArmSystem")
            DaqExit()
        End Try
    End Sub
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Private Sub MakeDisplayChannels()
        Dim Index As Long
        Try
            'use contents of scan list to determine number of channels that will be displayed
            Dim pChannel As Scannable
            List.Columns.Clear()

            List.Columns.Add("Scan", 80, HorizontalAlignment.Right)
            For Index = 1 To pScanList.Count
                pChannel = pScanList.Item(Index)
                List.Columns.Add(pChannel.Name, 80, HorizontalAlignment.Right)
            Next
            pChannel = Nothing 'destroy the object
        Catch
            MsgBox(Err.Description, vbCritical, "MakeDisplayChannels")
            DaqExit()
        End Try
    End Sub
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Private Sub DaqStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DaqStart.Click

        Try
            pAcq.Start()
            Status.Text() = "System Started..."
            DaqStart.Enabled = False
            Timer1.Enabled = True
        Catch
            MsgBox(Err.Description, vbCritical, "StartSystem")
        End Try

    End Sub
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Private Sub StopAcq_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StopAcq.Click
        Try
            Timer1.Enabled = False
            pAcq.Abort()
            Status.Text() = "System Stop..."
            Init.Enabled = True

        Catch
            MsgBox(Err.Description, vbCritical, "StartSystem")
        End Try

    End Sub

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        GetData()
    End Sub

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Private Sub GetData()


        Try
            'allocate array for our data
            Dim Data(100000) As Single 'Use Single because data will be in engineering units

            Dim ScansRetd As Long
            Dim Channel As Long
            Dim DesiredScans As Long
            Dim ArrayIndex As Long
            Dim itm As ListViewItem


            'request data.
            DesiredScans = 100
            ScansRetd = pAcq.DataStore.FetchData(Data, DesiredScans)
            If ScansRetd > 0 Then

                itm = New ListViewItem(Str$(List.Items.Count))
                List.Items.Add(itm)
                'print one value for each channel in the array
                For Channel = 1 To pScanList.Count
                    itm.SubItems.Add(String.Format("{0:00.0000}", Data(ArrayIndex)))
                    ArrayIndex = ArrayIndex + 1
                Next Channel
                Channel = 0
                'Next Scan
                Application.DoEvents()
                Status.Text() = "Scans displayed: " + Str$(List.Items.Count) + " " + "Scans to read: " + Str$(pAcq.DataStore.AvailableScans)
            End If
        Catch
            MsgBox(Err.Description, vbCritical, "GetSystemData")
            DaqExit()
        End Try
    End Sub


    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Private Sub DaqExit()
        Try
            If DEV = True Then pDev.Close()
            pSys.Close()
            pSys = Nothing
            End
        Catch
            MsgBox(Err.Description, vbCritical, "FormLoad")
        End Try
    End Sub

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
        End 'end program
    End Sub
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Protected Overrides Sub Finalize()
        MyBase.Finalize()
        DaqExit()
    End Sub

End Class




Rate this Article:

Attachments


daqcom2setup.exe daqcom2setup.exe (25.61 MB, 40 views)

DaqBook2000Example.zip DaqBook2000Example.zip (8.34 KB, 29 views)

Add Your Comments


For comments email TechSupport@mccdaq.com.

Details
Article ID: 50771

Last Modified:4/4/2019 4:00:55 PM

Article has been viewed 118 times.

Options