📄 comdraw.m
字号:
% --- Executes on selection change in popup_stop_bit.function popup_stop_bit_Callback(hObject, eventdata, handles)% hObject handle to popup_stop_bit (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: contents = get(hObject,'String') returns popup_stop_bit contents as cell array% contents{get(hObject,'Value')} returns selected item from popup_stop_bit% --- Executes during object creation, after setting all properties.function popup_parity_CreateFcn(hObject, eventdata, handles)% hObject handle to popup_parity (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: popupmenu controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));end% --- Executes on selection change in popup_parity.function popup_parity_Callback(hObject, eventdata, handles)% hObject handle to popup_parity (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: contents = get(hObject,'String') returns popup_parity contents as cell array% contents{get(hObject,'Value')} returns selected item from popup_parity% --- radio button mutual exclude function
function radio_mutual_exclude( h_on, h_off )
% h_on handle to the selected radio button
% h_off handle to all not selected radio buttons of same group
% Write by HouWu Wei
set( h_on, 'Value', 1 );
set( h_off, 'Value', 0 );
% --- Executes on button press in radio_hex_fmt.function radio_hex_fmt_Callback(hObject, eventdata, handles)% hObject handle to radio_hex_fmt (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hint: get(hObject,'Value') returns toggle state of radio_hex_fmt
h_on = handles.radio_hex_fmt;
h_off = handles.radio_asc_fmt;radio_mutual_exclude( h_on, h_off );% --- Executes on button press in radio_asc_fmt.function radio_asc_fmt_Callback(hObject, eventdata, handles)% hObject handle to radio_asc_fmt (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hint: get(hObject,'Value') returns toggle state of radio_asc_fmth_on = handles.radio_asc_fmt;
h_off = handles.radio_hex_fmt;
radio_mutual_exclude( h_on, h_off );% --- Executes during object creation, after setting all properties.function edit_send_box_CreateFcn(hObject, eventdata, handles)% hObject handle to edit_send_box (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit_send_box_Callback(hObject, eventdata, handles)% hObject handle to edit_send_box (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit_send_box as text% str2double(get(hObject,'String')) returns contents of edit_send_box as a double
% --- ascii string to hex numbersfunction hexnum = asciistr_to_hex_nums( ascStr )
% ascStr is need transf string
len = length( ascStr );
hexnum= [];
for k = 1:len;
hexasc = ascStr(k);
if hexasc>='0'&& hexasc<='9'
hextmp = hexasc-'0';
elseif hexasc>='A' && hexasc<='F'
hextmp = hexasc-'A'+10;
elseif hexasc>='a' && hexasc<='f'
hextmp = hexasc-'a'+10;
else
hextmp = 0;
end
if bitand(k,1)==1;
hexval = hextmp;
else
hexnum(k/2) = hexval*16+hextmp;
end
end
% --- Executes on button press in pbutton_send_data.function pbutton_send_data_Callback(hObject, eventdata, handles)% hObject handle to pbutton_send_data (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)
global handle_comtxtstr = get( handles.edit_send_box, 'String' );
sendfmt = get( handles.radio_asc_fmt, 'Value' );
if sendfmt==1.0
fwrite( handle_com,txtstr );
else hexnum = asciistr_to_hex_nums( txtstr );
fwrite( handle_com, hexnum );
%len = length( hexnum );
%for k = 1:len;
% fwrite( handle_com, hexnum(k) );
%end
end% --- Executes during object creation, after setting all properties.function edit_dc1_offset_CreateFcn(hObject, eventdata, handles)% hObject handle to edit_dc1_offset (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit_dc1_offset_Callback(hObject, eventdata, handles)% hObject handle to edit_dc1_offset (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit_dc1_offset as text% str2double(get(hObject,'String')) returns contents of edit_dc1_offset as a double% --- Executes during object creation, after setting all properties.function edit_ac1_amp_CreateFcn(hObject, eventdata, handles)% hObject handle to edit_ac1_amp (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit_ac1_amp_Callback(hObject, eventdata, handles)% hObject handle to edit_ac1_amp (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit_ac1_amp as text% str2double(get(hObject,'String')) returns contents of edit_ac1_amp as a double% --- Executes during object creation, after setting all properties.function edit_dc2_offset_CreateFcn(hObject, eventdata, handles)% hObject handle to edit_dc2_offset (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit_dc2_offset_Callback(hObject, eventdata, handles)% hObject handle to edit_dc2_offset (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit_dc2_offset as text% str2double(get(hObject,'String')) returns contents of edit_dc2_offset as a double% --- Executes during object creation, after setting all properties.function edit_ac2_amp_CreateFcn(hObject, eventdata, handles)% hObject handle to edit_ac2_amp (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit_ac2_amp_Callback(hObject, eventdata, handles)% hObject handle to edit_ac2_amp (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit_ac2_amp as text% str2double(get(hObject,'String')) returns contents of edit_ac2_amp as a double% --- Executes when user attempts to close figure1.function figure1_CloseRequestFcn(hObject, eventdata, handles)% hObject handle to figure1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)
global handle_com%com_str = get(handles.popup_com_port,'String'); %get COM ports list
%sel_val = get(handles.popup_com_port,'Value'); %get COM ports list
%sel_str = com_str{ sel_val }; %get old COM port name
%handle_com = serial( sel_str );
%fclose( handle_com );
%delete( handle_com );
%clear handle_com ;
try
fclose( handle_com );
delete( handle_com );
clear handle_com ;
catch
warning( 'Not find COM port opened' );
end% Hint: delete(hObject) closes the figuredelete(hObject);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -