Using a script to change uicontrol values in a gui
Show older comments
I have a code that initializes a GUI, and then take serial data, compares it to excel master files, and then changes the colors of some uipanels in the gui. this is the code, the comments are generally prototyping or holdovers from other codes I incorporated:
delete(instrfind('Port', 'COM3'));
tag = serial('COM3'); %check which port is used
fopen(tag);
MyGUI;
BOX = char(zeros(2,14));
i=1;
c=0;
TrueValueData = 'C:\MasterCodes.xlsx';
[~,~,TrueValMat] = xlsread(TrueValueData); % Creates matrix filled with the correct values,
% indexed by box, which is the first row
% all proceeding rows are the master value
function result(handles)
for i=1:9223372036854775807 %just keeps looping, will probably replace with a push button to kill
if i>10 %first couple reads are filled with unicode nonsense, this skips that stage
readData = fscanf(tag);
if length(readData)>12
BOX(str2num(readData(8)),1:14)= readData(11:24); % these numbers just give us what we want;
% tags come in initially with some gobbledy-gook
end
%
% if(length(readData)>10) %if chip has been read
%
% ReadChips
if strcmp(TrueValMat{2,1}, BOX(1,:))
set(handles.uipanel1, 'BackgroundColor', 'green');
else
set(handles.uipanel1, 'BackgroundColor', 'red');
end
if strcmp(TrueValMat{2,2}, BOX(2,:))
set(handles.uipanel2, 'Backgroundcolor', 'green');
else
set(handles.uipanel2, 'Backgroundcolor', 'red');
end
if strcmp(TrueValMat{2,1}, BOX(1,:))...
&& strcmp(TrueValMat{2,2}, BOX(2,:)) == 1
break
end
end
end
end
function uipanel1_Callback(hObject, eventdata, handles)
result;
function uipanel2_Callback(hObject, eventdata, handles)
result;
end
end
The problem is that this doesnt actually do anything, the GUI comes up, but the loop doesn't iterate, and the colors don't change in the GUI.
edit: added in loop break point
1 Comment
avram alter
on 16 Sep 2019
Accepted Answer
More Answers (0)
Categories
Find more on App Building in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!