Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: inputParser not validating serial object correctly
Date: Tue, 2 Oct 2007 17:07:44 +0000 (UTC)
Organization: KTH
Lines: 52
Message-ID: <fdttt0$q4u$1@fred.mathworks.com>
References: <1190511764.536671.125930@y42g2000hsy.googlegroups.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-06-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1191344864 26782 172.30.248.36 (2 Oct 2007 17:07:44 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 2 Oct 2007 17:07:44 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1670
Xref: news.mathworks.com comp.soft-sys.matlab:431046



 "G.A.M." <x0Zero@gmail.com> wrote in message 
<1190511764.536671.125930@y42g2000hsy.googlegroups.com>...
> My error msg is:
> Argument 'serialPort' failed validation @(sp)isa
(sp,'serial').
> 
> My code is:
> 
> function status = DoSomethingWithSerialPort(serialPort, 
varargin)
> 
> 	p = inputParser;
> 	p.addRequired('serialPort', @(sp)isa(sp, 'serial'));
> 	p.addParamValue('test','', @ischar);
> 	p.parse('serialPort', varargin{:});
> 	test= p.Results.test;
>        %etc.
> 
> After getting the error, I checked the class of the 
function
> parameter, and it was as expected:
> class(serialPort)
> ans = serial
> 
> Then, to continue debugging, I created this anonymous 
function in the
> workspace:
> x = @(sp)isa(sp, 'serial')
> 
> I used it to check the input parameter and it was again 
as expected:
> x(serialPort)
> ans =      1
> 
> So does anyone have any idea why I get the error shown at 
the top?
> Thanks.
> 

The example, publish_ip, in the documentation uses the same 
name ("script") for both the name of the required variable 
and the variable itself, which is asking for mistakes. 

In this line 

p.parse( serialPort, varargin{:});

<serialPort> is the name of the input variable. You have 
two blips too many.

/ per