87 lines
2.5 KiB
C#
87 lines
2.5 KiB
C#
|
|
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)
|
|||
|
|
{
|
|||
|
|
int iChannel;
|
|||
|
|
IntPtr hDevice; // device object handle
|
|||
|
|
Int32 DeviceID; // device ID
|
|||
|
|
Int32 Key;
|
|||
|
|
Byte[] bDISts = new Byte[16];
|
|||
|
|
Byte[] bDOSts = new Byte[16];
|
|||
|
|
|
|||
|
|
|
|||
|
|
DeviceID = 0;
|
|||
|
|
hDevice = PCI2312.PCI2312_CreateDevice(DeviceID); // Create Device object
|
|||
|
|
if (hDevice == (IntPtr)(-1))
|
|||
|
|
{
|
|||
|
|
Console.WriteLine("CreateDevice Error...");
|
|||
|
|
_getch();
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
for (iChannel = 0; iChannel < 16; iChannel++)
|
|||
|
|
{
|
|||
|
|
if (iChannel % 2 == 0)
|
|||
|
|
bDOSts[iChannel] = 0; // ż<><C5BC>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD>Ϊ<EFBFBD>͵<EFBFBD>ƽ"0"
|
|||
|
|
else
|
|||
|
|
bDOSts[iChannel] = 1; // <20><><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD>Ϊ<EFBFBD>ߵ<EFBFBD>ƽ"1"
|
|||
|
|
}
|
|||
|
|
Repeat:
|
|||
|
|
for (iChannel = 0; iChannel < 16; iChannel++)
|
|||
|
|
{
|
|||
|
|
Console.WriteLine("bDOSts[{0}] = {1}", iChannel, bDOSts[iChannel]);
|
|||
|
|
}
|
|||
|
|
Console.WriteLine("Press any key to set DO\n\n");
|
|||
|
|
_getch();
|
|||
|
|
if (!(PCI2312.PCI2312_SetDeviceDO(hDevice, bDOSts)>0)) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
{
|
|||
|
|
Console.WriteLine("SetDeviceDO Error...\n");
|
|||
|
|
_getch();
|
|||
|
|
goto Exit;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
Console.WriteLine("\n");
|
|||
|
|
Console.WriteLine("Press any key to get DI\n\n");
|
|||
|
|
_getch();
|
|||
|
|
if (!(PCI2312.PCI2312_GetDeviceDI(hDevice, bDISts)>0)) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
{
|
|||
|
|
Console.WriteLine("PCI2312_GetDeviceDI...\n");
|
|||
|
|
_getch();
|
|||
|
|
goto Exit;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
for (iChannel = 0; iChannel < 16; iChannel++)
|
|||
|
|
{
|
|||
|
|
Console.WriteLine("bDISts[{0}] = {1}", iChannel, bDISts[iChannel]);
|
|||
|
|
}
|
|||
|
|
Console.WriteLine("\n");
|
|||
|
|
|
|||
|
|
Console.WriteLine("Press ESC to quit\n");
|
|||
|
|
Key = _getch();
|
|||
|
|
if (Key != 27) goto Repeat;
|
|||
|
|
|
|||
|
|
Exit:
|
|||
|
|
PCI2312.PCI2312_ReleaseDevice(hDevice);
|
|||
|
|
return ;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|