How can I solve a subscript dimension mismatch problem reading from serial buffer using Arduino?

Problem: After approx 350 readings from serial buffer I get the following error....
??? Subscripted assignment dimension mismatch.
Error in ==> Pressure_Sensor_Scope_v2>togglebutton1_Callback at 229
Pressure(i,:) = str2num(tline);
When working, Pressure(i,:) looks like this....
-0.41 -0.30 18.42
When it fails, Pressure(i,:) looks like this....
-0.46 -018.47
When I use Arduino's serial monitor, the readout just runs perfectly for as long as I've tried, approximately 2 minutes as opposed to the 18 seconds with Matlab.
I should add that tline is read from...
[tline,count] = fgets(obj);
where: obj = serial(com_port);
Thank you for your time.

 采纳的回答

Characters have been lost. You need to ensure that flow control is in place and that the baud rate is not too high.
And when working with serial ports you should be validating the strings before storing them into data structures as valid data. Serial ports can lose data and serial ports are not error corrected.
Didn't anyone in the Arduino design team learn from the old days of using modems?? XMODEM, Y-MODEM, zmodem...

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 MATLAB Support Package for Arduino Hardware 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by