unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls; type TForm1 = class(TForm) Label1: TLabel; rateLBL: TLabel; TrackBar1: TTrackBar; fopenBTN: TButton; goBTN: TButton; OpenDialog1: TOpenDialog; BlurbMemo: TMemo; procedure fopenBTNClick(Sender: TObject); procedure goBTNClick(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormCreate(Sender: TObject); procedure TrackBar1Change(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; fName : AnsiString; Done : Boolean; DeviceIndex : LongWord; implementation uses AIOUSB, DetectUnit; {$R *.DFM} procedure TForm1.fopenBTNClick(Sender: TObject); begin if OpenDialog1.Execute then begin fName := OpenDialog1.FileName; goBTN.Enabled := true; end; end; procedure TForm1.goBTNClick(Sender: TObject); var TheFile : TStringList; NumDacs : Integer; Line : array [0..127] of Char; Count : Integer; FrameData : array [0..8191] of WORD; index : Integer; FramePoints : DWORD; LineIndex : Integer; CurrentNum : array [0..6] of Char; CurrentIndex : Integer; LineNumber : Integer; Status : LongWord; Clock : Double; oldDacs : Integer; begin TheFile := TStringList.Create; TheFile.LoadFromFile(fName); done := false; index := 0; LineNumber := 0; FramePoints := 0; oldDacs := 8; Clock := TrackBar1.Position * 1000.0; DACOutputOpen(DeviceIndex, Clock); DACOutputSetCount(DeviceIndex, oldDacs); repeat CurrentIndex := 0; numDacs := 0; LineIndex := 0; StrPCopy(line, TheFile.Strings[LineNumber]); for count := 0 to strlen(line) do begin if (Line[LineIndex] <> ',') and (Line[LineIndex] <> #0) then begin CurrentNum[CurrentIndex] := Line[LineIndex]; inc(CurrentIndex); inc(LineIndex); end else begin CurrentNum[CurrentIndex] := #0; FrameData[index] := StrToIntDef(CurrentNum, 5000); if FrameData[index] <> 5000 then begin inc(numDacs); inc(LineIndex); inc(index); CurrentIndex := 0; end else begin Break; end; end; end; inc(LineNumber); if LineNumber = TheFile.Count then LineNumber := 0; if (numDacs = oldDacs) then begin inc(FramePoints); if (index + numDACS > 8191) then begin DACOutputSetCount(DeviceIndex, NumDacs); repeat status := DACOutputFrame(DeviceIndex, FramePoints, @FrameData[0]); until status <> ERROR_NOT_READY; index := 0; FramePoints := 0; end; end else begin DACOutputSetCount(DeviceIndex, oldDacs); repeat status := DACOutputFrame(DeviceIndex, FramePoints, @FrameData[0]); until status <> ERROR_NOT_READY; for count := 0 to numDacs do FrameData[count] := FrameData[count + index]; index := numDacs; FramePoints := 1; oldDacs := numDacs; end; Application.ProcessMessages; until done = true; end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin Done := true; BlurbMemo.Lines.Add('Exiting. This may take a few moments.'); end; procedure TForm1.FormCreate(Sender: TObject); var DetectForm: TDetectForm; begin DetectForm := TDetectForm.Create(Self); if DetectForm.ShowModal = mrOK then begin DeviceIndex := DetectForm.DeviceIndex; DetectForm.Free; end else begin DetectForm.Free; Application.Terminate; Exit; end; OpenDialog1.InitialDir := GetCurrentDir; end; procedure TForm1.TrackBar1Change(Sender: TObject); var Clock : Double; CtrDivisor : word; begin Clock := TrackBar1.Position * 1000.0; CtrDivisor := Round(12000000 / Clock); //This is an advanced command intended to help ACCES's test department. //It simply changes the DAC output rate "live", something not recommended for normal users. GenericVendorWrite(DeviceIndex, $B2, 0, CtrDivisor, 0, nil); rateLBL.Caption := IntToStr(TrackBar1.Position) + 'KHz'; end; end.