3 (c) 2003-2004 Jelmer Vernooij <jelmer@samba.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <sys/termios.h>
24 #include <sys/types.h>
33 #include <sys/ioctl.h>
43 static char *available_pins[] = { "TXD", "DTR", "DSR", "RTS", "CTS", NULL };
45 static int ser_init(char *location)
47 fd = open(location?location:"/dev/ttyS0", O_RDWR | O_NOCTTY);
49 perror("Error opening serial port");
56 static int ser_close()
62 static void ser_set(int p)
66 if(ioctl (fd, TIOCMGET, &status) < 0) {
73 if(ioctl (fd, TIOCSBRK, 0) < 0) perror("ioctl");
75 case SER_PIN_DTR: status |= TIOCM_DTR; break;
76 case SER_PIN_DSR: status |= TIOCM_LE; break;
77 case SER_PIN_RTS: status |= TIOCM_RTS; break;
78 case SER_PIN_CTS: status |= TIOCM_CTS; break;
80 if(ioctl (fd, TIOCMSET, &status) < 0) perror("ioctl");
83 static void ser_clear(int p)
87 if(ioctl (fd, TIOCMGET, &status) < 0) {
94 if(ioctl (fd, TIOCCBRK, 0) < 0) perror("ioctl");
96 case SER_PIN_DTR: status &=~TIOCM_DTR; break;
97 case SER_PIN_DSR: status &=~TIOCM_LE; break;
98 case SER_PIN_RTS: status &=~TIOCM_RTS; break;
99 case SER_PIN_CTS: status &=~TIOCM_CTS; break;
101 fprintf(stderr, "Write not available for pin %s\n", available_pins[p]);
105 if(ioctl (fd, TIOCMSET, &status) < 0) perror("ioctl");
108 static int ser_get(int p)
111 if(ioctl(fd, TIOCMGET, &status) < 0) perror("ioctl");
113 case SER_PIN_DTR: return (status & TIOCM_DTR?1:0);
114 case SER_PIN_RTS: return (status & TIOCM_RTS?1:0);
115 case SER_PIN_DSR: return (status & TIOCM_DSR?1:0);
116 case SER_PIN_CTS: return (status & TIOCM_CTS?0:1);
118 fprintf(stderr, "Read not available for pin %s\n", available_pins[p]);
123 struct pins_backend serial = {