0.6.3 Changes since last version
[digitaldcpower] / ddcp-script-setval.c
diff --git a/ddcp-script-setval.c b/ddcp-script-setval.c
new file mode 100644 (file)
index 0000000..506975a
--- /dev/null
@@ -0,0 +1,41 @@
+/* vim: set sw=8 ts=8 si et: */
+/* 
+ * Linux software to communicate with the DDCP
+ * Written by Guido Socher 
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+#include <termios.h>
+
+int main(int argc, char *argv[])
+{
+        char *device;
+        char *str;
+        int fd;
+
+        if (argc != 3){
+                printf("USAGE: ddcp-script-setval \"u=33\" /dev/ttyUSB0\n");
+                printf("or     ddcp-script-setval \"u=33\" /dev/ttyUSB1\n");
+                exit(0);
+        }
+        str=argv[1];
+        device=argv[2];
+
+        /* Set up io port correctly, and open it... */
+        fd = open(device, O_WRONLY );
+        if (fd == -1) {
+                fprintf(stderr, "ERROR: open for %s failed.\n",device);
+                exit(1);
+        }
+        write(fd,"\r",1); 
+        usleep(100000); // commands are polled in the avr and it can take 100ms
+        write(fd,str,strlen(str)); 
+        write(fd,"\r",1); 
+        close(fd);
+        usleep(150000);
+        return(0);
+}