GUI problem while doing serial communication

I am doing serial communication between matlab and controller. I have created a GUI. The problem is whenever I am starting serial communication the GUI doesn't appears but when I terminate the program GUI appears. I want GUI to appear in real time.I am not getting the problem.

Respuestas (1)

Walter Roberson
Walter Roberson el 13 de Abr. de 2016

0 votos

Create serial object BytesAvailableFcn callbacks to handle the serial data, instead of looping around checking for data.
There is a sample GUI for serial communications in the File Exchange

5 comentarios

Nachiket Patki
Nachiket Patki el 13 de Abr. de 2016
Sir thanks for your reply. What I did is I created push button for serial communication to set up and then when input comes I put if condition like if S1=='A' change the color. But the problem is color is not changing only serial communication happens. What to do?
Nachiket Patki
Nachiket Patki el 14 de Abr. de 2016
Editada: Walter Roberson el 14 de Abr. de 2016
Its something like this.....
function pushbutton1_Callback(hObject, eventdata, handles)
global S1;global r1;
r1 = serial('COM16','BaudRate',9600);
fopen(r1);
set(r1,'Timeout',10);
S1=fgets(r1)
function varargout = AjayGUI_OutputFcn(hObject, eventdata, handles)
global S1;
if (S1=='A')
set(c21,'FaceColor','g')
set(c22,'FaceColor','w')
set(r2,'FaceColor','w')
set(c23,'FaceColor','w')
elseif (S1=='B')
set(r2,'FaceColor','w')
set(c23,'FaceColor','w')
set(c22,'FaceColor','g')
set(c21,'FaceColor','w')
elseif (S1=='C')
set(r2,'FaceColor','w')
set(c23,'FaceColor','g')
set(c22,'FaceColor','w')
set(c21,'FaceColor','w')
elseif (S1=='D')
set(r2,'FaceColor','r')
set(c23,'FaceColor','w')
set(c22,'FaceColor','w')
set(c21,'FaceColor','w')
end
axis off;
Walter Roberson
Walter Roberson el 14 de Abr. de 2016
The *OutputFcn is not called until you are exiting the GUI, by which time you are probably destroying the graphics.
Nachiket Patki
Nachiket Patki el 9 de Mayo de 2016
so how to slove this calling function problem? Where should I call it?
Walter Roberson
Walter Roberson el 9 de Mayo de 2016
It would seem to make the most sense to put the display code in pushbutton1_Callback, or at least have pushbutton1_Callback call the display code.
Note: fgets() returns the line terminator as part of the string, but you are using == to do comparisons. You should use fgetl() and you should use strcmp()

Iniciar sesión para comentar.

Categorías

Más información sobre Data Type Identification en Centro de ayuda y File Exchange.

Preguntada:

el 12 de Abr. de 2016

Comentada:

el 9 de Mayo de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by