// 本程序演示目的:将开关量输出偶数通道置成关状态,将奇数通道置成开关状态。 // 另外读回开关量输入状态。 #include "stdafx.h" #include "windows.h" #include "stdio.h" #include "conio.h" #include "PCI2312.h" int main(int argc, char* argv[]) { int iChannel; BYTE bDISts[16], bDOSts[16]; HANDLE hDevice; int DeviceLgcID = 0; hDevice = PCI2312_CreateDevice(DeviceLgcID); if(hDevice == INVALID_HANDLE_VALUE) { printf("CreateDevice 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"); char Key; printf("Press ESC to quit\n"); Key = _getch(); if(Key != 27) goto Repeat; Exit: PCI2312_ReleaseDevice(hDevice); return 0; }