> From: "James Bean" <[EMAIL PROTECTED]> > Has anyone every setup an external open/close relay, off say a serial > interface, and have an extension trigger the relay?
The following will do the trick. Just add a 5vdc solid state relay ('cause you can't sink too much current out of the RS232C port). Substitute "2", "4" or "6" in the code below to turn on either DTR, RTS or both signals. "0" for off. Change SWDEV in the lpswitch.h file to be the serial port you intend to use for the relay. I'm using some optically isolated relays I found in town for $5.00 Cdn. The box to put it in cost more than the relay. There is a bunch of extra defines in the .h file that were needed for the larger project this was part of. Just ignore them, they won't hurt. Call this program from your dialplan, and voila. Compile with cc -i lpon.c -o lpon /* * lpon.c Lineprinter ON * *** test program only ** * * (c) David Cook, 1994 * * Set signlal lines on serial port to turn on 5vdc * signal. Used for solid-state relay (low current * draw on RS232C port) to switch high voltage/high * current load for printer. * * Part of an intelligent print spooler to only power * on/off high draw printer when required. * * Usage: lpon <device> <bits to set> * For example, lpon /dev/cua4 4 to set bit 3 on * port /dev/cua4. * "4" = 00000100 or bit 3 which is DTR * "2" = 00000010 or bit 2 which is RTS * "6" = 00000110 or both DRT & RTS */ #include <sys/types.h> #include <sys/ioctl.h> #include <termios.h> #include <fcntl.h> #include <errno.h> #include <stdlib.h> #include <unistd.h> #include <stdio.h> #include <signal.h> #include "lpswitch.h" /* Main program. */ int main(int argc, char **argv) { struct termios port_config; int fd; int set_bits = 6; /* Open monitor device. */ if ((fd = open(SWDEV, O_RDWR | O_NDELAY)) < 0) { fprintf(stderr, "lpswtich: %s: %s\n", SWDEV, sys_errlist[errno]); exit(1);} cfmakeraw( &port_config ); port_config.c_iflag=port_config.c_iflag|IXON; port_config.c_oflag=port_config.c_oflag|CLOCAL|~CRTSCTS; tcsetattr( fd, TCSANOW, &port_config ); ioctl(fd, TIOCMSET, &set_bits ); sleep(5); close(fd); } /* lpswitch.h * include file for lpswitchd configuration * (c) 1994, David Cook <[EMAIL PROTECTED]> */ #include<termios.h> #define FILTERDEUG 0 /* filter app debug */ #define DAEMONDEBUG 0 /* daemon app debug */ #define VERSION "0.6" /* appl version number*/ #define LOCKF "/var/run/lpswitchd.pid" /* lock/PID file */ #define READYFILE "/tmp/lpready" /* printer ready file */ #define RQSTFILE "/tmp/lprequest" /* lprequest file */ #define LPDEV "/dev/lp0" /* physical lp device */ #define SWDEV "/dev/ttyC0" /* switch port-HW box */ #define SPEED B9600 /* port baud rate */ #define RESET B0 /* reset by 0 speed */ #define WARMUP 45 /* 45 sec warmup delay*/ #define IDLE 1200 /* 1200 seconds (20min) idle delay */ #define XON 17 /* XON character */ #define XOFF 19 /* XOFF character */ #define ABORTTIME 90 /* Max before abort */ dbc. David Cook _______________________________________________ Asterisk-Users mailing list Asterisk-Users@lists.digium.com http://lists.digium.com/mailman/listinfo/asterisk-users To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users