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:
timer object communication via socket

Subject: timer object communication via socket

From: Jose

Date: 10 Jul, 2010 23:21:07

Message: 1 of 5

Hello to everyone, I have this function in my slave computer that receive signal from the master, it start fine, the problem is when I call the function pausexx in the uicontrol, I forze to the slave to do not communicate with the master, but when I call the function pausexx again to restart the communication the communication is lost, and I would like to recovery it, but i do not know how I can do it.

Thanks in advance.


function panel
close all
clc
clear all
%figure
global sock

global datax ai
% Connect to the server on port 3000
% servername=169.254.245.219
svrsock = mslisten(3000);
sock=msaccept(svrsock);
msclose(svrsock);

w=waitforbuttonpress
disp('Button click')
% Receive the variable -- 5 second
% timeout before failure

epsn=0;


global sdata
global adc
global suc

global datax


global sm_ack
global sm_init
global sm_startmove
global sm_endmove
global sm_adc
global sm_elpsn
%
global dir_bk
global dir_fwd
global el_notloaded
global el_up
global el_surf
global el_cx
global el_broken

global hz stat



% 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=receivestructure(sock)


sendvar2m=1;



stat=true
     
t1 = timer('TimerFcn',{@timerFun},'executionmode','fixedrate');
start(t1)
global sendvar2m

global sm_ack
global sm_init
global sm_startmove
global sm_endmove
global sm_adc
global sm_elpsn
%
global dir_bk
global dir_fwd
global el_notloaded
global el_up
global el_surf
global el_cx
global el_broken

global hz stat





function timerFun(obj,~)
 
   stat

   if stat==true
   
    hstop=uicontrol (gcf,'String','Stop','Position',[10,10,60,20],'Callback','pausexx');
    
   
       
   if sendvar2m ~=0
   s=receivestructure(sock)
   else
   suc=1
   end
    
    



if sendvar2m > 0
s.smtype=sm_startmove;
s.username='Jose';
s.eldir=dir_fwd;
s.elno=3;
sendstructure(sock,s)
s
pause(hz)

s.smtype=sm_endmove;
s.elno=3;
sendstructure (sock,s)
s
elseif sendvar2m < 0
s.smtype=sm_startmove;
s.eldir=dir_bk;
s.username='Jose';
s.elno=3;
sendstructure(sock,s);
pause(hz)
s.smtype=sm_endmove;
s.elno=3;
sendstructure (sock,s);
 else
 s.smtype=sm_elpsn;
 s.elno=3;
 end
     

  
   end
end
% close the socket
msclose(sock);
   %end

end


function pausexx

global stat

stat =~ stat;

return
end

Subject: timer object communication via socket

From: us

Date: 10 Jul, 2010 23:59:07

Message: 2 of 5

"Jose " <jose.l.vega@gmail.com> wrote in message <i1av93$onq$1@fred.mathworks.com>...
> Hello to everyone, I have this function in my slave computer that receive signal from the master, it start fine, the problem is when I call the function pausexx in the uicontrol, I forze to the slave to do not communicate with the master, but when I call the function pausexx again to restart the communication the communication is lost, and I would like to recovery it, but i do not know how I can do it.
>
> Thanks in advance.
>
>
> function panel
> close all
> clc
> clear all
> %figure
> global sock
>
> global datax ai
> % Connect to the server on port 3000
> % servername=169.254.245.219
> svrsock = mslisten(3000);
> sock=msaccept(svrsock);
> msclose(svrsock);
>
> w=waitforbuttonpress
> disp('Button click')
> % Receive the variable -- 5 second
> % timeout before failure
>
> epsn=0;
>
>
> global sdata
> global adc
> global suc
>
> global datax
>
>
> global sm_ack
> global sm_init
> global sm_startmove
> global sm_endmove
> global sm_adc
> global sm_elpsn
> %
> global dir_bk
> global dir_fwd
> global el_notloaded
> global el_up
> global el_surf
> global el_cx
> global el_broken
>
> global hz stat
>
>
>
> % 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=receivestructure(sock)
>
>
> sendvar2m=1;
>
>
>
> stat=true
>
> t1 = timer('TimerFcn',{@timerFun},'executionmode','fixedrate');
> start(t1)
> global sendvar2m
>
> global sm_ack
> global sm_init
> global sm_startmove
> global sm_endmove
> global sm_adc
> global sm_elpsn
> %
> global dir_bk
> global dir_fwd
> global el_notloaded
> global el_up
> global el_surf
> global el_cx
> global el_broken
>
> global hz stat
>
>
>
>
>
> function timerFun(obj,~)
>
> stat
>
> if stat==true
>
> hstop=uicontrol (gcf,'String','Stop','Position',[10,10,60,20],'Callback','pausexx');
>
>
>
> if sendvar2m ~=0
> s=receivestructure(sock)
> else
> suc=1
> end
>
>
>
>
>
> if sendvar2m > 0
> s.smtype=sm_startmove;
> s.username='Jose';
> s.eldir=dir_fwd;
> s.elno=3;
> sendstructure(sock,s)
> s
> pause(hz)
>
> s.smtype=sm_endmove;
> s.elno=3;
> sendstructure (sock,s)
> s
> elseif sendvar2m < 0
> s.smtype=sm_startmove;
> s.eldir=dir_bk;
> s.username='Jose';
> s.elno=3;
> sendstructure(sock,s);
> pause(hz)
> s.smtype=sm_endmove;
> s.elno=3;
> sendstructure (sock,s);
> else
> s.smtype=sm_elpsn;
> s.elno=3;
> end
>
>
>
> end
> end
> % close the socket
> msclose(sock);
> %end
>
> end
>
>
> function pausexx
>
> global stat
>
> stat =~ stat;
>
> return
> end

those numeous lines of ML code are very idiosyncratic and cannot be reproduced by most CSSMers...
show the most parsimonious snippet that re-creates your problem...

us

Subject: timer object communication via socket

From: Jose

Date: 11 Jul, 2010 00:24:05

Message: 3 of 5

ok, I try to be more clear

"us " <us@neurol.unizh.ch> wrote in message <i1b1gb$828$1@fred.mathworks.com>...
> "Jose " <jose.l.vega@gmail.com> wrote in message <i1av93$onq$1@fred.mathworks.com>...
> > Hello to everyone, I have this function in my slave computer that receive signal from the master, it start fine, the problem is when I call the function pausexx in the uicontrol, I forze to the slave to do not communicate with the master, but when I call the function pausexx again to restart the communication the communication is lost, and I would like to recovery it, but i do not know how I can do it.
> >
> > Thanks in advance.
> >
> >
> > function panel
> > close all
> > clc
> > clear all
> > %figure
> > global sock
> >
> > global datax ai
> > % Connect to the server on port 3000
> > % servername=169.254.245.219
> > svrsock = mslisten(3000);
> > sock=msaccept(svrsock);
> > msclose(svrsock);
> >
> > w=waitforbuttonpress
> > disp('Button click')
> > % Receive the variable -- 5 second
> > % timeout before failure
> >
> > epsn=0;
> >
> >
> > global sdata
> > global adc
> > global suc
> >
> > global datax
> >
> >
> > global sm_ack
> > global sm_init
> > global sm_startmove
> > global sm_endmove
> > global sm_adc
> > global sm_elpsn
> > %
> > global dir_bk
> > global dir_fwd
> > global el_notloaded
> > global el_up
> > global el_surf
> > global el_cx
> > global el_broken
> >
> > global hz stat
> >
> >
> >
> > % 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=receivestructure(sock)
> >
> >
> > sendvar2m=1;
> >
> >
> >
> > stat=true
> >
> > t1 = timer('TimerFcn',{@timerFun},'executionmode','fixedrate');
> > start(t1)
> > global sendvar2m
> >
> > global sm_ack
> > global sm_init
> > global sm_startmove
> > global sm_endmove
> > global sm_adc
> > global sm_elpsn
> > %
> > global dir_bk
> > global dir_fwd
> > global el_notloaded
> > global el_up
> > global el_surf
> > global el_cx
> > global el_broken
> >
> > global hz stat
> >
> >
> >
> >
> >
> > function timerFun(obj,~)
> >
> > stat
> >
> > if stat==true
> >
> > hstop=uicontrol (gcf,'String','Stop','Position',[10,10,60,20],'Callback','pausexx');
> >
> >
> >
> > if sendvar2m ~=0
> > s=receivestructure(sock)
> > else
> > suc=1
> > end
> >
> >
> >
> >
> >
> > if sendvar2m > 0
> > s.smtype=sm_startmove;
> > s.username='Jose';
> > s.eldir=dir_fwd;
> > s.elno=3;
> > sendstructure(sock,s)
> > s
> > pause(hz)
> >
> > s.smtype=sm_endmove;
> > s.elno=3;
> > sendstructure (sock,s)
> > s
> > elseif sendvar2m < 0
> > s.smtype=sm_startmove;
> > s.eldir=dir_bk;
> > s.username='Jose';
> > s.elno=3;
> > sendstructure(sock,s);
> > pause(hz)
> > s.smtype=sm_endmove;
> > s.elno=3;
> > sendstructure (sock,s);
> > else
> > s.smtype=sm_elpsn;
> > s.elno=3;
> > end
> >
> >
> >
> > end
> > end
> > % close the socket
> > msclose(sock);
> > %end
> >
> > end
> >
> >
> > function pausexx
> >
> > global stat
> >
> > stat =~ stat;
> >
> > return
> > end
>
> those numeous lines of ML code are very idiosyncratic and cannot be reproduced by most CSSMers...
> show the most parsimonious snippet that re-creates your problem...
>
> us

Subject: timer object communication via socket

From: Jose

Date: 11 Jul, 2010 00:32:05

Message: 4 of 5

Now is more clear, thanks.

function panel

% Connect to the server on port 3000
% servername=169.254.245.219
svrsock = mslisten(3000);
sock=msaccept(svrsock);
msclose(svrsock);

s=receivestructure(sock)
stat=true;
t1 = timer('TimerFcn',@timerFun,'executionmode','fixedrate');
start(t1)

global stat

function timerFun(obj,~)
 
 if stat==true
   
      
    s=receivestructure(sock)
   
    sendstructure(sock,s)

    hpause=uicontrol('String', 'pause',...
       'Position', [260,10,60,20]);
    set(hpause,'Callback',@(src,event)pausexx(src,event,t1));
  
   end
end

msclose(sock);
    

end








"Jose " <jose.l.vega@gmail.com> wrote in message <i1b2v5$560$1@fred.mathworks.com>...
> ok, I try to be more clear
>
> "us " <us@neurol.unizh.ch> wrote in message <i1b1gb$828$1@fred.mathworks.com>...
> > "Jose " <jose.l.vega@gmail.com> wrote in message <i1av93$onq$1@fred.mathworks.com>...
> > > Hello to everyone, I have this function in my slave computer that receive signal from the master, it start fine, the problem is when I call the function pausexx in the uicontrol, I forze to the slave to do not communicate with the master, but when I call the function pausexx again to restart the communication the communication is lost, and I would like to recovery it, but i do not know how I can do it.
> > >
> > > Thanks in advance.
> > >
> > >
> > > function panel
> > > close all
> > > clc
> > > clear all
> > > %figure
> > > global sock
> > >
> > > global datax ai
> > > % Connect to the server on port 3000
> > > % servername=169.254.245.219
> > > svrsock = mslisten(3000);
> > > sock=msaccept(svrsock);
> > > msclose(svrsock);
> > >
> > > w=waitforbuttonpress
> > > disp('Button click')
> > > % Receive the variable -- 5 second
> > > % timeout before failure
> > >
> > > epsn=0;
> > >
> > >
> > > global sdata
> > > global adc
> > > global suc
> > >
> > > global datax
> > >
> > >
> > > global sm_ack
> > > global sm_init
> > > global sm_startmove
> > > global sm_endmove
> > > global sm_adc
> > > global sm_elpsn
> > > %
> > > global dir_bk
> > > global dir_fwd
> > > global el_notloaded
> > > global el_up
> > > global el_surf
> > > global el_cx
> > > global el_broken
> > >
> > > global hz stat
> > >
> > >
> > >
> > > % 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=receivestructure(sock)
> > >
> > >
> > > sendvar2m=1;
> > >
> > >
> > >
> > > stat=true
> > >
> > > t1 = timer('TimerFcn',{@timerFun},'executionmode','fixedrate');
> > > start(t1)
> > > global sendvar2m
> > >
> > > global sm_ack
> > > global sm_init
> > > global sm_startmove
> > > global sm_endmove
> > > global sm_adc
> > > global sm_elpsn
> > > %
> > > global dir_bk
> > > global dir_fwd
> > > global el_notloaded
> > > global el_up
> > > global el_surf
> > > global el_cx
> > > global el_broken
> > >
> > > global hz stat
> > >
> > >
> > >
> > >
> > >
> > > function timerFun(obj,~)
> > >
> > > stat
> > >
> > > if stat==true
> > >
> > > hstop=uicontrol (gcf,'String','Stop','Position',[10,10,60,20],'Callback','pausexx');
> > >
> > >
> > >
> > > if sendvar2m ~=0
> > > s=receivestructure(sock)
> > > else
> > > suc=1
> > > end
> > >
> > >
> > >
> > >
> > >
> > > if sendvar2m > 0
> > > s.smtype=sm_startmove;
> > > s.username='Jose';
> > > s.eldir=dir_fwd;
> > > s.elno=3;
> > > sendstructure(sock,s)
> > > s
> > > pause(hz)
> > >
> > > s.smtype=sm_endmove;
> > > s.elno=3;
> > > sendstructure (sock,s)
> > > s
> > > elseif sendvar2m < 0
> > > s.smtype=sm_startmove;
> > > s.eldir=dir_bk;
> > > s.username='Jose';
> > > s.elno=3;
> > > sendstructure(sock,s);
> > > pause(hz)
> > > s.smtype=sm_endmove;
> > > s.elno=3;
> > > sendstructure (sock,s);
> > > else
> > > s.smtype=sm_elpsn;
> > > s.elno=3;
> > > end
> > >
> > >
> > >
> > > end
> > > end
> > > % close the socket
> > > msclose(sock);
> > > %end
> > >
> > > end
> > >
> > >
> > > function pausexx
> > >
> > > global stat
> > >
> > > stat =~ stat;
> > >
> > > return
> > > end
> >
> > those numeous lines of ML code are very idiosyncratic and cannot be reproduced by most CSSMers...
> > show the most parsimonious snippet that re-creates your problem...
> >
> > us

Subject: timer object communication via socket

From: Steven Lord

Date: 12 Jul, 2010 14:32:09

Message: 5 of 5


"Jose " <jose.l.vega@gmail.com> wrote in message
news:i1b3e5$36k$1@fred.mathworks.com...
> Now is more clear, thanks.
>
> function panel
>
> % Connect to the server on port 3000 % servername=169.254.245.219
> svrsock = mslisten(3000); sock=msaccept(svrsock);
> msclose(svrsock);
>
> s=receivestructure(sock)
> stat=true;
> t1 = timer('TimerFcn',@timerFun,'executionmode','fixedrate');
> start(t1)
> global stat
> function timerFun(obj,~)
> if stat==true s=receivestructure(sock)
> sendstructure(sock,s)
>
> hpause=uicontrol('String', 'pause',...
> 'Position', [260,10,60,20]);
> set(hpause,'Callback',@(src,event)pausexx(src,event,t1));
> end
> end
>
> msclose(sock);
>
> end

There's very little chance that anyone on the newsgroup will be able to help
you debug this issue. Your function calls a large number of other functions
that you have not provided (either directly or by linking to where you
obtained them; since they're likely quite long, please don't post them
directly.) It also looks like it depends on some server listening for a
connection on port 3000 -- not everyone here will have the ability or
knowledge to set up a server and open a port on that server.

You're likely going to need to work with whomever gave you the functions
"mslisten", "msaccept", "msclose", etc. to diagnose what's going on. At
some point, you may also need/want to involve Technical Support -- but I
think that would probably be premature at this point.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

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