?? sys.dpr
字號:
program Sys;
{$APPTYPE CONSOLE}
uses
SysUtils,
PCI8613 in 'PCI8613.pas';
Function getch() : Integer; Stdcall; External'MSVCRT.DLL' name'_getch';
Function kbhit() : Integer; Stdcall; External'MSVCRT.DLL' name'_kbhit';
Function WaitForSingleObject(hHandle: LongInt; dwMilliseconds: LongWord) : LongWord; Stdcall; External'kernel32.dll' name'WaitForSingleObject';
// 獲得用戶選擇的輸入量程
Function SelectInputRange() : Integer;
var
InputRange : LongInt;
begin
Repeat
Writeln('0. -10V ~ +10V');
Writeln('1. -5V ~ +5V');
Writeln('2. 0V ~ +10V');
Writeln('Please Select Input Range[0-2]:');
Readln(InputRange);
until(inputRange>=0) and (InputRange<=2); // 判斷用戶選擇的量程是否合法,不合法,則重新選擇
SelectInputRange := InputRange;
end;
Var
hDevice : LongInt; // 設備對象句柄
DeviceLgcID : Integer; // 物理設備ID號(由板上JP1決定)
ADPara : PCI8613_PARA_AD; // 硬件參數
ADStatus : PCI8613_STATUS_AD;
bFirstWait : Boolean = True; // 為每次等待只顯示一次提示
Index : Integer;
nADChannel : Integer = 0;
ADData : SmallInt;
fVolt : Single;
InputRange : Integer;
bReturn : Boolean;
ADBuffer : Array [0..8191] of LongWord;
nReadSizeWords: LongInt; // 每次讀取AD數據的長度(字)
nRetSizeWords : LongInt;
Label ExitRead0;
Label ExitRead1;
begin
{ TODO -oUser -cConsole Main : Insert code here }
DeviceLgcID := 0;
hDevice := PCI8613_CreateDevice(DeviceLgcID); // 創建設備對象
if(hDevice = -1) then
begin
Writeln('Create Device Error!');
getch();
exit; // 如果創建設備對象失敗,則返回
end;
InputRange := SelectInputRange(); // 要求用戶從鍵盤上選擇輸入量程
// 預置硬件參數
ADPara.ADMode := PCI8613_ADMODE_SEQUENCE; // AD模式為連續模式
ADPara.FirstChannel := 0; // 首通道
ADPara.LastChannel := 3; // 末通道
ADPara.Frequency := 10000; // 采樣頻率(Hz)
ADPara.GroupInterval := 50; // 組間間隔(uS)
ADPara.LoopsOfGroup := 1; // 組內各通道點數
ADPara.Gains := PCI8613_GAINS_1MULT;
ADPara.InputRange := InputRange; // 模擬量輸入量程范圍
ADPara.TriggerMode := PCI8613_TRIGMODE_SOFT; // 觸發模式為軟件觸發
ADPara.TriggerSource := PCI8613_TRIGSRC_ATR; // 觸發源
ADPara.TriggerType := PCI8613_TRIGTYPE_EDGE; // 觸發類型為邊沿觸發
ADPara.TriggerDir := PCI8613_TRIGDIR_NEGATIVE; // 觸發方向為負向
ADPara.TrigWindow := 40; // 觸發靈敏度
ADPara.ClockSource := PCI8613_CLOCKSRC_IN; // 時鐘源選用板內時鐘源
ADPara.bClockOutput := 0; // 禁止時鐘輸出
ADPara.GroundingMode := PCI8613_GNDMODE_SE; // 單端方式(SE:Single end)
ADPara.TimeoutForNpt := 10; // 在非空方式下,設置超時時間為10秒鐘(只在非空查詢方式下有效)
bReturn :=PCI8613_InitDeviceProAD(hDevice, @ADPara);
if(bReturn = False) then // 初始化硬件
begin
Writeln('PCI8613_InitDeviceDmaAD Error ...');
getch();
goto ExitRead1;
end;
nReadSizeWords := 1024*4; // 將數據長度字轉換為雙字
if PCI8613_StartDeviceProAD(hDevice) = false then // 啟動設備
begin
Writeln(' StartDeviceAD Error... ');
getch();
goto ExitRead0;
end;
While( kbhit()= 0 ) do // While( kbhit() = 0 ) do
begin
bFirstWait := TRUE;
while(TRUE) do // 查詢當前物理緩沖區數據是否已準備就緒
begin
if PCI8613_GetDevStatusProAD(hDevice, @ADStatus) = false then
begin
Writeln('GetDevStatusProAD Error...');
getch();
goto ExitRead0;
end;
if ADStatus.bHalf = 1 then
begin
break; // 若板載FIFO存儲器數據量達到半滿以上,則退出狀態查詢,開始讀取半滿數據
end
else
begin
if bFirstWait = true then
begin
writeln('請等待,您可以按任意鍵退出,但請不要直接關閉窗口強制退出...');
bFirstWait := FALSE;
end;
if(kbhit()<>0) then
goto ExitRead0; // 如果用戶按鍵,則退出
end;
end; // while(TRUE) do
if(PCI8613_ReadDeviceProAD_Half(hDevice, @ADBuffer, nReadSizeWords, @nRetSizeWords)= false ) then
begin
writeln('ReadDeviceProAD_Half Error...');
getch();
goto ExitRead0;
end;
fVolt := 0;
nADChannel := ADPara.FirstChannel;
for index := 0 to 63 do
begin
if kbhit()<> 0 then
goto ExitRead0;
ADData := ADBuffer[Index] and $0FFF;
// 將原碼轉換為電壓值
case InputRange of
PCI8613_INPUT_N10000_P10000mV: // -10V - +10V
fVolt := ADData*(20000.00/4096) - 10000.00;
PCI8613_INPUT_N5000_P5000mV: // -5V - +5V
fVolt := ADData*(10000.00/4096) - 5000.00;
PCI8613_INPUT_0_P10000mV: // 0V - +10V
fVolt := ADData*(10000.00/4096);
else
end;
Write(format('CH%d=%6.2f ',[nADChannel, fVolt])); // 顯示電壓值
nADChannel := nADChannel + 1;
if nADChannel > ADPara.LastChannel then
begin
nADChannel := ADPara.FirstChannel;
writeln;
end;
end;
end; // While(PCI8613_kbhit() = true) do
ExitRead0:
getch();
PCI8613_ReleaseDeviceProAD(hDevice); // 釋放AD
ExitRead1:
PCI8613_ReleaseDevice(hDevice); // 釋放設備對象
getch();
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -