如何通过Matlab正确读取串口数据 [英] How to read serial data correctly through Matlab

查看:19
本文介绍了如何通过Matlab正确读取串口数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Matlab 从通过微处理器的串行端口读取数据.数据为十六进制格式,每个样本为 4 字节(32 位).当我读取这些数据时,我得到一些与传输数据不匹配的随机数字序列.下面是我的代码

I am using Matlab to read data from a serial port coming through a microprocessor. The data is in hexadecimal format with each sample of 4 bytes(32 bits). When I read this data, I get some random sequence of numbers which don't match the transmitted data. Below is my code

s = serial('COM16'); %assigns the object s to serial port

set(s, 'InputBufferSize', 128); %number of bytes in inout buffer
set(s, 'FlowControl', 'none');
set(s, 'BaudRate', 921600);
set(s, 'Parity', 'none');
set(s, 'DataBits', 8);
set(s, 'StopBit', 1);
set(s, 'Timeout',100);
%clc;

disp(get(s,'Name'));
prop(1)=(get(s,'BaudRate'));
prop(2)=(get(s,'DataBits'));
prop(3)=(get(s, 'StopBit'));
prop(4)=(get(s, 'InputBufferSize'));

disp([num2str(prop)]);

fopen(s);           %opens the serial port

data = fscanf(s);

fclose(s); %close the serial port

请告诉我我做错了什么才能获得正确的心音.谢谢

Please tell me what I am doing wrong do that I can get the correct heart sound. thanks

推荐答案

您可以将波特率降低到更标准的值,例如 115200.

You can lower the baudrate to something more standard, like 115200.

您也可以尝试使用终端程序.

You can also try with a terminal program.

这篇关于如何通过Matlab正确读取串口数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆