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

80 lines
1.6 KiB
C

#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[])
{
BYTE bDISts[16];
BYTE bDOSts[16];
int iChannel;
char Key;
HANDLE hDevice;
int DeviceLgcID = 0;
HINSTANCE hInst = LoadLibrary("MSVCRT.DLL");
getch = GetProcAddress(hInst, "_getch");
kbhit = GetProcAddress(hInst, "_kbhit");
hDevice = PCI2312_CreateDevice(DeviceLgcID);
if(hDevice == INVALID_HANDLE_VALUE)
{
printf("Create Device Error...\n");
getch();
return 0;
}
// 强烈建议对于所有硬件参数结构都必须初始化成确定值
memset(bDOSts, 0x00, sizeof(bDOSts));
for(iChannel=0; iChannel<16; iChannel++)
{
if(iChannel%2 == 0)
bDOSts[iChannel] = 0; // 偶数通道赋为低电平"0"
else
bDOSts[iChannel] = 1; // 奇数通道赋为高电平"1"
}
Repeat:
for(iChannel=0; iChannel<16; iChannel++)
{
printf("bDOSts[%d] = %d\n", iChannel, bDOSts[iChannel]);
}
printf("Press any key to set DO\n\n");
getch();
if(!PCI2312_SetDeviceDO(hDevice, bDOSts)) // 开关量输出
{
printf("SetDeviceDO Error...\n");
getch();
goto Exit;
}
printf("\n");
printf("Press any key to get DI\n\n");
getch();
if(!PCI2312_GetDeviceDI(hDevice, bDISts)) // 开关量输入
{
printf("PCI2312_GetDeviceDI...\n");
getch();
goto Exit;
}
for(iChannel=0; iChannel<16; iChannel++)
{
printf("bDISts[%d] = %d\n", iChannel, bDISts[iChannel]);
}
printf("\n");
printf("Press ESC to quit\n");
Key = getch();
if(Key != 27) goto Repeat;
Exit:
PCI2312_ReleaseDevice(hDevice);
return 0;
}