声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 2605|回复: 2

[综合讨论] [求助]matlab能不能扫描串口数据

[复制链接]
发表于 2005-9-21 17:29 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
rt
回复
分享到:

使用道具 举报

发表于 2005-9-21 22:01 | 显示全部楼层

回复:(ecass)[求助]matlab能不能扫描串口数据

matlab可以实现串口通信
发表于 2005-9-23 21:12 | 显示全部楼层

回复:(ecass)[求助]matlab能不能扫描串口数据

<P>我这里有一个程序,实现了PC与单片机串口通信,看看对你是否有帮助</P>
<P>function instrcallback(obj, event)<BR>%INSTRCALLBACK Display event information for the event.<BR>%<BR>%    INSTRCALLBACK(OBJ, EVENT) displays a message which contains the <BR>%    type of the event, the time of the event and the name of the<BR>%    object which caused the event to occur.  <BR>%<BR>%    If an error event occurs, the error message is also displayed.  <BR>%    If a pin event occurs, the pin that changed value and the pin <BR>%    value is also displayed. <BR>%<BR>%    INSTRCALLBACK is an example callback function. Use this callback <BR>%    function as a template for writing your own callback function.<BR>%<BR>%    Example:<BR>%       s = serial(\'COM1\');<BR>%       set(s, \'OutputEmptyFcn\', {\'instrcallback\'});<BR>%       fopen(s);<BR>%       fprintf(s, \'*IDN?\', \'async\');<BR>%       idn = fscanf(s);<BR>%       fclose(s);<BR>%       delete(s);<BR>%</P>
<P>%    MP 2-24-00<BR>%    Copyright 1999-2001 The MathWorks, Inc. <BR>%    $Revision: 1.2 $  $Date: 2001/03/19 15:26:54 $</P>
<P><BR>% Define error message.<BR>error1 = \'Type \'\'help instrument\\instrcallback\'\' for an example using INSTRCALLBACK.\';</P>
<P><PTCH nargin<br>case 0<BR>   error(sprintf([\'This function may not be called with 0 inputs.\\n\',...<BR>         \'Type \'\'help instrument\\instrcallback\'\' for an example using INSTRCALLBACK.\']));<BR>case 1<BR>   error(error1);<BR>case 2<BR>   if ~isa(obj, \'instrument\') | ~isa(event, \'struct\')<BR>      error(error1);<BR>   end   <BR>   if ~(isfield(event, \'Type\') &amp; isfield(event, \'Data\'))<BR>      error(error1);<BR>   end<BR>end   </P>
<br>
<P>% Determine the type of event.<BR>EventType = event.Type;</P>
<P>% Determine the time of the error event.<BR>EventData = event.Data;<BR>EventDataTime = EventData.AbsTime;<BR>   <BR>% Convert the clock time to a datenum so that it can be converted to the<BR>% display string.<BR>EventDataTime = num2cell(EventDataTime);<BR>EventDataTime = datenum(EventDataTime{:});</P>
<P>% Create a display indicating the type of event, the time of the event and<BR>% the name of the object.<BR>name = get(obj, \'Name\');<BR>fprintf([EventType \' event occurred at \' datestr(EventDataTime,13),...<BR>\' for the object: \' name \'.\\n\']);</P>
<P>% Display the error string.<BR>if strcmp(lower(EventType), \'error\')<BR>fprintf([EventData.Message \'\\n\']);<BR>end</P>
<P>% Display the pinstatus information.<BR>if strcmp(lower(EventType), \'pinstatus\')<BR>    fprintf([EventData.Pin \' is \'\'\' EventData.PinValue \'\'\'.\\n\']);<BR>end</P>
<P>%Define the serial buffer array.<BR>out=zeros(200,1);</P>
<P>%Function of serial event operation.<BR>out=fread(obj, 200, \'uint8\')   %Recieve 200 bytes from MCU.<BR>end</P>
<P>% Function of drawing a waveform. <BR>time1=1:1.8:360;<BR>plot(time1, out(:),\'.r\');<BR>%plot(time1, out_filter (:),\'--.b\');<BR>legend(\'距离定位\',1); <BR>      grid on;      <BR>title(\'测量信号波形图\');<BR>% end</P>
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-6 05:46 , Processed in 0.102344 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表