2021a Serial Port not reading correctly
10 views (last 30 days)
I am using Matlab to read data from a device using a serial port connection. The device is sending data continuously, and has an LCD screen showing the current value, updated every 0.5 seconds. The values are typically in the range 12000-13000. I have one function which connects to the device, and a separate function which reads data from the device into a variable, although the example code I've shown here is a subset of the overall program.
I was using v2019a originally, and was able to connect to the device successfully and read data from it. However, I was not able to flush the device buffer, so it always read from the start rather than taking the most recent value. I've attached some example code and output below, showing values in the range expected.
pause(6) %allow device to boot
I upgraded to v2021a so that I could flush the buffer before reading data. I am updating my code to reflect changes between the versions, but have noticed that it is no longer reading the serial data correctly. There are repeated values, and values outside the expected range. I've attached the example code and two sets of output below. The device was both digitally and physically (USB) disconnected between the two runs that generated the output data. Many of the output values are identical between the two runs, and some are outside the device output range.
pause(6) %allows the device to boot up after connection
pause(1) %allow the buffer to get sufficient data
Can you advise what I am doing wrong in the 2021a set up please?