#include "dioapp.h" HANDLE hPort; DWORD DIO_Dir; DWORD dwBytesRead, dwBytesWritten; DWORD settings; hPort=CreateFile(TEXT("DIO1:"), //port name (UNICODE compatible) GENERIC_READ | GENERIC_WRITE, //open for read-write 0, //com port cannot be shared NULL, //always NULL for Windows CE OPEN_EXISTING, //for communication resource 0, //non-overlapped operation only NULL); //always NULL for Windows CE
if(hPort!=INVALID_HANDLE_VALUE) { DeviceIoControl(hPort,DIO_IOCTL_GET_DIRECTION,NULL, 0,&DIO_Dir,DIO_SIZE,&dwBytesRead,NULL); DIO_Dir |= 0x0000C000;//set bits 14 and 15 high to enable //CPLDIO3 and 4 as outputs DeviceIoControl(hPort,DIO_IOCTL_SET_DIRECTION,&DIO_Dir, DIO_SIZE,NULL,0,&dwBytesWritten,NULL); ReadFile(hPort,&settings,4,&dwBytesRead, NULL); while(1) { settings &= 0xFFFFEFFF;//set bit 15 low WriteFile(hPort, &settings, 4, &dwBytesWritten, NULL); settings |= 0x00008000;//set bit 15 high WriteFile(hPort, &settings, 4, &dwBytesWritten, NULL); } CloseHandle(hPort); }
|