/* file: daq_test0.c $Id: daq_test0.c,v 1.2 2003/07/24 18:59:46 developer Exp developer $ Test program for DIY Electronics Kit 93 PC Data Acquisition UNIT (DAQ). This is intended to work with the Linux device driver "daq.c". daq_test0 [-i | -a] By default, this program sends the following sequence of bytes to the digital output (DOUT) pins of the data acquisition device: 00000001 00000011 ... 01111111 11111111 00000000 Hit the "enter" key to advance to the next output pattern. The program will terminate when it has cycled once through the nine patterns. There are two command-line options: -i Test the digital input capability. In this case, "enter" causes the program to re-read and display the DIN values. You will need to use ^C to terminate the program. -n where n is an integer between 0 and 10. Test the analog output capability, by setting it to n volts (assuming DAQ internal jumper is set for 10 volt range). Hit the "enter" key to terminate the program. --Ted Baker, 24 July 2003 */ #include #include #include #include #include #include #include #include #define DAQ_NAME "/dev/daq" void usage(void) { fprintf (stderr, "usage: daq_test [ -i | -n ]\n"); fprintf (stderr, "tests the functionality of the gizmo\n"); fprintf (stderr, "\n"); fprintf (stderr, " no options \t test the LEDs\n"); fprintf (stderr, "\n"); fprintf (stderr, " -n \t\t test the solenoid\n"); fprintf (stderr, " \t\t where n is the volts applied to the solenoid\n"); fprintf (stderr, " \t\t voltage values can be between 0-10\n"); fprintf (stderr, "\n"); fprintf (stderr, " -i \t\t tests the digital input capability\n"); exit (-1); } int main(const int argc, const char * argv[]) { int gfd; unsigned char i; unsigned data; if ((gfd = open (DAQ_NAME, O_RDWR)) < 0) { perror ("open: " DAQ_NAME); return -1; } if (argc > 2) usage(); if ((argc == 2) && (!strcmp (argv[1],"-i"))) { /* test digital input */ fprintf (stderr, "testing digital input (DIN)\n"); fprintf (stderr, "(Try applying signal to a pin and hitting \n" "to see if it changes the output. Use ^C to quit.\n\n"); for (;;) { if (read (gfd, &data, 2) != 2) { perror ("read: " DAQ_NAME); return -1; } fprintf (stderr, "digital input bit values:\n"); for (i=0; i<16; i++) { fprintf (stderr, " %2d", i); } fprintf (stderr, "\n"); for (i=0; i<16; i++) { fprintf (stderr, " %1d", (data >> i) & 0x01); } fprintf (stderr, "\n"); getc(stdin); } } else if (argc == 2) { if (argv[1][0] != '-') usage(); errno = 0; data = strtol(argv[1] + 1, NULL, 10); if (errno || (data < 0) || (data > 10)) usage(); /* test analog output (AOUT) */ fprintf (stderr, "testing analog output (AOUT) at %2d volts\n", data); if (write (gfd, &data, 2) != 2) { perror ("write (analog) " DAQ_NAME); exit (-1); } getc(stdin); data = 0; fprintf (stderr, "wrote 0x%2.2x, awaiting keyboard input\n", i); if (write (gfd, &data, 2) != 2) { perror ("write (analog) " DAQ_NAME); exit (-1); } fprintf (stderr, "wrote 0x%2.2x, done\n", i); } else { /* test digital output (DOUT) */ fprintf (stderr, "testing digital output (DOUT) with 8 patterns\n"); i = 0; do { i=i*2+1; if (write (gfd, &i, 1) != 1) { perror ("write (digital) " DAQ_NAME); return -1; } fprintf (stderr, "wrote 0x%2.2x, awaiting keyboard input\n", i); getc(stdin); } while (i < 255); i = 0; if (write (gfd, &i, 1) != 1) { perror ("write" DAQ_NAME); return -1; } fprintf (stderr, "wrote 0x%2x, done\n", i); } return 0; }