(完整版)MATLAB串口通信设计源码
- 格式:docx
- 大小:17.36 KB
- 文档页数:8
文章标题:探索Matlab中的串口通信系统设计在当前的现代通信系统中,串口通信系统设计已经成为一项至关重要的任务。
在Matlab中,借助各种工具和函数,我们可以设计出高效、稳定和灵活的串口通信系统。
本文将从简单到复杂、由浅入深地探讨Matlab中的串口通信系统设计,为读者提供全面的了解和深入的思考。
1. 串口通信系统概述在进行Matlab中的串口通信系统设计之前,我们首先需要了解串口通信系统的基本概念和原理。
串口通信是通过串行接口进行数据传输的一种通信方式,它在各种领域中都有着广泛的应用,包括嵌入式系统、通信设备、工业控制等。
Matlab作为强大的工程计算软件,为我们提供了丰富的工具和函数来进行串口通信系统设计,包括串口对象、串口配置、数据读写等功能。
2. Matlab中的串口通信基本操作在Matlab中,我们可以通过串口对象来进行串口通信的基本操作。
我们需要创建一个串口对象,并进行相应的配置,包括波特率、数据位、停止位、校验位等参数。
我们可以使用该串口对象来进行数据的读写操作,可以发送数据到外部设备,也可以接收来自外部设备的数据。
通过Matlab中丰富的串口函数,我们可以轻松实现串口通信系统的基本功能。
3. Matlab中的串口通信系统设计在实际的工程应用中,我们通常需要设计更加复杂和灵活的串口通信系统。
在Matlab中,我们可以借助信号处理工具箱、通信工具箱等功能来进行串口通信系统的设计。
通过信号处理工具箱,我们可以实现对串口数据的解调、调制、滤波等操作,从而提高通信系统的稳定性和性能。
而通信工具箱中的各种算法和工具则可以帮助我们实现更加复杂的通信协议和数据处理。
4. 个人观点和总结在我看来,Matlab是一款非常适合进行串口通信系统设计的软件,它不仅提供了丰富的工具和函数,还具备强大的计算能力和灵活的编程环境。
通过Matlab,我们可以实现从简单到复杂的串口通信系统设计,为各种应用场景提供定制化的解决方案。
【STM32H7的DSP教程】第9章Matlab的串⼝通信实现第9章 Matlab的串⼝通信实现本章节主要为⼤家讲解Matlab的串⼝⽅式波形数据传输和后期数据分析功能,⾮常实⽤。
9.1 初学者重要提⽰9.2 程序设计框架9.3 下位机STM32H7程序设计9.4 上位机Matlab程序设计9.5 Matlab上位机程序运⾏9.6 实验例程说明(MDK)9.7 实验例程说明(IAR)9.8 总结9.1 初学者重要提⽰1、测试本章节例程注意事项。
请优先运⾏开发板,然后运⾏matlab。
调试matlab串⼝数据发送前,请务必关闭串⼝助⼿。
2、函数delete(instrfindall);如果不⽤matlab了,请在matlab的命令输⼊窗⼝调⽤此函数,防⽌matlab⼀直占⽤串⼝。
9.2 程序设计框架上位机和下位机的程序设计框架如下:上位机和下位机做了⼀个简单的同步,保证数据通信不出错。
9.3 下位机STM32H7程序设计STM32H7端的程序设计思路。
9.3.1 第1步,发送的数据格式为了⽅便数据发送,专门设计了⼀个数据格式:__packed typedef struct{uint16_t data1;uint16_t data2;uint16_t data3;uint8_t data4;uint8_t data5;uint8_t data6;uint8_t data7;}SENDPARAM_T;SENDPARAM_T g_SendData;9.3.2 第2步,接收同步信号$Matlab发送同步信号$(ASCII编码值是13)给开发板。
int main(void)/* 省略未写,仅留下关键代码 *//* 进⼊主程序循环体 */while (1){/* 判断定时器超时时间 */if (bsp_CheckTimer(0)){/* 每隔100ms 进来⼀次 */bsp_LedToggle(2);}if (comGetChar(COM1, &read)){/* 接收到同步帧'$'*/if(read == 13){bsp_LedToggle(4);bsp_DelayMS(10);Serial_sendDataMATLAB();}}}}通过函数comGetChar获取串⼝接收到的数据,如果数值是13,说明接收到Matlab发送过来的同步信号了。
matlab之串口通信matlab之串口通信串口通信,一般是指RS232、RS422之间的通信。
matlab中有专门的serial函数来创建串口对象。
设串口ID号为COM1,则创建方法为:复制内容到剪贴板代码:>>scom= serial('com1');创建完串口对象后,一般需要设置串口对象的属性,否则,串口不会相互通信。
复制内容到剪贴板代码:>> get(scom)ByteOrder = littleEndianBytesAvailable = 0BytesAvailableFcn =BytesAvailableFcnCount = 48BytesAvailableFcnMode = terminatorBytesToOutput = 0ErrorFcn =InputBufferSize = 512Name= Serial-COM1ObjectVisibility = onOutputBufferSize = 512OutputEmptyFcn =RecordDetail = compactRecordMode = overwriteRecordName = record.txtRecordStatus = offStatus = closedTag=Timeout = 10TimerFcn =TimerPeriod = 1TransferStatus = idleType= serialUserData = []ValuesReceived = 0ValuesSent = 0SERIAL specific properties:BaudRate= 9600BreakInterruptFcn =DataBits = 8DataTerminalReady = onFlowControl = noneParity = nonePinStatus = [1x1 struct]PinStatusFcn =Port= COM1ReadAsyncMode = continuousRequestToSend = offStopBits = 1Terminator = LF这些属性中,要使串口真正通信,一般要设置这几个属性:BaudRate:波特率;Parity:奇偶校验类型;DataBits:数据位,一般为8,不用设置;StopBits:停止位,一般为1,不用设置;TimerFcn :定时回调函数;TimerPeriod:定时周期;BytesAvailableFcn:字节计数回调函数BytesAvailableFcnCount:字节计数BytesAvailableFcnMode:一般设置为字节模式,即byte串口通信时,数据一般按帧传送,有的数据量比较大,会将帧打包后发送。
matlab串口程序Matlab是一种功能强大的编程语言和数学软件环境,被广泛应用于科学计算、数据可视化、机器学习等领域。
其中,串口通信是Matlab中常见的应用之一,通过串口可以实现与外部设备的数据交互,例如与传感器、机器人等进行通信。
本文将介绍如何使用Matlab进行串口通信的编程。
我们需要了解一些基本概念。
串口通信是通过计算机的串行接口与外部设备进行数据传输的一种方式。
在Matlab中,可以使用Serial对象来实现串口通信。
Serial对象提供了一系列函数,用于打开、关闭、读取和写入串口数据。
在使用Serial对象之前,需要先创建该对象并设置相关参数,如串口号、波特率、数据位数、停止位等。
在Matlab中,首先需要创建一个Serial对象,可以使用以下代码实现:```s = serial('COM1'); % 创建Serial对象,指定串口号为COM1```上述代码中,'COM1'表示串口号,可以根据实际情况进行修改。
创建Serial对象后,还需要设置相关参数,例如波特率、数据位数、停止位等,可以使用以下代码实现:```set(s, 'BaudRate', 9600); % 设置波特率为9600set(s, 'DataBits', 8); % 设置数据位数为8set(s, 'StopBits', 1); % 设置停止位为1```上述代码中,'BaudRate'表示波特率,可以根据实际情况进行修改,常见的波特率有9600、115200等;'DataBits'表示数据位数,一般为8位;'StopBits'表示停止位,一般为1位。
设置完参数后,还需要打开串口以便进行数据的读取和写入。
可以使用以下代码打开串口:```fopen(s); % 打开串口```打开串口后,我们可以使用Serial对象提供的函数进行数据的读取和写入。
4.3.1 串口通信程序流程图(1)串口通信程序代码void Uart_Init(void){TMOD |= 0x20; //设置定时器1为8位自动重装模式TH1 = 0xfd;/*波特率9600的初值*/TL1 = 0xfd;/*和高8位一样*/TR1 = 1; /*打开中时器*/SM0 = 0;/**/SM1 = 1;/*8位串口模式*/REN = 1;/*允许串口接收*/ES = 1;/ *打开串口中断*/}void Uart_PutChar(unsigned char ch){ES = 0;//关闭串口中断SBUF = ch; /*把数据送给sbuf缓存器中*/while (!TI);TI = 0; /*发送完成,TI清为0*/ES = 1; /* 打开串口中断 */}void UART_RX_INT(void) interrupt 4{if (RI) /*收到数据*/{RI = 0; /*收到清0*/rxBuf[rxCount] = SBUF; //保存串口数据到接收缓冲区if (rxBuf[0] == 0xAA) //找头,数据帧头问0xAA{rxCount++; //如果找到数据帧头,则往下存储串口数据,下标后移if (rxCount == 4)rxCount = 0;//一帧4个数据,一帧满则重新接收if (rxBuf[3] == 0x55)//判断数据帧尾,数据帧尾为0x55{alarm_temp_L = rxBuf[1];//数据帧的第二个字节是报警温度下限,单位是度alarm_temp_H = rxBuf[2]; //数据帧的第三个字节是报警温度下限,单位是度}}}。
通信原理matlab代码以下为一篇关于通信原理的1500-2000字文章,主要讨论了使用MATLAB编写通信原理相关代码的步骤。
通信原理是现代通信系统的基础,通过使用各种信号处理技术和模型,使信息能够在发送和接收设备之间进行传输和解码。
在通信原理的研究中,MATLAB是一种常用的工具,它提供了一系列函数和工具箱,可用于模拟和分析各种通信系统。
在开始使用MATLAB编写通信原理相关代码之前,首先需要安装MATLAB软件。
安装完成后,可以打开MATLAB环境,通过编写和执行代码实现通信原理的模拟和分析。
第一步是导入需要用到的工具箱和相关函数。
MATLAB提供了多个通信系统工具箱,包括通信系统工具箱、数字信号处理工具箱和无线通信工具箱等。
使用`import`关键字可以导入特定的工具箱和函数。
matlabimport commsys.*;import dsp.*;import wireless.*;第二步是设置通信系统的参数。
通信系统的参数包括发送和接收设备的特性、信道特性和数据传输速率等。
通过定义这些参数,可以在整个通信系统中进行一致的模拟和分析。
matlabsampling_frequency = 10e6; 采样频率carrier_frequency = 2.4e9; 载波频率data_rate = 1e6; 数据传输速率snr = 10; 信噪比第三步是生成发送信号。
发送信号的生成主要是根据具体的通信系统规范和调制方案来确定。
比如,要生成一个使用QPSK调制方案的信号,可以使用`comm.QPSKModulator`工具箱生成调制器,并通过调用`step`函数传入待调制的数据。
matlabmodulator = comm.QPSKModulator();data = randi([0 3], 1000, 1); 生成随机的待调制数据modulated_signal = step(modulator, data);第四步是加入信道特性和噪声。
matlab gui串口数据例程在MATLAB中创建一个GUI来读取串口数据是一个常见的任务。
首先,你需要确保已经安装了MATLAB的Instrument Control Toolbox,这样才能够进行串口通讯。
接下来,我将为你提供一个简单的例程,来演示如何在MATLAB中创建一个GUI来读取串口数据。
首先,你需要创建一个GUI,你可以使用MATLAB自带的GUIDE 工具来创建。
在GUI上放置一个按钮用于打开串口,一个按钮用于关闭串口,一个文本框用于显示读取的数据,以及其他你需要的控件。
接下来,你需要编写一些代码来实现串口的打开、关闭和读取数据的功能。
下面是一个简单的例程,假设你的串口对象是serialPort:matlab.% 创建串口对象。
serialPort = serial('COM1'); % 假设你的串口是COM1。
% 设置串口参数。
set(serialPort, 'BaudRate', 9600); % 设置波特率为9600。
% 创建GUI.f = figure;openButton = uicontrol('Style', 'pushbutton', 'String', '打开串口', 'Callback', {@openSerial, serialPort});closeButton = uicontrol('Style', 'pushbutton', 'String', '关闭串口', 'Callback', {@closeSerial, serialPort});textBox = uicontrol('Style', 'edit', 'String', '','Position', [10 10 200 20]);% 打开串口的回调函数。
function varargout = PJSerialCOM(varargin)% PJSERIALCOM M-file for PJSerialCOM.fig% PJSERIALCOM, by itself, creates a new PJSERIALCOM or raises the existing% singleton*.%% H = PJSERIALCOM returns the handle to a new PJSERIALCOM or the handle to% the existing singleton*.%% PJSERIALCOM('CALLBACK',hObject,eventData,handles,...) calls thelocal% function named CALLBACK in PJSERIALCOM.M with the given input arguments.%% PJSERIALCOM('Property','Value',...) creates a new PJSERIALCOM or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before PJSerialCOM_OpeningFcn gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to PJSerialCOM_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 PJSerialCOM% Last Modified by GUIDE v2.5 26-May-2012 18:45:14 % Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct( 'gui_Name' 'gui_Singleton' 'gui_OpeningFcn''gui_OutputFcn''gui_LayoutFcn''gui_Callback' if nargin && ischar(varargin{1})gui_State.gui_Callback =str2func(varargin{1}); endif nargout[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); elsegui_mainfcn(gui_State, varargin{:});end% End initialization code - DO NOT EDIT% --- Executes just before PJSerialCOM is made visible.function PJSerialCOM_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 MATLABmfilename, ... gui_Singleton, ..., @PJSerialCOM_OpeningFcn,@PJSerialCOM_OutputFcn, [] , ... []);% handles structure with handles and user data (see GUIDATA)% varargin command line arguments to PJSerialCOM (see VARARGIN)% Choose default command line output for PJSerialCOM handles.output = hObject;% Update handles structure guidata(hObject, handles);% UIWAIT makes PJSerialCOM wait for user response (see UIRESUME) % uiwait(handles.figPJSerialCOM); set(handles.btnClosePort, 'Enable' , 'off' ); set(handles.btnSendData, 'Enable' , 'Off' );setappdata(handles.figPJSerialCOM, 'u' , '' );% --- Outputs from this function are returned to the command line.function varargout = PJSerialCOM_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 structure varargout{1} = handles.output;% --- Executes on selection change in pumComPort. function pumComPort_Callback(hObject, eventdata, handles)% hObject handle to pumComPort (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 pumComPort contents as cell array% contents{get(hObject,'Value')} returns selected item frompumComPort % --- Executes during object creation, after setting all properties. functionpumComPort_CreateFcn(hObject, eventdata, handles) % hObject handle to pumComPort (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. get(0, 'defaultUicontrolBackgroundColor' set(hObject, 'BackgroundColor' , 'white' );end% --- Executes on selection change in pumBaudRate. functionpumBaudRate_Callback(hObject, eventdata, handles)if ispc && isequal(get(hObject, 'BackgroundColor' ),))% hObject handle to pumBaudRate (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 pumBaudRate contents as cellarray% contents{get(hObject,'Value')} returns selected item frompumBaudRate % --- Executes during object creation, after setting all properties.function pumBaudRate_CreateFcn(hObject, eventdata, handles)% hObject handle to pumBaudRate (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 && isequal(get(hObject, 'BackgroundColor' ), get(0,'defaultUicontrolBackgroundColor' )) set(hObject, 'BackgroundColor' , 'white' );end% --- Executes on selection change in pumDataBits. functionpumDataBits_Callback(hObject, eventdata, handles)% hObject handle to pumDataBits (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 pumDataBits contents as cellarray% contents{get(hObject,'Value')} returns selected item frompumDataBits % --- Executes during object creation, after setting all properties.function pumDataBits_CreateFcn(hObject, eventdata, handles)% hObject handle to pumDataBits (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 ISPCand COMPUTER.if ispc && isequal(get(hObject, get(0, 'defaultUicontrolBackgroundColor' set(hObject, 'BackgroundColor'end% --- Executes on selection change in pumStopBits.function pumStopBits_Callback(hObject, eventdata, handles)% hObject handle to pumStopBits (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB 'BackgroundColor' )) , 'white' ); ),% handles structure with handles and user data (see GUIDATA) % Hints:contents = get(hObject,'String') returns pumStopBits contents as cell array% contents{get(hObject,'Value')} returns selected item frompumStopBits% --- Executes during object creation, after setting all properties. functionpumStopBits_CreateFcn(hObject, eventdata, handles)% hObject handle to pumStopBits (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 && isequal(get(hObject, 'BackgroundColor' ),get(0, 'defaultUicontrolBackgroundColor' )) set(hObject, 'BackgroundColor' ,'white' );end% --- Executes on selection change in pumParity.function pumParity_Callback(hObject, eventdata, handles)% hObject handle to pumParity (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') array% contents{get(hObject,'Value')} % --- Executes duringobject creation, after setting all properties. function pumParity_CreateFcn(hObject, eventdata, handles)% hObject handle to pumParity (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 ISPCand COMPUTER.if ispc && isequal(get(hObject, 'BackgroundColor' ),get(0, 'defaultUicontrolBackgroundColor' )) set(hObject, 'BackgroundColor' ,'white' );end % --- Executes on selection change in pumFlowControl. functionpumFlowControl_Callback(hObject, eventdata, handles)% hObject handle to pumFlowControl (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 pumFlowControl contentsreturns pumParity contents returns selected item from as cell pumParityas cell array% contents{get(hObject,'Value')} returns selected item frompumFlowControl % --- Executes during object creation, after setting all properties. function pumFlowControl_CreateFcn(hObject, eventdata, handles)% hObject handle to pumFlowControl (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 && isequal(get(hObject, 'BackgroundColor' ), get(0,'defaultUicontrolBackgroundColor' )) set(hObject, 'BackgroundColor' , 'white' );endfunction edtRecvData_Callback(hObject, eventdata, handles)% hObject handle to edtRecvData (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 edtRecvData as text% str2double(get(hObject,'String')) returns contents of edtRecvDataas a double% --- Executes during object creation, after setting all properties. functionedtRecvData_CreateFcn(hObject, eventdata, handles)% hObject handle to edtRecvData (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 && isequal(get(hObject, 'BackgroundColor' ),get(0, 'defaultUicontrolBackgroundColor' )) set(hObject, 'BackgroundColor' , 'white' );end function edtSendData_Callback(hObject, eventdata, handles)% hObject handle to edtSendData (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 edtSendData as text% str2double(get(hObject,'String')) returns contents of edtSendDataas a double% --- Executes during object creation, after setting all properties. functionedtSendData_CreateFcn(hObject, eventdata, handles) % hObject handle to edtSendData (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 && isequal(get(hObject, 'BackgroundColor' ), get(0,'defaultUicontrolBackgroundColor' ))set(hObject, 'BackgroundColor' , 'white' );end % --- Executes on button press in btnOpenPort.function btnOpenPort_Callback(hObject, eventdata, handles)% hObject handle to btnOpenPort (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)comPort=get(handles.pumComPort, 'String' );handles.u_sCom=serial(comPort{get(handles.pumComPort, 'Value'baudRate=get(handles.pumBaudRate, set(handles.u_sCom, 'BaudRate' te,'Value' )}));dataBits=get(handles.pumDataBits,set(handles.u_sCom, 'DataBits' ts,'Value' )}));stopBits=get(handles.pumStopBits,set(handles.u_sCom, 'StopBits' ts,'Value' )})); parity=get(handles.pumParity, if strcmp(parity, '?T' )==1set(handles.u_sCom, 'Parity' else'String' );,str2double(baudRate{get(handles.pumBaudRa 'String' );,str2double(dataBits{get(handles.pumDataBi 'String' );,str2double(stopBits{get(handles.pumStopBi'String' );, 'none' );if strcmp(parity,set(handles.u_sCom, elseif strcmp(parity, set(handles.u_sCom, elseset(handles.u_sCom, end '??D £?e'==i'Parity' , 'odd' );'??D £?e'==i'Parity' , 'even' )'Parity' , 'none' )end endflowControl=get(handles.pumFlowControl,if strcmp(flowControl, '?T' )==1 set(handles.u_sCom, 'FlowControl' else'String' ); , 'none' );if strcmp(flowControl, set(handles.u_sCom, elseo 2?t' )==1'FlowControl' , 'hardware' );if strcmp(flowControl, set(handles.u_sCom, elseset(handles.u_sCom,「?t')==1'FlowControl' , 'software' );'FlowControl' , 'none' );)});fopen(handles.u_sCom); set(handles.txtStatus, set(hObject, 'Enable'set(handles.btnClosePort, %handles.u_timer=timer('TimerFcn',{@ReadCom,handles},'Period',1,'ExecutionMode','fixedrate');guidata(hObject,handles);set(handles.btnSendData, 'Enable' , 'On' );% function ReadCom(obj,eventdata,handles)% set(handles.txtStatus,'String','?y? u ? ae ? e y?Y');% readString=fread(handles.u_sCom,10);% set(handles.edtRecvData,'String',readString);% set(handles.txtStatus,'String','? oe ? e y?Y3 e 1|');% --- Executes on button press in btnClosePort.function btnClosePort_Callback(hObject, eventdata, handles)% hObject handle to btnClosePort (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB %handles structure with handles and user data (see GUIDATA)fclose(handles.u_sCom); % stop(handles.u_timer);% delete(handles.u_timer); handles.u_sCom=0; guidata(hObject,handles);set(handles.txtStatus, set(handles.btnOpenPort, set(handles.btnSendData,set(hObject, 'Enable' % --- Executes on button press in btnSendData.function btnSendData_Callback(hObject, eventdata, handles)% hObject handle to btnSendData (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)sendString=get(handles.edtSendData, 'String' );fwrite(handles.u_sCom,sendString);set(handles.txtStatus, 'String' set(handles.edtSendData, 'String'% start(handles.u_timer);,'7 ? ^e y?Y3 e 1): , '' ); function BytesAvailableFcnCallback(t,eventdata,handles)readString=fread(handles.u_sCom,1);u=getappdata(handles.figPJSerialCOM, 'u' ); endend endset(handles.u_sCom,set(handles.u_sCom,set(handles.u_sCom,set(handles.u_sCom, set(handles.u_sCom,les});'Timeout' ,1); 'InputBufferSize' ,1024); 'BytesAvailableFcnMode' 'BytesAvailableFcnCount' 'BytesAvailableFcn' , 'byte' ); ,1); ,{@BytesAvailableFcnCallback,hand'Stri ng' ,'‘ 6 ?a??? u 3e 1|'); , 'off' ); 'Enable' , 'On' );'String' , '1? ±????u 3e 1|' ); 'Enable', 'On' );'Enable' , 'Off' );, 'Off' );u=[u readString]; setappdata(handles.figPJSerialCOM,set(handles.edtRecvData, 'String'set(handles.txtStatus, 'String' % --- Executes on button press in btnExitProgram.function btnExitProgram_Callback(hObject, eventdata, handles) % hObject handle to btnExitProgram (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) close(handles.figPJSerialCOM);'u' ,u); ,u);'? oe ?e y?Y3e 1|');。