[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: COMEDI wrapper (was: Re: Data acquisition in Octave)
From: |
Olaf Till |
Subject: |
Re: COMEDI wrapper (was: Re: Data acquisition in Octave) |
Date: |
Fri, 21 Nov 2008 12:08:28 +0100 |
User-agent: |
Mutt/1.5.13 (2006-08-11) |
On Thu, Nov 20, 2008 at 12:04:49PM -0500, John W. Eaton wrote:
> I have the beginnings of a package here:
>
> ftp://velveeta.che.wisc.edu/pub/octave-comedi/comedi-0.1.tar.gz
>
Some first remarks:
The crash:
octave-3.0.2:1> dev = comedi_open ("/dev/comedi0")
dev = <comedi_t object>
octave-3.0.2:2> comedi_close (dev)
ans = 0
octave-3.0.2:3> comedi_close (dev)
panic: Segmentation fault -- stopping myself...
attempting to save variables to `octave-core'...
error: octave_base_value::save_binary(): wrong type argument `comedi_t'
save to `octave-core' complete
Segmentation fault
address@hidden:~/devel/src/octave-comedi-0.1/src$
can probably be cured by something like this patch:
--- orig-comedi_open.cc 2008-11-20 17:16:50.000000000 +0100
+++ comedi_open.cc 2008-11-21 10:45:39.000000000 +0100
@@ -163,6 +163,8 @@
bool print_as_scalar (void) const { return true; }
+ void comedi_t_set_null (void) {dev = NULL;}
+
private:
comedi_t *dev;
@@ -222,6 +224,25 @@
return retval;
}
+static void
+octave_comedi_t_set_null (octave_value& arg)
+{
+
+ try
+ {
+ octave_base_value& rep = (octave_base_value&) arg.get_rep ();
+
+ octave_comedi_t& val = dynamic_cast<octave_comedi_t&> (rep);
+
+ val.comedi_t_set_null ();
+ }
+ catch (std::bad_cast)
+ {
+ error ("invalid conversion to comedi_t_value");
+ }
+
+}
+
class
octave_comedi_range : public octave_base_value
{
@@ -361,8 +382,11 @@
{
comedi_t *it = octave_get_comedi_t_object (args(0));
- if (! error_state)
+ if (! error_state && it) {
retval = comedi_close (it);
+ octave_value arg0 = args(0);
+ octave_comedi_t_set_null (arg0);
+ }
else
error ("comedi_close: expecting comedi_t object argument");
}
-------------- end of patch -------------------
result of patch:
octave-3.0.2:1> dev = comedi_open ("/dev/comedi0")
dev = <comedi_t object>
octave-3.0.2:2> comedi_close (dev)
ans = 0
octave-3.0.2:3> comedi_close (dev)
error: comedi_close: expecting comedi_t object argument
octave-3.0.2:3>
comedilib allocates comedi_range's for fields within comedi_t, frees
the ranges in comedi_close and luckily sets the pointers to NULL after
freeing, so it's probably not problematic to wrap comedi_range into an
octave_value as you did.
However, one usually allocates some more with or for comedilib. I
don't know if wrapping those into octave_value is feasible, since I do
not know the Octave internals good enough:
- comedi_polynomial_t
for comedi_to/from_physical (comedi_to/from_phys is deprecated);
allocated by user, filled in by comedilib, one potentially for each
range in each channel in each device;
could probably have values instead of pointers in the class, so
probably no problems due to (de)allocation
- comedi_calibration_t
one instance (necessary) per device, allocated and freed with
comedilib functions, independently of comedi_t structure; user can
create arbitrarily many (equal) instances --- so it should
automatically be freed if an Octave user variable containing it gets
overwritten or out of scope, or if the user clears it; probably you
have means to do this in Octave ...
- some allocations for filling in the comedi_cmd and comedi_insn
structures
similar problem as the last
Olaf