Timer encounters error on non-structure array

1 次查看(过去 30 天)
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.

回答(1 个)

Jan
Jan 2014-1-19
'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);
...

类别

Help CenterFile Exchange 中查找有关 Programming Utilities 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by