Path: news.mathworks.com!newsfeed-00.mathworks.com!newscon02.news.prodigy.net!prodigy.net!news.glorb.com!postnews.google.com!r29g2000hsg.googlegroups.com!not-for-mail
From:  "G.A.M." <x0Zero@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Need both modes of BytesAvailableFcnMode at the same time
Date: Tue, 25 Sep 2007 15:58:30 -0000
Organization: http://groups.google.com
Lines: 72
Message-ID: <1190735910.568277.10280@r29g2000hsg.googlegroups.com>
References: <1190513835.238939.231600@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 1190735910 6556 127.0.0.1 (25 Sep 2007 15:58:30 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Tue, 25 Sep 2007 15:58:30 +0000 (UTC)
In-Reply-To: <1190514606.733448.89200@n39g2000hsh.googlegroups.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: r29g2000hsg.googlegroups.com; posting-host=24.129.101.179;
Xref: news.mathworks.com comp.soft-sys.matlab:430104



On Sep 22, 10:30 pm, "G.A.M." <x0Z...@gmail.com> wrote:
> On Sep 22, 10:17 pm, "G.A.M." <x0Z...@gmail.com> wrote:
>
>
>
> > The data sent back from my instrument are of two types:
> > 1. short codes under 20 bytes containing status info
> > 2. data over 1000 bytes
>
> > The data is not terminated with any special character. However, I
> > believe all the status codes are terminated with a decimal value of 13
> > (carriage return).
>
> > In order to be notified of the status codes and the data, I have been
> > using these definitions:
> > 'BytesAvailableFcnMode','byte',...
> > 'BytesAvailableFcnCount',5,...
>
> > With those I'm sure to be notified of any status codes, but when I
> > actually get data, the BytesAvailableFcn is called over 200 times for
> > one buffer of data.
>
> > I'm sometimes getting some hard to diagnose errors in the following
> > line in my instrument callback:
> > feval(val{1}, obj, eventStruct, val{2:end})
>
> > I'm thinking it may be due to the above BytesAvailableFcn issue when
> > multiple data buffers are sent close together.
>
> > Can anyone suggest a better solution for reading my serial data?
> > Thanks. I appreciate any suggestions.
>
> Here is an old message from 2002 with a similar question. If anyone
> has an answer to this older question, that would probably solve my
> issue too. Here is the older question:
>
> % Newsgroups: comp.soft-sys.matlab
> % From: "Fred Dilkes"
> % Date: Thu, 18 Jul 2002 16:45:16 -0400
> % Local: Thurs, Jul 18 2002 4:45 pm
> % Subject: BytesAvailable on a serial device
> %
> % I'm having difficulty handling variable-length message packets from
> a
> % device connected by RS232 to a PC running Matlab 6.1.
> %
> % The device sends some long binary message packets (say 16k bytes)
> and
> % some short messages (4 bytes) to the PC.  I'm trying to handle them
> % both with a Matlab serial object by setting 'BytesAvailableFcnCount'
> % to 4 and 'BytesAvailableFcn' to an event-handling function.  The
> % event-handler uses fread to read the first 4 bytes and then it
> % decides whether or not it needs to read the other 16k-4.
> %
> % The problem is that each long message now generates 16k/4=4096 calls
> % to the event-handling function.  The first call reads all 16k, but
> % the last 4095 calls are just overhead since there are no more bytes
> % to read.  They just slow down my GUI.
> %
> % Can anybody tell me whether there is a better way to handle
> % variable-length message packets?
> %
> % Thanks,
> % Fred

If I have a lot of bytes coming in via the serial port, can I change
the mode of the BytesAvailableFcn in the midst of receiving this data?
Could I start off with a small value for bytes count and increase it
to a larger value at a certain point? Would the change be effective
quickly enough to alter the way the BytesAvailableFcn is called for
the remaining data? Thanks.