Clear Filters
Clear Filters

Timer encounters error on non-structure array

1 view (last 30 days)
Matuno
Matuno on 19 Jan 2014
Answered: Jan on 19 Jan 2014
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.

Answers (1)

Jan
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);
...

Categories

Find more on Programming Utilities in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!