📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Button2: TButton;
Button3: TButton;
Button5: TButton;
Button6: TButton;
Timer1: TTimer;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button5Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
//This file contains some structure which defined by ele for
//control ac6112 control register
type
AC6112_INI_BYTE = record
ad_mode: ULONG;
start_end_chn: ULONG;
ad_timer: ULONG;
da_mode: ULONG;
kFifo_Notify_Length: ULONG;
Irq_Enable: ULONG;
Event_Enable: ULONG;
Event: ULONG;
EventFifoFull: ULONG;
end;
PAC6112_INI_BYTE = ^AC6112_INI_BYTE;
type
AC6112_STATEx = record
HardwareState: ULONG;
Irq_Enable: ULONG;
Event_Enable: ULONG;
SoftFifoCapacity: ULONG;
SoftFifoItemForRead: ULONG;
SoftFifoItemForWrite: ULONG;
end;
PAC6112_STATEx = ^AC6112_STATEx;
var
Form1: TForm1;
hDevice: ULONG;
StateOf6112: AC6112_STATEx;
buf: array[0..1] of AC6112_INI_BYTE;
ErrorOf6112: ULONG;
tempio: ULONG ;
FifoHard: array[0..5096] of ULONG; // ac6112 板载FIFO
kBuffer: array[0..500000] of ULONG;
di_data: ULONG;
tempstr: array[0..1000] of BYTE;
nOutput :ULONG;
implementation
function AC6112_CreateDevice( CardNo:ULONG; ErrorOf6112:PULONG):ULONG; stdcall; external 'ac6112.dll';
function AC6112_CloseDevice( hDevice:ULONG):Integer; stdcall; external 'ac6112.dll';
function AC6112_INI( hDevice:ULONG; initword: PAC6112_INI_BYTE ):Integer; stdcall; external 'ac6112.dll';
function AC6112_STATE( hDevice:ULONG; state: PAC6112_STATEx):Integer; stdcall; external 'ac6112.dll';
function AC6112_RUN( hDevice:ULONG):Integer; stdcall; external 'ac6112.dll';
function AC6112_AD_CHN( hDevice:ULONG; chn:ULONG):Integer; stdcall; external 'ac6112.dll';
function AC6112_STOP( hDevice:ULONG):Integer; stdcall; external 'ac6112.dll';
function AC6112_AD_MODE( hDevice:ULONG; DaMode:ULONG):Integer; stdcall; external 'ac6112.dll';
function AC6112_AD_TIMER( hDevice:ULONG; DaMode:ULONG):Integer; stdcall; external 'ac6112.dll';
function AC6112_READ_KFIFO( hDevice:ULONG; Buffer:PULONG; Length:ULONG):Integer; stdcall; external 'ac6112.dll';
function AC6112_READ_HARD_FIFO( hDevice:ULONG; Buffer:PULONG; Length:ULONG):Integer; stdcall; external 'ac6112.dll';
function AC6112_IO_MODE( hDevice:ULONG; IOMode:ULONG):Integer; stdcall; external 'ac6112.dll';
function AC6112_DI( hDevice:ULONG; DIData:PULONG):Integer; stdcall; external 'ac6112.dll';
function AC6112_DO( hDevice:ULONG; DOData:ULONG):Integer; stdcall; external 'ac6112.dll';
function AC6112_RCOUNTER( hDevice:ULONG; CounterData:PULONG):Integer; stdcall; external 'ac6112.dll';
function AC6112_WCOUNTER( hDevice:ULONG; CounterData:ULONG):Integer; stdcall; external 'ac6112.dll';
function AC6112_RTIMER( hDevice:ULONG; TimerData:PULONG):Integer; stdcall; external 'ac6112.dll';
function AC6112_DA0( hDevice:ULONG; Length:ULONG):Integer; stdcall; external 'ac6112.dll';
function AC6112_DA1( hDevice:ULONG; Length:ULONG):Integer; stdcall; external 'ac6112.dll';
function AC6112_DA_MODE( hDevice:ULONG; DaMode:ULONG):Integer; stdcall; external 'ac6112.dll';
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
label1.Caption :=inttostr(hDevice);
AC6112_IO_MODE(hDevice, 1);
AC6112_DO(hDevice, $55aa);
AC6112_DI(hDevice, @di_data);
label1.Caption := inttostr(di_data shr 8)+' '+inttostr(di_data and $ff);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
hDevice:=AC6112_CreateDevice(0, @ErrorOf6112);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
AC6112_STOP(hDevice);
if Timer1.Enabled = false then Timer1.Enabled := false;
if hDevice <> null then AC6112_CloseDevice(hDevice); //关闭设备驱动
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
AC6112_DA_MODE(hDevice, 0);
AC6112_DA0(hDevice, $fff0);
AC6112_DA1(hDevice, $8000);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
//------- AD -------------------
//---- 1简单查询法,可以在小数据量快速采集的情况下使用 -------- OK ----------
//当用户希望快速采样小量数据(比如希望采集一个数据),可以通过判断非空标志进行采集
//当启动AD采样后,发现AC6112 FIFO非空,说明至少采集了一个数据,即可读取,不必等待FIFO半满后才读取
buf[0].Irq_Enable:= 0;//禁止AC6112中断工作
buf[0].kFifo_Notify_Length:= 100000;//软件FIFO通知门限为100000采样点,此时该值无效
buf[0].start_end_chn:= 0;//起止通道为0
buf[0].ad_mode := 0;//AD采样模式为0
buf[0].da_mode := 0;//DA输出模式为0
buf[0].ad_timer := 20;//AD采样时间定时器为10
buf[0].Event_Enable := 0;//禁止使用事件通知
buf[0].Event := $ffffffff;//空事件句柄
buf[0].EventFifoFull := $ffffffff;//空事件句柄
AC6112_INI(hDevice, @buf[0]);// 设置相关参数
AC6112_RUN(hDevice);//启动AD采样
AC6112_STATE(hDevice,@StateOf6112);//读AC6112状态(状态位的含义,请参考说明书)
label2.Caption := inttostr(StateOf6112.SoftFifoCapacity );
label1.Caption := inttostr(StateOf6112.HardwareState );
repeat
AC6112_STATE(hDevice,@StateOf6112);//读AC6112状态(状态位的含义,请参考说明书)
// if((StateOf6112.HardwareState and 4) = 0) then//是否溢出
// label1.Caption := 'AD Overflow';
// label1.Caption :=inttostr(StateOf6112.HardwareState );
until (StateOf6112.HardwareState and 1) = 1;//可根据FIFO状态进行选择(如,FIFO非空,FIFO半满,FIFO溢出)
AC6112_STATE(hDevice,@StateOf6112);//读AC6112状态(状态位的含义,请参考说明书)
label2.Caption := inttostr(StateOf6112.SoftFifoCapacity );
label1.Caption := inttostr(StateOf6112.HardwareState );
AC6112_READ_HARD_FIFO(hDevice, @FifoHard[0],1);
label1.Caption := inttostr(FifoHard[0]);
AC6112_STOP(hDevice); //溢出后停止采样
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
AC6112_STATE(hDevice, @StateOf6112);//获得AC6112硬件状态,软件FIFO状态
if StateOf6112.SoftFifoItemForRead >=100000 then begin
AC6112_READ_KFIFO(hDevice, @kBuffer[0], 100000);//从软FIFO中取采样数据,长度为100000个采样点
Label2.Caption :='Hardware State = '+inttostr(StateOf6112.HardwareState)+
'Can read From KFIFO= '+inttostr(StateOf6112.SoftFifoItemForRead);
Label3.Caption :='AD Data= '+inttostr(kBuffer[0])+
' '+inttostr(kBuffer[1])+
' '+inttostr(kBuffer[2])+
' '+inttostr(kBuffer[3])+
' '+inttostr(kBuffer[4])+
' '+inttostr(kBuffer[5])+
' '+inttostr(kBuffer[6])+
' '+inttostr(kBuffer[7]);
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
//------- 2中断+查询方法---适合大数据量采集,利用事件以外的方法 --OK ------------
buf[0].Irq_Enable := 1;//允许AC6112中断工作
buf[0].kFifo_Notify_Length := 100000;//软件FIFO通知门限为100000采样点,事件无效时该值无效
buf[0].start_end_chn := 7 shl 5;//起止通道为0
buf[0].ad_mode := 0;//AD采样模式为0
buf[0].da_mode := 0;//DA输出模式为0
buf[0].ad_timer := 20;//AD采样时间定时器为10
buf[0].Event_Enable := 0;//禁止事件通知
buf[0].Event := $ffffffff;//空事件句柄
buf[0].EventFifoFull := $ffffffff;//空事件句柄
AC6112_INI(hDevice, @buf[0]);// 设置相关参数
AC6112_RUN(hDevice);//启动AD
Timer1.Interval := 55;//定时器为100ms
Timer1.Enabled :=TRUE; //启动定时器
end;
procedure TForm1.Button4Click(Sender: TObject);
var
ss: ULONG;
begin
end;
procedure TForm1.Button6Click(Sender: TObject);
var
counter_data: ULONG;
timer_data: ULONG;
begin
AC6112_WCOUNTER(hDevice, 20000);
AC6112_RCOUNTER(hDevice, @counter_data);
AC6112_RTIMER(hDevice, @timer_data);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -