Thread Subject: Need both modes of BytesAvailableFcnMode at the same time

Subject: Need both modes of BytesAvailableFcnMode at the same time

From: "G.A.M.

Date: 23 Sep, 2007 02:17:15

Message: 1 of 4

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.

Subject: Need both modes of BytesAvailableFcnMode at the same time

From: "G.A.M.

Date: 23 Sep, 2007 02:30:06

Message: 2 of 4

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

Subject: Need both modes of BytesAvailableFcnMode at the same time

From: "G.A.M.

Date: 25 Sep, 2007 15:58:30

Message: 3 of 4

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.

Subject: Need both modes of BytesAvailableFcnMode at the same time

From: G.A.M.

Date: 2 Oct, 2007 15:08:54

Message: 4 of 4

 "G.A.M." <x0Zero@gmail.com> wrote in message
<1190735910.568277.10280@r29g2000hsg.googlegroups.com>...
> 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
> >
[snip]
> >
> > 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.
>


I'm about to give up on solving this elegantly, but I'm
going to try again and see if I can get an answer to this
question. I appreciate any thoughts anyone can offer. :)

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
bytesavailablefcn G.A.M. 2 Oct, 2007 11:10:24
serial G.A.M. 2 Oct, 2007 11:10:24
serial port G.A.M. 2 Oct, 2007 11:10:24
com port G.A.M. 2 Oct, 2007 11:10:24
instrument G.A.M. 2 Oct, 2007 11:10:24
input G.A.M. 2 Oct, 2007 11:10:24
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com