Timeout period for serialdev does not work after deploying it on raspberry pi.

1 visualización (últimos 30 días)
I was using serialdev to read() data from my arduino to the raspberry pi. I set the timeout period to 20 seconds and observed it truly waited 20 seconds to complete the object creation when running the code on matlab. However, after deploying it on the raspberry pi as a standalone program, I observed it no longer had that 20 seconds waiting time. Instead, it automatically returned an empty value at the time read() was called while not having yet recieved any data from the arduino. Are there any fixes for this?
PS: I am using this function to get a signal from the arduino as to when to snapshot() using the webcam() api for raspberry pi.
  3 comentarios
Nirmalkumar Doreraju
Nirmalkumar Doreraju el 29 de Abr. de 2020
“Timeout” feature in serialdev-IO is not codegen capable and this limitation will be addressed in future releases.
For now, can you please try the following code snippet to see if it satisfies your requirement?
Assuming that the file name is testSerial.m
function testSerial()
rObj = raspi();
serialObj = serialdev(rObj,'/dev/serial0',115200); % Use appropriate serial port and baudrate
% Assuming that as and when there is a data from serial, a snapshot needs
% to be taken. If it is a one time thing, then please enclose read inside a
% loop like this,
% data = uint8(0);
% while(!data)
% data = read(sd,1,'uint8')
% end
while(1)
data = read(serialObj,1,'uint8');
if(data == 1) % Compare with appropriate data
% Perform a snapshot and continue with the logic
end
end
The idea is to check if serial device has received any data in a polling mechanism.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

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

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by