<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/156592</link>
    <title>MATLAB Central Newsreader - Need both modes of BytesAvailableFcnMode at the same time</title>
    <description>Feed for thread: Need both modes of BytesAvailableFcnMode at the same time</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Sun, 23 Sep 2007 02:17:15 -0400</pubDate>
      <title>Need both modes of BytesAvailableFcnMode at the same time</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/156592#393539</link>
      <author> &quot;G.A.M.</author>
      <description>The data sent back from my instrument are of two types:&lt;br&gt;
1. short codes under 20 bytes containing status info&lt;br&gt;
2. data over 1000 bytes&lt;br&gt;
&lt;br&gt;
The data is not terminated with any special character. However, I&lt;br&gt;
believe all the status codes are terminated with a decimal value of 13&lt;br&gt;
(carriage return).&lt;br&gt;
&lt;br&gt;
In order to be notified of the status codes and the data, I have been&lt;br&gt;
using these definitions:&lt;br&gt;
'BytesAvailableFcnMode','byte',...&lt;br&gt;
'BytesAvailableFcnCount',5,...&lt;br&gt;
&lt;br&gt;
With those I'm sure to be notified of any status codes, but when I&lt;br&gt;
actually get data, the BytesAvailableFcn is called over 200 times for&lt;br&gt;
one buffer of data.&lt;br&gt;
&lt;br&gt;
I'm sometimes getting some hard to diagnose errors in the following&lt;br&gt;
line in my instrument callback:&lt;br&gt;
feval(val{1}, obj, eventStruct, val{2:end})&lt;br&gt;
&lt;br&gt;
I'm thinking it may be due to the above BytesAvailableFcn issue when&lt;br&gt;
multiple data buffers are sent close together.&lt;br&gt;
&lt;br&gt;
Can anyone suggest a better solution for reading my serial data?&lt;br&gt;
Thanks. I appreciate any suggestions.</description>
    </item>
    <item>
      <pubDate>Sun, 23 Sep 2007 02:30:06 -0400</pubDate>
      <title>Re: Need both modes of BytesAvailableFcnMode at the same time</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/156592#393541</link>
      <author> &quot;G.A.M.</author>
      <description>On Sep 22, 10:17 pm, &quot;G.A.M.&quot; &amp;lt;x0Z...@gmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; The data sent back from my instrument are of two types:&lt;br&gt;
&amp;gt; 1. short codes under 20 bytes containing status info&lt;br&gt;
&amp;gt; 2. data over 1000 bytes&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; The data is not terminated with any special character. However, I&lt;br&gt;
&amp;gt; believe all the status codes are terminated with a decimal value of 13&lt;br&gt;
&amp;gt; (carriage return).&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; In order to be notified of the status codes and the data, I have been&lt;br&gt;
&amp;gt; using these definitions:&lt;br&gt;
&amp;gt; 'BytesAvailableFcnMode','byte',...&lt;br&gt;
&amp;gt; 'BytesAvailableFcnCount',5,...&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; With those I'm sure to be notified of any status codes, but when I&lt;br&gt;
&amp;gt; actually get data, the BytesAvailableFcn is called over 200 times for&lt;br&gt;
&amp;gt; one buffer of data.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I'm sometimes getting some hard to diagnose errors in the following&lt;br&gt;
&amp;gt; line in my instrument callback:&lt;br&gt;
&amp;gt; feval(val{1}, obj, eventStruct, val{2:end})&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I'm thinking it may be due to the above BytesAvailableFcn issue when&lt;br&gt;
&amp;gt; multiple data buffers are sent close together.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Can anyone suggest a better solution for reading my serial data?&lt;br&gt;
&amp;gt; Thanks. I appreciate any suggestions.&lt;br&gt;
&lt;br&gt;
Here is an old message from 2002 with a similar question. If anyone&lt;br&gt;
has an answer to this older question, that would probably solve my&lt;br&gt;
issue too. Here is the older question:&lt;br&gt;
&lt;br&gt;
% Newsgroups: comp.soft-sys.matlab&lt;br&gt;
% From: &quot;Fred Dilkes&quot;&lt;br&gt;
% Date: Thu, 18 Jul 2002 16:45:16 -0400&lt;br&gt;
% Local: Thurs, Jul 18 2002 4:45 pm&lt;br&gt;
% Subject: BytesAvailable on a serial device&lt;br&gt;
%&lt;br&gt;
% I'm having difficulty handling variable-length message packets from&lt;br&gt;
a&lt;br&gt;
% device connected by RS232 to a PC running Matlab 6.1.&lt;br&gt;
%&lt;br&gt;
% The device sends some long binary message packets (say 16k bytes)&lt;br&gt;
and&lt;br&gt;
% some short messages (4 bytes) to the PC.  I'm trying to handle them&lt;br&gt;
% both with a Matlab serial object by setting 'BytesAvailableFcnCount'&lt;br&gt;
% to 4 and 'BytesAvailableFcn' to an event-handling function.  The&lt;br&gt;
% event-handler uses fread to read the first 4 bytes and then it&lt;br&gt;
% decides whether or not it needs to read the other 16k-4.&lt;br&gt;
%&lt;br&gt;
% The problem is that each long message now generates 16k/4=4096 calls&lt;br&gt;
% to the event-handling function.  The first call reads all 16k, but&lt;br&gt;
% the last 4095 calls are just overhead since there are no more bytes&lt;br&gt;
% to read.  They just slow down my GUI.&lt;br&gt;
%&lt;br&gt;
% Can anybody tell me whether there is a better way to handle&lt;br&gt;
% variable-length message packets?&lt;br&gt;
%&lt;br&gt;
% Thanks,&lt;br&gt;
% Fred</description>
    </item>
    <item>
      <pubDate>Tue, 25 Sep 2007 15:58:30 -0400</pubDate>
      <title>Re: Need both modes of BytesAvailableFcnMode at the same time</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/156592#393881</link>
      <author> &quot;G.A.M.</author>
      <description>On Sep 22, 10:30 pm, &quot;G.A.M.&quot; &amp;lt;x0Z...@gmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; On Sep 22, 10:17 pm, &quot;G.A.M.&quot; &amp;lt;x0Z...@gmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; The data sent back from my instrument are of two types:&lt;br&gt;
&amp;gt; &amp;gt; 1. short codes under 20 bytes containing status info&lt;br&gt;
&amp;gt; &amp;gt; 2. data over 1000 bytes&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; The data is not terminated with any special character. However, I&lt;br&gt;
&amp;gt; &amp;gt; believe all the status codes are terminated with a decimal value of 13&lt;br&gt;
&amp;gt; &amp;gt; (carriage return).&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; In order to be notified of the status codes and the data, I have been&lt;br&gt;
&amp;gt; &amp;gt; using these definitions:&lt;br&gt;
&amp;gt; &amp;gt; 'BytesAvailableFcnMode','byte',...&lt;br&gt;
&amp;gt; &amp;gt; 'BytesAvailableFcnCount',5,...&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; With those I'm sure to be notified of any status codes, but when I&lt;br&gt;
&amp;gt; &amp;gt; actually get data, the BytesAvailableFcn is called over 200 times for&lt;br&gt;
&amp;gt; &amp;gt; one buffer of data.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; I'm sometimes getting some hard to diagnose errors in the following&lt;br&gt;
&amp;gt; &amp;gt; line in my instrument callback:&lt;br&gt;
&amp;gt; &amp;gt; feval(val{1}, obj, eventStruct, val{2:end})&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; I'm thinking it may be due to the above BytesAvailableFcn issue when&lt;br&gt;
&amp;gt; &amp;gt; multiple data buffers are sent close together.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Can anyone suggest a better solution for reading my serial data?&lt;br&gt;
&amp;gt; &amp;gt; Thanks. I appreciate any suggestions.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Here is an old message from 2002 with a similar question. If anyone&lt;br&gt;
&amp;gt; has an answer to this older question, that would probably solve my&lt;br&gt;
&amp;gt; issue too. Here is the older question:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; % Newsgroups: comp.soft-sys.matlab&lt;br&gt;
&amp;gt; % From: &quot;Fred Dilkes&quot;&lt;br&gt;
&amp;gt; % Date: Thu, 18 Jul 2002 16:45:16 -0400&lt;br&gt;
&amp;gt; % Local: Thurs, Jul 18 2002 4:45 pm&lt;br&gt;
&amp;gt; % Subject: BytesAvailable on a serial device&lt;br&gt;
&amp;gt; %&lt;br&gt;
&amp;gt; % I'm having difficulty handling variable-length message packets from&lt;br&gt;
&amp;gt; a&lt;br&gt;
&amp;gt; % device connected by RS232 to a PC running Matlab 6.1.&lt;br&gt;
&amp;gt; %&lt;br&gt;
&amp;gt; % The device sends some long binary message packets (say 16k bytes)&lt;br&gt;
&amp;gt; and&lt;br&gt;
&amp;gt; % some short messages (4 bytes) to the PC.  I'm trying to handle them&lt;br&gt;
&amp;gt; % both with a Matlab serial object by setting 'BytesAvailableFcnCount'&lt;br&gt;
&amp;gt; % to 4 and 'BytesAvailableFcn' to an event-handling function.  The&lt;br&gt;
&amp;gt; % event-handler uses fread to read the first 4 bytes and then it&lt;br&gt;
&amp;gt; % decides whether or not it needs to read the other 16k-4.&lt;br&gt;
&amp;gt; %&lt;br&gt;
&amp;gt; % The problem is that each long message now generates 16k/4=4096 calls&lt;br&gt;
&amp;gt; % to the event-handling function.  The first call reads all 16k, but&lt;br&gt;
&amp;gt; % the last 4095 calls are just overhead since there are no more bytes&lt;br&gt;
&amp;gt; % to read.  They just slow down my GUI.&lt;br&gt;
&amp;gt; %&lt;br&gt;
&amp;gt; % Can anybody tell me whether there is a better way to handle&lt;br&gt;
&amp;gt; % variable-length message packets?&lt;br&gt;
&amp;gt; %&lt;br&gt;
&amp;gt; % Thanks,&lt;br&gt;
&amp;gt; % Fred&lt;br&gt;
&lt;br&gt;
If I have a lot of bytes coming in via the serial port, can I change&lt;br&gt;
the mode of the BytesAvailableFcn in the midst of receiving this data?&lt;br&gt;
Could I start off with a small value for bytes count and increase it&lt;br&gt;
to a larger value at a certain point? Would the change be effective&lt;br&gt;
quickly enough to alter the way the BytesAvailableFcn is called for&lt;br&gt;
the remaining data? Thanks.</description>
    </item>
    <item>
      <pubDate>Tue, 02 Oct 2007 15:08:54 -0400</pubDate>
      <title>Re: Need both modes of BytesAvailableFcnMode at the same time</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/156592#394795</link>
      <author>G.A.M. </author>
      <description>&amp;nbsp;&quot;G.A.M.&quot; &amp;lt;x0Zero@gmail.com&amp;gt; wrote in message&lt;br&gt;
&amp;lt;1190735910.568277.10280@r29g2000hsg.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; On Sep 22, 10:30 pm, &quot;G.A.M.&quot; &amp;lt;x0Z...@gmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; &amp;gt; On Sep 22, 10:17 pm, &quot;G.A.M.&quot; &amp;lt;x0Z...@gmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; The data sent back from my instrument are of two types:&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; 1. short codes under 20 bytes containing status info&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; 2. data over 1000 bytes&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
[snip]&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Here is an old message from 2002 with a similar&lt;br&gt;
question. If anyone&lt;br&gt;
&amp;gt; &amp;gt; has an answer to this older question, that would&lt;br&gt;
probably solve my&lt;br&gt;
&amp;gt; &amp;gt; issue too. Here is the older question:&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; % Newsgroups: comp.soft-sys.matlab&lt;br&gt;
&amp;gt; &amp;gt; % From: &quot;Fred Dilkes&quot;&lt;br&gt;
&amp;gt; &amp;gt; % Date: Thu, 18 Jul 2002 16:45:16 -0400&lt;br&gt;
&amp;gt; &amp;gt; % Local: Thurs, Jul 18 2002 4:45 pm&lt;br&gt;
&amp;gt; &amp;gt; % Subject: BytesAvailable on a serial device&lt;br&gt;
&amp;gt; &amp;gt; %&lt;br&gt;
&amp;gt; &amp;gt; % I'm having difficulty handling variable-length message&lt;br&gt;
packets from&lt;br&gt;
&amp;gt; &amp;gt; a&lt;br&gt;
&amp;gt; &amp;gt; % device connected by RS232 to a PC running Matlab 6.1.&lt;br&gt;
&amp;gt; &amp;gt; %&lt;br&gt;
&amp;gt; &amp;gt; % The device sends some long binary message packets (say&lt;br&gt;
16k bytes)&lt;br&gt;
&amp;gt; &amp;gt; and&lt;br&gt;
&amp;gt; &amp;gt; % some short messages (4 bytes) to the PC.  I'm trying&lt;br&gt;
to handle them&lt;br&gt;
&amp;gt; &amp;gt; % both with a Matlab serial object by setting&lt;br&gt;
'BytesAvailableFcnCount'&lt;br&gt;
&amp;gt; &amp;gt; % to 4 and 'BytesAvailableFcn' to an event-handling&lt;br&gt;
function.  The&lt;br&gt;
&amp;gt; &amp;gt; % event-handler uses fread to read the first 4 bytes and&lt;br&gt;
then it&lt;br&gt;
&amp;gt; &amp;gt; % decides whether or not it needs to read the other 16k-4.&lt;br&gt;
&amp;gt; &amp;gt; %&lt;br&gt;
&amp;gt; &amp;gt; % The problem is that each long message now generates&lt;br&gt;
16k/4=4096 calls&lt;br&gt;
&amp;gt; &amp;gt; % to the event-handling function.  The first call reads&lt;br&gt;
all 16k, but&lt;br&gt;
&amp;gt; &amp;gt; % the last 4095 calls are just overhead since there are&lt;br&gt;
no more bytes&lt;br&gt;
&amp;gt; &amp;gt; % to read.  They just slow down my GUI.&lt;br&gt;
&amp;gt; &amp;gt; %&lt;br&gt;
&amp;gt; &amp;gt; % Can anybody tell me whether there is a better way to&lt;br&gt;
handle&lt;br&gt;
&amp;gt; &amp;gt; % variable-length message packets?&lt;br&gt;
&amp;gt; &amp;gt; %&lt;br&gt;
&amp;gt; &amp;gt; % Thanks,&lt;br&gt;
&amp;gt; &amp;gt; % Fred&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; If I have a lot of bytes coming in via the serial port,&lt;br&gt;
can I change&lt;br&gt;
&amp;gt; the mode of the BytesAvailableFcn in the midst of&lt;br&gt;
receiving this data?&lt;br&gt;
&amp;gt; Could I start off with a small value for bytes count and&lt;br&gt;
increase it&lt;br&gt;
&amp;gt; to a larger value at a certain point? Would the change be&lt;br&gt;
effective&lt;br&gt;
&amp;gt; quickly enough to alter the way the BytesAvailableFcn is&lt;br&gt;
called for&lt;br&gt;
&amp;gt; the remaining data? Thanks.&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
&lt;br&gt;
I'm about to give up on solving this elegantly, but I'm&lt;br&gt;
going to try again and see if I can get an answer to this&lt;br&gt;
question. I appreciate any thoughts anyone can offer. :)</description>
    </item>
  </channel>
</rss>

