unit MainUnit; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls; type TMainForm = class(TForm) ScrollBox1: TScrollBox; ControlPanel: TPanel; VoltPanel: TPanel; CountPanel: TPanel; SpacerBevel: TBevel; ADPollTime: TTimer; GoButton: TButton; StopButton: TButton; procedure FormCreate(Sender: TObject); procedure ADPollTimeTimer(Sender: TObject); procedure GoButtonClick(Sender: TObject); procedure StopButtonClick(Sender: TObject); private { Private declarations } public { Public declarations } end; var MainForm: TMainForm; implementation {$R *.DFM} uses AIOUSB, DetectUnit; var DeviceIndex: LongWord; VoltLabel: array of TLabel; CountGauge: array of TProgressBar; const Channels = 2; procedure TMainForm.FormCreate(Sender: TObject); var Status, PID: LongWord; DetectForm: TDetectForm; I: Integer; begin DeviceIndex := diOnly; //If you only have the one board, QueryDeviceInfo() with diOnly will succeed //with the right PID. If you have more than one board, or haven't plugged it //in, it will fail, and this code will pop up the detector form so the user //can pick a board or cancel. Status := QueryDeviceInfo(DeviceIndex, @PID, nil, nil, nil, nil); if (Status <> ERROR_SUCCESS) or not (((PID >= $8070) and (PID <= $807F)) or ((PID >= $8036) and (PID <= $8037))) then 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; end; //Unsleep the DAC/ADC reference. DACSetBoardRange(DeviceIndex, 2); SetLength(VoltLabel, Channels); SetLength(CountGauge, Channels); SpacerBevel.Height := 17 * Channels + 2; for I := 0 to Channels-1 do begin VoltLabel[I] := TLabel.Create(Self); with VoltLabel[I] do begin AutoSize := False; Alignment := taCenter; Layout := tlCenter; Align := alTop; Top := 18 * I; Height := 17; Caption := 'Ch ' + IntToStr(I); Parent := VoltPanel; end; CountGauge[I] := TProgressBar.Create(Self); with CountGauge[I] do begin Smooth := True; Color := clLime; //ForeColor := clBtnText; //BackColor := clBtnFace; Align := alTop; Top := 18 * I; Height := 17; Parent := CountPanel; Min := $0000; Max := $FFFF; end; end; end; procedure TMainForm.GoButtonClick(Sender: TObject); begin GoButton.Enabled := False; StopButton.Enabled := True; ADPollTime.Enabled := True; end; procedure TMainForm.StopButtonClick(Sender: TObject); begin ADPollTime.Enabled := False; GoButton.Enabled := True; StopButton.Enabled := False; end; procedure TMainForm.ADPollTimeTimer(Sender: TObject); var Status: LongWord; Counts: array of Word; Channel: Integer; begin SetLength(Counts, Channels); Status := ADC_GetScan(DeviceIndex, @Counts[0]); if Status <> ERROR_SUCCESS then begin StopButton.Click; Application.MessageBox(PChar('Error ' + IntToStr(Status) + ' from ADC_GetScan.'), 'ADC_GetScan Error', MB_ICONEXCLAMATION); Exit; end; for Channel := 0 to Channels - 1 do begin CountGauge[Channel].Position := Counts[Channel]; VoltLabel[Channel].Caption := 'Ch ' + IntToStr(Channel) + ': ' + IntToHex(Counts[Channel], 4); end; end; end.