📄 mainform.pas
字号:
unit MainForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Driver, Global;
type
TfrmADExp = class(TForm)
Label2: TLabel;
Range: TLabel;
Label1: TLabel;
Label3: TLabel;
Group: TGroupBox;
labDeviceName: TLabel;
BtnSelectDeivce: TButton;
BtnStart: TButton;
BtnExit: TButton;
CmbChannel: TComboBox;
CmbRange: TComboBox;
CmbExpChan: TComboBox;
CmbBoardID: TComboBox;
procedure BtnSelectDeivceClick(Sender: TObject);
procedure CmbChannelChange(Sender: TObject);
procedure BtnExitClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure BtnStartClick(Sender: TObject);
private
{ Private declarations }
lDeviceNumber : Longint;
public
{ Public declarations }
end;
var
frmADExp: TfrmADExp;
implementation
uses ReadForm;
{$R *.dfm}
{*************************************************************
* Function: Handle the error code. If the input error code > 0,
* it means some error apperent. This function can
* show the error message to a message box and stop
* this application.
* Input: The error code.
* return: none
************************************************************* }
Function DoesErr(var lErrCode: LongInt): integer;
var
szErrMsg : string[100];
pszErrMsg : PChar;
begin
{Check the pressed error code}
If (lErrCode <> 0) Then
begin
pszErrMsg := @szErrMsg;
DRV_GetErrorMessage(lErrCode, pszErrMsg);
Application.MessageBox(pszErrMsg, 'Error!!', MB_OK);
DoesErr := 1;
end
else
DoesErr := 0;
end;
procedure TfrmADExp.BtnSelectDeivceClick(Sender: TObject);
var
szDeviceName : array[0..100] of char;
i : Smallint;
strTemp : AnsiString;
szExpName : array[0..100] of char; // expansion name
begin
{Select devcie from device list}
lErrCde := DRV_SelectDevice( frmADExp.Handle, False, lDeviceNumber,
@szDeviceName[0]);
if( DoesErr(lErrCde) = 1 ) then
Exit;
labDeviceName.Caption := szDeviceName;
{Get device features for filling every control's items}
lErrCde := DRV_DeviceOpen( lDeviceNumber, lDeviceHandle);
if( DoesErr(lErrCde) = 1 ) then
Exit;
ptDevGetFeatures.buffer := @dfDevFeatures;
ptDevGetFeatures.size := SizeOf(DEVFEATURES);
lErrCde := DRV_DeviceGetFeatures(lDeviceHandle,ptDevGetFeatures);
if( DoesErr(lErrCde) = 1 ) then
begin
DRV_DeviceClose(lDeviceHandle);
Exit;
end;
CmbChannel.Clear();
if ((dfDevFeatures.usMaxAIDiffChl = 0) and
(dfDevFeatures.usMaxAISiglChl = 0)) then
Exit;
ptAIGetConfig.buffer := @DevCfg;
ptAIGetConfig.size := SizeOf(DEVCONFIG_AI);
// call AIGetConfig
lErrCde := DRV_AIGetConfig(lDeviceHandle,ptAIGetConfig);
if( DoesErr(lErrCde) = 1 ) then
begin
DRV_DeviceClose(lDeviceHandle);
Exit;
end;
usMaxChannel := dfDevFeatures.usMaxAISiglChl;
CmbChannel.Clear();
// setting dialog box for channel setting
// fill in the channel listbox with the available channel
// in the AI subsection (start with channel 0)
for i := 0 to usMaxChannel - 1 do
begin
strTemp := IntToStr(i);
if( i = DevCfg.usCjcChannel) then
begin
strTemp := strTemp+'(CJC Channel)';
end
else if( DevCfg.Daughter[i].dwBoardID <> 0) then
begin
strTemp:=strTemp+' (';
DRV_BoardTypeMapBoardName(DevCfg.Daughter[i].dwBoardID,
@szExpName[0]);
strTemp:=strTemp+szExpName;
strTemp:=strTemp+')';
end;
CmbChannel.items.Add(strTemp);
end;
CmbChannel.ItemIndex :=0;
// initialize input channel
// if the selected channel is associated with an expansion board,
// fill in the Exp. channel listbox with the available expansion board
// channel.
if ( (DevCfg.usNumExpChan > 0) and
(DevCfg.Daughter[gwChannel].dwBoardID<>0 ) and
(gwChannel <> DevCfg.usCjcChannel) and
(DevCfg.Daughter[gwChannel].dwBoardID <> BD_PCLD8115) ) then
begin
CmbExpChan.Enabled := true;
CmbExpChan.Clear();
for i:=0 to DevCfg.Daughter[gwChannel].usNum-1 do
begin
strTemp:=IntToStr(i);
CmbExpChan.Items.Add(strTemp);
end;
CmbExpChan.ItemIndex :=0;
end
else
begin
CmbExpChan.Enabled := false;
usExpChan := 0;
end;
if (DevCfg.Daughter[gwChannel].dwBoardID = BD_PCLD788) then
begin
CmbBoardID.Enabled :=true;
CmbBoardID.Clear();
for i:=0 to DevCfg.Daughter[gwChannel].usCards-1 do
begin
strTemp:=IntToStr(i);
CmbBoardID.Items.Add(strTemp);
end;
CmbBoardID.ItemIndex :=0;
end
else
begin
usBoardID := 0;
CmbBoardID.Enabled := false;
end;
// third: initialize Input Range List Combobox with device features
if ((dfDevFeatures.usNumGain <> 0) and
(DevCfg.Daughter[gwChannel].dwBoardID = 0) and
(DevCfg.usCjcChannel <> gwChannel)) then
begin
CmbRange.Enabled := true;
CmbRange.Clear();
for i := 0 to dfDevFeatures.usNumGain-1 do
CmbRange.Items.Add(dfDevFeatures.glGainList[i].szGainStr);
CmbRange.ItemIndex := 0;
end
else
begin
gwGain := 0;
CmbRange.Enabled := false;
end;
// fourth: close device
DRV_DeviceClose(lDeviceHandle);
end;
procedure TfrmADExp.CmbChannelChange(Sender: TObject);
var
i : Smallint;
strTemp : AnsiString;
begin
gwChannel:=CmbChannel.ItemIndex;
// initialize input channel
// if the selected channel is associated with an expansion board,
// fill in the Exp. channel listbox with the available expansion board
// channel.
if ( (DevCfg.usNumExpChan > 0) and
(DevCfg.Daughter[gwChannel].dwBoardID<>0 ) and
(gwChannel <> DevCfg.usCjcChannel) and
(DevCfg.Daughter[gwChannel].dwBoardID <> BD_PCLD8115) ) then
begin
CmbExpChan.Enabled := true;
CmbExpChan.Clear();
for i:=0 to DevCfg.Daughter[gwChannel].usNum-1 do
begin
strTemp:=IntToStr(i);
CmbExpChan.Items.Add(strTemp);
end;
CmbExpChan.ItemIndex :=0;
end
else
begin
CmbExpChan.Enabled := false;
usExpChan := 0;
end;
if (DevCfg.Daughter[gwChannel].dwBoardID = BD_PCLD788) then
begin
CmbBoardID.Enabled :=true;
CmbBoardID.Clear();
for i:=0 to DevCfg.Daughter[gwChannel].usCards-1 do
begin
strTemp:=IntToStr(i);
CmbBoardID.Items.Add(strTemp);
end;
CmbBoardID.ItemIndex :=0;
end
else
begin
usBoardID := 0;
CmbBoardID.Enabled := false;
end;
// third: initialize Input Range List Combobox with device features
if ((dfDevFeatures.usNumGain <> 0) and
(DevCfg.Daughter[gwChannel].dwBoardID = 0) and
(DevCfg.usCjcChannel <> gwChannel)) then
begin
CmbRange.Enabled := true;
CmbRange.Clear();
for i := 0 to dfDevFeatures.usNumGain-1 do
CmbRange.Items.Add(dfDevFeatures.glGainList[i].szGainStr);
CmbRange.ItemIndex := 0;
end
else
begin
gwGain := 0;
CmbRange.Enabled := false;
end;
end;
procedure TfrmADExp.BtnExitClick(Sender: TObject);
begin
Close();
end;
procedure TfrmADExp.FormCreate(Sender: TObject);
begin
BtnSelectDeivceClick(Sender);
end;
procedure TfrmADExp.BtnStartClick(Sender: TObject);
begin
gwChannel:=CmbChannel.ItemIndex;
gwGain := CmbRange.ItemIndex;
usExpChan := CmbExpChan.ItemIndex; // expansion channel
usBoardID := CmbBoardID.ItemIndex; // Board ID
if( CmbRange.Enabled = false) then
gwGain:=0;
if( CmbExpChan.Enabled = false) then
usExpChan:=0;
if( CmbBoardID.Enabled = false) then
usBoardID:=0;
if (gnNumOfSubdevices = 0) then
lErrCde := DRV_DeviceOpen( lDeviceNumber, lDeviceHandle)
else
lErrCde := DRV_DeviceOpen(lDeviceNumber,lDeviceHandle);
if( DoesErr(lErrCde) = 1 ) then
begin
DRV_DeviceClose(lDeviceHandle);
Exit;
end;
lErrCde := DRV_DeviceGetFeatures(lDeviceHandle,ptDevGetFeatures);
if( DoesErr(lErrCde) = 1 ) then
begin
DRV_DeviceClose(lDeviceHandle);
Exit;
end;
//
// configures the gain for the specifed analog input channel
//
if(DevCfg.Daughter[gwChannel].dwBoardID = 0) then
begin
ptAIConfig.DasGain := dfDevFeatures.glGainList[gwGain].usGainCde;
ptAIConfig.DasChan := gwChannel;
lErrCde := DRV_AIConfig(lDeviceHandle, ptAIConfig);
if( DoesErr(lErrCde) = 1 ) then
begin
DRV_DeviceClose(lDeviceHandle);
Exit;
end;
end;
frmADExp.Hide();
frmValue.Show();
frmValue.Timer1.Enabled := true;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -