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

📄 eventthread.pas

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

interface


uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls,Global,Driver,event;

type
  PT_ThreadData = Record
                  lDriverHandle:    Longint;
                  stCounts:         ^TStaticText;
                  stFrequency:      ^TStaticText;
                  stIntSource:      ^TStaticText;
   end;

  TEventThread = class(TThread)
  private
    { Private declarations }
  protected
    procedure Execute; override;

  public
    MData         : PT_ThreadData;
    constructor Create(TData: PT_ThreadData);
  end;

implementation



{ 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 TEventThread.UpdateCaption;
    begin
      Form1.Caption := 'Updated in a thread';
    end; }

{ TEventThread }

constructor TEventThread.Create(TData: PT_ThreadData);
Begin
	MData := TData;

	inherited Create(True);

End;

procedure TEventThread.Execute;
var
    ptCheckEvent: PT_CheckEvent;
    dwStartTime    :Longint;
    dwCurrentTime  :Longint;
    dwTime         :Longint;
    dwEventCount   :Longint;
    ratio          :Single;
    usEventType    :Smallint;

begin
  { Place thread code here }

    dwCount := 0;
    dwEventCount := 0;
    szStatus := '00000000';
    ptCheckEvent.EventType := @usEventType;
    ptCheckEvent.Milliseconds := 1000;
    dwStartTime := GetTickCount();
    while(not Terminated)do
    begin
       if(DRV_CheckEvent(MData.lDriverHandle, ptCheckEvent) = SUCCESS)then
       begin
           case usEventType of
		ADS_EVT_INTERRUPT_DI0:           // interrupt event from DI1
                begin
                    szStatus:='00000001';
                    dwEventCount := dwEventCount+1;
                    dwCount := dwCount+1;
                end;
           else

                szStatus:='00000000';
           end;
           dwCurrentTime := GetTickCount();
           dwTime := dwCurrentTime - dwStartTime;

           if (dwTime > 1000)then
           begin
               ratio := (dwEventCount / dwTime) * 1000.0;
	       szBuf := FloatToStr(ratio);
	       dwEventCount := 0;
               dwStartTime := GetTickCount();
           end;
           if(dwCount>100000)then
           begin
               dwCount := dwCount - 100000;
           end;


       end;
    end;
end;

end.

⌨️ 快捷键说明

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