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

1 view (last 30 days)
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.

Accepted Answer

Walter Roberson
Walter Roberson on 8 Jul 2015
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...

More Answers (0)

Categories

Find more on Arduino Hardware in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!