Re: Adding a listener java/MATLAB interface



"Donn Shull" <donn.shull.no_spam@xxxxxxxxxxxxx> wrote in message <gg5d6v$r97$1@xxxxxxxxxxxxxxxxxx>...
"Bob " <rshankle@xxxxxxx> wrote in message <gg4ic6$p7v$1@xxxxxxxxxxxxxxxxxx>...
Hi,

I have a client/server program where the client calls java server code running in MATLAB.

The Server receives an XML filename from the remote client and sends the file name on to a function in MATLAB, the function returns another filename which contains the results of the simulation.

Everything works well when I use CompletetionObservers, but I want to add a listener to monitor a progress variable in the MATLAB function. This variable needs to be monitored by the java code in MATLAB.

Example: function [xmlout] = process(XMLin)

.... readBuilderXML(XMLin)....

for i = 1:100
do something....

pctComplete = i;

end

xmlout = "output_file"


(end of example)

What I need is for a java function to be called everytime pctComplete is changed so I can send a status message back to the remote client program.

Any suggestions or example programs are greatly appreciated.

thank you!
Bob

Hi Bob,

My first suggestion would be to place the call to your java code in the loop of your process function. That seems the most simple and direct.

If you really want to try using listeners. You could search the toolbox directories for handle.listener to find examples of how to use it. An example to play around with would use MATLAB's under documented UDD objects.

First somewhere on your MATLAB path create a directory @loop and below that directory create a subdirectory @counter. In the @loop directory create an m file named schema.m with the following code:

function schema()
schema.package('loop');
return;

Next in the @counter create an m file named schema.m with the following code:

function schema()
hCreateInPackage = findpackage('loop');
hThisClass = schema.class(hCreateInPackage, 'counter');
hThisProp = schema.prop(hThisClass, 'index', 'MATLAB array');
hThisProp.FactoryValue = 1:100;
schema.prop(hThisProp, 'PropertyUpdate', 'handle');
hPropUpdateListener = handle.listener(hThisClass, hThisProp, 'PropertyPostGet', @myJavaCallback);
hThisProp.PropertyUpdate = hPropUpdateListener;
return;

function myJavaCallback(obj, eventData)
disp('hello from callback');
% place your call to the java code here
return;

Finally in the @counter directory create an m file named counter.mwith the following code:

function self = MyClass(varargin)
self = loop.counter;
return;

To use this object try this code

percent = loop.counter;
for count = percent.index
disp('Do Something');
percent.index;
end

Good Luck,

Donn


Hi Donn,

I made it to the end of your first sentence:

My first suggestion would be to place the call to your java code in the loop of your >process function. That seems the most simple and direct

A lightbulb went on in my head and I was good to go after that. Thank you very much for the reply, I didn't need to try the rest of your response.

thanks agian,
Bob

.



Relevant Pages

  • Re: Adding a listener java/MATLAB interface
    ... I have a client/server program where the client calls java server code running in MATLAB. ... The Server receives an XML filename from the remote client and sends the file name on to a function in MATLAB, the function returns another filename which contains the results of the simulation. ...
    (comp.soft-sys.matlab)
  • Adding a listener java/MATLAB interface
    ... I have a client/server program where the client calls java server code running in MATLAB. ... The Server receives an XML filename from the remote client and sends the file name on to a function in MATLAB, the function returns another filename which contains the results of the simulation. ...
    (comp.soft-sys.matlab)
  • Re: add a uicontainer or uipanel to a JPanel
    ... An axis is ultimately what I wanted to add to to a ... The uicontainers and uipanels and axes, for that matter, ... As for putting an axes in a Java container, ... Java enables richer GUI than Matlab ...
    (comp.soft-sys.matlab)
  • Re: add a uicontainer or uipanel to a JPanel
    ... An axis is ultimately what I wanted to add to to a ... The uicontainers and uipanels and axes, for that matter, ... As for putting an axes in a Java container, ... Java enables richer GUI than Matlab ...
    (comp.soft-sys.matlab)
  • JAVA Unsatisfied Link Error
    ... I've been getting rather frustrated with the native interface to JAVA ... I wish to load some Java classes that use the JNI ... decided to test it in Matlab. ... In particular I compiled in the Swig ...
    (comp.soft-sys.matlab)