How to use DataAvailableFcn in Bluetooth Low Energy

Hi,
I'm struggling with DataAvailableFcn to receive data from Bluetooth Low Energy device (ESP32).
I put this function in endless loop
while 1 > 0
c.DataAvailableFcn = @getValue;
end
I got data only when I terminate .m script.
The second question is how to use DataAvailableFcn in appdesigner. There are private functions with app argument, for example:
connect(app)
However function that handle DataAbailableFcn should be like this:
function getValue(src, evt)
Thanks for any help in advance!

 채택된 답변

Dhruv
Dhruv 2023년 3월 24일

0 개 추천

The reason for not receiving data from the Bluetooth Low Energy device using the ‘DataAvailableFcn’ is because the MATLAB program is unable to execute any other commands outside the loop. MATLAB has a single thread of execution, which means that it can only execute one task at a time. When entering an endless loop, MATLAB is not able to execute any other commands, including those related to Bluetooth communication.
To solve this issue, you can use the ‘pause’ function within the loop to allow MATLAB to execute other commands, including those related to Bluetooth communication.
For the second question regarding ‘DataAvailableFcn’ in App Designer, try defining the ‘getValue’ function as a private function within the App Designer class, and then set the ‘DataAvailableFcn’ property of the Bluetooth object to call that function. This can be done by using the app argument within the ‘getValue’ function to access the necessary properties of the App Designer class.
I hope this helps!

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

제품

릴리스

R2021b

질문:

2022년 12월 9일

답변:

2023년 3월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by