Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

OBJ must be connected to the hardware with FOPEN.

553 views
Skip to first unread message

Dong Joo Kang

unread,
Aug 2, 2015, 11:20:10 AM8/2/15
to
Hi, I makes gui for serial communication

I have problem timer and fopen.
Here is my error message, 'error OBJ must be connected to the hardware with FOPEN.'

my code is too long so i capture part.

-----------------------------------------------------------------------------------------------
function GCS_initial1_OpeningFcn(hObject, eventdata, handles, varargin)
%Serial Port update
serialPorts = instrhwinfo('serial');
nPorts = length(serialPorts.SerialPorts);
set(handles.COMPORT_popup, 'String', ...
[{'Select a port'} ; serialPorts.SerialPorts ]);
set(handles.COMPORT_popup, 'Max', 2);

%repeat 0.5sec print data
handles.t=timer('TimerFcn', {@data_cal, hObject},'Period',0.5,'ExecutionMode', 'fixedRate');
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

function Open_button_Callback(hObject, eventdata, handles)
serPortn = get(handles.COMPORT_popup, 'Value');
if(serPortn==1)
errordlg('Select valid COM port');
else

serList = get(handles.COMPORT_popup,'String');
serPort = serList{serPortn};

Xbee_Comport = serial(serPort, 'BaudRate', 9600,'DataBits',8,'StopBits',1);
Xbee_Comport.Terminator = 'CR/LF';
Xbee_Comport.BytesAvailableFcnMode = 'terminator';

try
fopen(Xbee_Comport);
handles.Xbee_Comport=Xbee_Comport;
fp1 = fopen('data_log.txt', 'w');
set(handles.Serial_State, 'String', 'Serial Open');
handles.fp1=fp1;
fprintf(handles.fp1,'Start Record Data\n');
start(handles.t);

catch e
errordlg(e.message);

end
end
guidata(hObject, handles);

function Close_button_Callback(hObject, eventdata, handles)
% hObject handle to Close_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
fprintf(handles.fp1,'Finish Record Data\n');
fclose(handles.Xbee_Comport);
fclose(handles.fp1);
stop(handles.t);
set(handles.Serial_State, 'String', 'Serial Close');

function data_cal(obj,event,hfigure)
handles=guidata(hfigure);
XbeeToData;

--------------------------------------------------------------------------------------------
---------XbeeToData.m-----------------
global DATA;
DATA=fscanf(handles.Xbee_Comport);
fprintf(handles.fp1,DATA);

dpb

unread,
Aug 2, 2015, 11:28:06 AM8/2/15
to
On 08/02/2015 10:20 AM, Dong Joo Kang wrote:
> Hi, I makes gui for serial communication
>
> I have problem timer and fopen. Here is my error message, 'error OBJ
> must be connected to the hardware with FOPEN.'
>
> my code is too long so i capture part.

....

> function Open_button_Callback(hObject, eventdata, handles)
> serPortn = get(handles.COMPORT_popup, 'Value');
> if(serPortn==1)
> errordlg('Select valid COM port');
> else
> serList = get(handles.COMPORT_popup,'String');
> serPort = serList{serPortn};
> Xbee_Comport = serial(serPort, 'BaudRate', 9600,'DataBits',8,'StopBits',1);
> Xbee_Comport.Terminator = 'CR/LF';
> Xbee_Comport.BytesAvailableFcnMode = 'terminator';
>
> try
> fopen(Xbee_Comport);
> handles.Xbee_Comport=Xbee_Comport;
> fp1 = fopen('data_log.txt', 'w');
> set(handles.Serial_State, 'String', 'Serial Open');
> handles.fp1=fp1;
> fprintf(handles.fp1,'Start Record Data\n');
> start(handles.t);
> catch e
> errordlg(e.message);
> end
> end
...

So, you're not checking the returned status of the FOPEN() call; what is
it when you use DEBUG??? (One presumes owing to the error message that
it will be '{closed}'. Your mission, should you choose to accept it,
will then be to uncover "why?" and resolve talking to the device at the
command line before worrying about complex code.

--


--
0 new messages