How to use DataAvailableFcn in Bluetooth Low Energy

4 visualizaciones (últimos 30 días)
DomiNICK
DomiNICK el 9 de Dic. de 2022
Respondida: Dhruv el 24 de Mzo. de 2023
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!

Respuesta aceptada

Dhruv
Dhruv el 24 de Mzo. de 2023
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!

Más respuestas (0)

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by