📄 eventthread.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "EventThread.h"
#include "DiintForm.h"
#include "..\..\..\..\include\driver.h"
#include "stdio.h"
#pragma package(smart_init)
extern LONG lDriverHandle;
extern BOOL bThreadStop;
char szStatus[10];
char szBuf[20];
DWORD dwCount = 0;
//---------------------------------------------------------------------------
// Important: Methods and properties of objects in VCL can only be
// used in a method called using Synchronize, for example:
//
// Synchronize(UpdateCaption);
//
// where UpdateCaption could look like:
//
// void __fastcall TEventThread::UpdateCaption()
// {
// Form1->Caption = "Updated in a thread";
// }
//---------------------------------------------------------------------------
__fastcall TEventThread::TEventThread(bool CreateSuspended)
: TThread(CreateSuspended)
{
}
//---------------------------------------------------------------------------
void __fastcall TEventThread::Execute()
{
//---- Place thread code here ----
PT_CheckEvent ptCheckEvent;
DWORD dwStartTime;
DWORD dwCurrentTime;
DWORD dwTime;
DWORD dwEventCount = 0;
float ratio;
USHORT usEventType;
strcpy(szStatus,"00000000");
ptCheckEvent.EventType = &usEventType;
ptCheckEvent.Milliseconds = 1000;
dwStartTime = GetTickCount();
while(!Terminated){
if(DRV_CheckEvent(lDriverHandle, (LPT_CheckEvent)&ptCheckEvent) == SUCCESS){
switch(usEventType)
{
case ADS_EVT_INTERRUPT_DI0 : // interrupt event from DI0
strcpy(szStatus,"00000001");
dwEventCount++;
dwCount++;
break;
default :strcpy(szStatus,"00000000");
break;
}
dwCurrentTime = GetTickCount();
if ((dwTime = dwCurrentTime - dwStartTime) > 1000)
{
ratio = (float)(((float)dwEventCount / (float)dwTime) * 1000.0);
sprintf( szBuf, "%.3f", ratio );
dwStartTime = GetTickCount();
dwEventCount = 0;
}
if(dwCount>100000){
dwCount -= 100000;
}
}
}
bThreadStop = True;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -