- Asynchronous reading: Instead of “fscanf” consider using “BytesAvailableFcn” property of the serial port object.
- Non-blocking read: Use the “BytesAvailable” property of the serial port object to check if the data is available before attempting to read it.
Reading serial port data in MATLAB background
12 次查看(过去 30 天)
显示 更早的评论
Hi There,
I have wrote a program in MATLAB that countiously read data through the serial port (from Arduino) in the background. To perform this im using the bytesavailable function in MATLAB 2019.
Essentially I need to run this in MATLAB background so I can run other codes.
When I Press the RUN button, Its looks like that it runs in background, but as soon I run other codes, it will get stuck in a long pause and it never excecutes.
Im thinking the problem might be related to fscanf function that I use to read the data.
I would appreciate it if someone can provide me with suggestions. Maybe I could use other functions in MATLAB 2019?
Best,
Nikan
0 个评论
回答(1 个)
Manas
2023-10-4
Hey Nikan Fakhari,
I understand that you are code is getting paused indefinitely when you run it along with other codes.
Based on your assumption that it depends on “fscanf” function, consider the following workarounds to see if it resolves the issue,
I suggest you refer to this documentation to learn more about the serial port object: https://in.mathworks.com/help/instrument/serial.html
Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 MATLAB Support Package for USB Webcams 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!