From: <ean...@us...> - 2012-09-10 13:19:06
|
Revision: 10995 http://octave.svn.sourceforge.net/octave/?rev=10995&view=rev Author: eandrius Date: 2012-09-10 13:18:55 +0000 (Mon, 10 Sep 2012) Log Message: ----------- instrument-control: parallel, fix for constructor argument parsing and textinfo Modified Paths: -------------- trunk/octave-forge/main/instrument-control/src/parallel/parallel.cc Modified: trunk/octave-forge/main/instrument-control/src/parallel/parallel.cc =================================================================== --- trunk/octave-forge/main/instrument-control/src/parallel/parallel.cc 2012-09-10 13:11:53 UTC (rev 10994) +++ trunk/octave-forge/main/instrument-control/src/parallel/parallel.cc 2012-09-10 13:18:55 UTC (rev 10995) @@ -99,7 +99,8 @@ Open Parallel interface.\n \ \n\ @var{path} - the interface path of type String. If omitted defaults to '/dev/parport0'.@*\ -@var{direction} - the direction of interface drivers of type Integer, see: @seealso{pp_datadir} for more info.\n \ +@var{direction} - the direction of interface drivers of type Integer, see: @seealso{pp_datadir} for more info.\ +If omitted defaults to 1 (Input).\n \ \n\ The parallel() shall return instance of @var{octave_parallel} class as the result @var{parallel}.\n \ @end deftypefn") @@ -108,13 +109,9 @@ error("parallel: Windows platform support is not yet implemented, go away..."); return octave_value(); #endif - + int nargin = args.length(); - // Default values - int oflags = O_RDWR; - string path("/dev/parport0"); - // Do not open interface if return value is not assigned if (nargout != 1) { @@ -122,14 +119,56 @@ return octave_value(); } + // Default values + int oflags = O_RDWR; + int dir = 1; // Input + string path("/dev/parport0"); + + + if (!type_loaded) + { + octave_parallel::register_type(); + type_loaded = true; + } + + // Parse the function arguments + if (args.length() > 0) + { + if (args(0).is_string()) + { + path = args(0).string_value(); + } + else + { + print_usage(); + return octave_value(); + } + + } + + // is_float_type() is or'ed to allow expression like ("", 123), without user + // having to use ("", int32(123)), as we still only take "int_value" + if (args.length() > 1) + { + if (args(1).is_integer_type() || args(1).is_float_type()) + { + dir = args(1).int_value(); + } + else + { + print_usage(); + return octave_value(); + } + } + // Open the interface octave_parallel* retval = new octave_parallel(); if (retval->open(path, oflags) < 0) return octave_value(); - - // Set direction to Input - retval->set_datadir(1); + // Set direction + retval->set_datadir(dir); + return octave_value(retval); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |