📄 main.pas
字号:
unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, DAQAOLib_TLB, OleCtrls;
type
TfrmMain = class(TForm)
GroupBox1: TGroupBox;
Label1: TLabel;
Label2: TLabel;
cmdSelectDevice: TButton;
txtDeviceNum: TEdit;
txtDeviceName: TEdit;
DAQAO1: TDAQAO;
cmdExit: TButton;
GroupBox2: TGroupBox;
GroupBox3: TGroupBox;
chkSyncAOEnable: TCheckBox;
GroupBox4: TGroupBox;
GroupBox5: TGroupBox;
optVoltageOut: TRadioButton;
optCurrentOut0: TRadioButton;
optCurrentOut4: TRadioButton;
chkSyncEnable0: TCheckBox;
chkSyncEnable1: TCheckBox;
chkSyncEnable2: TCheckBox;
chkSyncEnable3: TCheckBox;
chkSyncEnable4: TCheckBox;
chkSyncEnable5: TCheckBox;
chkSyncEnable6: TCheckBox;
chkSyncEnable7: TCheckBox;
ScanTimer: TTimer;
cmdOutputStart: TButton;
cmdOutputStop: TButton;
txtOutputValue: TEdit;
Label5: TLabel;
GroupBox6: TGroupBox;
txtScanTime: TEdit;
Label4: TLabel;
chkSyncEnable8: TCheckBox;
chkSyncEnable9: TCheckBox;
chkSyncEnable10: TCheckBox;
chkSyncEnable11: TCheckBox;
chkSyncEnable13: TCheckBox;
chkSyncEnable14: TCheckBox;
chkSyncEnable15: TCheckBox;
chkSyncEnable16: TCheckBox;
chkSyncEnable17: TCheckBox;
chkSyncEnable18: TCheckBox;
chkSyncEnable19: TCheckBox;
chkSyncEnable20: TCheckBox;
chkSyncEnable21: TCheckBox;
chkSyncEnable22: TCheckBox;
chkSyncEnable23: TCheckBox;
chkSyncEnable24: TCheckBox;
chkSyncEnable25: TCheckBox;
chkSyncEnable26: TCheckBox;
chkSyncEnable27: TCheckBox;
chkSyncEnable28: TCheckBox;
chkSyncEnable29: TCheckBox;
chkSyncEnable30: TCheckBox;
chkSyncEnable31: TCheckBox;
chkSyncEnable12: TCheckBox;
procedure cmdSelectDeviceClick(Sender: TObject);
procedure cmdExitClick(Sender: TObject);
procedure chkSyncAOEnableClick(Sender: TObject);
procedure txtScanTimeChange(Sender: TObject);
procedure ScanTimerTimer(Sender: TObject);
procedure cmdOutputStartClick(Sender: TObject);
procedure cmdOutputStopClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure txtDeviceNumChange(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
gOutputValue : array[0..3] of Single;
gIndex : Integer;
chkSyncEnable : array[0..31] of TCheckBox;
implementation
{$R *.DFM}
procedure ErrorMsgBox( sErrMsg : WideString);
var
sErrString : AnsiString;
sCaption : AnsiString;
begin
sErrString := sErrMsg;
sCaption := frmMain.Caption + ' Error';
Application.MessageBox(@sErrString[1], @sCaption[1], MB_OK or MB_ICONEXCLAMATION);
end;
procedure TfrmMain.cmdSelectDeviceClick(Sender: TObject);
var
i : Integer;
begin
{Select Device from list}
DAQAO1.SelectDevice;
txtDeviceNum.Text := IntToStr(DAQAO1.DeviceNumber);
txtDeviceName.Text := DAQAO1.DeviceName;
// Open device
If DAQAO1.OpenDevice Then
begin
ErrorMsgBox(DAQAO1.ErrorMessage);
Exit;
end;
if DAQAO1.MaxChannel = 0 then
begin
ShowMessage('Function Not Supported');
DAQAO1.CloseDevice;
Exit;
end;
//Initialize channel check box
for i := 0 to 31 do
begin
If DAQAO1.MaxChannel > i Then
chkSyncEnable[i].Enabled := True
Else
chkSyncEnable[i].Enabled := False;
end;
//Set SyncAo enable
DAQAO1.SetSynchronous (True);
//Close Device
If DAQAO1.CloseDevice Then
Begin
ErrorMsgBox(DAQAO1.ErrorMessage);
Exit;
End;
end;
procedure TfrmMain.cmdExitClick(Sender: TObject);
begin
Application.Terminate;
end;
procedure TfrmMain.chkSyncAOEnableClick(Sender: TObject);
begin
If chkSyncAOEnable.Checked Then
DAQAO1.SetSynchronous (True)
Else
DAQAO1.SetSynchronous (False);
end;
procedure TfrmMain.txtScanTimeChange(Sender: TObject);
begin
ScanTimer.Interval := StrToInt(txtScanTime.Text);
end;
procedure TfrmMain.ScanTimerTimer(Sender: TObject);
Var
err : Boolean;
i : Integer;
begin
//Output value
for i := 0 to 31 do
begin
If chkSyncEnable[i].Checked Then
begin
DAQAO1.Channel := i;
err := False;
try
err := DAQAO1.RealOutput (gOutputValue[gIndex]);
except
on E: Exception do
begin
ScanTimer.Enabled := False;
MessageDlg(E.Message, mtError, [mbOk], E.HelpContext);
Exit;
end;
end;
If err Then
Begin
ScanTimer.Enabled := False;
ErrorMsgBox(DAQAO1.ErrorMessage);
Exit;
End;
end;
end;
// Start SyncAO
If DAQAO1.SynchronousOutput Then
Begin
ScanTimer.Enabled := False;
ErrorMsgBox(DAQAO1.ErrorMessage);
Exit;
End;
//Update text output value
txtOutputValue.Text := CurrToStr(gOutputValue[gIndex]);
inc(gIndex);
If gIndex > 3 Then
gIndex := 0;
end;
procedure TfrmMain.cmdOutputStartClick(Sender: TObject);
begin
//Open Device
If DAQAO1.OpenDevice Then
Begin
ErrorMsgBox(DAQAO1.ErrorMessage);
Exit;
End;
//Set Outputtype & initialize output value
If optVoltageOut.Checked Then
begin
gOutputValue[0] := 0;
gOutputValue[1] := 1.25;
gOutputValue[2] := 2.5;
gOutputValue[3] := 5;
DAQAO1.OutputType := adVoltage;
end;
If optCurrentOut0.Checked Then
begin
gOutputValue[0] := 0;
gOutputValue[1] := 5;
gOutputValue[2] := 10;
gOutputValue[3] := 20;
DAQAO1.OutputType := adCurrent;
End;
If optCurrentOut4.Checked Then
begin
gOutputValue[0] := 4;
gOutputValue[1] := 10;
gOutputValue[2] := 15;
gOutputValue[3] := 20;
DAQAO1.OutputType := adCurrent;
end;
//Reset button state
cmdOutputStart.Enabled := False;
cmdOutputStop.Enabled := True;
cmdExit.Enabled := False;
cmdSelectDevice.Enabled := False;
//Enable ScanTimer
ScanTimer.Enabled := True;
end;
procedure TfrmMain.cmdOutputStopClick(Sender: TObject);
begin
//Disable ScanTimer
ScanTimer.Enabled := False;
//Close Device
If DAQAO1.CloseDevice Then
Begin
ErrorMsgBox(DAQAO1.ErrorMessage);
Exit;
End;
cmdOutputStart.Enabled := True;
cmdOutputStop.Enabled := False;
cmdExit.Enabled := True;
cmdSelectDevice.Enabled := True;
end;
procedure TfrmMain.FormCreate(Sender: TObject);
begin
chkSyncEnable[0] := chkSyncEnable0;
chkSyncEnable[1] := chkSyncEnable1;
chkSyncEnable[2] := chkSyncEnable2;
chkSyncEnable[3] := chkSyncEnable3;
chkSyncEnable[4] := chkSyncEnable4;
chkSyncEnable[5] := chkSyncEnable5;
chkSyncEnable[6] := chkSyncEnable6;
chkSyncEnable[7] := chkSyncEnable7;
chkSyncEnable[8] := chkSyncEnable8;
chkSyncEnable[9] := chkSyncEnable9;
chkSyncEnable[10] := chkSyncEnable10;
chkSyncEnable[11] := chkSyncEnable11;
chkSyncEnable[12] := chkSyncEnable12;
chkSyncEnable[13] := chkSyncEnable13;
chkSyncEnable[14] := chkSyncEnable14;
chkSyncEnable[15] := chkSyncEnable15;
chkSyncEnable[16] := chkSyncEnable16;
chkSyncEnable[17] := chkSyncEnable17;
chkSyncEnable[18] := chkSyncEnable18;
chkSyncEnable[19] := chkSyncEnable19;
chkSyncEnable[20] := chkSyncEnable20;
chkSyncEnable[21] := chkSyncEnable21;
chkSyncEnable[22] := chkSyncEnable22;
chkSyncEnable[23] := chkSyncEnable23;
chkSyncEnable[24] := chkSyncEnable24;
chkSyncEnable[25] := chkSyncEnable25;
chkSyncEnable[26] := chkSyncEnable26;
chkSyncEnable[27] := chkSyncEnable27;
chkSyncEnable[28] := chkSyncEnable28;
chkSyncEnable[29] := chkSyncEnable29;
chkSyncEnable[30] := chkSyncEnable30;
chkSyncEnable[31] := chkSyncEnable31;
ScanTimer.Enabled := False;
cmdSelectDeviceClick(sender);
// Setting initial value
txtDeviceNum.Text := IntToStr(DAQAO1.DeviceNumber);
txtDeviceName.Text := DAQAO1.DeviceName;
end;
procedure TfrmMain.txtDeviceNumChange(Sender: TObject);
begin
DAQAO1.DeviceNumber := StrToInt(txtDeviceNum.Text);
txtDeviceName.Text := DAQAO1.DeviceName;
end;
procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ScanTimer.Enabled := False;
DAQAO1.CloseDevice;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -