Azzera filtri
Azzera filtri

Timer encounters error on non-structure array

1 visualizzazione (ultimi 30 giorni)
Matuno
Matuno il 19 Gen 2014
Risposto: Jan il 19 Gen 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.

Risposte (1)

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

Categorie

Scopri di più su Programming Utilities in Help Center e File Exchange

Tag

Non è stata ancora inserito alcun tag.

Community Treasure Hunt

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

Start Hunting!

Translated by