- 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!