Script interface (ddcp-script) support for windows
[digitaldcpower] / ddcp-script-setval.c
1 /* vim: set sw=8 ts=8 si et: */
2 /* 
3  * Linux software to communicate with the DDCP
4  * Written by Guido Socher 
5  */
6
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <unistd.h>
10 #include <string.h>
11 #include <fcntl.h>
12 #include <termios.h>
13
14 int main(int argc, char *argv[])
15 {
16         char *device;
17         char *str;
18         int fd;
19
20         if (argc != 3){
21                 printf("USAGE: ddcp-script-setval \"command\" com-port-device\n");
22                 printf("Example, linux: ddcp-script-setval \"u=33\" /dev/ttyUSB0\n");
23                 printf("Example, mac: ddcp-script-setval \"u=33\" /dev/tty.usbserial-*\n");
24                 exit(0);
25         }
26         str=argv[1];
27         device=argv[2];
28
29         /* Set up io port correctly, and open it... */
30         fd = open(device, O_WRONLY );
31         if (fd == -1) {
32                 fprintf(stderr, "ERROR: open for %s failed.\n",device);
33                 exit(1);
34         }
35         write(fd,"\r",1); 
36         usleep(100000); // commands are polled in the avr and it can take 100ms
37         write(fd,str,strlen(str)); 
38         write(fd,"\r",1); 
39         close(fd);
40         usleep(150000);
41         return(0);
42 }