waitfor( ) isn't working for a SerialPort

8 vues (au cours des 30 derniers jours)
Gavin
Gavin le 21 Sep 2024
Commenté : Gavin le 23 Sep 2024
Seems simple my code does this to be sure everything has been processed from the USB port connected to an Arduino Pico.
if (app.PicoCom.NumBytesAvailable>0)
PicoInput(app,app.PicoCom); % Call the callback 'by hand'
waitfor(app.PicoCom,NumBytesAvailable,0); % wait until it's REALLY done
end
I seem to need this because even though the trigger is "terminator" and call back has:
while (app.PicoCom.NumBytesAvailable>0)
raw = readline(src);
% Do the processing needed
end
sometimes data gets left in the buffer.
So here's the relevant help on waitfor():
waitfor(obj,propname,propvalue) specifies a value that the property must change to before execution can resume. If the specified property is already equal to propvalue, then waitfor returns immediately and execution resumes.
I assume that obj is the Serial Handle and I'm waiting for the property NumBytesAvailable to be 0
Here is what I get when it's run
Warning: Error executing listener callback for PostSet event on TotalBytesWritten
dynamic property in object of matlabshared.asyncio.internal.Channel class:
Unrecognized function or variable 'NumBytesAvailable'.
Error in MouseOdor20/RunTrial (line 419)
waitfor(app.PicoCom,NumBytesAvailable,0); % wait until it's REALLY done

Réponse acceptée

Walter Roberson
Walter Roberson le 21 Sep 2024
waitfor(app.PicoCom, 'NumBytesAvailable', 0); % wait until it's REALLY done
  1 commentaire
Gavin
Gavin le 23 Sep 2024
quote the property! You would think mLint could have figured that one out!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by