unit pad128s; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls; type TMainForm = class(TForm) Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; SetupPanel: TPanel; Label5: TLabel; BaseEdit: TEdit; Label6: TLabel; ScansEdit: TEdit; Label7: TLabel; DataButton: TButton; ExitButton: TButton; DataPanel: TPanel; Label8: TLabel; Label9: TLabel; Label10: TLabel; Label11: TLabel; Label12: TLabel; Label13: TLabel; Label14: TLabel; Label15: TLabel; RunTimer: TTimer; Label16: TLabel; procedure RunTimerTimer(Sender: TObject); procedure DataButtonClick(Sender: TObject); procedure ExitButtonClick(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var MainForm: TMainForm; base : word; ch : word = 0; //number of channels selected scans : word = 0; //number of times to scan each channel before returning data buffer : array[0..255] of word; //place to store data read from the fifo implementation uses ACCES32; var //chbox and chedit dynamically created at runtime chbox:array[0..7] of TCheckBox; //channel boxes chedit:array[0..7] of TEdit; //data display boxes Procedure STARTCONVERSION; Begin OutPort(base + 16, $0001);//send START to chip End; Procedure RESET; Begin OutPort(base + 16, $0002); // send RESET to chip End; Procedure CALIBRATE; Begin OutPort(base + 16, $0008); // calibrate End; Procedure SETCHANNEL; var offset : word; val : word; loopval : word; i : word; Begin offset := 0; val := 0; loopval := 0; for i := 0 to 7 do begin if chbox[i].Checked then begin OutPort(base+offset, val); inc(offset,2); //inc ram pointer address only if channel is selected inc(ch); //number of channels selected loopval := val; end; inc(val,4); //inc value to write whether channel is selected or not end; dec(offset,2);//set offset to last outport value to write loop bit OutPort(base+offset, loopval + 1); //set loop bit on last box checked End; {$R *.DFM} procedure TMainForm.RunTimerTimer(Sender: TObject); var x,i : word; Begin RESET; SETCHANNEL; RESET; STARTCONVERSION; for x := 0 to (scans-1) do begin for i := 0 to 7 do begin if chbox[i].Checked then begin //this delay is appropriate for a 200MHz Pentium //for faster computers, call ProcessMessages more than once Application.ProcessMessages; //delay Application.ProcessMessages; //delay buffer[x * (ch+1) + i] := InPort(base+24) and $0FFF;//read data into buffer end; end; end; for x := 0 to (scans-1) do begin for i := 0 to 7 do begin if chbox[i].Checked then chedit[i].Text := ' ' + IntToHex((buffer[x * (ch+1) + i]),3) else chedit[i].Text := ' '; end; end; ch := 0; //reset for next time through loop, incremented in SETCHANNEL end; procedure TMainForm.DataButtonClick(Sender: TObject); begin base := StrToInt('$' + BaseEdit.Text); scans := StrToInt(ScansEdit.Text); RESET; CALIBRATE; if RunTimer.Enabled = true then begin RunTimer.Enabled := false; DataButton.Caption := 'Get Data'; end else begin RunTimer.Enabled := true; DataButton.Caption := 'Stop Data'; end; end; procedure TMainForm.ExitButtonClick(Sender: TObject); begin Application.Terminate; end; procedure TMainForm.FormCreate(Sender: TObject); var i : word; begin if (InPortB($61) = $AA55) then begin Application.MessageBox('ACCESNT.SYS not detected. Please copy ACCESNT.SYS into [NT]/system32/drivers and re-run this sample.', 'Warning', IDOK); end; for i := 0 to 7 do begin chedit[i]:=TEdit.Create(self); //data display edit boxes chedit[i].Parent := DataPanel; chedit[i].Left := 8 + (i * 48); chedit[i].Top := 32; chedit[i].Width := 46; chedit[i].Height := 21; chedit[i].TabStop := false; chedit[i].Text := ' '; end; for i := 0 to 3 do begin chbox[i]:=TCheckBox.Create(self); //channel select boxes chbox[i].Parent := SetupPanel; chbox[i].Left := 192; chbox[i].Top := 32 + (i * 17); chbox[i].Width := 97; chbox[i].Height := 17; chbox[i].Checked := false; chbox[i].TabOrder := i + 2; //tab stops 0 and 1 are base and scan edit boxes chbox[i].Caption := 'Channel ' + (IntToStr(i)); end; for i := 4 to 7 do begin chbox[i]:=TCheckBox.Create(self); //channel select boxes chbox[i].Parent := SetupPanel; chbox[i].Left := 296; chbox[i].Top := 32 + ((i-4) * 17); chbox[i].Width := 97; chbox[i].Height := 17; chbox[i].Checked := false; chbox[i].TabOrder := i + 2; //tab stops 0 and 1 are base and scan edit boxes chbox[i].Caption := 'Channel ' + (IntToStr(i)); end; end; end.