久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 25773|回復: 37
打印 上一主題 下一主題
收起左側

matlab中GUI的串口調試程序(發送與接收,很全面)

  [復制鏈接]
跳轉到指定樓層
樓主
基于matlab中的GUI串口調試程序(發送與接收,很全面),可以調試檢測串口,參數設置靈活,在GUI面板上操作簡易。



源程序下載:
matlab中GUI的串口調試程序.zip (13.33 KB, 下載次數: 722)




源碼:
  1. function varargout = untitled(varargin)
  2. % UNTITLED M-file for untitled.fig
  3. %      UNTITLED, by itself, creates a new UNTITLED or raises the existing
  4. %      singleton*.
  5. %
  6. %      H = UNTITLED returns the handle to a new UNTITLED or the handle to
  7. %      the existing singleton*.
  8. %
  9. %      UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local
  10. %      function named CALLBACK in UNTITLED.M with the given input arguments.
  11. %
  12. %      UNTITLED('Property','Value',...) creates a new UNTITLED or raises the
  13. %      existing singleton*.  Starting from the left, property value pairs are
  14. %      applied to the GUI before untitled_OpeningFcn gets called.  An
  15. %      unrecognized property name or invalid value makes property application
  16. %      stop.  All inputs are passed to untitled_OpeningFcn via varargin.
  17. %
  18. %      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
  19. %      instance to run (singleton)".
  20. %
  21. % See also: GUIDE, GUIDATA, GUIHANDLES

  22. % Edit the above text to modify the response to help untitled

  23. % Last Modified by GUIDE v2.5 07-Sep-2013 13:47:05

  24. % Begin initialization code - DO NOT EDIT
  25. gui_Singleton = 1;
  26. gui_State = struct('gui_Name',       mfilename, ...
  27.                    'gui_Singleton',  gui_Singleton, ...
  28.                    'gui_OpeningFcn', @untitled_OpeningFcn, ...
  29.                    'gui_OutputFcn',  @untitled_OutputFcn, ...
  30.                    'gui_LayoutFcn',  [] , ...
  31.                    'gui_Callback',   []);
  32. if nargin && ischar(varargin{1})
  33.     gui_State.gui_Callback = str2func(varargin{1});
  34. end

  35. if nargout
  36.     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
  37. else
  38.     gui_mainfcn(gui_State, varargin{:});
  39. end
  40. % End initialization code - DO NOT EDIT


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

  48. % 初始化
  49. set(handles.caiji,'UserData',0);
  50. setappdata(handles.save,'ApplicationData',0);

  51. % Choose default command line output for untitled
  52. handles.output = hObject;

  53. % Update handles structure
  54. guidata(hObject, handles);

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


  57. % --- Outputs from this function are returned to the command line.
  58. function varargout = untitled_OutputFcn(hObject, eventdata, handles)
  59. % varargout  cell array for returning output args (see VARARGOUT);
  60. % hObject    handle to figure
  61. % eventdata  reserved - to be defined in a future version of MATLAB
  62. % handles    structure with handles and user data (see GUIDATA)

  63. % Get default command line output from handles structure
  64. varargout{1} = handles.output;


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

  70. clc;

  71. s1 = instrfind('Type','serial','Port','COM1','Tag','');    % 查看端口是否存在
  72. s2 = instrfind('Type','serial','Port','COM2','Tag','');
  73. s3 = instrfind('Type','serial','Port','COM3','Tag','');    % 查看端口是否存在
  74. s4 = instrfind('Type','serial','Port','COM4','Tag','');
  75. % 獲取參數值


  76. if (isempty(s1) && get(handles.port,'Value')==1 )           % 如果端口1存在,存創建端口
  77.     s = serial('COM1');                   % 創建串口號
  78.     if(get(handles.botelv,'Value')==1)    % 設置串口參數
  79.         s.BaudRate = 1200;                  
  80.     elseif(get(handles.botelv,'Value')==2)
  81.         s.BaudRate = 2400;   
  82.     elseif(get(handles.botelv,'Value')==3)
  83.         s.BaudRate = 4800;   
  84.     elseif(get(handles.botelv,'Value')==4)
  85.         s.BaudRate = 9600;  
  86.     elseif(get(handles.botelv,'Value')==5)
  87.         s.BaudRate = 19200;
  88.     elseif(get(handles.botelv,'Value')==6)
  89.         s.BaudRate = 38400;
  90.     elseif(get(handles.botelv,'Value')==7)
  91.         s.BaudRate = 76800;
  92.     elseif(get(handles.botelv,'Value')==8)
  93.         s.BaudRate = 115200;  
  94.     end
  95.     if(get(handles.jiaoyanw,'Value')==1)
  96.         s.Parity = 'none';                      % 無校驗位
  97.     elseif(get(handles.jiaoyanw,'Value')==2)
  98.         s.Parity = 'odd';                      % 偶校驗
  99.     elseif(get(handles.jiaoyanw,'Value')==3)
  100.         s.Parity = 'even';                      % 奇校驗
  101.     end
  102.     if(get(handles.dataw,'Value')==1)           % 數據位
  103.         s.DataBits = 8;
  104.     elseif(get(handles.dataw,'Value')==2)
  105.         s.DataBits = 7;
  106.     elseif(get(handles.dataw,'Value')==3)
  107.         s.DataBits = 6;
  108.     elseif(get(handles.dataw,'Value')==4)
  109.         s.DataBits = 5;
  110.     end
  111.     if(get(handles.stopw,'Value')==1)           % 停止位
  112.         s.StopBits = 1;
  113.     elseif(get(handles.stopw,'Value')==2)
  114.         s.StopBits = 1.5;
  115.     elseif(get(handles.stopw,'Value')==3)
  116.         s.StopBits = 2;  
  117.     end
  118.     s.Timeout = 0.1;
  119.     s.InputBufferSize = 3072;
  120.     s.OutputBufferSize = 3072;
  121.     s.ReadAsyncMode = 'continuous';
  122.    
  123.     handles.sbuff = s;
  124.     guidata(hObject, handles);
  125.     s.BytesAvailableFcnMode = 'byte';
  126.     s.BytesAvailableFcnCount = 10;
  127.     s.BytesAvailableFcn = {@recive_data, handles};
  128.     fopen(s);
  129.     set(handles.caiji,'Enable','On');
  130.     set(handles.off,'Enable','On');
  131.     set(handles.on,'Enable','Off');
  132.     set(handles.edit1,'String','打開成功!');
  133.     set(handles.exit,'Enable','Off');
  134.     set(handles.edit1,'backgroundcolor',[0 1 0]);
  135.    
  136. elseif (isempty(s2) && get(handles.port,'Value')==2 )        % 如果端口2存在,存創建端口
  137.     s = serial('COM2');                   % 創建串口號
  138.     if(get(handles.botelv,'Value')==1)    % 設置串口參數
  139.         s.BaudRate = 1200;                  
  140.     elseif(get(handles.botelv,'Value')==2)
  141.         s.BaudRate = 2400;   
  142.     elseif(get(handles.botelv,'Value')==3)
  143.         s.BaudRate = 4800;   
  144.     elseif(get(handles.botelv,'Value')==4)
  145.         s.BaudRate = 9600;  
  146.     elseif(get(handles.botelv,'Value')==5)
  147.         s.BaudRate = 19200;
  148.     elseif(get(handles.botelv,'Value')==6)
  149.         s.BaudRate = 38400;
  150.     elseif(get(handles.botelv,'Value')==7)
  151.         s.BaudRate = 76800;
  152.     elseif(get(handles.botelv,'Value')==8)
  153.         s.BaudRate = 115200;  
  154.     end
  155.     if(get(handles.jiaoyanw,'Value')==1)
  156.         s.Parity = 'none';                      % 無校驗位
  157.     elseif(get(handles.jiaoyanw,'Value')==2)
  158.         s.Parity = 'odd';                      % 偶校驗
  159.     elseif(get(handles.jiaoyanw,'Value')==3)
  160.         s.Parity = 'even';                      % 奇校驗
  161.     end
  162.     if(get(handles.dataw,'Value')==1)           % 數據位
  163.         s.DataBits = 8;
  164.     elseif(get(handles.dataw,'Value')==2)
  165.         s.DataBits = 7;
  166.     elseif(get(handles.dataw,'Value')==3)
  167.         s.DataBits = 6;
  168.     elseif(get(handles.dataw,'Value')==4)
  169.         s.DataBits = 5;
  170.     end
  171.     if(get(handles.stopw,'Value')==1)           % 停止位
  172.         s.StopBits = 1;
  173.     elseif(get(handles.stopw,'Value')==2)
  174.         s.StopBits = 1.5;
  175.     elseif(get(handles.stopw,'Value')==3)
  176.         s.StopBits = 2;  
  177.     end
  178.     s.Timeout = 0.1;
  179.     s.InputBufferSize = 3072;
  180.     s.OutputBufferSize = 3072;
  181.     s.ReadAsyncMode = 'continuous';
  182.    
  183.     handles.sbuff = s;
  184.     guidata(hObject, handles);
  185.     s.BytesAvailableFcnMode = 'byte';
  186.     s.BytesAvailableFcnCount = 10;
  187.     s.BytesAvailableFcn = {@recive_data, handles};
  188.     fopen(s);
  189.     set(handles.caiji,'Enable','On');
  190.     set(handles.off,'Enable','On');
  191.     set(handles.on,'Enable','Off');
  192.     set(handles.exit,'Enable','Off');
  193.     set(handles.edit1,'String','打開成功!');
  194.     set(handles.edit1,'backgroundcolor',[0 1 0]);
  195.    
  196. elseif (isempty(s3) && get(handles.port,'Value')==3 )        % 如果端口3存在,存創建端口
  197.     s = serial('COM3');                   % 創建串口號
  198.     if(get(handles.botelv,'Value')==1)    % 設置串口參數
  199.         s.BaudRate = 1200;                  
  200.     elseif(get(handles.botelv,'Value')==2)
  201.         s.BaudRate = 2400;   
  202.     elseif(get(handles.botelv,'Value')==3)
  203.         s.BaudRate = 4800;   
  204.     elseif(get(handles.botelv,'Value')==4)
  205.         s.BaudRate = 9600;  
  206.     elseif(get(handles.botelv,'Value')==5)
  207.         s.BaudRate = 19200;
  208.     elseif(get(handles.botelv,'Value')==6)
  209.         s.BaudRate = 38400;
  210.     elseif(get(handles.botelv,'Value')==7)
  211.         s.BaudRate = 76800;
  212.     elseif(get(handles.botelv,'Value')==8)
  213.         s.BaudRate = 115200;  
  214.     end
  215.     if(get(handles.jiaoyanw,'Value')==1)
  216.         s.Parity = 'none';                      % 無校驗位
  217.     elseif(get(handles.jiaoyanw,'Value')==2)
  218.         s.Parity = 'odd';                      % 偶校驗
  219.     elseif(get(handles.jiaoyanw,'Value')==3)
  220.         s.Parity = 'even';                      % 奇校驗
  221.     end
  222.     if(get(handles.dataw,'Value')==1)           % 數據位
  223.         s.DataBits = 8;
  224.     elseif(get(handles.dataw,'Value')==2)
  225.         s.DataBits = 7;
  226.     elseif(get(handles.dataw,'Value')==3)
  227.         s.DataBits = 6;
  228.     elseif(get(handles.dataw,'Value')==4)
  229.         s.DataBits = 5;
  230.     end
  231.     if(get(handles.stopw,'Value')==1)           % 停止位
  232.         s.StopBits = 1;
  233.     elseif(get(handles.stopw,'Value')==2)
  234.         s.StopBits = 1.5;
  235.     elseif(get(handles.stopw,'Value')==3)
  236.         s.StopBits = 2;  
  237.     end
  238.     s.Timeout = 0.1;
  239.     s.InputBufferSize = 3072;
  240.     s.OutputBufferSize = 3072;
  241.     s.ReadAsyncMode = 'continuous';
  242.    
  243.     handles.sbuff = s;
  244.     guidata(hObject, handles);
  245.     s.BytesAvailableFcnMode = 'byte';
  246.     s.BytesAvailableFcnCount = 10;
  247.     s.BytesAvailableFcn = {@recive_data, handles};
  248.     fopen(s);
  249.     set(handles.caiji,'Enable','On');
  250.     set(handles.off,'Enable','On');
  251.     set(handles.on,'Enable','Off');
  252.     set(handles.exit,'Enable','Off');
  253.     set(handles.edit1,'String','打開成功!');
  254.     set(handles.edit1,'backgroundcolor',[0 1 0]);
  255.    
  256. elseif (isempty(s4) && get(handles.port,'Value')==4 )        % 如果端口4存在,存創建端口
  257.     s = serial('COM4');                   % 創建串口號
  258.     if(get(handles.botelv,'Value')==1)    % 設置串口參數
  259.         s.BaudRate = 1200;                  
  260.     elseif(get(handles.botelv,'Value')==2)
  261.         s.BaudRate = 2400;   
  262.     elseif(get(handles.botelv,'Value')==3)
  263.         s.BaudRate = 4800;   
  264.     elseif(get(handles.botelv,'Value')==4)
  265.         s.BaudRate = 9600;  
  266.     elseif(get(handles.botelv,'Value')==5)
  267.         s.BaudRate = 19200;
  268.     elseif(get(handles.botelv,'Value')==6)
  269.         s.BaudRate = 38400;
  270.     elseif(get(handles.botelv,'Value')==7)
  271.         s.BaudRate = 76800;
  272.     elseif(get(handles.botelv,'Value')==8)
  273.         s.BaudRate = 115200;  
  274.     end
  275.     if(get(handles.jiaoyanw,'Value')==1)
  276.         s.Parity = 'none';                      % 無校驗位
  277.     elseif(get(handles.jiaoyanw,'Value')==2)
  278.         s.Parity = 'odd';                      % 偶校驗
  279.     elseif(get(handles.jiaoyanw,'Value')==3)
  280.         s.Parity = 'even';                      % 奇校驗
  281.     end
  282.     if(get(handles.dataw,'Value')==1)           % 數據位
  283.         s.DataBits = 8;
  284.     elseif(get(handles.dataw,'Value')==2)
  285.         s.DataBits = 7;
  286.     elseif(get(handles.dataw,'Value')==3)
  287.         s.DataBits = 6;
  288.     elseif(get(handles.dataw,'Value')==4)
  289.         s.DataBits = 5;
  290.     end
  291.     if(get(handles.stopw,'Value')==1)           % 停止位
  292.         s.StopBits = 1;
  293.     elseif(get(handles.stopw,'Value')==2)
  294.         s.StopBits = 1.5;
  295.     elseif(get(handles.stopw,'Value')==3)
  296.         s.StopBits = 2;  
  297.     end
  298.     s.Timeout = 0.1;
  299.     s.InputBufferSize = 3072;
  300.     s.OutputBufferSize = 3072;
  301.     s.ReadAsyncMode = 'continuous';
  302.    
  303.     handles.sbuff = s;
  304.     guidata(hObject, handles);
  305.     s.BytesAvailableFcnMode = 'byte';
  306.     s.BytesAvailableFcnCount = 10;
  307.     s.BytesAvailableFcn = {@recive_data, handles};
  308.     fopen(s);
  309.     set(handles.caiji,'Enable','On');
  310.     set(handles.off,'Enable','On');
  311.     set(handles.on,'Enable','Off');
  312.     set(handles.exit,'Enable','Off');
  313.     set(handles.edit1,'String','打開成功!');
  314.     set(handles.edit1,'backgroundcolor',[0 1 0]);
  315. else
  316.     msgbox('串口不存在或被占用!');
  317.     set(handles.edit1,'String','打開失敗!');
  318.     set(handles.edit1,'backgroundcolor',[1 0/255 0]);
  319. end

  320.    
  321. % 中斷處理程序
  322. function recive_data(t,  event, handles)

  323. if(getappdata(handles.caiji,'ApplicationData')~=0)            % 收到單擊采集信號的信息
  324.    
  325.     g = handles.sbuff;
  326.     [out,huanchongcout] = fread(g,10);                       % 讀取數據
  327. %     plot(handles.axes1,out);  
  328.     % 解析數據
  329.     if(out(1)==128 && bitxor(bitxor(bitxor(bitxor(out(2),out(3)),out(4)),out(5)),out(6)) == out(7))
  330.         data2 = dec2bin(out(2),8);
  331.         data3 = dec2bin(out(3),8);
  332.         data4 = dec2bin(out(4),8);
  333.         data5 = dec2bin(out(5),8);
  334.         data6 = dec2bin(out(6),8);
  335.         cur_data0 = 0;      % 初始化脈沖值
  336.         cur_data1 = dec2bin(cur_data0,32);   % 轉成二進制,有效位數為32
  337.         cur_data1(1:4) = data6(5:8);
  338.         cur_data1(5:11) = data5(2:8);
  339.         cur_data1(12:18) = data4(2:8);
  340.         cur_data1(19:25) = data3(2:8);
  341.         cur_data1(26:32) = data2(2:8);
  342.         cur_data2 = cur_data1;
  343.         set(handles.current_data,'String',bin2dec(cur_data2));
  344.     end
  345.    
  346.    
  347.     if(getappdata(handles.save,'ApplicationData') ~=0)        % 開始存儲數據
  348.         
  349.         File = get(handles.save_play,'String');
  350.         fid = fopen(File,'a');
  351.         fprintf(fid,'%d\t',bin2dec(cur_data2));
  352.         fprintf(fid,'\n');
  353.         fclose(fid);
  354.         
  355.     end      
  356. end  


  357. % --- Executes on button press in off.
  358. function off_Callback(hObject, eventdata, handles)
  359. % hObject    handle to off (see GCBO)
  360. % eventdata  reserved - to be defined in a future version of MATLAB
  361. % handles    structure with handles and user data (see GUIDATA)

  362.     s = handles.sbuff;      % 傳遞
  363.     fclose(s);              % 關閉串口設備對象
  364.     delete(s);              % 刪除內存中的串口設備對象
  365.     clear s;                % 清除工作區間的串口設備對象
  366.     setappdata(handles.axes1,'ApplicationData',0);  % 清空緩存數據
  367.     set(handles.axes1,'UserData',0);                % 將計數器清0
  368.     set(handles.save,'UserData',0);                 % 將數據保存區清0
  369.     set(handles.edit1,'String','串口關閉');
  370.     set(handles.edit1,'backgroundcolor',[0 0/255 1]);
  371.     set(handles.caiji,'Enable','Off');
  372.     set(handles.on,'Enable','On');
  373.     set(handles.save,'Enable','Off');
  374.     set(handles.off,'Enable','Off');
  375.     set(handles.exit,'Enable','On');
  376. % --- Executes on selection change in port.
  377. function port_Callback(hObject, eventdata, handles)
  378. % hObject    handle to port (see GCBO)
  379. % eventdata  reserved - to be defined in a future version of MATLAB
  380. % handles    structure with handles and user data (see GUIDATA)

  381. % Hints: contents = cellstr(get(hObject,'String')) returns port contents as cell array
  382. %        contents{get(hObject,'Value')} returns selected item from port


  383. % --- Executes during object creation, after setting all properties.
  384. function port_CreateFcn(hObject, eventdata, handles)
  385. % hObject    handle to port (see GCBO)
  386. % eventdata  reserved - to be defined in a future version of MATLAB
  387. % handles    empty - handles not created until after all CreateFcns called

  388. % Hint: popupmenu controls usually have a white background on Windows.
  389. %       See ISPC and COMPUTER.
  390. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  391.     set(hObject,'BackgroundColor','white');
  392. end


  393. % --- Executes on selection change in botelv.
  394. function botelv_Callback(hObject, eventdata, handles)
  395. % hObject    handle to botelv (see GCBO)
  396. % eventdata  reserved - to be defined in a future version of MATLAB
  397. % handles    structure with handles and user data (see GUIDATA)

  398. % Hints: contents = cellstr(get(hObject,'String')) returns botelv contents as cell array
  399. %        contents{get(hObject,'Value')} returns selected item from botelv


  400. % --- Executes during object creation, after setting all properties.
  401. function botelv_CreateFcn(hObject, eventdata, handles)
  402. % hObject    handle to botelv (see GCBO)
  403. % eventdata  reserved - to be defined in a future version of MATLAB
  404. % handles    empty - handles not created until after all CreateFcns called

  405. % Hint: popupmenu controls usually have a white background on Windows.
  406. %       See ISPC and COMPUTER.
  407. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  408.     set(hObject,'BackgroundColor','white');
  409. end


  410. % --- Executes on selection change in dataw.
  411. function dataw_Callback(hObject, eventdata, handles)
  412. % hObject    handle to dataw (see GCBO)
  413. % eventdata  reserved - to be defined in a future version of MATLAB
  414. % handles    structure with handles and user data (see GUIDATA)

  415. % Hints: contents = cellstr(get(hObject,'String')) returns dataw contents as cell array
  416. %        contents{get(hObject,'Value')} returns selected item from dataw


  417. % --- Executes during object creation, after setting all properties.
  418. function dataw_CreateFcn(hObject, eventdata, handles)
  419. % hObject    handle to dataw (see GCBO)
  420. % eventdata  reserved - to be defined in a future version of MATLAB
  421. % handles    empty - handles not created until after all CreateFcns called

  422. % Hint: popupmenu controls usually have a white background on Windows.
  423. %       See ISPC and COMPUTER.
  424. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  425.     set(hObject,'BackgroundColor','white');
  426. end


  427. % --- Executes on selection change in jiaoyanw.
  428. function jiaoyanw_Callback(hObject, eventdata, handles)
  429. % hObject    handle to jiaoyanw (see GCBO)
  430. % eventdata  reserved - to be defined in a future version of MATLAB
  431. % handles    structure with handles and user data (see GUIDATA)

  432. % Hints: contents = cellstr(get(hObject,'String')) returns jiaoyanw contents as cell array
  433. %        contents{get(hObject,'Value')} returns selected item from jiaoyanw


  434. % --- Executes during object creation, after setting all properties.
  435. function jiaoyanw_CreateFcn(hObject, eventdata, handles)
  436. % hObject    handle to jiaoyanw (see GCBO)
  437. % eventdata  reserved - to be defined in a future version of MATLAB
  438. % handles    empty - handles not created until after all CreateFcns called

  439. % Hint: popupmenu controls usually have a white background on Windows.
  440. %       See ISPC and COMPUTER.
  441. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  442.     set(hObject,'BackgroundColor','white');
  443. end


  444. % --- Executes on selection change in stopw.
  445. function stopw_Callback(hObject, eventdata, handles)
  446. % hObject    handle to stopw (see GCBO)
  447. % eventdata  reserved - to be defined in a future version of MATLAB
  448. % handles    structure with handles and user data (see GUIDATA)

  449. % Hints: contents = cellstr(get(hObject,'String')) returns stopw contents as cell array
  450. %        contents{get(hObject,'Value')} returns selected item from stopw


  451. % --- Executes during object creation, after setting all properties.
  452. function stopw_CreateFcn(hObject, eventdata, handles)
  453. % hObject    handle to stopw (see GCBO)
  454. % eventdata  reserved - to be defined in a future version of MATLAB
  455. % handles    empty - handles not created until after all CreateFcns called

  456. % Hint: popupmenu controls usually have a white background on Windows.
  457. %       See ISPC and COMPUTER.
  458. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  459.     set(hObject,'BackgroundColor','white');
  460. end

  461. % --- Executes during object creation, after setting all properties.
  462. function axes1_CreateFcn(hObject, eventdata, handles)
  463. % hObject    handle to axes1 (see GCBO)
  464. % eventdata  reserved - to be defined in a future version of MATLAB
  465. % handles    empty - handles not created until after all CreateFcns called

  466. % Hint: place code in OpeningFcn to populate axes1

  467. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  468.     set(hObject,'BackgroundColor','white');
  469. end

  470. % --- Executes on button press in caiji.
  471. function caiji_Callback(hObject, eventdata, handles)
  472. % hObject    handle to caiji (see GCBO)
  473. % eventdata  reserved - to be defined in a future version of MATLAB
  474. % handles    structure with handles and user data (see GUIDATA)
  475. %  data = handles.data;

  476. % 發送信號,傳遞給中斷,將信號暫存在采集控件中

  477. % t = str2num(get(handles.save_time,'String'));
  478. index = get(handles.save_lujin,'UserData');         % 是否設定存儲路徑
  479. g = handles.sbuff;
  480. [a,b] = fread(g);
  481. if ( b==0 )
  482.     msgbox('當前無數據輸入!');
  483.     set(handles.save,'Enable','Off');
  484. else
  485.     if(get(handles.caiji,'UserData')==0)
  486.         set(handles.caiji,'String','停止采集');
  487.         set(handles.caiji,'BackgroundColor',[1 0 0]);
  488.         setappdata(handles.caiji,'ApplicationData',1);   % 用于傳遞給中斷響應函數,可以接收并顯示數據了
  489.         set(handles.caiji,'UserData',1);
  490.         if(  index~=0 )                                       % 設定存儲條件
  491.             set(handles.save,'Enable','On');
  492.         else
  493.             set(handles.save,'Enable','Off');
  494.         end
  495.     else
  496.         set(handles.caiji,'String','開始采集');
  497.         setappdata(handles.caiji,'ApplicationData',0);
  498.         set(handles.caiji,'BackgroundColor',[0.8 0.8 0.8]);
  499.         set(handles.caiji,'UserData',0);
  500.         set(handles.save,'Enable','Off');
  501.         set(handles.save_time,'String',0);
  502.     end
  503.    
  504. end
  505. % --- Executes on button press in save.
  506. function save_Callback(hObject, eventdata, handles)
  507. % hObject    handle to save (see GCBO)
  508. % eventdata  reserved - to be defined in a future version of MATLAB
  509. % handles    structure with handles and user data (see GUIDATA)

  510. % 發送開始存儲信號,并帶有時間控制功能

  511.   setappdata(handles.save,'ApplicationData',1);
  512. % g = handles.sbuff;
  513. % [data,b] = fread(g)
  514.   t = str2num(get(handles.save_time,'String'));
  515.   acc_time = t;        % 中間變量     
  516.   set(handles.time_play,'String',num2str(t));
  517.   for i = 1:t         % 時間顯示     
  518.       
  519.      pause(0.995);
  520.      set(handles.time_play,'String',num2str(acc_time-1));   
  521.      acc_time = acc_time-1;     
  522.       
  523.   end   
  524.   setappdata(handles.save,'ApplicationData',0);
  525. %   File = get(handles.save_play,'String');                     % 獲取存儲路徑
  526. %   fopen(File);
  527. %   g = handles.sbuff;
  528. %   [data,b] = fread(g)
  529. %   fprintf(File,'%12.8e\t',data);
  530. %  save ( File ,'uint8','data');
  531. % --- Executes on button press in exit.
  532. function exit_Callback(hObject, eventdata, handles)
  533. % hObject    handle to exit (see GCBO)
  534. % eventdata  reserved - to be defined in a future version of MATLAB
  535. % handles    structure with handles and user data (see GUIDATA)

  536. close(gcbf);

  537. function save_play_Callback(hObject, eventdata, handles)
  538. % hObject    handle to save_play (see GCBO)
  539. % eventdata  reserved - to be defined in a future version of MATLAB
  540. % handles    structure with handles and user data (see GUIDATA)

  541. % Hints: get(hObject,'String') returns contents of save_play as text
  542. %        str2double(get(hObject,'String')) returns contents of save_play as a double


  543. % --- Executes during object creation, after setting all properties.
  544. function save_play_CreateFcn(hObject, eventdata, handles)
  545. % hObject    handle to save_play (see GCBO)
  546. % eventdata  reserved - to be defined in a future version of MATLAB
  547. % handles    empty - handles not created until after all CreateFcns called

  548. % Hint: edit controls usually have a white background on Windows.
  549. %       See ISPC and COMPUTER.
  550. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  551.     set(hObject,'BackgroundColor','white');
  552. end


  553. % --- Executes on button press in save_lujin.
  554. function save_lujin_Callback(hObject, eventdata, handles)
  555. % hObject    handle to save_lujin (see GCBO)
  556. % eventdata  reserved - to be defined in a future version of MATLAB
  557. % handles    structure with handles and user data (see GUIDATA)
  558. set(handles.save,'Enable','On');
  559. [file, pathname, index] = uiputfile({'*.txt';'*.dat';'*.mat'},'文件另存為');
  560. file1 = strcat(pathname,file);
  561. set(handles.save_play,'String',file1);
  562. set(handles.save_lujin,'UserData',index);      % 判斷是否設定了保存文件的路徑

  563. function save_time_Callback(hObject, eventdata, handles)
  564. % hObject    handle to save_time (see GCBO)
  565. % eventdata  reserved - to be defined in a future version of MATLAB
  566. % handles    structure with handles and user data (see GUIDATA)

  567. % Hints: get(hObject,'String') returns contents of save_time as text
  568. %        str2double(get(hObject,'String')) returns contents of save_time as a double



  569. % --- Executes during object creation, after setting all properties.
  570. function save_time_CreateFcn(hObject, eventdata, handles)
  571. % hObject    handle to save_time (see GCBO)
  572. % eventdata  reserved - to be defined in a future version of MATLAB
  573. % handles    empty - handles not created until after all CreateFcns called

  574. % Hint: edit controls usually have a white background on Windows.
  575. %       See ISPC and COMPUTER.
  576. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  577.     set(hObject,'BackgroundColor','white');
  578. end


  579. % --- Executes during object creation, after setting all properties.
  580. function time_play_CreateFcn(hObject, eventdata, handles)
  581. % hObject    handle to time_play (see GCBO)
  582. % eventdata  reserved - to be defined in a future version of MATLAB
  583. % handles    empty - handles not created until after all CreateFcns called



  584. function current_data_Callback(hObject, eventdata, handles)
  585. % hObject    handle to current_data (see GCBO)
  586. % eventdata  reserved - to be defined in a future version of MATLAB
  587. % handles    structure with handles and user data (see GUIDATA)

  588. % Hints: get(hObject,'String') returns contents of current_data as text
  589. %        str2double(get(hObject,'String')) returns contents of current_data as a double


  590. % --- Executes during object creation, after setting all properties.
  591. function current_data_CreateFcn(hObject, eventdata, handles)
  592. % hObject    handle to current_data (see GCBO)
  593. % eventdata  reserved - to be defined in a future version of MATLAB
  594. % handles    empty - handles not created until after all CreateFcns called

  595. % Hint: edit controls usually have a white background on Windows.
  596. %       See ISPC and COMPUTER.
  597. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  598.     set(hObject,'BackgroundColor','white');
  599. end
復制代碼


評分

參與人數 1黑幣 +5 收起 理由
wohuonini + 5

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:229874 發表于 2017-8-29 15:20 | 只看該作者
學習一下,正需要這個
回復

使用道具 舉報

板凳
ID:234844 發表于 2017-10-12 21:37 | 只看該作者
你好我現在也是在做這個,但是設置的是每個一定的時間顯示一個接收的數據,但是數據卻不是按延時時間顯示的,大神知道這是怎么回事嗎
回復

使用道具 舉報

地板
ID:254599 發表于 2017-11-28 11:54 | 只看該作者
i頂一下
回復

使用道具 舉報

5#
ID:256701 發表于 2017-12-3 10:13 | 只看該作者
真是太棒了!對我幫助很大。謝謝樓主!
回復

使用道具 舉報

6#
ID:256701 發表于 2017-12-3 10:14 | 只看該作者
真是太棒了!對我幫助很大,謝謝樓主!
回復

使用道具 舉報

7#
ID:167718 發表于 2017-12-19 18:21 | 只看該作者
正在學習這個,多謝
回復

使用道具 舉報

8#
ID:262276 發表于 2017-12-20 09:46 | 只看該作者
vivipp 發表于 2017-12-3 10:14
真是太棒了!對我幫助很大,謝謝樓主!

運行之后顯示  無數據輸入,這個該怎么改?
回復

使用道具 舉報

9#
ID:277651 發表于 2018-1-19 10:39 | 只看該作者
正需要這個  趕緊看看
回復

使用道具 舉報

10#
ID:240600 發表于 2018-3-15 10:33 | 只看該作者
來學習一下,不知道2017版本的可以直接調用不
回復

使用道具 舉報

11#
ID:299685 發表于 2018-3-30 21:59 | 只看該作者
正需要這個,學習一下,謝謝
回復

使用道具 舉報

12#
ID:305837 發表于 2018-4-11 14:25 | 只看該作者
學習一下,正需要這個
回復

使用道具 舉報

13#
ID:265142 發表于 2018-4-12 14:40 | 只看該作者
正需要這個,看看
回復

使用道具 舉報

14#
ID:336626 發表于 2018-5-23 16:46 | 只看該作者
非常贊,多謝樓主了
回復

使用道具 舉報

15#
ID:398830 發表于 2018-9-17 02:29 | 只看該作者
太給力了,感謝樓主!
回復

使用道具 舉報

16#
ID:399168 發表于 2018-9-17 18:54 | 只看該作者
想看看
回復

使用道具 舉報

17#
ID:401307 發表于 2018-9-22 14:21 | 只看該作者
謝謝謝謝!!!
回復

使用道具 舉報

18#
ID:437624 發表于 2018-12-2 13:38 | 只看該作者
不錯,哎沒錢幣下載啊,誰能傳一份
回復

使用道具 舉報

19#
ID:143203 發表于 2019-3-20 08:48 | 只看該作者
怎么 運行???
回復

使用道具 舉報

20#
ID:115379 發表于 2019-4-28 22:02 | 只看該作者
謝謝善于分享的人
回復

使用道具 舉報

21#
ID:409871 發表于 2019-5-5 10:08 | 只看該作者
感謝分享
回復

使用道具 舉報

22#
ID:536286 發表于 2019-5-12 17:31 | 只看該作者
學習一下
回復

使用道具 舉報

23#
ID:537668 發表于 2019-5-14 09:36 | 只看該作者

真是太棒了!對我幫助很大,謝謝樓主!
回復

使用道具 舉報

24#
ID:312058 發表于 2019-7-9 20:49 | 只看該作者
多謝樓主分享
回復

使用道具 舉報

25#
ID:317193 發表于 2019-7-14 17:55 | 只看該作者
學習一下,正需要這個
回復

使用道具 舉報

26#
ID:481460 發表于 2019-7-26 09:38 | 只看該作者
正在做這個,guide的串口調試程序,實時接收數據顯示并繪圖,學習下
回復

使用道具 舉報

27#
ID:541439 發表于 2019-8-30 15:26 | 只看該作者
謝謝分享,學習中
回復

使用道具 舉報

28#
ID:620618 發表于 2019-10-8 17:20 | 只看該作者
謝謝分享,學習中,,不知道是否可以實現CAN
回復

使用道具 舉報

29#
ID:637330 發表于 2019-12-9 09:37 | 只看該作者
正在做matlab串口通信,現在matlab可以接收到串口發送的數據,但是串口接收不到matlab發送的數據,不知道是什么情況啊
回復

使用道具 舉報

30#
ID:477218 發表于 2019-12-20 21:44 | 只看該作者
謝謝樓主,樓主好人一生平安。
回復

使用道具 舉報

31#
ID:688169 發表于 2020-1-26 00:49 | 只看該作者
方常棒的教學,正需要這個!
回復

使用道具 舉報

32#
ID:90713 發表于 2020-2-17 11:17 | 只看該作者
我的MATLAB版本是2018,這個程序運行報錯,哪位有解決方法嗎

1.png (20.01 KB, 下載次數: 155)

截圖

截圖
回復

使用道具 舉報

33#
ID:404423 發表于 2020-4-13 17:46 | 只看該作者
vgboy8866 發表于 2020-2-17 11:17
我的MATLAB版本是2018,這個程序運行報錯,哪位有解決方法嗎

我也是這樣請問解決了嘛
回復

使用道具 舉報

34#
ID:514296 發表于 2020-6-2 16:19 | 只看該作者
雖然是舊帖,還是感謝一下分享。
回復

使用道具 舉報

35#
ID:437554 發表于 2020-8-12 11:07 | 只看該作者
需要看看有沒有用
回復

使用道具 舉報

36#
ID:853439 發表于 2020-12-2 21:49 | 只看該作者
不錯的程序,正好需要!
回復

使用道具 舉報

37#
ID:487635 發表于 2021-5-9 21:26 | 只看該作者
有定位最后的圖嗎
回復

使用道具 舉報

38#
ID:956957 發表于 2022-5-14 15:10 | 只看該作者
提示串口不存在或被調用,但是實際沒有啊,怎么解決
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 欧美成人a | 成人免费视频在线观看 | 精品自拍视频 | 在线一区二区三区 | 久草院线 | 免费一区二区 | 亚洲欧美日韩在线 | 日本精品视频 | 91在线色视频 | av免费观看在线 | 91久久夜色 | 欧美电影在线观看网站 | 国产精品一区久久久 | 欧美一区二区大片 | 亚洲天堂日韩精品 | 日韩一区二区三区在线视频 | 极品电影院 | 色偷偷噜噜噜亚洲男人 | 不用播放器看的av | 毛片在线看片 | 午夜免费小视频 | 四虎影院免费在线 | 国产免费又色又爽又黄在线观看 | 五月网婷婷 | 国产高清视频在线观看播放 | 亚洲国产精品网站 | 国产一级黄色网 | 欧美成人a∨高清免费观看 91伊人 | 午夜免费在线 | 精品国产区 | 欧美日韩中文国产一区发布 | 日韩免费在线 | 女人一区| h视频免费在线观看 | 香蕉一区| 国产精品国产三级国产aⅴ无密码 | jdav视频在线观看免费 | 不卡在线视频 | 亚洲精品中文字幕av | 亚洲精品乱码久久久久久久久久 | 色综合久久88色综合天天 |