Main c Matlap v1.3

download Main c Matlap v1.3

of 16

Transcript of Main c Matlap v1.3

  • 7/31/2019 Main c Matlap v1.3

    1/16

    function varargout = mayquetvai(varargin)% MAYQUETVAI MATLAB code for mayquetvai.fig% MAYQUETVAI, by itself, creates a new MAYQUETVAI or raises the existing% singleton*.%% H = MAYQUETVAI returns the handle to a new MAYQUETVAI or the handle to% the existing singleton*.%% MAYQUETVAI('CALLBACK',hObject,eventData,handles,...) calls the local% function named CALLBACK in MAYQUETVAI.M with the given input arguments.%% MAYQUETVAI('Property','Value',...) creates a new MAYQUETVAI or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before mayquetvai_OpeningFcn gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to mayquetvai_OpeningFcn via varargin.%% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one% instance to run (singleton)".%

    % See also: GUIDE, GUIDATA, GUIHANDLES

    % Edit the above text to modify the response to help mayquetvai

    % Last Modified by GUIDE v2.5 10-Oct-2012 05:29:43

    % Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ...

    'gui_Singleton', gui_Singleton, ...'gui_OpeningFcn', @mayquetvai_OpeningFcn, ...'gui_OutputFcn', @mayquetvai_OutputFcn, ...'gui_LayoutFcn', [] , ...

    'gui_Callback', []);ifnargin && ischar(varargin{1})gui_State.gui_Callback = str2func(varargin{1});

    end

    ifnargout[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});

    elsegui_mainfcn(gui_State, varargin{:});

    end% End initialization code - DO NOT EDIT

    % --- Executes just before mayquetvai is made visible.function mayquetvai_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% varargin command line arguments to mayquetvai (see VARARGIN)

    % Choose default command line output for mayquetvaihandles.output = hObject;

  • 7/31/2019 Main c Matlap v1.3

    2/16

    % Update handles structureguidata(hObject, handles);axis(handles.axes1,'off');axis(handles.axes2,'off');

    set(handles.text1,'string','Design by Hong Ngc Hai _ C4-5.P307_HBKHN');global vid i duongdan tamx tamy xvat yvat xvatfull yvatfull zvatfull cam ;

    vid=0;i=0;duongdan=0;tamx=[];tamy=[];xvat=1;yvat=1;xvatfull=[];yvatfull=[];zvatfull=[];cam=0;

    % UIWAIT makes mayquetvai wait for user response (see UIRESUME)% uiwait(handles.figure1);

    % --- Outputs from this function are returned to the command line.function varargout = mayquetvai_OutputFcn(hObject, eventdata, handles)% varargout cell array for returning output args (see VARARGOUT);% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB

    % handles structure with handles and user data (see GUIDATA)

    % Get default command line output from handles structurevarargout{1} = handles.output;

    % --- Executes on button press in pushbutton4.function pushbutton4_Callback(hObject, eventdata, handles)% hObject handle to pushbutton4 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global xyzvatpath=cd;

    [FileName,PathName] = uigetfile({'*.txt';'*.xls'},'Hay lua chon File du lieu dang TEXT hoac EXCEL !!!');cd(PathName);xyzvat=dlmread(FileName);cd(path);set(handles.text1,'string','D Liu c Nhp');

    % --- Executes on button press in pushbutton5.function pushbutton5_Callback(hObject, eventdata, handles)% hObject handle to pushbutton5 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)

    global xyzvataxes(handles.axes2);cla(handles.axes1);cla(handles.axes2);Tri = nhom_cac_dinh_mesh(xyzvat);

    trimesh(Tri,xyzvat(:,1),xyzvat(:,2),xyzvat(:,3),'FaceColor', 'none','EdgeColor','blue');axis equal;axis on;set(handles.text1,'string','Hon Tt M Phng');

  • 7/31/2019 Main c Matlap v1.3

    3/16

    % --- Executes on button press in pushbutton1.function pushbutton1_Callback(hObject, eventdata, handles)% hObject handle to pushbutton1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global vid duongdan path i cam

    i=0;imaqhwinfo;vid=0;duongdan=0;ifcam==0

    msgbox('Hay Chon CAMERA','ERROR CAMERA','error');elsevid=videoinput('winvideo',cam,'YUY2_640x480');bat_camera_trong_axes(vid,handles.axes1);ve_tam_ngam_muc_tieu(320,240);ifduongdan==0[path,duongdan]=tao_thu_muc_luu_anh();endcd(path);

    end

    % --- Executes on button press in pushbutton2.function pushbutton2_Callback(hObject, eventdata, handles)% hObject handle to pushbutton2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)

    global s vid i j duongdan xvatfull yvatfull zvatfull xvat yvat path bamnut thongso tamx tamy bankinh tam_bankinh;xvat=0; yvat=0;%Tien hanh do dat//////////////////////////////////////////////ifvid==0

    gui_haybatcamera;elseifbamnut==1nguong=thongso{1}(1)/256;p=thongso{2}(1);q=thongso{3}(1);

    elsenguong=150/256;p=10;q=10;

    endend

    for j=1:qyvat=0;a=mod(j,2);

    for i=1:pifa == 1

    fwrite(s,17);% cho truc y quay theo time chieu thuanend

    ifa == 0fwrite(s,18);% cho truc y quay theo time chieu nghich

    end

  • 7/31/2019 Main c Matlap v1.3

    4/16

    pause(1);rgb = getsnapshot(vid);rgb1=ycbcr2rgb(rgb);bw=rgb2nhiphan(rgb1,nguong);luu_anh(i,rgb,bw,duongdan);giatri=kiem_tra_co_vet_hay_khong(bw);ifgiatri==1[xc,yc]=xu_ly_anh(rgb,bw);tamx=cat(1,tamx,xc)tamy=cat(1,tamy,yc)zvat = ham_truyen(xc,yc,100,50,4)xvatfull=cat(1,xvatfull,xvat);yvatfull=cat(1,yvatfull,yvat);zvatfull=cat(1,zvatfull,zvat);axes(handles.axes2);cla(handles.axes2);plot3(xvatfull,yvatfull,zvatfull);axis equal;%fprintf(s,'2');pause(0.7);yvat=yvat+0.5;

    set(handles.text1,'string','ang thu d liuCh t');elseset(handles.text1,'string','ERRORVui lng restart v lm li t u');endendfwrite(s,19);% cho truc x quay 1 timepause(1);duongdan=tao_thu_muc_2(path);

    % for k=1:p% fprintf(s,'3');pause(1);%end

    % fprintf(s,'4');pause(0.7);xvat=xvat+0.5;

    endxyzvat = [xvatfull yvatfull zvatfull];tam_bankinh=[tamx tamy bankinh];

    %dlmwrite('toadovat.txt', xyzvat, 'delimiter', ' \t', 'precision', 6);%dlmwrite('toadovat.xls', xyzvat, 'delimiter', ' \t', 'precision', 6);dlmwrite('tam_bankinh.xls', tam_bankinh, 'delimiter', '\t', 'precision', 6);set(handles.text1,'string','Hon tt thu d liu');cd(path);

    % --- Executes on button press in pushbutton3.

    function pushbutton3_Callback(hObject, eventdata, handles)% hObject handle to pushbutton3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)

    % --- Executes on button press in togglebutton3.function togglebutton3_Callback(hObject, eventdata, handles)% hObject handle to togglebutton3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB

  • 7/31/2019 Main c Matlap v1.3

    5/16

    % handles structure with handles and user data (see GUIDATA)

    % Hint: get(hObject,'Value') returns toggle state of togglebutton3global s conectifconect==1dongco3= get(hObject,'Value');ifdongco3 == get(hObject,'Max')

    fwrite(s,9);elseifdongco3 == get(hObject,'Min')

    fwrite(s,10);endelse

    msgbox('Please Conect Motor','ERROR','error')set(handles.togglebutton3,'Value',0);

    end

    % --- Executes on button press in togglebutton2.function togglebutton2_Callback(hObject, eventdata, handles)

    % hObject handle to togglebutton2 (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 togglebutton2global s conectifconect==1dongco2= get(hObject,'Value');ifdongco2 == get(hObject,'Max')

    fwrite(s,7);elseifdongco2 == get(hObject,'Min')

    fwrite(s,8);

    endelsemsgbox('Please Conect Motor','ERROR','error')set(handles.togglebutton2,'Value',0);

    end

    % --- Executes on button press in togglebutton2.function togglebutton1_Callback(hObject, eventdata, handles)% hObject handle to togglebutton2 (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 togglebutton2global s conectifconect==1dongco1= get(hObject,'Value');ifdongco1 == get(hObject,'Max')

    fwrite(s,5);elseifdongco1 == get(hObject,'Min')

    fwrite(s,6);

  • 7/31/2019 Main c Matlap v1.3

    6/16

    endelse

    msgbox('Please Conect Motor','ERROR','error')set(handles.togglebutton1,'Value',0);

    end

    % --------------------------------------------------------------------function Conect_ClickedCallback(hObject, eventdata, handles)% hObject handle to Conect (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global s conect COM

    s = serial(COM);s.Baudrate=9600;s.InputBufferSize=8000;s.Terminator='';conect=1;stop=0;

    baoloi(s);

    set(handles.text2,'string','Conecting...');

    % --------------------------------------------------------------------function Disconect_ClickedCallback(hObject, eventdata, handles)% hObject handle to Disconect (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global s conect

    fclose(s);clear s;conect=0;

    set(handles.text2,'string','Disconect...');

    % --------------------------------------------------------------------function Restart_ClickedCallback(hObject, eventdata, handles)% hObject handle to Restart (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global s conect stop

    luachon =gui_reset('Title','RESET Chuong Trinh');switch lower(luachon)case'khong'

    % do nothingcase'co'%Xoa het du lieu vua thu va RESET cac bien.cla(handles.axes1,'reset'); %clears the axescla(handles.axes2,'reset'); %clears the axesclear global;axis(handles.axes1,'off');axis(handles.axes2,'off');

    clear s;conect=0;

  • 7/31/2019 Main c Matlap v1.3

    7/16

    stop=0;set(handles.text2,'string','Restart');set(handles.togglebutton1,'Value',0);set(handles.togglebutton2,'Value',0);set(handles.togglebutton3,'Value',0);set(handles.radiobutton4,'Value',1);

    set(handles.text1,'string','RESTART Xong...Lm Li T u i...:))');fclose(s);end

    % --------------------------------------------------------------------function com_Callback(hObject, eventdata, handles)% hObject handle to com (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)

    % --------------------------------------------------------------------

    function com1_Callback(hObject, eventdata, handles)% hObject handle to com1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global COM

    COM='COM1';set(handles.text2,'string','COM1');

    % --------------------------------------------------------------------function com2_Callback(hObject, eventdata, handles)% hObject handle to com2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB

    % handles structure with handles and user data (see GUIDATA)global COMCOM='COM2';set(handles.text2,'string','COM2');

    % --------------------------------------------------------------------function com3_Callback(hObject, eventdata, handles)% hObject handle to com3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global COM

    COM='COM3';set(handles.text2,'string','COM3');

    % --------------------------------------------------------------------

    function com4_Callback(hObject, eventdata, handles)% hObject handle to com4 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global COM

    COM='COM4';set(handles.text2,'string','COM4');

    % --------------------------------------------------------------------function com5_Callback(hObject, eventdata, handles)% hObject handle to com5 (see GCBO)

  • 7/31/2019 Main c Matlap v1.3

    8/16

    % eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global COM

    COM='COM5';set(handles.text2,'string','COM5');

    % --------------------------------------------------------------------function com6_Callback(hObject, eventdata, handles)% hObject handle to com6 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global COM

    COM='COM6';set(handles.text2,'string','COM6');

    % --------------------------------------------------------------------function com7_Callback(hObject, eventdata, handles)% hObject handle to com7 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global COM

    COM='COM7';

    set(handles.text2,'string','COM7');

    function baoloi(obj)errorOccurred = false;jobject = igetfield(obj, 'jobject');

    warnState = warning('backtrace', 'off');

    % Call fopen on each java object. Keep looping even% if one of the objects could not be opened.for i=1:length(jobject),

    try

    fopen(jobject(i));catch aExceptionerrorOccurred = true;msg = aException.message;

    endend

    % Report error if one occurred.iferrorOccurred

    iflength(jobject) == 1errordlg('Please Check COM','Error');

    elsewarning('MATLAB:serial:fopen:invalid','An object in OBJ could not be opened or was already open.');

    endend

    warning(warnState);

    % --- Executes when selected object is changed in uipanel6.function uipanel6_SelectionChangeFcn(hObject, eventdata, handles)% hObject handle to the selected object in uipanel6% eventdata structure with the following fields (see UIBUTTONGROUP)

  • 7/31/2019 Main c Matlap v1.3

    9/16

    % EventName: string 'SelectionChanged' (read only)% OldValue: handle of the previously selected object or empty if none was selected% NewValue: handle of the currently selected object% handles structure with handles and user data (see GUIDATA)global s conectifconect==1switch get(eventdata.NewValue,'Tag')

    case'radiobutton4'fwrite(s,1); %chon toc do min

    case'radiobutton2'fwrite(s,2); %chon toc do 1

    case'radiobutton3'fwrite(s,3); %chon toc do 2

    case'radiobutton1'fwrite(s,4); %chon toc do max

    endelse

    msgbox('Please Conect Motor','ERROR','error')set(handles.radiobutton4,'Value',1);

    end

    % --- Executes on button press in togglebutton8.function togglebutton8_Callback(hObject, eventdata, handles)% hObject handle to togglebutton8 (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 togglebutton8global s conectifconect==1chieu1= get(hObject,'Value');ifchieu1== get(hObject,'Max')

    fwrite(s,11);set(handles.togglebutton8,'string','Ra');elseifchieu1 == get(hObject,'Min')

    fwrite(s,12);set(handles.togglebutton8,'string','Vo');

    endelse

    msgbox('Please Conect Motor','ERROR','error')set(handles.togglebutton8,'Value',0);

    end

    % --- Executes on button press in togglebutton9.

    function togglebutton9_Callback(hObject, eventdata, handles)% hObject handle to togglebutton9 (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 togglebutton9global s conectifconect==1chieu2= get(hObject,'Value');ifchieu2== get(hObject,'Max')

  • 7/31/2019 Main c Matlap v1.3

    10/16

    fwrite(s,13);set(handles.togglebutton9,'string','Tri');

    elseifchieu2 == get(hObject,'Min')fwrite(s,14);set(handles.togglebutton9,'string','Phi');

    endelse

    msgbox('Please Conect Motor','ERROR','error')set(handles.togglebutton9,'Value',0);

    end

    % --- Executes on button press in togglebutton10.function togglebutton10_Callback(hObject, eventdata, handles)% hObject handle to togglebutton10 (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 togglebutton10global s conect

    ifconect==1chieu3= get(hObject,'Value');ifchieu3== get(hObject,'Max')

    fwrite(s,15);set(handles.togglebutton10,'string','Xung');

    elseifchieu3 == get(hObject,'Min')fwrite(s,16);set(handles.togglebutton10,'string','Ln');

    endelse

    msgbox('Please Conect Motor','ERROR','error')set(handles.togglebutton10,'Value',0);

    end

    % --------------------------------------------------------------------function camera_Callback(hObject, eventdata, handles)% hObject handle to camera (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)

    % --------------------------------------------------------------------function cam1_Callback(hObject, eventdata, handles)% hObject handle to cam1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB

    % handles structure with handles and user data (see GUIDATA)global camcam=1;

    % --------------------------------------------------------------------function cam2_Callback(hObject, eventdata, handles)% hObject handle to cam2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global cam

  • 7/31/2019 Main c Matlap v1.3

    11/16

    cam=2;

    % --------------------------------------------------------------------function cam3_Callback(hObject, eventdata, handles)% hObject handle to cam3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global cam

    cam=3;

    % --------------------------------------------------------------------function cam4_Callback(hObject, eventdata, handles)% hObject handle to cam4 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global cam

    cam=4;

    % --------------------------------------------------------------------

    function cam5_Callback(hObject, eventdata, handles)% hObject handle to cam5 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global cam

    cam=5;

    % --------------------------------------------------------------------function thongso_Callback(hObject, eventdata, handles)% hObject handle to thongso (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)

    global thongso bamnut;prompt={'Nguong anh sang:';'Buoc ngang:';'Buoc doc:'};name='Cau hinh thong so he thong';formats(1) = struct('type','edit','format','float');formats(2) = struct('type','edit','format','float');formats(3) = struct('type','edit','format','float');

    defaultanswer={150,10,10};[thongso,canceled] = nhapthongsohethong(prompt,name,formats,defaultanswer);bamnut=1;

    set(handles.text1,'string','Nhp Thng S Thnh Cng');

    % --------------------------------------------------------------------function exit_ClickedCallback(hObject, eventdata, handles)% hObject handle to exit (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)set(handles.text1,'string','Design by Hong Ngc Hai _ C4-5.P307_HBKHN');global s;luachon =gui_exit('Title','Thoat Khoi Chuong Trinh');

    switch lower(luachon)case'khong'

  • 7/31/2019 Main c Matlap v1.3

    12/16

    % do nothingcase'co'

    close(handles.figure1);fclose(s);clear all;

    end

    % --- Executes on button press in pushbutton7.function pushbutton7_Callback(hObject, eventdata, handles)% hObject handle to pushbutton7 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)rotate3d off;

    pan off;zoom on;

    % --- Executes on button press in pushbutton8.function pushbutton8_Callback(hObject, eventdata, handles)

    % hObject handle to pushbutton8 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)pan off;

    zoom off;rotate3d on;

    % --- Executes on button press in pushbutton9.function pushbutton9_Callback(hObject, eventdata, handles)% hObject handle to pushbutton9 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)

    rotate3d off;zoom off;pan on;

    % --- Executes on button press in pushbutton10.function pushbutton10_Callback(hObject, eventdata, handles)% hObject handle to pushbutton10 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)datacursormode on;

    % --- Executes on button press in pushbutton16.function pushbutton16_Callback(hObject, eventdata, handles)% hObject handle to pushbutton16 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global s conect stop

    luachon =gui_reset('Title','RESET Chuong Trinh');switch lower(luachon)case'khong'

  • 7/31/2019 Main c Matlap v1.3

    13/16

    % do nothingcase'co'

    %Xoa het du lieu vua thu va RESET cac bien.cla(handles.axes1,'reset'); %clears the axescla(handles.axes2,'reset'); %clears the axesclear global;axis(handles.axes1,'off');axis(handles.axes2,'off');

    clear s;conect=0;stop=0;set(handles.text2,'string','Restart');set(handles.togglebutton1,'Value',0);set(handles.togglebutton2,'Value',0);set(handles.togglebutton3,'Value',0);set(handles.radiobutton4,'Value',1);

    set(handles.text1,'string','RESTART Xong...Lm Li T u i...:))');fclose(s);end

    % --- Executes on button press in pushbutton17.function pushbutton17_Callback(hObject, eventdata, handles)% hObject handle to pushbutton17 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)set(handles.text1,'string','Design by Hong Ngc Hai _ C4-5.P307_HBKHN');global s;luachon =gui_exit('Title','Thoat Khoi Chuong Trinh');

    switch lower(luachon)case'khong'

    % do nothingcase'co'

    close(handles.figure1);fclose(s);clear all;

    end

    % --- Executes on selection change in popupmenu2.function popupmenu2_Callback(hObject, eventdata, handles)% hObject handle to popupmenu2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)

    % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu2 contents as cell array% contents{get(hObject,'Value')} returns selected item from popupmenu2global camval = get(hObject,'Value');switch val

    case 1cam=1;

    case 2cam=2;

  • 7/31/2019 Main c Matlap v1.3

    14/16

    case 3cam=3;

    case 4cam=4;

    case 5cam=5;

    case 6cam=6;

    end

    % --- Executes during object creation, after setting all properties.function popupmenu2_CreateFcn(hObject, eventdata, handles)% hObject handle to popupmenu2 (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.ifispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

    set(hObject,'BackgroundColor','white');end

    % --- Executes on button press in pushbutton11.function pushbutton11_Callback(hObject, eventdata, handles)% hObject handle to pushbutton11 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global s conect COM

    s = serial(COM);s.Baudrate=9600;s.InputBufferSize=8000;

    s.Terminator='';conect=1;stop=0;

    baoloi(s);set(handles.text2,'string','Conecting...');

    % --- Executes on button press in pushbutton12.function pushbutton12_Callback(hObject, eventdata, handles)% hObject handle to pushbutton12 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global s conect

    fclose(s);clear s;conect=0;set(handles.text2,'string','Disconect...');

    % --- Executes on selection change in popupmenu1.function popupmenu1_Callback(hObject, eventdata, handles)% hObject handle to popupmenu1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)

  • 7/31/2019 Main c Matlap v1.3

    15/16

    % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array% contents{get(hObject,'Value')} returns selected item from popupmenu1global COMval = get(hObject,'Value');switch val;

    case 1COM='COM1';set(handles.text2,'string','COM1');

    case 2COM='COM2';set(handles.text2,'string','COM2');

    case 3COM='COM3';set(handles.text2,'string','COM3');

    case 4COM='COM4';set(handles.text2,'string','COM4');

    case 5COM='COM5';

    set(handles.text2,'string','COM5');case 6

    COM='COM6';set(handles.text2,'string','COM6');

    end

    % --- Executes during object creation, after setting all properties.function popupmenu1_CreateFcn(hObject, eventdata, handles)% hObject handle to popupmenu1 (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.ifispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

    set(hObject,'BackgroundColor','white');end

    % --- Executes on button press in pushbutton18.function pushbutton18_Callback(hObject, eventdata, handles)% hObject handle to pushbutton18 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)

    global thongso bamnut;prompt={'Nguong anh sang:';'Buoc ngang:';'Buoc doc:'};name='Cau hinh thong so he thong';formats(1) = struct('type','edit','format','float');formats(2) = struct('type','edit','format','float');formats(3) = struct('type','edit','format','float');

    defaultanswer={150,10,10};[thongso,canceled] = nhapthongsohethong(prompt,name,formats,defaultanswer);bamnut=1;

  • 7/31/2019 Main c Matlap v1.3

    16/16

    set(handles.text1,'string','Nhp Thng S Thnh Cng');