0.6.3 Changes since last version
[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 \"u=33\" /dev/ttyUSB0\n");
22                 printf("or     ddcp-script-setval \"u=33\" /dev/ttyUSB1\n");
23                 exit(0);
24         }
25         str=argv[1];
26         device=argv[2];
27
28         /* Set up io port correctly, and open it... */
29         fd = open(device, O_WRONLY );
30         if (fd == -1) {
31                 fprintf(stderr, "ERROR: open for %s failed.\n",device);
32                 exit(1);
33         }
34         write(fd,"\r",1); 
35         usleep(100000); // commands are polled in the avr and it can take 100ms
36         write(fd,str,strlen(str)); 
37         write(fd,"\r",1); 
38         close(fd);
39         usleep(150000);
40         return(0);
41 }