MATLAB serial timeout handling.

A have a "default"-configured serial port. How do I implement timeout error handling?
If I do something like this:
try
fread(SerialObject, 1, 'uint8');
catch err
myError(err)
end
it does not read that as an error (never executes catch block).
What is the proper way to handle it in this situation?

Antworten (2)

Chirag Gupta
Chirag Gupta am 22 Jul. 2011

1 Stimme

The Timeout is a warning and hence you are unable to catch it. Searching a little, I found a couple of references that might be helpful:
May be something like this:
lastwarn('');
try
fread(s)
if(~isempty(lastwarn))
error(lastwarn)
end
catch err
err
end
Chirag Gupta
Chirag Gupta am 22 Jul. 2011

0 Stimmen

3 Kommentare

Adam
Adam am 22 Jul. 2011
I am reading serial data in "continous" mode, so the timeout won't trigger ErrorFcn.
Chirag Gupta
Chirag Gupta am 22 Jul. 2011
Note this will only work for async operations
Adam
Adam am 22 Jul. 2011
Chirag -- exactly! So what is a good way to handle this on synchronous serial connections?

Melden Sie sich an, um zu kommentieren.

Kategorien

Produkte

Gefragt:

am 22 Jul. 2011

Community Treasure Hunt

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

Start Hunting!

Translated by