Path: news.mathworks.com!not-for-mail
From: "Philip Borghesani" <philip_borghesani@mathworks.spam>
Newsgroups: comp.soft-sys.matlab
Subject: Re: inputParser not validating serial object correctly
Date: Mon, 24 Sep 2007 10:08:17 -0400
Organization: The MathWorks, Inc.
Lines: 40
Message-ID: <fd8gch$fvn$1@fred.mathworks.com>
References: <1190511764.536671.125930@y42g2000hsy.googlegroups.com>
Reply-To: "Philip Borghesani" <philip_borghesani@mathworks.spam>
NNTP-Posting-Host: borghesani.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1190642897 16375 144.212.105.103 (24 Sep 2007 14:08:17 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 24 Sep 2007 14:08:17 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138
Xref: news.mathworks.com comp.soft-sys.matlab:429908



You have the inputs to parse wrong try:
p.parse(varargin{:});
or
parse(p,varargin{:})

Phil

"G.A.M." <x0Zero@gmail.com> wrote in message news: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.
>