How can I create GUI's that work together using tcpip and timer?

17 views (last 30 days)
I have three GUI's that work properly when invoked alone. The main GUI has the ability of invoking the other two with push buttons. My problem is the following: I need to record in a txt file information coming from tcpip, my program executes a function handle when the buffer is full and plots and saves that data in the main GUI. When I click at any of the other two GUI's they are created but the figure is not current and so I cannot use them. I believe the tcp handle to the plotting and saving function makes the main GUI figure current every time the buffer fills up. How can I make the other GUI's figures current (that use timers) without having to stop plotting or saving the data? Any help would be greatly appreciated.
Luis

Answers (1)

Walter Roberson
Walter Roberson on 1 Jul 2013
Edited: Walter Roberson on 1 Jul 2013
  2 Comments
Luis
Luis on 2 Jul 2013
I have been using:
axes(handles.axesacq);
to solve the issue of plotting in the right figure. The real isue is that since the callback function from the tcpip object that is invoked by the BytesAvailablefcn occures very often, I cannot use the other Gui when opened with a pushbutton callback since the main Gui is always current. How can I solve this?
Luis
Luis on 2 Jul 2013
I create the tcpip object inside the opening function in the main gui like this:
% Create interface tcpip object
handles.interfaceObject = tcpip('143.167.52.176', 778);
set(handles.interfaceObject, 'InputBufferSize', 19200);
handles.interfaceObject.BytesAvailableFcn = {@localRead, hObject, handles};
handles.interfaceObject.BytesAvailableFcnMode = 'byte';
handles.interfaceObject.BytesAvailableFcnCount = 19200;
The BytesAvailableFcn callback is the following:
function localRead(interfaceObject,~,hObject,handles)
% Read the desired number of data bytes
data = fread(interfaceObject,19200);
gdata = zeros(25600,1);
j=1;
for i=1:4:25600
gdata(i) = 0;
gdata(i+1)=data(j);
gdata(i+2)=data(j+1);
gdata(i+3)=data(j+2);
j=j+3;
end
gdata=typecast(uint8(gdata'),'uint32');
l=1;
odata=zeros(40,160);
for j=1:160
for i=1:40
odata(i,j)=gdata(l);
l=l+1;
end
end
% Save the data and plot
data = get(handles.figure1,'UserData');
status = data.expstatus;
data = get(handles.figure1,'UserData');
m = data.channel;
up = data.up;
down = data.down;
start = data.plotime;
finish = start + (160/2048);
data.plotime = finish;
if (up - down) < 2000000
set(handles.down,'Enable','off');
set(handles.up2,'Enable','off');
else
set(handles.down,'Enable','on');
set(handles.up2,'Enable','on');
end
x = linspace(start,finish,160);
if status == 0
%SOMETHING HERE TO PERMIT EXPERIMENT WINDOW
axes(handles.axesacq);
plot(x,odata(m,:))
t = get(handles.channel,'String');
title(t(m)); grid on; axis([start finish down up]);
elseif status == 1
set(figure1,'Visibility', 'off');
end
% SAVE DATA TO TEXT FILE TO AVOID REACHING MATRIX LIMIT
data.counter = data.counter + 1;
dlmwrite(data.filename,odata,'-append', 'delimiter', ',');
dlmwrite(data.filename,x,'-append', 'delimiter', ',');
% UPDATE USERDATA
set(handles.figure1,'UserData', data);
The previous code is all inside a main gui that has the ability of calling other two guis via pushbuttons. These new gui's use timers to plot images on their respective axes. These do not work properly when the main gui is working at the same time but do work properly when used alone.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!