MATLAB Answers

How to make a panel in Guide change color

조회 수: 2(최근 30일)
avram alter
avram alter 5 Sep 2019
편집: avram alter 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):
tag = serial('COM3'); %check which port is used
%readData = fscanf(tag); %initialize
%writeData = uint16(500); % 0x01F4
%fwrite(tag, writeData, 'uint16') %write data
BOX = char(zeros(2,14));
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
% if(length(readData)>10) %if chip has been read
% ReadChips
if strcmp(TrueValMat{2,1}, BOX(1,:))
disp('hurray1')%set(handles.uipanel3, 'Backgroundcolor', 'g');
disp('not hurray1') %set(handles.uipanel3, 'Backgroundcolor', 'r');
if strcmp(TrueValMat{2,2}, BOX(2,:))
disp('hurray2') %set(handles.uipanel2, 'Backgroundcolor', 'g');
disp('not hurray2') %set(handles.uipanel2, 'Backgroundcolor', 'r');
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
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

표시 이전 댓글 수: 3
avram alter
avram alter 5 Sep 2019
How would that call to my GUI? NameofUipanel would allow it to find the GUI i'm working with? Like how would I call to activate my specific GUI, when there are dozens being used by other systems on the same computer? And the name of the panel is the tag, or the title, when veiwing in guide?
thanks for the help, I really appreciate it
Walter Roberson
Walter Roberson 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 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.

로그인 to comment.


이 질문에 답변하려면 로그인을(를) 수행하십시오.





Translated by