#include "windows.h" #include #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; // 内部中断计数 int outIntCount = 0; // 外部中断计数 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) // 等待中断发生 break; if(kbhit()) break; } outIntCount++; // 外部中断计数 inIntCount = PCI2312_GetDeviceIntCount(hDevice); // 获得内部中断计数 printf("outIntCount=%d, inIntCount=%d\n", outIntCount, inIntCount); } Exit: PCI2312_ReleaseDeviceInt(hDevice); // 释放中断资源 PCI2312_ReleaseDevice(hDevice); // 释放设备对象 return 0; }