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

2 次查看(过去 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
“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 个)

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by