Timer encounters error on non-structure array
1 view (last 30 days)
Show older comments
Trying to use Timer in GUI. While attempting in following code it is showing error.
function main_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
handles.timer = timer(...
'ExecutionMode', 'fixedRate', ... % Run timer repeatedly
'Period', 1, ... % Initial period is 1 sec.
'TimerFcn', {@send_Callback,hObject});
guidata(hObject, handles);
function send_Callback(hObject, eventdata, handles)
comma = get(handles.Tx_send, 'String');%Tx_send is a text field
TxText = char(comma);
sf = rc4e2(TxText,key);%rc4e2 is an encryption
key = TxText;
DBC = char(sf);
disp(DBC);
fwrite(handles.serConn, DBC);%serConn is COM port
The error: Error while evaluating TimerFcn for timer 'timer-1'. Attempt to reference field of non-structure array.
0 Comments
Answers (1)
Jan
on 19 Jan 2014
'TimerFcn', {@send_Callback,hObject}
Now the 3rd input of send_Callback is hObject, the handle provided to the Opening-function. It is not clear, why you store this handle in the field "output". In the callback send_Callback it seems like you expect the 3rd input to be the handles struct and access the fields Tx_send and serConn, but here handles is the graphics handle.
I guess you want something like this:
function send_Callback(hObject, eventdata, hObject)
handles = guidata(hObject);
...
0 Comments
See Also
Categories
Find more on Dialog Boxes in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!