unit MainUnit; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TMainForm = class(TForm) BlurbMemo: TMemo; GoButton: TButton; procedure FormCreate(Sender: TObject); procedure GoButtonClick(Sender: TObject); private { Private declarations } public { Public declarations } end; var MainForm: TMainForm; implementation {$R *.DFM} uses AIOUSB; var DeviceIndex: LongWord; procedure TMainForm.FormCreate(Sender: TObject); var Status, PID: LongWord; begin //This simply tries diOnly, instead of trying to detect a board by using GetDevices() and looping over QueryDeviceInfo(). DeviceIndex := diOnly; Status := QueryDeviceInfo(DeviceIndex, @PID, nil, nil, nil, nil); if Status = ERROR_FILE_NOT_FOUND then BlurbMemo.Lines.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.' else if Status = ERROR_DUP_NAME then BlurbMemo.Lines.Text := 'Multiple devices found. This sample only works with one.' else if Status <> ERROR_SUCCESS then BlurbMemo.Lines.Text := 'Error ' + IntToStr(Status) + ' detecting devices.' else if not (PID = $4002) then BlurbMemo.Lines.Text := 'A device was detected, but not one supported by this sample.' else begin BlurbMemo.Lines.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.'#13#10#13#10 ; GoButton.Enabled := True; end; end; procedure TMainForm.GoButtonClick(Sender: TObject); var DACData: array of Word; Status: LongWord; I, Channel: Integer; ClockHz, F: Double; ChannelTheta: array[0..7] of Integer; begin 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 do ChannelTheta[I] := 0; SetLength(DACData, 80000); for I := 0 to High(DACData) do begin 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 := $FFF / 2 * (Sin(F) + 1); //Convert from ±1 to 0-FFF. DACData[I] := Round(F); //Round near and store. if Channel = 7 then DACData[I] := DACData[I] or $2000; //If it's the last channel, set the End-Of-DACs bit. end; I := High(DACData); DACData[I] := DACData[I] or $1000; //Set the Loop bit on the last sample of the whole pattern. BlurbMemo.Lines.Add('Loading...'); Status := DACOutputProcess(DeviceIndex, ClockHz, Length(DACData), @DACData[0]); if Status = ERROR_SUCCESS then BlurbMemo.Lines.Add('Now running; you can close this sample and it will keep running. Check it out with a scope.') else BlurbMemo.Lines.Add('Error ' + IntToStr(Status) + ' from DACOutputProcess.') ; end; end.