Create GUI for plotting serial string data
显示 更早的评论
Hi, im developing a system control to display some sensors with a PSoC and then send that data (strings) into Matlab by the serial port. I've succeded plotting them in the workspace, but now im trying to develop a GUI in order to display these sensor graphs. the matlab´s code is the shown below:
clear all;
close all;
clc;
%Inicialización del puertos
paco=0
PS=serial('COM2');
set(PS,'Baudrate',300); % se configura la velocidad a 300
set(PS,'StopBits',1); % se configura bit de parada a uno
set(PS,'DataBits',8); % se configura que el dato es de 8 bits, debe estar entre 5 y 8
set(PS,'Parity','none'); % se configura sin paridad
set(PS,'Terminator','CR/LF');% “c” caracter con que finaliza el envío. \r\n
set(PS,'OutputBufferSize',512); % ”n” es el número de bytes a enviar
set(PS,'InputBufferSize' ,512); % ”n” es el número de bytes a recibir
set(PS,'Timeout',5); % 5 segundos de tiempo de espera
interrruptores='interruptores';
fopen(PS);
%iniciañización de las variables
K1=[]; K2=[]; K3=[]; K4=[]; K5=[];
encendido=1;
while (encendido==1)
Instruccion=fscanf(PS,'%s');
Dato=fscanf(PS,'%s');
switch(Instruccion)
case 'FSR'
K1=[K1 str2num(Dato)*0.01953125]
case 'AX'
K2=[K2 str2num(Dato)*0.01953125]
case 'AY'
K3=[K3 str2num(Dato)*0.01953125]
case 'HALL'
K4=[K4 str2num(Dato)]
case 'Fin'
paco=1;% Mensaje que le hace salir del bucle
otherwise
K5=[K5 str2num(Dato)]
end
figure(1)
hold off;
plot(K1,'g')
hold on;
plot(K2,'r')
hold on;
plot(K3,'b')
hold on;
plot(K4,'y')
end;
%Cerrado bueno
fclo se(PS);
delete(PS);
clear PS;
INSTRFIND
The GUI I want to do just contains one axes and a start button and i just would like to know where to use this code, can anybody help me?? Thanks in advance
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!