Any way to get "one-shot" callback events? (Instrument callbacks)

2 visualizzazioni (ultimi 30 giorni)
I'm trying to figure out how to manage the multiple callback events from a serial-port object.
I have a serial-port object with a BytesAvailableFcn that's triggered when there are a sufficient number of bytes in the input buffer. The incoming data-rate is moderately fast (a few 10s of kb/s), but incoming packets could be as small as 12-bytes. If I set my BytesAvailableFcnCount to be as small as 12-bytes, I get drowned in the overhead of processing the callbacks (i.e., one call for every 12-bytes). If I set the BytesAvailableFcnCount larger (say 100 bytes), then the problem goes away (but I lose the ability to respond promptly to short packets).
What I'd really like to do is just limit the callback events to be a one-shot event that I would manually re-enable when I leave the callback. Is there any way to do something like this?
I've tried a workaround that has helped a little bit:
function my_data_callback(port,event)
%Prevent multiple invocations of callback
if port.UserData.is_processing
return;
else
port.UserData.is_processing = 1;
end
%do some stuff
%Exit and re-enable callback
port.UserData.is_processing = 0;
But even touching the port object like this has too much overhead (profiling this reports a lot of time spent in serial.subsref and other object validity checks. I can do similar sorts of things with persistent variables, but debugging then becomes difficult.
Any thoughts?

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by