function varargout = gui_rx(varargin)
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @gui_rx_OpeningFcn, ...
'gui_OutputFcn', @gui_rx_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- CONDICIONES INICIALES DEL PROGRAMA
function gui_rx_OpeningFcn(hObject, eventdata, handles, varargin)
% Centrar la GUI
movegui(hObject,'center')
%axes(handles.axes5);
img=imread('inaoe.jpg');
handles.axes5=imshow(img);
img2=imread('itsal.jpg');
handles.axes9=imshow(img2);
% Deshabilitar botón de envío serial y parada del bucle
set(handles.rx_b,'Enable','off')
set(handles.inicio,'Enable','off')
set(handles.stop_b,'Enable','off')
set(handles.parar,'Enable','off')
set(handles.guardar,'Enable','off')
handles.acc=[ ];
global datos
global tiempo valores
valores=0;
tiempo=0;
datos=0;
% Choose default command line output for gui_rx
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = gui_rx_OutputFcn(hObject, eventdata, handles)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- ABRIR PUERTO SERIAL.
function com_ser_Callback(hObject, eventdata, handles)
% Desactivar botón actual
set(hObject,'Enable','off')
pause(0.1)
% Tomar y verificar el ID del puerto serial
com=get(handles.com_e,'String');
if isempty(com)||isnan(str2double(com))
return
end
% Obtener velocidad (baudrate)
contents = get(handles.los_baud,'String');
vel=str2double(contents{get(handles.los_baud,'Value')});
% Configuración del puerto serial
handles.Se = serial(['COM',com]);%Seleccionar puerto COM1
set(handles.Se,'BaudRate',vel);%Velocidad 9600 baudios
set(handles.Se,'DataBits',8);%8 bits de datos
set(handles.Se,'Parity','none');%Sin control de paridad
set(handles.Se,'StopBits',1);%Un bit de parada
set(handles.Se,'FlowControl','none');%Sin control de flujo
set(handles.Se,'Terminator',13);%Terminador
set(handles.Se,'TimeOut',2);%Tiempo de espera
% Abrir el puerto serial
%fopen(handles.Se);
% Mensaje de apertura del puerto serial
msgbox(['Puerto COM',com,' Correcto'],'RS_232')
% Habilitar botón de envío
set(handles.rx_b,'Enable','on')
set(handles.inicio,'Enable','on')
set(handles.stop_b,'Enable','on')
set(handles.parar,'Enable','on')
set(handles.guardar,'Enable','off')
% Actualizar estructura handles
guidata(hObject,handles)
% --- FUNCIÓN DE CIERRE DE GUI.
function figure1_CloseRequestFcn(hObject, eventdata, handles)
try
fclose(handles.Se);%Cerrar puerto serial
catch
end
delete(hObject);
% --- FUNCIÓN DE RECEPCIÓN SERIAL.
function rx_b_Callback(hObject, eventdata, handles)
fopen(handles.Se);
% Borrar edit-text de recepción de mensaje
set(handles.editor,'String','')
axes(handles.axes3);
cla reset;
% Desactivar botón actual
set(handles.rx_b,'Enable','off');
set(handles.inicio,'Enable','off');
set(handles.datos_guardados,'Enable','off');
set(handles.abrir_archivo,'Enable','off');
set(handles.abrir,'Enable','off');
pause(0.1)
global datos tiempo valores
% Matriz de concatenación
handles.acc=[ ];
valores=[ ];
% Vector para guardar los datos obtenidos de la lectura
datos=zeros( );
tiempo=1;
% Poner a 0 el ID de parada del ciclo "while"
set(handles.stop_b,'UserData',0)
set(handles.parar,'UserData',0)
% Ciclo de adquisición
while 1
if get(handles.stop_b,'UserData') % Verificar ID de parada
get(handles.parar,'UserData')
break
end
% Si hay datos en buffer de recepción, leerlo
if handles.Se.BytesAvailable
lectura=fscanf(handles.Se,'%d'); % Leer buffer de entrada
tiempo=tiempo+1;
%A=A(1:end-1); % Quitar "terminator" (~)
valores=[tiempo lectura];
handles.acc=[handles.acc, lectura]; % Concatenar mensaje
set(handles.editor,'String',handles.acc)% Escribir mensaje
datos(tiempo)=(lectura(1));
title('GRÁFICA DE TEMPERATURA');
xlabel('Tiempo (s)');
ylabel('Temperatura (°C)');
hold on;
ylim([0 datos(tiempo)+100]);
xlim([0 tiempo+10]);
plot(handles.axes3,datos,'LineWidth',2);grid on;box on;
drawnow
end
pause(0.02);
end
% ------ FUNCION PARA ADQUIRIR DATOS
function inicio_Callback(hObject, eventdata, handles)
% hObject handle to inicio (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
fopen(handles.Se);
% Borrar edit-text de recepción de mensaje
set(handles.editor,'String','')
axes(handles.axes3);
cla reset;
% Desactivar botón actual
set(handles.rx_b,'Enable','off');
set(handles.inicio,'Enable','off');
set(handles.datos_guardados,'Enable','off');
set(handles.abrir_archivo,'Enable','off');
set(handles.abrir,'Enable','off');
pause(0.1)
global datos tiempo valores
% Matriz de concatenación
handles.acc=[ ];
valores=[ ];
% Vector para guardar los datos obtenidos de la lectura
datos=zeros( );
tiempo=1;
% Poner a 0 el ID de parada del ciclo "while"
set(handles.stop_b,'UserData',0)
set(handles.parar,'UserData',0)
% Ciclo de adquisición
while 1
if get(handles.stop_b,'UserData') % Verificar ID de parada
get(handles.parar,'UserData')
break
end
% Si hay datos en buffer de recepción, leerlo
if handles.Se.BytesAvailable
lectura=fscanf(handles.Se,'%d'); % Leer buffer de entrada
tiempo=tiempo+1;
%A=A(1:end-1); % Quitar "terminator" (~)
valores=[tiempo lectura];
handles.acc=[handles.acc, lectura]; % Concatenar mensaje
set(handles.editor,'String',handles.acc)% Escribir mensaje
datos(tiempo)=(lectura(1));
title('GRÁFICA DE TEMPERATURA');
xlabel('Tiempo (s)');
ylabel('Temperatura (°C)');
hold on;
ylim([0 datos(tiempo)+100]);
xlim([0 tiempo+10]);
plot(handles.axes3,datos,'LineWidth',2);grid on;box on;
drawnow
end
pause(0.02);
end
% --- FUNCIÓN DE PARADA DEL CICLO DE ADQUISICIÓN.
function stop_b_Callback(hObject, eventdata, handles)
% Colocar el ID en 1 para romper el ciclo while
set(handles.stop_b,'UserData',1)
set(handles.parar,'UserData',1)
% Cerrar el puerto serial
if strcmp(handles.Se.Status,'open')
fclose(handles.Se);
%delete(handles.Se);
end
% Habilitar botones
set(handles.rx_b,'Enable','off')
set(handles.inicio,'Enable','off')
set(handles.com_ser,'Enable','on')
set(handles.guardar,'Enable','on')
set(handles.datos_guardados,'Enable','on')
set(handles.abrir_archivo,'Enable','on')
set(handles.abrir,'Enable','on')
% Borrar edit-text
%set(handles.editor,'String','')
% Mensaje de aviso de cierre del puerto
warndlg('Recepcion Finalizada','WARNING RS-232')
% Actualizar estructura handles
guidata(hObject,handles)
% ----- FUNCION PARA PARAR EL PUERTO SERIAL
function parar_Callback(hObject, eventdata, handles)
% Colocar el ID en 1 para romper el ciclo while
set(handles.stop_b,'UserData',1)
set(handles.parar,'UserData',1)
% Cerrar el puerto serial
if strcmp(handles.Se.Status,'open')
fclose(handles.Se);
%delete(handles.Se);
end
% Habilitar botones
set(handles.rx_b,'Enable','off')
set(handles.inicio,'Enable','off')
set(handles.com_ser,'Enable','on')
set(handles.guardar,'Enable','on')
set(handles.datos_guardados,'Enable','on')
set(handles.abrir_archivo,'Enable','on')
set(handles.abrir,'Enable','on')
% Borrar edit-text
%set(handles.editor,'String','')
% Mensaje de aviso de cierre del puerto
warndlg('Recepcion Finalizada','WARNING RS-232')
% Actualizar estructura handles
guidata(hObject,handles)
% --- Executes when figure1 is resized.
function figure1_ResizeFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% ----- FUNCION GUARDAR DATOS
function guardar_Callback(hObject, eventdata, handles)
global datos
[filename pathname] = uiputfile( '*.txt');
if filename==0
return;
else
datos_nuevos = datos;
fid=fopen([pathname, filename],'w');
fprintf(fid,'%d\t\n',datos_nuevos);
fclose(fid);
warndlg('Datos guardados correctamente','AVISO')
end
%guidata(hObject,handles);
% ----- FUNCION PARA BORRAR DATOS
function borrar_Callback(hObject, eventdata, handles)
set(handles.editor,'String','')
axes(handles.axes3);
cla reset;
% ---- FUNCION PARA ABRIR DATOS
function abrir_Callback(hObject, eventdata, handles)
mostrar_datos;
% ---- FUNCION PARA CERRAR EL PROGRAMA
function cerrar_Callback(hObject, eventdata, handles)
opc=questdlg('¿Desea salir del programa?','SALIR','Si','No','No');
if strcmp(opc,'No')
return;
end
clear,clc,close all
% --------------------------------------------------------------------
function archivo_Callback(hObject, eventdata, handles)
% hObject handle to archivo (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function editar_Callback(hObject, eventdata, handles)
% hObject handle to editar (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function herramientas_Callback(hObject, eventdata, handles)
% hObject handle to herramientas (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function ayuda_Callback(hObject, eventdata, handles)
% hObject handle to ayuda (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function exportar_Callback(hObject, eventdata, handles)
% hObject handle to exportar (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function informacion_Callback(hObject, eventdata, handles)
% hObject handle to informacion (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in datos_guardados.
function datos_guardados_Callback(hObject, eventdata, handles)
% hObject handle to datos_guardados (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
mostrar_datos;
% --------------------------------------------------------------------
function abrir_archivo_ClickedCallback(hObject, eventdata, handles)
mostrar_datos;
% --------------------------------------------------------------------
function guardar_figura_ClickedCallback(hObject, eventdata, handles)
global datos
[filename pathname] = uiputfile( '*.txt');
if filename==0
return;
else
datos_nuevos = datos;
fid=fopen([pathname, filename],'w');
fprintf(fid,'%d\t\n',datos_nuevos);
fclose(fid);
warndlg('Datos guardados correctamente','AVISO')
end
%guidata(hObject,handles);