How to use DataAvailableFcn in Bluetooth Low Energy

4 次查看(过去 30 天)
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
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 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by