|
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.
|