📄 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;
case ADS_EVT_INTERRUPT_DI1 : // interrupt event from DI1
strcpy(szStatus,"00000010");
dwEventCount++;
dwCount++;
break;
case ADS_EVT_INTERRUPT_DI2 : // interrupt event from DI2
strcpy(szStatus,"00000100");
dwEventCount++;
dwCount++;
break;
case ADS_EVT_INTERRUPT_DI3 : // interrupt event from DI3
strcpy(szStatus,"00001000");
dwEventCount++;
dwCount++;
break;
case ADS_EVT_INTERRUPT_DI4 : // interrupt event from DI4
strcpy(szStatus,"00010000");
dwEventCount++;
dwCount++;
break;
case ADS_EVT_INTERRUPT_DI5 : // interrupt event from DI5
strcpy(szStatus,"00100000");
dwEventCount++;
dwCount++;
break;
case ADS_EVT_INTERRUPT_DI6 : // interrupt event from DI6
strcpy(szStatus,"01000000");
dwEventCount++;
dwCount++;
break;
case ADS_EVT_INTERRUPT_DI7 : // interrupt event from DI7
strcpy(szStatus,"10000000");
dwEventCount++;
dwCount++;
break;
case ADS_EVT_INTERRUPT:
strcpy(szStatus,"Happened"); //for old envent: not sepcify the bit
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 );
dwEventCount = 0;
dwStartTime = GetTickCount();
}
if(dwCount>100000){
dwCount -= 100000;
}
}
}
bThreadStop = True;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -