Real time audio data plot from COM/serial port

조회 수: 10 (최근 30일)
Kulbir
Kulbir 2023년 4월 7일
댓글: Kulbir 2023년 4월 14일
need to know how i can plot audio data in real-time from serial port. am getting error using this code.
clear; clc;
%create a serial object
s= serialport("COM4", 115200);
%open serial port
fopen(s);
%plotting data
i= 1;
while(1)
data(i)= str2double(fscanf(s));
plot(data);
pause(0.01);
i= i+1;
end
%error i am getting is---
Error using fopen
First input must be a file name or a file identifier.
Error in pltsril (line 5)
fopen(s);

답변 (1개)

Cris LaPierre
Cris LaPierre 2023년 4월 7일
fopen does not work with a serialport object. See the available methods here:
You likely want read.
  댓글 수: 27
Walter Roberson
Walter Roberson 2023년 4월 13일
Using readline(device) is not going to be useful for you. You need to find out what data format the device is sending, and you need to use read() of the device, probably using one of the commands I showed above.
What model of device are you reading from?
Kulbir
Kulbir 2023년 4월 14일
hello sir, i am in need your inputs, thank you

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Serial and USB Communication에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by