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

조회 수: 1 (최근 30일)
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
Nirmalkumar Doreraju
Nirmalkumar Doreraju 2020년 4월 29일
“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.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Raspberry Pi Hardware에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by