getting errors in ic tester code

4 visualizaciones (últimos 30 días)
KALANKAR KHUSHI PRAFUL
KALANKAR KHUSHI PRAFUL el 16 de Abr. de 2024
Respondida: Karanjot el 25 de Abr. de 2024
Dot indexing is not supported for variables of this type.
Error in ic_tester>popupmenu1_CreateFcn (line 116)
set(handles.text2, 'String', 'Please select an option from the dropdown');
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in ic_tester (line 41)
gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)ic_tester('popupmenu1_CreateFcn',hObject,eventdata,guidata(hObject))
im getting these errors while running my ic tester code
below is my code from ic_tester.m file
function varargout = ic_tester(varargin)
% IC_TESTER MATLAB code for ic_tester.fig
% IC_TESTER, by itself, creates a new IC_TESTER or raises the existing
% singleton*.
%
% H = IC_TESTER returns the handle to a new IC_TESTER or the handle to
% the existing singleton*.
%
% IC_TESTER('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in IC_TESTER.M with the given input arguments.
%
% IC_TESTER('Property','Value',...) creates a new IC_TESTER or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before ic_tester_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to ic_tester_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Last Modified by GUIDE v2.5 27-Nov-2016 17:28:30
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ic_tester_OpeningFcn, ...
'gui_OutputFcn', @ic_tester_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
end
function ic_tester_OpeningFcn(hObject, ~, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to ic_tester (see VARARGIN)
% Choose default command line output for ic_tester
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
set(handles.text2, 'String', 'Welcome! Click on "Connect" to start');
end
function varargout = ic_tester_OutputFcn(~, ~, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
end
function connectToArduino(handles)
try
handles.a = arduino('COM8');
set(handles.text2, 'String', 'Connected');
catch
set(handles.text2, 'String', 'Failed to connect to Arduino');
end
end
function pushbutton1_Callback(~, ~, handles)
set(handles.text2, 'String', 'Connecting...');
connectToArduino(handles);
end
function popupmenu1_CreateFcn(hObject, ~, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function pushbutton2_Callback(~, ~, handles)
if ~isfield(handles, 'a')
set(handles.text2, 'String', 'Arduino not connected');
return;
end
end
global n;
if isempty(n)
set(handles.text2, 'String', 'Please select an option from the dropdown');
return;
end
try
a = handles.a;
switch n
case 1
% Your logic for case 1 here
a.pinMode(2,'output'); % Changed from 13 to 2
a.pinMode(3,'output');
a.pinMode(4,'input'); % Changed from 2 to 3
a.pinMode(5,'output');
a.pinMode(6,'input'); % Changed from 3 to 4
a.pinMode(7,'input');
a.pinMode(8,'output');
a.pinMode(9,'output');
a.pinMode(10,'input');
a.pinMode(11,'output');
a.pinMode(12,'output');
a.digitalWrite(2,0);
a.digitalWrite(3,0);
a.digitalWrite(5,0);
a.digitalWrite(8,0);
a.digitalWrite(9,0);
a.digitalWrite(11,0);
a.digitalWrite(12,0);
pause(0.1);
t11=a.digitalRead(4);
t12=a.digitalRead(6);
t13=a.digitalRead(7);
t14=a.digitalRead(10);
if (t11==1 && t12==1 && t13==1 && t14==1)
a.digitalWrite(2,1);
a.digitalWrite(3,1);
a.digitalWrite(5,1);
a.digitalWrite(8,1);
a.digitalWrite(9,1);
a.digitalWrite(11,1);
a.digitalWrite(12,1);
pause(0.1);
t21=a.digitalRead(4);
t22=a.digitalRead(6);
t23=a.digitalRead(7);
t24=a.digitalRead(10);
if (t21==0 && t22==0 && t23==0 && t24==0)
set(handles.text2,'String','IC is in working condition');
else
set(handles.text2,'String','Faulty IC');
end
else
set(handles.text2,'String','Faulty IC');
end
case 2
% Your logic for case 2 here
a.pinMode(13,'input');
a.pinMode(2,'output');
a.pinMode(3,'output');
a.pinMode(4,'input');
a.pinMode(5,'output');
a.pinMode(6,'output');
a.pinMode(7,'output');
a.pinMode(8,'output');
a.pinMode(9,'input');
a.pinMode(10,'output');
a.pinMode(11,'output');
a.pinMode(12,'input');
a.digitalWrite(2,0);
a.digitalWrite(3,0);
a.digitalWrite(5,0);
a.digitalWrite(6,0);
a.digitalWrite(7,0);
a.digitalWrite(8,0);
a.digitalWrite(10,0);
a.digitalWrite(11,0);
pause(0.1);
t11=a.digitalRead(13);
t12=a.digitalRead(4);
t13=a.digitalRead(9);
t14=a.digitalRead(12);
if (t11==1 && t12==1 && t13==1 && t14==1)
a.digitalWrite(2,0);
a.digitalWrite(3,1);
a.digitalWrite(5,0);
a.digitalWrite(6,1);
a.digitalWrite(7,0);
a.digitalWrite(8,1);
a.digitalWrite(10,0);
a.digitalWrite(11,1);
pause(0.1);
t21=a.digitalRead(13);
t22=a.digitalRead(4);
t23=a.digitalRead(9);
t24=a.digitalRead(12);
if (t21==0 && t22==0 && t23==0 && t24==0)
a.digitalWrite(2,1);
a.digitalWrite(3,0);
a.digitalWrite(5,1);
a.digitalWrite(6,0);
a.digitalWrite(7,1);
a.digitalWrite(8,0);
a.digitalWrite(10,1);
a.digitalWrite(11,0);
pause(0.1);
t31=a.digitalRead(13);
t32=a.digitalRead(4);
t33=a.digitalRead(9);
t34=a.digitalRead(12);
if (t31==0 && t32==0 && t33==0 && t34==0)
a.digitalWrite(2,1);
a.digitalWrite(3,1);
a.digitalWrite(5,1);
a.digitalWrite(6,1);
a.digitalWrite(7,1);
a.digitalWrite(8,1);
a.digitalWrite(10,1);
a.digitalWrite(11,1);
pause(0.1);
t41=a.digitalRead(13);
t42=a.digitalRead(4);
t43=a.digitalRead(9);
t44=a.digitalRead(12);
if (t41==0 && t42==0 && t43==0 && t44==0)
set(handles.text2,'String','IC is in working condition');
else
set(handles.text2,'String','Faulty IC');
end
else
set(handles.text2,'String','Faulty IC');
end
else
set(handles.text2,'String','Faulty IC');
end
else
set(handles.text2,'String','Faulty IC');
end
case 3
% Your logic for case 3 here
a.pinMode(13,'output');
a.pinMode(2,'input');
a.pinMode(3,'output');
a.pinMode(4,'input');
a.pinMode(5,'output');
a.pinMode(6,'input');
a.pinMode(7,'input');
a.pinMode(8,'output');
a.pinMode(9,'input');
a.pinMode(10,'output');
a.pinMode(11,'input');
a.pinMode(12,'output');
a.digitalWrite(13,1);
a.digitalWrite(3,1);
a.digitalWrite(5,1);
a.digitalWrite(8,1);
a.digitalWrite(10,1);
a.digitalWrite(12,1);
pause(0.1);
t11=a.digitalRead(2);
t12=a.digitalRead(4);
t13=a.digitalRead(6);
t14=a.digitalRead(7);
t15=a.digitalRead(9);
t16=a.digitalRead(11);
if (t11==0 && t12==0 && t13==0 && t14==0 && t15==0 && t16==0)
a.digitalWrite(13,0);
a.digitalWrite(3,0);
a.digitalWrite(5,0);
a.digitalWrite(8,0);
a.digitalWrite(10,0);
a.digitalWrite(12,0);
pause(0.1);
t11=a.digitalRead(2);
t12=a.digitalRead(4);
t13=a.digitalRead(6);
t14=a.digitalRead(7);
t15=a.digitalRead(9);
t16=a.digitalRead(11);
if (t11==1 && t12==1 && t13==1 && t14==1 && t15==1 && t16==1)
set(handles.text2,'String','IC is in working condition');
else
set(handles.text2,'String','Faulty IC');
end
else
set(handles.text2,'String','Faulty IC');
end
case 4
% Your logic for case 4 here
a.pinMode(13,'output');
a.pinMode(2,'output');
a.pinMode(3,'input');
a.pinMode(4,'output');
a.pinMode(5,'output');
a.pinMode(6,'input');
a.pinMode(7,'input');
a.pinMode(8,'output');
a.pinMode(9,'output');
a.pinMode(10,'input');
a.pinMode(11,'output');
a.pinMode(12,'output');
a.digitalWrite(13,0);
a.digitalWrite(2,0);
a.digitalWrite(4,0);
a.digitalWrite(5,0);
a.digitalWrite(8,0);
a.digitalWrite(9,0);
a.digitalWrite(11,0);
a.digitalWrite(12,0);
pause(0.1);
t11=a.digitalRead(3);
t12=a.digitalRead(6);
t13=a.digitalRead(7);
t14=a.digitalRead(10);
if (t11==0 && t12==0 && t13==0 && t14==0)
a.digitalWrite(13,0);
a.digitalWrite(2,1);
a.digitalWrite(4,0);
a.digitalWrite(5,1);
a.digitalWrite(8,0);
a.digitalWrite(9,1);
a.digitalWrite(11,0);
a.digitalWrite(12,1);
pause(0.1);
t21=a.digitalRead(3);
t22=a.digitalRead(6);
t23=a.digitalRead(7);
t24=a.digitalRead(10);
if (t21==0 && t22==0 && t23==0 && t24==0)
a.digitalWrite(13,1);
a.digitalWrite(2,0);
a.digitalWrite(4,1);
a.digitalWrite(5,0);
a.digitalWrite(8,1);
a.digitalWrite(9,0);
a.digitalWrite(11,1);
a.digitalWrite(12,0);
pause(0.1);
t31=a.digitalRead(3);
t32=a.digitalRead(6);
t33=a.digitalRead(7);
t34=a.digitalRead(10);
if (t31==0 && t32==0 && t33==0 && t34==0)
a.digitalWrite(13,1);
a.digitalWrite(2,1);
a.digitalWrite(4,1);
a.digitalWrite(5,1);
a.digitalWrite(8,1);
a.digitalWrite(9,1);
a.digitalWrite(11,1);
a.digitalWrite(12,1);
pause(0.1);
t41=a.digitalRead(3);
t42=a.digitalRead(6);
t43=a.digitalRead(7);
t44=a.digitalRead(10);
if (t41==1 && t42==1 && t43==1 && t44==1)
set(handles.text2,'String','IC is in working condition');
else
set(handles.text2,'String','Faulty IC');
end
else
set(handles.text2,'String','Faulty IC');
end
else
set(handles.text2,'String','Faulty IC');
end
else
set(handles.text2,'String','Faulty IC');
end
case 5
% Your logic for case 5 here
a.pinMode(13,'output');
a.pinMode(2,'output');
a.pinMode(3,'input');
a.pinMode(4,'output');
a.pinMode(5,'output');
a.pinMode(6,'input');
a.pinMode(7,'input');
a.pinMode(8,'output');
a.pinMode(9,'output');
a.pinMode(10,'input');
a.pinMode(11,'output');
a.pinMode(12,'output');
a.digitalWrite(13,0);
a.digitalWrite(2,0);
a.digitalWrite(4,0);
a.digitalWrite(5,0);
a.digitalWrite(8,0);
a.digitalWrite(9,0);
a.digitalWrite(11,0);
a.digitalWrite(12,0);
pause(0.1);
t11=a.digitalRead(3);
t12=a.digitalRead(6);
t13=a.digitalRead(7);
t14=a.digitalRead(10);
if (t11==0 && t12==0 && t13==0 && t14==0)
a.digitalWrite(13,0);
a.digitalWrite(2,1);
a.digitalWrite(4,0);
a.digitalWrite(5,1);
a.digitalWrite(8,0);
a.digitalWrite(9,1);
a.digitalWrite(11,0);
a.digitalWrite(12,1);
pause(0.1);
t21=a.digitalRead(3);
t22=a.digitalRead(6);
t23=a.digitalRead(7);
t24=a.digitalRead(10);
if (t21==1 && t22==1 && t23==1 && t24==1)
a.digitalWrite(13,1);
a.digitalWrite(2,0);
a.digitalWrite(4,1);
a.digitalWrite(5,0);
a.digitalWrite(8,1);
a.digitalWrite(9,0);
a.digitalWrite(11,1);
a.digitalWrite(12,0);
pause(0.1);
t31=a.digitalRead(3);
t32=a.digitalRead(6);
t33=a.digitalRead(7);
t34=a.digitalRead(10);
if (t31==1 && t32==1 && t33==1 && t34==1)
a.digitalWrite(13,1);
a.digitalWrite(2,1);
a.digitalWrite(4,1);
a.digitalWrite(5,1);
a.digitalWrite(8,1);
a.digitalWrite(9,1);
a.digitalWrite(11,1);
a.digitalWrite(12,1);
pause(0.1);
t41=a.digitalRead(3);
t42=a.digitalRead(6);
t43=a.digitalRead(7);
t44=a.digitalRead(10);
if (t41==1 && t42==1 && t43==1 && t44==1)
set(handles.text2,'String','IC is in working condition');
else
set(handles.text2,'String','Faulty IC');
end
else
set(handles.text2,'String','Faulty IC');
end
else
set(handles.text2,'String','Faulty IC');
end
else
set(handles.text2,'String','Faulty IC');
end
case 6
% Your logic for case 6 here
a.pinMode(13,'output');
a.pinMode(2,'output');
a.pinMode(3,'input');
a.pinMode(4,'output');
a.pinMode(5,'output');
a.pinMode(6,'input');
a.pinMode(7,'input');
a.pinMode(8,'output');
a.pinMode(9,'output');
a.pinMode(10,'input');
a.pinMode(11,'output');
a.pinMode(12,'output');
a.digitalWrite(13,0);
a.digitalWrite(2,0);
a.digitalWrite(4,0);
a.digitalWrite(5,0);
a.digitalWrite(8,0);
a.digitalWrite(9,0);
a.digitalWrite(11,0);
a.digitalWrite(12,0);
pause(0.1);
t11=a.digitalRead(3);
t12=a.digitalRead(6);
t13=a.digitalRead(7);
t14=a.digitalRead(10);
if (t11==0 && t12==0 && t13==0 && t14==0)
a.digitalWrite(13,0);
a.digitalWrite(2,1);
a.digitalWrite(4,0);
a.digitalWrite(5,1);
a.digitalWrite(8,0);
a.digitalWrite(9,1);
a.digitalWrite(11,0);
a.digitalWrite(12,1);
pause(0.1);
t21=a.digitalRead(3);
t22=a.digitalRead(6);
t23=a.digitalRead(7);
t24=a.digitalRead(10);
if (t21==1 && t22==1 && t23==1 && t24==1)
a.digitalWrite(13,1);
a.digitalWrite(2,0);
a.digitalWrite(4,1);
a.digitalWrite(5,0);
a.digitalWrite(8,1);
a.digitalWrite(9,0);
a.digitalWrite(11,1);
a.digitalWrite(12,0);
pause(0.1);
t31=a.digitalRead(3);
t32=a.digitalRead(6);
t33=a.digitalRead(7);
t34=a.digitalRead(10);
if (t31==1 && t32==1 && t33==1 && t34==1)
a.digitalWrite(13,1);
a.digitalWrite(2,1);
a.digitalWrite(4,1);
a.digitalWrite(5,1);
a.digitalWrite(8,1);
a.digitalWrite(9,1);
a.digitalWrite(11,1);
a.digitalWrite(12,1);
pause(0.1);
t41=a.digitalRead(3);
t42=a.digitalRead(6);
t43=a.digitalRead(7);
t44=a.digitalRead(10);
if (t41==0 && t42==0 && t43==0 && t44==0)
set(handles.text2,'String','IC is in working condition');
else
set(handles.text2,'String','Faulty IC');
end
else
set(handles.text2,'String','Faulty IC');
end
else
set(handles.text2,'String','Faulty IC');
end
else
set(handles.text2,'String','Faulty IC');
end
otherwise
set(handles.text2, 'String', 'Invalid option selected');
end
catch
set(handles.text2, 'String', 'Error testing IC');
end
end
function pushbutton3_Callback(~, ~, handles)
if isfield(handles, 'a')
delete(handles.a);
set(handles.text2, 'String', 'Arduino disconnected');
end
end

Respuestas (1)

Karanjot
Karanjot el 25 de Abr. de 2024
Hi,
The error message you're encountering, "Dot indexing is not supported for variables of this type," typically occurs when you attempt to access a structure field on a variable that MATLAB does not recognize as a structure or an object that supports dot indexing.
The error originates from your popupmenu1_CreateFcn function. The crucial thing to note is that during the execution of CreateFcn (Create Function) callbacks, the handles structure might not be fully initialized, hence the error when you try to use dot indexing on it. This is hinted at in the generated comment within your code:
% handles empty - handles not created until after all CreateFcns called
I recommend you the following potential solutions:
  1. Ensure Proper Initialization within the CreateFcn block
  2. Delaying the Access to handles: If you need to initialize or set properties of other UI components indirectly related to the one being created, consider doing so in the OpeningFcn or by triggering a custom initialization function after the GUI is fully loaded. This ensures that all handles are properly initialized before you attempt to access them.
  3. Check for Field Existence: In cases where you might still need to access handles in a situation where its full initialization isn't guaranteed, always check for the existence of the field first using:
isfield(handles, 'text2')
I hope this helps!

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by