USB callback “terminator” fails to trigger a read when messages are close together
My App Designer program uses USB communication to an Arduino
It usually works but every once in a while Matlab fails to read.
configureCallback(app.PicoCom,"terminator",@app.PicoInput);
…
function PicoInput(app,src,~)
% check if there is more than 1 line. For some reason I don’t get another callback!!!
while (app.PicoCom.NumBytesAvailable>0)
raw = readline(src);
I’ve already added the while loop which mostly fixed it except if the messages are 20msec apart.
The only time it fails (and not very often) is between 2 messages that are known to be 20 ms apart.
When it fails (App Designer says "Run" … no action), I can go into the debugger (with a special pause I put in to read app properties) and check with
K>> app.PicoCom
ans =
Serialport with properties:
Port: "COM6"
BaudRate: 57600
NumBytesAvailable: 11
K>> read(app.PicoCom,11,"char")
ans =
‘z73851718
‘
And there it sits, not being read.
Sure, there are probably work arounds (I’m open to suggestions to manage it now) but isn’t this a bug!
My next attempt to handle this is to add a pause(0.03); at the end of the while loop but this is very unsatisfying and how do I know it will NEVER fail?My App Designer program uses USB communication to an Arduino
It usually works but every once in a while Matlab fails to read.
configureCallback(app.PicoCom,"terminator",@app.PicoInput);
…
function PicoInput(app,src,~)
% check if there is more than 1 line. For some reason I don’t get another callback!!!
while (app.PicoCom.NumBytesAvailable>0)
raw = readline(src);
I’ve already added the while loop which mostly fixed it except if the messages are 20msec apart.
The only time it fails (and not very often) is between 2 messages that are known to be 20 ms apart.
When it fails (App Designer says "Run" … no action), I can go into the debugger (with a special pause I put in to read app properties) and check with
K>> app.PicoCom
ans =
Serialport with properties:
Port: "COM6"
BaudRate: 57600
NumBytesAvailable: 11
K>> read(app.PicoCom,11,"char")
ans =
‘z73851718
‘
And there it sits, not being read.
Sure, there are probably work arounds (I’m open to suggestions to manage it now) but isn’t this a bug!
My next attempt to handle this is to add a pause(0.03); at the end of the while loop but this is very unsatisfying and how do I know it will NEVER fail? My App Designer program uses USB communication to an Arduino
It usually works but every once in a while Matlab fails to read.
configureCallback(app.PicoCom,"terminator",@app.PicoInput);
…
function PicoInput(app,src,~)
% check if there is more than 1 line. For some reason I don’t get another callback!!!
while (app.PicoCom.NumBytesAvailable>0)
raw = readline(src);
I’ve already added the while loop which mostly fixed it except if the messages are 20msec apart.
The only time it fails (and not very often) is between 2 messages that are known to be 20 ms apart.
When it fails (App Designer says "Run" … no action), I can go into the debugger (with a special pause I put in to read app properties) and check with
K>> app.PicoCom
ans =
Serialport with properties:
Port: "COM6"
BaudRate: 57600
NumBytesAvailable: 11
K>> read(app.PicoCom,11,"char")
ans =
‘z73851718
‘
And there it sits, not being read.
Sure, there are probably work arounds (I’m open to suggestions to manage it now) but isn’t this a bug!
My next attempt to handle this is to add a pause(0.03); at the end of the while loop but this is very unsatisfying and how do I know it will NEVER fail? usb terminate based callback fails occasionally MATLAB Answers — New Questions