int main ( int argc, char *argv[] ){ if ( argc != 2 ) /* argc should be 2 for correct execution */ { fprintf(stderr,"usage: %s valve_position\ne.g. \"./riech-o-mat 11000\"\n", argv[0] ); } else { /* Open device*/ devHandle = IowKitOpenDevice(); if (devHandle == NULL) { fprintf(stderr, "Error opening device \"iowarior\". make sure it's connected.\n"); exit(1); } /* Convert command line arg to dword*/ DWORD valvepos = 0xFFFF; int bitpos = 0; char* cp; for (cp = argv[1]; *cp != 0; ++cp, ++bitpos) { DWORD bit = (isValveOnChar(*cp) ? 1 : 0); valvepos = valvepos ^ (bit << bitpos); } iowHandle = IowKitGetDeviceHandle(1); IowKitSetWriteTimeout(iowHandle, 10); WriteSimple(iowHandle,valvepos); IowKitCloseDevice(devHandle); } return 0; }
int init() { if (iow == NULL) { iow = IowKitOpenDevice(); if (iow == NULL) { printf("No device!\n"); fflush(stdout); return 2; } else { WCHAR sn[9]; IowKitGetSerialNumber(iow, sn); printf("PID %x, S/N \"%ws\"\n\n", IowKitGetProductId(iow), sn); fflush(stdout); return 1; } //else } else { IowKitCloseDevice(iow); return 0; } //else } //init