X-Git-Url: http://git.rot13.org/?p=digitaldcpower;a=blobdiff_plain;f=ddcp-script-ttyinit.c;fp=ddcp-script-ttyinit.c;h=238c0023dd802bd2558f83902315001ff775c368;hp=0000000000000000000000000000000000000000;hb=93791a25a42c0d48fa5a62c41d5907fae5829fee;hpb=1d6d9149f9b438f797a7af85c0454e38a2767a95 diff --git a/ddcp-script-ttyinit.c b/ddcp-script-ttyinit.c new file mode 100644 index 0000000..238c002 --- /dev/null +++ b/ddcp-script-ttyinit.c @@ -0,0 +1,42 @@ +/* vim: set sw=8 ts=8 si et: */ +/* Linux software to set the speed on the serial line +* Written by Guido Socher +* run this program like this: +* ttydevinit /dev/ttyUSB0 (for usb com1) and then use +* cat > /dev/ttyUSB0 to write or cat /dev/ttyUSB0 to read the answers +*/ + +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + struct termios portset; + char *device; + int fd; + + if (argc != 2){ + printf("USAGE: ddcp-script-ttyinit /dev/ttyUSB0\n"); + printf("or ddcp-script-ttyinit /dev/ttyUSB1\n"); + exit(0); + } + device=argv[1]; + + /* Set up io port correctly, and open it... */ + fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY); + if (fd == -1) { + fprintf(stderr, "ERROR: open for %s failed.\n",device); + exit(1); + } + tcgetattr(fd, &portset); + cfmakeraw(&portset); + cfsetospeed(&portset, B9600); /* speed */ + //cfsetospeed(&portset, B115200); /* speed */ + //cfsetospeed(&portset, B19200); /* speed */ + tcsetattr(fd, TCSANOW, &portset); + close(fd); + return(0); +}