SSPC-Tester/Driver/急停报警相关资料/PCI2312 Samples/LabWindows/Simple/Int/Sys.c

78 lines
1.3 KiB
C
Raw Normal View History

#include "windows.h"
#include <PCI2312.H>
#include "stdio.h"
static int (__stdcall *getch)(void);
static int (__stdcall *kbhit)(void);
int main(int argc, char* argv[])
{
HANDLE hDevice;
HANDLE hEventInt;
int DeviceID;
int inIntCount = 0; // <20>ڲ<EFBFBD><DAB2>жϼ<D0B6><CFBC><EFBFBD>
int outIntCount = 0; // <20>ⲿ<EFBFBD>жϼ<D0B6><CFBC><EFBFBD>
HINSTANCE hInst = LoadLibrary("MSVCRT.DLL");
getch = GetProcAddress(hInst, "_getch");
kbhit = GetProcAddress(hInst, "_kbhit");
DeviceID = 0;
hDevice = PCI2312_CreateDevice( DeviceID );
if(hDevice == INVALID_HANDLE_VALUE)
{
printf("PCI2312_CreateDevice Error...\n");
getch();
goto Exit;
}
hEventInt = PCI2312_CreateSystemEvent();
if(hEventInt == INVALID_HANDLE_VALUE)
{
printf("\nCreate hEvent Error...\n");
getch();
goto Exit;
}
if(!PCI2312_InitDeviceInt(hDevice, hEventInt))
{
printf("Wait....\n");
getch();
}
while(!kbhit())
{
while(1)
{
if(WaitForSingleObject(hEventInt, 100) == WAIT_OBJECT_0) // <20>ȴ<EFBFBD><C8B4>жϷ<D0B6><CFB7><EFBFBD>
break;
if(kbhit()) break;
}
outIntCount++; // <20>ⲿ<EFBFBD>жϼ<D0B6><CFBC><EFBFBD>
inIntCount = PCI2312_GetDeviceIntCount(hDevice); // <20><><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2>жϼ<D0B6><CFBC><EFBFBD>
printf("outIntCount=%d, inIntCount=%d\n", outIntCount, inIntCount);
}
Exit:
PCI2312_ReleaseDeviceInt(hDevice); // <20>ͷ<EFBFBD><CDB7>ж<EFBFBD><D0B6><EFBFBD>Դ
PCI2312_ReleaseDevice(hDevice); // <20>ͷ<EFBFBD><CDB7><EFBFBD><E8B1B8><EFBFBD><EFBFBD>
return 0;
}