SSPC-Tester/Driver/急停报警相关资料/PCI2312 Samples/C#/Simple/INT/Program.cs

71 lines
2.1 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Threading;
namespace Sys
{
class Program
{
[DllImport("msvcrt.dll")]
public static extern int _getch();
[DllImport("msvcrt.dll")]
public static extern int _kbhit();
[DllImport("Kernel32.dll")]
public static extern int WaitForSingleObject(IntPtr hHandle, int dwMillisenconds);
static void Main(string[] args)
{
IntPtr hDevice; // device object handle
IntPtr hEventInt; // Interruption handle
Int32 DeviceID; // device ID
int inIntCount = 0; // <20>ڲ<EFBFBD><DAB2>жϼ<D0B6><CFBC><EFBFBD>
int outIntCount = 0; // <20>ⲿ<EFBFBD>жϼ<D0B6><CFBC><EFBFBD>
DeviceID = 0;
hDevice = PCI2312.PCI2312_CreateDevice(DeviceID); // Create Device object
if (hDevice == (IntPtr)(-1))
{
Console.WriteLine("CreateDevice Error...");
_getch();
return;
}
hEventInt = PCI2312.PCI2312_CreateSystemEvent();
if (hEventInt == (IntPtr)(-1))
{
Console.WriteLine("CreateSystemEvent Error...");
_getch();
goto Exit;
}
PCI2312.PCI2312_InitDeviceInt(hDevice, hEventInt);
Console.WriteLine(" wait...\n ");
while (_kbhit() == 0)
{
while (true)
{
if (WaitForSingleObject(hEventInt, 100) == 0) // <20>ȴ<EFBFBD><C8B4>жϷ<D0B6><CFB7><EFBFBD>
break;
if (_kbhit() != 0) break;
}
outIntCount++; // <20>ⲿ<EFBFBD>жϼ<D0B6><CFBC><EFBFBD>
inIntCount = PCI2312.PCI2312_GetDeviceIntCount(hDevice); // <20><><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2>жϼ<D0B6><CFBC><EFBFBD>
Console.WriteLine("outIntCount={0}, inIntCount={1}", outIntCount, inIntCount);
}
Exit:
PCI2312.PCI2312_ReleaseDeviceInt(hDevice); // <20>ͷ<EFBFBD><CDB7>ж<EFBFBD><D0B6><EFBFBD>Դ
PCI2312.PCI2312_ReleaseDevice(hDevice); // <20>ͷ<EFBFBD><CDB7><EFBFBD><E8B1B8><EFBFBD><EFBFBD>
return;
}
}
}