I am starting with MatLab.
I created a guide UI. I went ahead and assumed I could just add new feild to the handles structure created.
Can I do this?
For example, when I refer to handle.s in my program, I get an error that I am reffering to a non existing feild.
handles.s was created to store a serial port object generated in a function that initialises serial communication between my PC and a microcontroller.
the serial port object has methods and feild of its own...could it be that I cannot pass an object as a feild to the handles object that contains the property of the guide UI?
Here is the code I am working with
function [ s, flag] = setupSerial(comPort)
%Initialize serial port communication between Arduino and Matlab
%Ensure that the arduino is also communicating with Matlab at this time.
%if setup is complete then the value of setup is returned as 1 else 0.
flag =1;
s = serial(comPort);
set(s,'DataBits',8);
set(s,'StopBits',1);
set(s,'BaudRate',9600);
set(s,'Parity','none');
fopen(s);
a='b';
while (a~='a')
a=fread(s,1,'uchar');
end
if (a=='a')
disp('serial read');
end
fprintf(s,'%c','a');
mbox = msgbox('Serial Communication setup.'); uiwait(mbox);
fscanf(s,'%u');
end
Within my UserInterface.m file, I pass over the object in a claaback function as follows
function SerialBtn_Callback(hObject, eventdata, handles)
% hObject handle to SerialBtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA
comPort = get(handles.COMportTxt,'String');
if(~exist('serialFlag','var'))
[handles.s, handles.serialFlag] = setupSerial(comPort);
end
end
I get the error when I press the 'Home' button. Here is the callback funciton
function HomeButton_Callback(hObject, eventdata, handles)
% hObject handle to HomeButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp('home button pressed');
fprintf(handles.s,'%s', 'G2');
set(handles.CurrentPositionTxt, 'String', '0');
end
There error I get is the following
Reference to non-existent field 's'.
Here the GUI for you information