Matlab & Arduino serial communication -Warning: Unsuccessful read: The input buffer was filled before the Terminator was reached.. "

11 次查看(过去 30 天)
I am receiving the following message in matlab when trying to read from the serial port's input buffer.
Warning: Unsuccessful read: The input buffer was filled before the Terminator was reached..
In matlab I am using the BytesAvailableFcn to asynchronously check the input buffer for an event which is set to 'terniminator' which should be set to a linefeed:
arduino = serial('COM8','BaudRate',115200);
arduino.InputBufferSize = 1000; % set input buffer size
arduino.ReadAsyncMode = 'continuous'; % asynchronously fills the input buffer
arduino.Terminator = 'LF';
arduino.BytesAvailableFcnMode = 'terminator';
arduino.BytesAvailableFcn = @myCallback;
fopen(arduino);
fprintf(arduino,'*IDN?')
out = fscanf(arduino);
and my callback function:
function frame = myCallback(obj,event)
frame = fread(obj, obj.BytesAvailable);
disp(frame);
end
Now, strangely this method seems to work if I'm using the 'bytes' mode set to 901 bytes, but I cannot get it to work when checking for the terminator. And when using the bytes method the terminator is displayed in matlab, i.e. I see a '10' printed to the screen within the buffer size of 1000.
Any help is greatly appreciated!!
Cheers
  1 个评论
Sailesh Sidhwani
Sailesh Sidhwani 2017-7-28
Hi Nicholas,
Try setting a breakpoint in your callback function when in 'terminator' mode and see if there the terminator 'LF' is actually present in the input buffer. This would help in debugging the issue further.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Arduino Hardware 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by