VERSION 5.00 Begin VB.Form MainForm Caption = "DACOutputProcess Sample" ClientHeight = 3015 ClientLeft = 60 ClientTop = 345 ClientWidth = 5775 LinkTopic = "Form1" ScaleHeight = 3015 ScaleWidth = 5775 StartUpPosition = 2 'CenterScreen Begin VB.TextBox BlurbMemo Height = 2295 Left = 120 MultiLine = -1 'True TabIndex = 1 Top = 120 Width = 5535 End Begin VB.CommandButton GoButton Caption = "&Go" Height = 375 Left = 120 TabIndex = 0 Top = 2520 Width = 1095 End End Attribute VB_Name = "MainForm" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Const ERROR_SUCCESS = 0 Const ERROR_FILE_NOT_FOUND = 2 Const ERROR_DUP_NAME = 52 Const Pi = 3.14159265358979 Dim DeviceIndex As Long Private Sub Form_Load() Dim Status As Long, PID As Long 'This simply tries diOnly, instead of trying to detect a board by using GetDevices() and looping over QueryDeviceInfo(). DeviceIndex = diOnly Status = QueryDeviceInfo(DeviceIndex, PID, 0, 0, 0, 0) If Status = ERROR_FILE_NOT_FOUND Then BlurbMemo.Text = "No device found. Make sure the board is plugged in, and check Device Manager to see if it has an error or is stuck with a (D15 Lo) tag." ElseIf Status = ERROR_DUP_NAME Then BlurbMemo.Text = "Multiple devices found. This sample only works with one." ElseIf Status <> ERROR_SUCCESS Then BlurbMemo.Text = "Error " + Status + " detecting devices." ElseIf Not (PID = &H4002) Then BlurbMemo.Text = "A device was detected, but not one supported by this sample." Else BlurbMemo.Text = "This sample uses a single DACOutputProcess() call to control the arbitrary waveform generator. " _ + "The data loops sine waves, with a different frequency on each DAC, from 10 Hz to 80 Hz. " _ + "Click Go when ready." + vbCrLf + vbCrLf GoButton.Enabled = True End If End Sub Private Sub GoButton_Click() Const DACDataLen = 80000 Dim DACData(0 To DACDataLen - 1) As Integer Dim Status As Long Dim I As Long, Channel As Long Dim ClockHZ As Double, F As Double Dim ChannelTheta(0 To 7) As Long ClockHZ = 10000 'Each tick of the clock outputs all DAC channels in parallel. 'At 10000 Hz, DAC 0 will be 10 Hz, DAC 1 will be 20 Hz, DAC 2 will be 30 Hz, etc. For I = 0 To 7: ChannelTheta(I) = 0: Next For I = 0 To DACDataLen - 1 Channel = I Mod 8 ChannelTheta(Channel) = (ChannelTheta(Channel) + (1 + Channel)) Mod 1000 F = Pi * 2 / 1000 * ChannelTheta(Channel) 'Convert theta from integer permille to float radians. F = &HFFF / 2 * (Sin(F) + 1) 'Convert from ±1 to 0-FFF. DACData(I) = CLng(F) 'Round near and store. If Channel = 7 Then DACData(I) = DACData(I) Or &H2000 'If it's the last channel, set the End-Of-DACs bit. Next DACData(DACDataLen - 1) = DACData(DACDataLen - 1) Or &H1000 'Set the Loop bit on the last sample of the whole pattern. BlurbMemo.Text = BlurbMemo.Text + "Loading..." + vbCrLf Status = DACOutputProcess(DeviceIndex, ClockHZ, DACDataLen, DACData(0)) If Status = ERROR_SUCCESS Then BlurbMemo.Text = BlurbMemo.Text + "Now running; you can close this sample and it will keep running. Check it out with a scope." Else BlurbMemo.Text = BlurbMemo.Text + "Error " + Status + " from DACOutputProcess." End If End Sub