结构体内容引用自非结构体数组对象修改问题
functionfigure1_CloseRequestFcn(hObject,eventdata,handles)globalnumber;globalo_Serial...
function figure1_CloseRequestFcn(hObject, eventdata, handles)
global number;
global o_SerialPort;
%--------------关闭串口------------------------
if strcmp(o_SerialPort.Status,'open')
fclose(o_SerialPort);
end
number=[];
clear number;
delete(hObject);
%---------------按钮显示切换设置--------------
set(hObject,'Visible','off');
set(handles.pb_CloseSerialPort,'Position',get(handles.pb_OpenSerialPort,'Position'));
%-----------------端口初始化-------------------
set(handles.pb_CloseSerialPort,'Visible','on');
int_Index_COM=get(handles.pop_SerialPort,'Value');
string_COM=get(handles.pop_SerialPort,'String');
string_Select_COM=string_COM{int_Index_COM};
o_SerialPort=serial(string_Select_COM);
%---------------设置缓冲区大小为1M----------------
set(o_SerialPort,'InputBufferSize',1024000);
%--------------- EveBytesAvailableFcn事件回调函数-------------------
function EveBytesAvailableFcn( t,event,handles )
global o_SerialPort;
global number;
number=[number fread(o_SerialPort,10)'];
set(handles.edit_ReceiveData,'String',num2str(number));
% -------------------发送按钮回调------------------
unction pb_SendData_Callback(hObject, eventdata, handles)
global o_SerialPort;
string_edit_SendData=get(handles.edit_SendData,'String');
if(get(handles.cb_CharOrHex,'Value')==get(handles.cb_CharOrHex,'Max'))
fprintf(o_SerialPort,string_edit_SendData);
else
double_edit_SendData=str2num(string_edit_SendData);
fwrite(o_SerialPort,double_edit_SendData);
end
%--------------------串口下拉位选择-----------------
function pop_SerialPort_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
%------------------------------------------发送数据-------------------------------------
function edit_SendData_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
%------------------------------------------接收数据-------------------------------------
function edit_ReceiveData_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
结构体内容引用自非结构体数组对象。
出错 figure1_CloseRequestFcn (line 5)
if strcmp(o_SerialPort.Status,'open')
如何修改呢?谢谢 展开
global number;
global o_SerialPort;
%--------------关闭串口------------------------
if strcmp(o_SerialPort.Status,'open')
fclose(o_SerialPort);
end
number=[];
clear number;
delete(hObject);
%---------------按钮显示切换设置--------------
set(hObject,'Visible','off');
set(handles.pb_CloseSerialPort,'Position',get(handles.pb_OpenSerialPort,'Position'));
%-----------------端口初始化-------------------
set(handles.pb_CloseSerialPort,'Visible','on');
int_Index_COM=get(handles.pop_SerialPort,'Value');
string_COM=get(handles.pop_SerialPort,'String');
string_Select_COM=string_COM{int_Index_COM};
o_SerialPort=serial(string_Select_COM);
%---------------设置缓冲区大小为1M----------------
set(o_SerialPort,'InputBufferSize',1024000);
%--------------- EveBytesAvailableFcn事件回调函数-------------------
function EveBytesAvailableFcn( t,event,handles )
global o_SerialPort;
global number;
number=[number fread(o_SerialPort,10)'];
set(handles.edit_ReceiveData,'String',num2str(number));
% -------------------发送按钮回调------------------
unction pb_SendData_Callback(hObject, eventdata, handles)
global o_SerialPort;
string_edit_SendData=get(handles.edit_SendData,'String');
if(get(handles.cb_CharOrHex,'Value')==get(handles.cb_CharOrHex,'Max'))
fprintf(o_SerialPort,string_edit_SendData);
else
double_edit_SendData=str2num(string_edit_SendData);
fwrite(o_SerialPort,double_edit_SendData);
end
%--------------------串口下拉位选择-----------------
function pop_SerialPort_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
%------------------------------------------发送数据-------------------------------------
function edit_SendData_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
%------------------------------------------接收数据-------------------------------------
function edit_ReceiveData_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
结构体内容引用自非结构体数组对象。
出错 figure1_CloseRequestFcn (line 5)
if strcmp(o_SerialPort.Status,'open')
如何修改呢?谢谢 展开
1个回答
2018-07-21
展开全部
结构体成员在引用时,
如果结构体是变量,
可以使用.来引用(点引用符号),
如果是指针,必须使用->来引用。
当然如果不是C而是C++的话可能不这么严格了。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询