Path: news.mathworks.com!newsfeed-00.mathworks.com!news.kjsl.com!newsfeed.stanford.edu!postnews.google.com!50g2000hsm.googlegroups.com!not-for-mail
From:  "G.A.M." <x0Zero@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: inputParser not validating serial object correctly
Date: Wed, 03 Oct 2007 03:02:04 -0000
Organization: http://groups.google.com
Lines: 59
Message-ID: <1191380524.949164.278800@50g2000hsm.googlegroups.com>
References: <1190511764.536671.125930@y42g2000hsy.googlegroups.com>
NNTP-Posting-Host: 24.129.101.179
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
X-Trace: posting.google.com 1191380525 16204 127.0.0.1 (3 Oct 2007 03:02:05 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Wed, 3 Oct 2007 03:02:05 +0000 (UTC)
In-Reply-To: <fdttt0$q4u$1@fred.mathworks.com>
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7,gzip(gfe),gzip(gfe)
Complaints-To: groups-abuse@google.com
Injection-Info: 50g2000hsm.googlegroups.com; posting-host=24.129.101.179;
Xref: news.mathworks.com comp.soft-sys.matlab:431102



On Oct 2, 1:07 pm, "per isakson" <poi.nos...@bimDOTkthDOT.se> wrote:
>  "G.A.M." <x0Z...@gmail.com> wrote in message
>
> <1190511764.536671.125...@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

Thank you very much. I have looked at this example many times and I
never noticed the fact that I had the extra blips.