⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sys.dpr

📁 Delphi编的板卡内部程序。分享给大家
💻 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 SelectOutputRange() : Integer;
var
  OutputRange : LongInt;
begin
  Repeat
  Writeln('0.  0V    ~ +5V');
  Writeln('1.  0V    ~ +10V');
  Writeln('2. -5V   ~ +5V');
  Writeln('3. -10V  ~ +10V');
  Writeln('Please Select Input Range[0-3]:');
  Readln(OutputRange);
  until(OutputRange>=0) and (OutputRange<=3);   // 判断用户选择的量程是否合法,不合法,则重新选择

  SelectOutputRange := OutputRange;

end;

Var
  hDevice       : LongInt;                    // 设备对象句柄
  DeviceLgcID   : Integer;                    // 物理设备ID号(由板上JP1决定)
  bFirstWait    : Boolean = True;             // 为每次等待只显示一次提示
  nDAChannel    : Integer = 0;
  OutputRange   : Integer = 0;
  nDAData       : SmallInt = 0;
  Voltage       : Single;
  bRetStatus    : Boolean;                    // 函数的返回值
  Key           : Integer;

  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;

	OutputRange            := SelectOutputRange();      // 要求用户从键盘上选择输入量程

Repeat
	Writeln('Please Input nDAChannel[0, 4]:');
	Readln(nDAChannel);
	Writeln('Please Input Voltage[mV]:');
	Readln(Voltage);

	// 将原码转换为电压值
	case OutputRange of
	PCI8613_OUTPUT_0_P5000mV:                         // 0 - +5V
		nDAData := trunc(Voltage/(5000.0/4096));
	PCI8613_OUTPUT_0_P10000mV:                        // 0 - +10V
		nDAData := trunc(Voltage/(10000.0/4096));
	PCI8613_OUTPUT_N5000_P5000mV:                     // -5V - +5V
		nDAData := trunc(Voltage/(10000.0/4096) + 2048);
	PCI8613_OUTPUT_N10000_P10000mV:                   // -10V - +10V
		nDAData := trunc(Voltage/(20000.0/4096) + 2048);
  else
  end;
	// 控制边界
	if(nDAData > 4095) then
   nDAData := 4095;
	if(nDAData < 0) then
    nDAData := 0;

	Writeln(Format('nDAData = %d', [nDAData]));
	bRetStatus := PCI8613_InitDevProDA(hDevice, OutputRange, nDAChannel);
	if(bRetStatus = FALSE) then
  begin
		Writeln('InitDeviceDA Error...');
		getch();
    goto ExitRead0;
	end;

	bRetStatus := PCI8613_WriteDevProDA(hDevice, nDAData, nDAChannel);
	if (bRetStatus = FALSE) then
  begin
    Writeln('WriteDeviceDA Error...');
		getch();
    goto ExitRead0;
  end;

	Writeln('Press ESC to quit, other key to continue...');
	Key := getch();
  Writeln;
  Until (Key = 27);

ExitRead0:
	getch();
	PCI8613_ReleaseDevice( hDevice );                 // 释放设备对象
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -