Working with serial port in Raspberry Pi 3 B+

4 visualizaciones (últimos 30 días)
Hajar Abedifirouzjaei
Hajar Abedifirouzjaei el 31 de Mayo de 2020
Comentada: James Bittner el 10 de Nov. de 2021
Hi everyone,
I am a beginner in MATLAB and Raspberry Pi. I have a radar that is connected to my Raspberri Pi. I want to acquire data from the radar and process it by my desktop installation of MATLAB. I have used these code for connecting to Raspberry Piand its serial ports:
myraspi= raspi('192.168.137.46','pi','raspberry');
comportnum_str_Data='/dev/ttyACM1';
hDataPort=serialdev(myraspi,comportnum_str_Data,230400,8,'none',1);
comportnum_str_Cfg='/dev/ttyACM0';
hCfgPort=serialdev(myraspi,comportnum_str_Cfg,115200,8,'none',1);
So, my questions:
1- How can I open to these ports? As an example, in Linux and Windows we can use serial function for onnecting and 'fopen' for openning port.
2- How we can check port status? like windows that is:
hDataPort.BytesAvailable
3- How we can check port input buffer size? Like:
hDataPort.InputBufferSize

Respuestas (2)

Reeno Joseph
Reeno Joseph el 9 de Jul. de 2020
Hello Hajar
This feature is not available in raspi - MATLAB IO. We will consider your usecase for future enhancements.
Thanks,
Reeno Joseph
  1 comentario
Robert White
Robert White el 31 de Dic. de 2020
I also need to know BytesAvailable using Raspberry Pi from matlab ... is there no BytesAvailable property in the serial object? Is there any way to find out how many bytes are available?

Iniciar sesión para comentar.


Robert White
Robert White el 31 de Dic. de 2020
Editada: Robert White el 31 de Dic. de 2020
Here is an ugly way to read all available bytes and interpret them as an array of chars:
%Read serial port over raspberry pi
r=raspi
mySerialDev=serialdev(r,'/dev/ttyACM0',115200);
mySerialDev.Timeout=0.1;
data=read(mySerialDev,1,'char');
n=1;
clear mystring
while (~isempty(data))
mystring(n)=data;
n=n+1;
data=read(mySerialDev,1,'char');
end
disp(mystring)

Categorías

Más información sobre MATLAB Support Package for Raspberry Pi Hardware en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by