tweak voltage divider for my config
[digitaldcpower] / ddcp-script-ttyinit.c
1 /* vim: set sw=8 ts=8 si et: */
2 /* Linux software to set the speed on the serial line 
3 * Written by Guido Socher 
4 * run this program like this:
5 * ttydevinit /dev/ttyUSB0 (for usb com1) and then use
6 * cat > /dev/ttyUSB0 to write or cat /dev/ttyUSB0 to read the answers
7 */
8
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include <unistd.h>
12 #include <fcntl.h>
13 #include <termios.h>
14
15 int main(int argc, char *argv[])
16 {
17         struct termios portset;
18         char *device;
19         int fd;
20
21         if (argc != 2){
22                 printf("USAGE: ddcp-script-ttyinit com-port-device\n");
23                 printf("Example, linux: ddcp-script-ttyinit /dev/ttyUSB0\n");
24                 printf("Example, mac: ddcp-script-ttyinit /dev/tty.usbserial-*\n");
25                 exit(0);
26         }
27         device=argv[1];
28
29         /* Set up io port correctly, and open it... */
30         fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
31         if (fd == -1) {
32                 fprintf(stderr, "ERROR: open for %s failed.\n",device);
33                 exit(1);
34         }
35         tcgetattr(fd, &portset);
36         cfmakeraw(&portset);
37         cfsetospeed(&portset, B9600); /* speed */
38         //cfsetospeed(&portset, B115200); /* speed */
39         //cfsetospeed(&portset, B19200); /* speed */
40         tcsetattr(fd, TCSANOW, &portset);
41         close(fd);
42         return(0);
43 }