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

📄 getevent.pas

📁 usb4711A数据采集卡的DI转换通道程序
💻 PAS
字号:
unit GetEvent;

interface

uses
  Classes, Windows, SysUtils, Driver, Event;

type
  TGetEvent = class(TThread)
  private
    { Private declarations }
  protected
    procedure Execute; override;
  end;

implementation
uses frmMain;

{ Important: Methods and properties of objects in VCL or CLX can only be used
  in a method called using Synchronize, for example,

      Synchronize(UpdateCaption);

  and UpdateCaption could look like,

    procedure GetEvent.UpdateCaption;
    begin
      Form1.Caption := 'Updated in a thread';
    end; }

{ GetEvent }

procedure TGetEvent.Execute;
var
  i: Integer;
  dwStartTime: DWORD;
  dwCurrentTime: DWORD;
  dwTime: DWORD;
  fEventCount_IDI: array [0..3] of Real;
  ratio_IDI: array [0..3] of Real;
  szBuf_IDI: array [0..3] of string[20];
  usEventType: SHORT;
  res: Integer;
begin
  { Place thread code here }
  for i := 0 to 3 do
  begin
    fEventCount_IDI[ i ] := 0.0;
  end;

  ptCheckEvent.EventType := @usEventType;
  ptCheckEvent.Milliseconds := 1000;
  dwStartTime := GetTickCount();

  while ( m_bContinue ) do
  begin
    m_bFlag := TRUE;
    res := DRV_CheckEvent( m_DriverHandle, ptCheckEvent );
    if (res  = SUCCESS) then
    begin
      if ( ptCheckEvent.EventType^ = ADS_EVT_INTERRUPT_IDI0 ) then
      begin
        fEventCount_IDI[ 0 ] := fEventCount_IDI[ 0 ] + 1;
      end;
      if ( ptCheckEvent.EventType^ = ADS_EVT_INTERRUPT_IDI1 ) then
      begin
        fEventCount_IDI[ 1 ] := fEventCount_IDI[ 1 ] + 1;
      end;
      if ( ptCheckEvent.EventType^ = ADS_EVT_INTERRUPT_DI0 ) then
      begin
        fEventCount_IDI[ 2 ] := fEventCount_IDI[ 2 ] + 1;
      end;
      if ( ptCheckEvent.EventType^ = ADS_EVT_INTERRUPT_DI1 ) then
      begin
        fEventCount_IDI[ 3 ] := fEventCount_IDI[ 3 ] + 1;
      end;
    end;

    dwCurrentTime := GetTickCount();
    dwTime := dwCurrentTime - dwStartTime;
    if ( dwTime >= 1000 ) then
    begin
      for i := 0 to 3 do
      begin
        ratio_IDI[i] := fEventCount_IDI[i] / dwTime * 1000.0;
        szBuf_IDI[i] := Format('%.3f',  [ratio_IDI[i]]);
        fEventCount_IDI[i] := 0.0;
      end;

      Form1.editIntCount_IDI0.Text := szBuf_IDI[0];
      Form1.editIntCount_IDI1.Text := szBuf_IDI[1];
      Form1.editIntCount_DI0.Text := szBuf_IDI[2];
      Form1.editIntCount_DI1.Text := szBuf_IDI[3];

      dwStartTime := GetTickCount();
    end;
  end;
end;

end.

⌨️ 快捷键说明

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