]> rtime.felk.cvut.cz Git - mf6xx.git/commitdiff
Added Comedi userspace program for setting DACs. Tested. Working
authorRostislav Lisovy <lisovy@gmail.com>
Thu, 7 Apr 2011 22:58:48 +0000 (00:58 +0200)
committerRostislav Lisovy <lisovy@gmail.com>
Thu, 7 Apr 2011 23:00:36 +0000 (01:00 +0200)
src/comedi/simple_driver/userspace/dac_example/Makefile [new file with mode: 0644]
src/comedi/simple_driver/userspace/dac_example/main.c [new file with mode: 0644]
src/comedi/simple_driver/userspace/dout_example/main.c
src/comedi/simple_driver/userspace/mf624.h [moved from src/comedi/simple_driver/userspace/dout_example/mf624.h with 100% similarity]

diff --git a/src/comedi/simple_driver/userspace/dac_example/Makefile b/src/comedi/simple_driver/userspace/dac_example/Makefile
new file mode 100644 (file)
index 0000000..8e4f4ee
--- /dev/null
@@ -0,0 +1,2 @@
+all:
+       gcc main.c -o main -lcomedi -lm
diff --git a/src/comedi/simple_driver/userspace/dac_example/main.c b/src/comedi/simple_driver/userspace/dac_example/main.c
new file mode 100644 (file)
index 0000000..7e70a41
--- /dev/null
@@ -0,0 +1,40 @@
+#include <stdio.h>
+#include <comedilib.h>
+#include "../mf624.h"
+
+/* Converts Volts into format needed by card.
+Input should be integer (no float) */
+int phys_to_comedi(int val)
+{
+       if (val >= -10 && val <= 10) {
+               return 0x2000 + (val * (0x2000/10));
+       }
+       else {
+               return 0x2000; // 0V
+       }
+}
+
+int main(int argc, char* argv[])
+{
+       comedi_t* comedi_dev;
+       int status;
+       int channel = 0;
+       int range = 0;
+       int aref = 0;
+
+       comedi_dev = comedi_open("/dev/comedi0");
+       if (comedi_dev == NULL) {
+               comedi_perror("comedi_open");
+               return 1;
+       }
+
+       while(1) {
+               status = comedi_data_write(comedi_dev, MF624_AO_SUBDEV, channel, range, aref, phys_to_comedi(5));
+               if (status == -1) {
+                       comedi_perror("comedi_data_write");
+               }
+               sleep(1);
+       }
+
+       return 0;
+}
index 22b4f4e4c41faf3a9b7e80a5d72517b146a07561..58f61ece5cfa350a1b03dc99ac65a8b1aade1344 100644 (file)
@@ -1,6 +1,6 @@
 #include <stdio.h>
 #include <comedilib.h>
-#include "mf624.h"
+#include "../mf624.h"
 
 int main(int argc, char* argv[])
 {