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

2 ビュー (過去 30 日間)
Miguel Dorado
Miguel Dorado 2020 年 4 月 16 日
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 件のコメント
Miguel Dorado
Miguel Dorado 2020 年 4 月 16 日
I'm using the deploy function.
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 Center および File ExchangeRun on Target Hardware についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by