How to make a panel in Guide change color

3 views (last 30 days)
avram alter
avram alter on 5 Sep 2019
Edited: avram alter on 9 Sep 2019
I am working on a system where materials have to be placed in a certain box at a certain time. I am using Arduinos connected to RFID readers, to scan the marterials as they pass into the box. If the correct item is placed, a matlab GUI will show a green coor, whereas a wrong item will show a red color, and emit an brief alarm.
I have already written a code which reads the scanned tags in to matlab, and compares them to a master list, written in excel. the problem is that I don't know how to make the GUI work.
here is the existing code (it has been edited to the current one):
delete(instrfindall);
clear
clc
tag = serial('COM3'); %check which port is used
fopen(tag);
%readData = fscanf(tag); %initialize
%writeData = uint16(500); % 0x01F4
%fwrite(tag, writeData, 'uint16') %write data
BOX = char(zeros(2,14));
i=1;
c=0;
TrueValueData = 'C:\Location_of_true_values'
[~,~,TrueValMat] = xlsread(TrueValueData); % Creates matrix filled with the correct values,
% indexed by box, which is the first row
% all proceeding rows are the master values
for i=1:9223372036854775807
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,:))
disp('hurray1')%set(handles.uipanel3, 'Backgroundcolor', 'g');
else
disp('not hurray1') %set(handles.uipanel3, 'Backgroundcolor', 'r');
end
if strcmp(TrueValMat{2,2}, BOX(2,:))
disp('hurray2') %set(handles.uipanel2, 'Backgroundcolor', 'g');
else
disp('not hurray2') %set(handles.uipanel2, 'Backgroundcolor', 'r');
end
end
end
fclose(tag);
delete(tag);
there are a couple things in comments, those are mostly holdovers from the original utilization of this code, or some troubleshooting I did. the comments in the nested for function are placeholders at this point, indicating what I want to happen in the GUI.
So how do I make those things happen using guide?
Another thing is I want the code to ignore any input from the RFID readers once the correct tag has beren processed. I wouldn't want accidental eads to mess up the system.
I also want to change the
'COM3'
in line 4 of the above code to something that allows for multiple serial ports to be used synchronously. I read about a method here. But again, I dont know how to use the Parallel processing toolbox. I would asssume exchange the com numer to portid, but I am not sure exactly how that works. also, if there is a way to just read them in a manner that appears sycnhronous, that also would be perfect.
Any help would be
  6 Comments
Walter Roberson
Walter Roberson on 5 Sep 2019
You would create a GUI around the entire code. The initialization code would do an
instrfind('type', 'serial')
to get the names of the available serial ports. You would use those to populate the String property of a uicontrol style 'popup' or 'listbox' to have the user select the COM port. The callback on that uicontrol would execute the serial() command on the port and fopen() it and store the port object in an accessible place, and do the xlsread and store the results in an accessible place.
After that, instead of doing an infinite loop reading from the port, use BytesAvailableFcn callback on the serial port to trigger a callback when data is ready for you.
I suggest you look at GUIDE. GUIDE is not without its faults, but for a first GUI it can really help put together a framework.
avram alter
avram alter on 9 Sep 2019
I have changed my code so that I can subindex to cell types, and inserted placeholder code for the uipanel. the problem is with initializing the GUI. I reasd through your comment multiple times, and found it helpful. the problem is that I am very new to thius, and basically grabbing existing code, and then reading up on how to change it to suit my needs. its all very much on the fly. If you could find time to maybe explain you comment simpler, I would really appreciate that. again, thanks for all the help up until now, I really appreciate it.

Sign in to comment.

Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Tags

Products


Release

R2017a

Community Treasure Hunt

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

Start Hunting!