Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
problem with the timer object (Invalid handle object)

Subject: problem with the timer object (Invalid handle object)

From: Jose

Date: 8 Jun, 2010 15:45:21

Message: 1 of 7

Hello everyone, I try to use the timer object instead of a while loop, because it is necessary in my software.

The problem is, after the first iteration, I got the next message error:

??? Error while evaluating TimerFcn for timer 'timer-1'

Invalid handle object.

And I have not idea why is the problem, any help?

Here below, i attach the piece of my code:

******************************************



function proc1 (src, ~) % This function is called when I click a pushbutton (e)
in a global panel (mean GUI).

% Connect to the server on port 3000

svrsock = mslisten(3000);

sock=msaccept(svrsock)
msclose(svrsock);

global hfigure h1 h2 h3 h4
global isnr isnr2 isnr3 isnr4
global ssnr ssnr2 ssnr3 ssnr4
global snr snrtest
global icxx
global hz
global deltaz sm
global processpause
global sumcum
global anoise isxxy xcount
global t1 kj
global sdata
global adc
global suc

e=get(src,'parent');


if kj(e)>0 % To be sure if i push the button (e) in the main pannel
if ishandle(hfigure{e}) % for a second time nothing more happens.
    return;
end
end

kj(e)=1;








epsn=0

anoise(e)=0

% receive the variable1 over the socket
sm_ack=6;
sm_init=5;
sm_startmove=1;
sm_endmove=2;
sm_adc=3;
sm_elpsn=4;

dir_bk=0;
dir_fwd=1;
el_notloaded=0;
el_up=1;
el_surf=2;
el_cx=3;
el_broken=-1;


s=receivestructure2(sock)


sendvar2m=1;

 isxxy(e)=0;
 isnr=0;
 ssnr=zeros(1,100);
 isnr2=0;
 ssnr2=zeros(1,100);
 isnr3=0;
 ssnr3=zeros(1,100);
 isnr4=0;
 ssnr4=zeros(1,100);

%receiving data from the acquisition card.


ai = analoginput('nidaq','Dev1');

addchannel(ai, 1);

set(ai,'InputType');

set(ai,'InputType','SingleEnded');

Fs=25000;
duration=1;

ai.SampleRate = Fs;
ai.SamplesPerTrigger = duration*Fs;

set(ai,'TriggerType','manual');




deltaz=1;
hz(e)=0.1;
store(1)=-1;

s=makesdata;


icxx(e)=0;
xcount(e)=0;

processpause(e) = false;


% I think the mistake is here.


t1 = timer('TimerFcn',{@timerFun,e},'BusyMode','Queue','executionmode','fixedrate','period',0.5);
start(t1);


function timerFun(obj,~,e)
    
   
xdin=get(obj,'TasksExecuted')

 
% get the raw of data from the acquisition card
start(ai);
trigger(ai);
wait(ai,duration+1);
recvvar1 = getdata(ai);


if sendvar2m ~=0
 s=receivestructure(sock);
 else
 suc=1;
end


if suc>=0
    if s.smtype==4 & suc==0
        epsn=s.depth(3)
 
    end
data=recvvar1;

store(2)=epsn;
deltax=store(2)-store(1);
.
.
.
.
.
.
end

% close the socket


msclose(sock);
end

*********************************

Thnaks in advance.

Subject: problem with the timer object (Invalid handle object)

From: Walter Roberson

Date: 8 Jun, 2010 22:44:57

Message: 2 of 7

Jose wrote:
> Hello everyone, I try to use the timer object instead of a while loop,
> because it is necessary in my software.
>
> The problem is, after the first iteration, I got the next message error:
>
> ??? Error while evaluating TimerFcn for timer 'timer-1'
> Invalid handle object.
>
> And I have not idea why is the problem, any help?

Does it not indicate the line that is the problem?

In any case, at the command line, type

dbstop if error

and then execute the routine.

You do not appear, by the way, to be initializing "suc", at least not with
certainty. You also appear to be overwriting "s" (the socket) inside the timer
function, as your "sendvar2m" starts out 1 which is ~= 0

Subject: problem with the timer object (Invalid handle object)

From: Jose

Date: 8 Jun, 2010 23:31:04

Message: 3 of 7

Walter Roberson <roberson@hushmail.com> wrote in message <humh8f$klu$1@canopus.cc.umanitoba.ca>...
> Jose wrote:
> > Hello everyone, I try to use the timer object instead of a while loop,
> > because it is necessary in my software.
> >
> > The problem is, after the first iteration, I got the next message error:
> >
> > ??? Error while evaluating TimerFcn for timer 'timer-1'
> > Invalid handle object.
> >
> > And I have not idea why is the problem, any help?
>
> Does it not indicate the line that is the problem?
>
> In any case, at the command line, type
>
> dbstop if error
>
> and then execute the routine.
>
> You do not appear, by the way, to be initializing "suc", at least not with
> certainty. You also appear to be overwriting "s" (the socket) inside the timer
> function, as your "sendvar2m" starts out 1 which is ~= 0

Hello Walter,
It does not indicate waht line is the problem...
by the way, Thank you for your suggestion, i'll type this...on the other hand, I don´t think I have conflict with s, suc and sendvar2m...it works fine.

I'll let you know.

Subject: problem with the timer object (Invalid handle object)

From: Jose

Date: 9 Jun, 2010 14:48:10

Message: 4 of 7

"Jose " <jose.l.vega@gmail.com> wrote in message <humjro$dk9$1@fred.mathworks.com>...
> Walter Roberson <roberson@hushmail.com> wrote in message <humh8f$klu$1@canopus.cc.umanitoba.ca>...
> > Jose wrote:
> > > Hello everyone, I try to use the timer object instead of a while loop,
> > > because it is necessary in my software.
> > >
> > > The problem is, after the first iteration, I got the next message error:
> > >
> > > ??? Error while evaluating TimerFcn for timer 'timer-1'
> > > Invalid handle object.
> > >
> > > And I have not idea why is the problem, any help?
> >
> > Does it not indicate the line that is the problem?
> >
> > In any case, at the command line, type
> >
> > dbstop if error
> >
> > and then execute the routine.
> >
> > You do not appear, by the way, to be initializing "suc", at least not with
> > certainty. You also appear to be overwriting "s" (the socket) inside the timer
> > function, as your "sendvar2m" starts out 1 which is ~= 0
>
> Hello Walter,
> It does not indicate waht line is the problem...
> by the way, Thank you for your suggestion, i'll type this...on the other hand, I don´t think I have conflict with s, suc and sendvar2m...it works fine.
>
> I'll let you know.


Walter still doesn´t work when i add to my code dbstop if errot, we´ve got the same mistake:

??? Error while evaluating TimerFcn for timer 'timer-1'

Invalid handle object.

Any idea:

Subject: problem with the timer object (Invalid handle object)

From: Walter Roberson

Date: 9 Jun, 2010 14:54:45

Message: 5 of 7

Jose wrote:

> Walter still doesn´t work when i add to my code dbstop if errot, we´ve
> got the same mistake:
>
> ??? Error while evaluating TimerFcn for timer 'timer-1'
> Invalid handle object.
>
> Any idea:

Do not add

dbstop if error

to your code, just type it at the command line and then run your code.
When the problem occurs you will be put into the debugger and able to
see the problem and examine variables to determine what is being looked
at and what values are actually there.

Subject: problem with the timer object (Invalid handle object)

From: Jose

Date: 9 Jun, 2010 15:33:06

Message: 6 of 7

Walter Roberson <roberson@hushmail.com> wrote in message <VWNPn.124955$gv4.57406@newsfe09.iad>...
> Jose wrote:
>
> > Walter still doesn´t work when i add to my code dbstop if errot, we´ve
> > got the same mistake:
> >
> > ??? Error while evaluating TimerFcn for timer 'timer-1'
> > Invalid handle object.
> >
> > Any idea:
>
> Do not add
>
> dbstop if error
>
> to your code, just type it at the command line and then run your code.
> When the problem occurs you will be put into the debugger and able to
> see the problem and examine variables to determine what is being looked
> at and what values are actually there.

Sorry, itdoes not work, my software works like that:

1. run the main program, then a main panel (GUI_1) is coming up.

2. push the start button in the main panel, and another (GUI_2) appear.

3. push the button 1 in (GUI_2), and this button execute a callback to the function proc1 (code that you can see above)...
Proc1, is waiting for the data of the acquisition card generated for a master computer (simulate the data).

4. When proc1 in my laptop (slave) get the data, start the object timer, the first iteration is fine because the plots of the data analized is coming up in the GUI_2.

5. the problem is in the second iteration, once it get the new data from the acquisition card, the program is stop here with that error...and nothing happened
in my command window...even if I type at the beginning the command : dbstop if error.

I hope you understad better how my software works.

Is curious, but if i put i while loop, everything is fine, but i need to work with a timer object...because I have to use different fucntions proc1, proc2....proc10, which every one, independientelly call to a function analysis runining in a cluster, which is the server that analize my data from the acquisition card.

I hope you understand how my software works.

Subject: problem with the timer object (Invalid handle object)

From: Jose

Date: 9 Jun, 2010 17:44:23

Message: 7 of 7

"Jose " <jose.l.vega@gmail.com> wrote in message <huoc7i$f8$1@fred.mathworks.com>...
> Walter Roberson <roberson@hushmail.com> wrote in message <VWNPn.124955$gv4.57406@newsfe09.iad>...
> > Jose wrote:
> >
> > > Walter still doesn´t work when i add to my code dbstop if errot, we´ve
> > > got the same mistake:
> > >
> > > ??? Error while evaluating TimerFcn for timer 'timer-1'
> > > Invalid handle object.
> > >
> > > Any idea:
> >
> > Do not add
> >
> > dbstop if error
> >
> > to your code, just type it at the command line and then run your code.
> > When the problem occurs you will be put into the debugger and able to
> > see the problem and examine variables to determine what is being looked
> > at and what values are actually there.
>
> Sorry, itdoes not work, my software works like that:
>
> 1. run the main program, then a main panel (GUI_1) is coming up.
>
> 2. push the start button in the main panel, and another (GUI_2) appear.
>
> 3. push the button 1 in (GUI_2), and this button execute a callback to the function proc1 (code that you can see above)...
> Proc1, is waiting for the data of the acquisition card generated for a master computer (simulate the data).
>
> 4. When proc1 in my laptop (slave) get the data, start the object timer, the first iteration is fine because the plots of the data analized is coming up in the GUI_2.
>
> 5. the problem is in the second iteration, once it get the new data from the acquisition card, the program is stop here with that error...and nothing happened
> in my command window...even if I type at the beginning the command : dbstop if error.
>
> I hope you understad better how my software works.
>
> Is curious, but if i put i while loop, everything is fine, but i need to work with a timer object...because I have to use different fucntions proc1, proc2....proc10, which every one, independientelly call to a function analysis runining in a cluster, which is the server that analize my data from the acquisition card.
>
> I hope you understand how my software works.

Walter, thanks for your time, it works now.
The problem was a had a function called pause, and it was generating a conflict with the "pause command" of matlab.
Now is ok.

Tags for this Thread

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.

Contact us