From: Jonas on
Hi All,

I'm creating a relatively complicated program using a GUI and a UDP link between two computers. On the computer that does most of the work, I need to use arrays passed around in the GUI's handles structure within the datagram received function. The definition of the datagram recieved function is made like so:

comp.datagramreceivedfcn = {@comp_callback, handles}

The function is called when it should be, and it has the handles that were passed to it at the time of its definition. However, if the handles are updated elsewhere in the program (using guidata), they are NOT updated in the datagram received function. I don't understand this, as the handles are updated as desired in all the other callbacks (mostly pushbutton callbacks) without any special treatment.

Why does this happen and what can be done about it?

I'm using matlab 6.5.

Thanks
From: Jonas on
BTW, I forgot to mention in case there is any confusion, "comp" in the name of the UDP object.
From: Jonas on
Anyone?
From: Steven Lord on

"Jonas " <i_wear_pants(a)hotmail.com> wrote in message
news:hqqk6j$c$1(a)fred.mathworks.com...
> Hi All,
>
> I'm creating a relatively complicated program using a GUI and a UDP link
> between two computers. On the computer that does most of the work, I need
> to use arrays passed around in the GUI's handles structure within the
> datagram received function. The definition of the datagram recieved
> function is made like so:
>
> comp.datagramreceivedfcn = {@comp_callback, handles}

So this makes a copy of the handles structure _as it exists at the time this
line is called_ and stores that copy in the second element of this cell
array, then stores the cell array in the field datagramreceivedfcn of the
struct array comp.

> The function is called when it should be, and it has the handles that were
> passed to it at the time of its definition. However, if the handles are
> updated elsewhere in the program (using guidata), they are NOT updated in
> the datagram received function. I don't understand this, as the handles
> are updated as desired in all the other callbacks (mostly pushbutton
> callbacks) without any special treatment.

The handles were not "updated" in the other callbacks. When those callbacks
were called, a copy was made of the handles structure _as it existed at the
time the callback was called_ and that copy passed into the callback, as
part of the way the callback was invoked.

> Why does this happen and what can be done about it?

The easiest way to do this is to give comp.datagramreceivedfcn the callback
function handle and the handle to an object (like the GUI figure) from which
the callback can request an up-to-date copy of the handles structure, and
have the callback function's first action be to request a copy of said
handles structure.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


From: Jonas on
Alright, sounds good. A few questions though: How do I give the handles to an object, and do I need to do anything to ensure that they are up to date at the time the datagramreceivedfcn requests them from the object?