From 9ff8e2fa97a77e6bc01d7f53d20edcb7b9683db3 Mon Sep 17 00:00:00 2001
From: David Schleef <ds@schleef.org>
Date: Mon, 28 May 2001 03:57:32 +0000
Subject: [PATCH] Fix things so that they actually work

---
 python/Makefile.pre.in |  2 +-
 python/Setup.in        |  3 +-
 python/compy.c         | 40 +++++++++++++++------
 python/sample.py       | 79 +++---------------------------------------
 4 files changed, 37 insertions(+), 87 deletions(-)

diff --git a/python/Makefile.pre.in b/python/Makefile.pre.in
index 6d9190d..a9a7fc0 100644
--- a/python/Makefile.pre.in
+++ b/python/Makefile.pre.in
@@ -170,7 +170,7 @@ CONFIGC=	$(LIBPL)/config.c
 CONFIGCIN=	$(LIBPL)/config.c.in
 SETUP=		$(LIBPL)/Setup.thread $(LIBPL)/Setup.local $(LIBPL)/Setup
 
-SYSLIBS=	$(LIBM) $(LIBC)
+SYSLIBS=	$(LIBM) $(LIBC) -lcomedi
 
 ADDOBJS=	$(LIBPL)/python.o config.o
 
diff --git a/python/Setup.in b/python/Setup.in
index 1f08c79..c6ae49e 100644
--- a/python/Setup.in
+++ b/python/Setup.in
@@ -1 +1,2 @@
-comedi compy.c
+*shared*
+comedi compy.c -lcomedi
diff --git a/python/compy.c b/python/compy.c
index 7c54e2a..354bd6b 100644
--- a/python/compy.c
+++ b/python/compy.c
@@ -25,6 +25,7 @@ static comedi_t *compy_it[maxcards];
 static comedi_trig trig;
 static int trigchan[2];
 static printstats=1;
+static int debug = 1;
 
 /*******************************/
 static PyObject *
@@ -45,18 +46,34 @@ compy_open(self, args)
 
 	compy_it[card]=comedi_open(filen);
 
-	trig.data=&trigdata;
-	trig.mode=0;
-	trig.flags=0;
-	trig.n_chan=1;
-	trig.chanlist=trigchan;
-	trig.n=1;
-	trig.trigsrc=TRIG_NOW;
-	trig.data_len=1;
+	if(debug)
+		printf("open returned %p\n",compy_it[card]);
 
 	return Py_BuildValue("i", 1);
 }
 
+static PyObject *
+compy_read_data(PyObject *self, PyObject *args)
+{
+	int subd, chan;
+	int card;
+	lsampl_t data;
+
+	if (!PyArg_ParseTuple(args, "(iii)", &card, &subd, &chan))
+		return NULL;
+	if ((card < 0) || (card >= maxcards))
+		return NULL;
+	if(debug)
+		printf("compy trig dev %d subd %d chan %d\n",card,subd,chan);
+
+	comedi_data_read(compy_it[card],subd,chan,0,0,&data);
+
+	if(debug)
+		printf("comedi_data_read value %d\n",data);
+
+	return Py_BuildValue("i", data);
+}
+
 static PyObject *
 compy_trig(self, args)
 	PyObject *self;
@@ -115,9 +132,10 @@ compy_version(self, args)
 
 /* List of functions defined in the module */
 
-static PyMethodDef compy_methods[] = {
+static PyMethodDef comedi_methods[] = {
         {"open",	compy_open,	METH_VARARGS},
         {"trig",	compy_trig,	METH_VARARGS},
+        {"data_read",	compy_data_read,	METH_VARARGS},
         {"close",	compy_close,	METH_VARARGS},
         {"__version__",	compy_version,	METH_VARARGS},
         {NULL,		NULL}           /* sentinel */
@@ -126,10 +144,10 @@ static PyMethodDef compy_methods[] = {
 /* Initialization function for the module (*must* be called initxx) */
 
 DL_EXPORT(void)
-initcompy()
+initcomedi()
 {
         /* Create the module and add the functions */
-        (void) Py_InitModule("compy", compy_methods);
+        (void) Py_InitModule("comedi", comedi_methods);
 }
 
 
diff --git a/python/sample.py b/python/sample.py
index a95c5b2..c645efa 100755
--- a/python/sample.py
+++ b/python/sample.py
@@ -11,82 +11,13 @@
 import os
 import stat
 import time
-import compy			# important if you want to use compy
+import comedi			# important if you want to use compy
 from string import *
 
-#  this project uses 3 advantech PCM-3730's
-#  8 isolated outputs on dev 0
-#  8 isolated inputs on dev 3
-#  8 ttl outputs each on dev 1 & 2 not used
-#  8 ttl inputs each on dev 4 & 5 not used
+comedi.open(0,"/dev/comedi0",1)
 
-compypath0 = "/dev/comedi0"	# a little abstraction
-compypath1 = "/dev/comedi1"
-compypath2 = "/dev/comedi2"
+val = comedi.read_data((0,0,0));
+print val
 
-# ************ I/O definitions
-SolderSOV	= (0,0,1)
-Work0SOV	= (0,0,2)	# input card 0, dev 0, channel 2
-Work1SOV	= (0,0,3)
-Move1SOV	= (0,0,4)
-BlowSOV		= (0,0,5)
-SolderDn	= (0,3,2)
-SolderUp	= (0,3,3)
-Work0In		= (0,3,4)
-Work0Out	= (0,3,5)
-SolderPresent0	= (0,3,6)
-Work1In		= (1,3,0)
-Work1Out	= (1,3,1)
-SolderPresent1	= (1,3,2)
-MoveAt1		= (1,3,3)
-MoveAt0		= (1,3,4)
-PalmL		= (2,3,0)
-PalmR		= (2,3,1)	# input card 2, dev 3, channel 1
-PartPres0	= (2,3,2)
-PartPres1	= (2,3,3)
-
-compyif = compy.trig		# got rid of old work around of compy v2
-				# all new code should use compy.trig directly!!!
-
-# *********************************************
-def inout(SOV, Sin, Sout, Ppres, Head ):
-    "A task to manage one arm of a 'ping-pong' machine"
-    global SolderNow
-    compyif(SOV,0)	# reset
-    SolderNow[Head] = 0
-    while 1:
-        while not compyif(Sout,0):	# wait until out and ready
-            time.sleep(.001)
-        while compyif(Ppres,0):		# Wait for part to be removed
-            time.sleep(.001)
-        while not compyif(Ppres,0):	# Wait for part to be replaced
-            time.sleep(.001)
-        while compyif(PalmL,0) or compyif(PalmR,0):	# palms must not be blocked
-            time.sleep(.001)
-        while (not compyif(PalmL,0)) or (not compyif(PalmR,0)):	# wait for palms
-            time.sleep(.001)
-        SolderNow[Head] = 1		# signal that this side will be ready soon
-        compyif(SOV,1)			# go in
-        while not compyif(Sin,0):	# wait for in
-            time.sleep(.001)
-        SolderNow[Head] = 2
-        while SolderNow[Head]:		# wait for process
-            time.sleep(.001)
-            # Of course this won't exit, you don't have the other tasks that run
-            # the machine!!!!
-        compyif(SOV,0)			# go out
-
-
-# ************ comedi setup
-compy.open(0,compypath0,0)
-compy.open(1,compypath1,0)
-compy.open(2,compypath2,0)
-
-compyif(SolderSOV,0)	# solder up
-
-inout(Work0SOV,Work0In,Work0Out,PartPres0,0)
-
-compy.close(0)
-compy.close(1)
-compy.close(2)
+comedi.close(0)
 
-- 
2.26.2