Effacer les filtres
Effacer les filtres

Timer encounters error on non-structure array

1 vue (au cours des 30 derniers jours)
Matuno
Matuno le 19 Jan 2014
Réponse apportée : Jan le 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.

Réponses (1)

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

Catégories

En savoir plus sur Programming Utilities dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by