I have a code that scans incoming serial information in the form of an alphanumeric tag. The program then looks through an excel sheet to find that tag, and reports the sheet and row the tag appears in:
portlist = {'COM3', 'COM4', 'COM5', 'COM6'}; % , 'COM4', 'COM5', 'COM6'
nport = length(portlist);tags = cell(1, nport);cleanups = cell(1, nport);for portidx = 1 : nport delete(instrfind('Port', portlist{portidx})); % removes possibility for 'Port not available' error
tags{portidx} = serial(portlist{portidx}); %initializes the port to be used
fopen(tags{portidx}); %opens th eport
% cleanups{portidx} = onCleanup(@() fclose(portlist{portidx}));
cleanups{portidx} = onCleanup(@() fclose('all'));endaddpath('C:\Users\Administrator\Dropbox (********)\******** Team Folder\Matlab\RFID chip reader\RfidChipData');filename = 'CorrectedRFIDValues.xlsx';[~, sheets] = xlsfinfo(filename);in = char(zeros(1,14));decision = fscanf(tags{portidx}); in = decision(11:24);rows_found = [];sheets_found = {};for K = 1 : length(sheets) this_sheet = sheets{K}; [~, ~, raw] = xlsread(filename, this_sheet); [rowNum, colNum] = find( strcmp(in, raw)); if ~isempty(rowNum) rows_found = [rows_found; rowNum]; sheets_found = [sheets_found; repmat({this_sheet}, length(rowNum), 1)]; endenddisp(this_sheet)disp(rowNum)
later in the code, a number of different ports are utilized for a couple other reasons. for this section, only COM3 is used. I keep getting an index out of bounds error, but I am not sure where it is coming from:
Index exceeds the number of array elements (12).Error in Manual_auto_update2>Manual_auto_update2_OutputFcn (line 89)in = decision(11:24);Error in gui_mainfcn (line 264) feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles);Error in Manual_auto_update2 (line 42) gui_mainfcn(gui_State, varargin{:});
the information coming in from serial is a line, indicating a scanner number and the tag being scanned.
its looks like this:
Reader 1: 000000020F0D0%
for decision(11:24), i cut out only the tag from the entire line, as that is all I need to find in the excel sheet. I keep getting that error, however, even though I made a zeros matrix to be filled with the incoming tag. I got it to read a single time, which gave me the resulkts I was looking for. but now I have nothing. the entire code is below, which changes the color of a GUI panel based on a string comparison with the incoming serial tags, and the correct ones stored in the excel sheet. there is a number of different tags that work at different times, as well as for a number of different places.
Best Answer