/* $Id: k74.c,v 1.6 2000/09/08 12:13:31 root Exp root $ k74, kitsrus.com kit 74 parallel port relay driver Copyright (C) 2000 James Cameron (quozl@us.netrek.org) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef lint static char vcid[] = "$Id: k74.c,v 1.6 2000/09/08 12:13:31 root Exp root $"; #endif /* lint */ #include #include #include #include #include /* port access functions borrowed from prog84 */ int dev_port_fd = -1; void open_io() { dev_port_fd = open("/dev/port", O_RDWR); if(dev_port_fd < 0) { perror("/dev/port"); exit(errno); } } void close_io() { close(dev_port_fd); dev_port_fd = -1; } void out_byte(int port, unsigned char byte) { off_t s; int r; s = lseek(dev_port_fd, port, 0); if (s < 0) perror("lseek"); else if (s != port) fprintf(stderr, "hmmm: seeking to %d, went to %ld.\n", port, (long)s); r = write(dev_port_fd, &byte, 1); if (r != 1) { fprintf(stderr, "hmmm: write returned %d\n", r); if (r < 0) perror("write"); } } unsigned char in_byte(int port) { off_t s; int r; unsigned char ch = 0; s = lseek(dev_port_fd, port, 0); if (s < 0) perror("lseek"); else if (s != port) fprintf(stderr, "hmmm: seeking to %d, went to %ld.\n", port, (long)s); r = read(dev_port_fd, &ch, 1); if (r != 1) { fprintf(stderr, "hmmm: read returned %d\n", r); if (r < 0) perror("read"); } return ch; } static void copyright() { fprintf(stderr, "Kit 74 Parallel Port Relay Driver, 1.0\n" "Copyright (C) 2000 James Cameron (quozl@us.netrek.org)\n" "%s\n\n" "This program comes with ABSOLUTELY NO WARRANTY; for details see source.\n" "This is free software, and you are welcome to redistribute it under certain\n" "conditions; see source for details.\n\n", vcid); } static void usage() { copyright(); fprintf(stderr, "Usage: k74 [options] [bit] [command] ...\n" "\n" "Options\n" " -v --verbose issue copyright statement during operation\n" " -V --version display version information\n" " -h --help display program usage information\n" " -p --port n set parallel port for next operation (0,1,2)\n" " (n may also be 0x378, 0x278, or 0x3bc)\n" "Bits\n" " n bit number, zero through seven\n" " all all bits, mask 0xff\n" " lower lower half of byte, mask 0x0f\n" " upper upper half of byte, mask 0xf0\n" "\n" "Commands\n" " set set the bits\n" " clear clear the bits\n" " toggle change the state of the bits\n" " write n write decimal number n to the port\n" " read read the port and print on stdout in decimal\n" " watch continuous read and report changes\n" "\n" "Examples\n" " # k74 all set (turns on all bits)\n" " # k74 6 clear (turns off bit six)\n" ); } int main ( int argc, char *argv[] ) { int i, bit, port = 0x378; open_io(); /* process command line arguments */ for(i=1;i