how to update the value of a edit text in GUI ?

Hi all,
im trying to control an LED with Matlab GUI and serial port. I have already some functions and everything work when i put the code in the workspace. the Problem is with GUI: GUI takes the frequence 'f' and the desired voltage 'v' from the user and those will be the arguments of my control function. here is the code and when i run it, it works but when the user change the frequence or the voltage, there is no update, it still working with the old configurations.
[Locations of interest have been marked HERE]
delete(instrfind({'Port'},{'COM4'}))
clear s;
global s;
s=serial('COM4');
set(s,'BaudRate',115200);
fopen(s)
function turn_on_button_Callback(hObject, eventdata, handles)
global s;
f=get(handles.frequenz_ablesen,'String'); %HERE
if (str2num(f)>5000)
fprintf('Error: The frequenz must not be greater than 5000\n');
else
v=get(handles.spannung_ablesen,'String'); %HERE
fprintf(s,'%s\r','SDRVC A-01 0 0 str2num(f) str2num(v)') %HERE
fprintf(s,'%s\r','SDRVP A-01 1')
fprintf(s,'%s\r','SDRVW A-01 1')
end
function frequenz_ablesen_Callback(hObject, eventdata, handles)
function frequenz_ablesen_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function spannung_ablesen_Callback(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
i hope that someone can help me
thanks

Respuestas (2)

Walter Roberson
Walter Roberson el 6 de Feb. de 2017
Your line
fprintf(s,'%s\r','SDRVC A-01 0 0 str2num(f) str2num(v)') %HERE
is going to send literally
SDRVC A-01 0 0 str2num(f) str2num(v)
Try
fprintf(s, 'SDRVC A-01 0 0 %s %s\r', f, v)
derecho
derecho el 7 de Feb. de 2017

0 votos

Hi
thanks for the ansewer:) the cmd to send is SDRVC A-01 0 0 str2num(f) str2num(v), thats why i wonder why its not working. i tried yours but it still not working, ERROR the cmd is not defined. But when i put manually the frequency and the volt value in the GUI code, it work fine

1 comentario

When I say that it literally sends
SDRVC A-01 0 0 str2num(f) str2num(v)
I mean that after the '0 0 ', it would send 's' then 't' then 'r' then '2' and so on. Your command
fprintf(s,'%s\r','SDRVC A-01 0 0 str2num(f) str2num(v)') %HERE
does not evaluate the str2num, it puts in 's' 't' 'r' etc as strings.
If it would be more natural to you, you could use
fprintf(s, '%s\r', ['SDRVC A-01 0 0 ', str2num(f), ' ', str2num(v)] ) %HERE

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Preguntada:

el 6 de Feb. de 2017

Comentada:

el 7 de Feb. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by