#include #include #include #include "apcilib.h" int open_dev_file(); int main(int argc, char *argv[]) { __u8 RelayData[2]; int Result0, Result1; int fd; if ( argc < 1 ) { puts("Usage: PI16 [new relay mask, in hex]"); puts("Example: PI16 AA55"); return -1; } Result0 = sscanf(argv[1], "%X", &RelayData); if ( Result0 != 1 ) { printf("Error %d from sscanf reading \"%s\".\n", Result0, argv[1]); return -2; } fd = open_dev_file(); Result0 = apci_write8(fd, 0, 2, 0, RelayData[0]); Result1 = apci_write8(fd, 0, 2, 4, RelayData[1]); printf("Wrote %02X%02X (Got %d/%d)\n", RelayData[1], RelayData[0], Result0, Result1); Result0 = apci_read8(fd, 0, 2, 0, &RelayData[0]); Result1 = apci_read8(fd, 0, 2, 4, &RelayData[1]); printf("Read Back %02X%02X (Got %d/%d)\n", RelayData[1], RelayData[0], Result0, Result1); close(fd); return 0; } int open_dev_file() { int fd; fd = open("/dev/apci", O_RDONLY); if (fd < 0) { printf("Device file could not be opened. Please ensure the iogen driver module is loaded.\n"); exit(0); } return fd; }