Connection of BLE device with Simulink

2 ビュー (過去 30 日間)
Lucas Speck
Lucas Speck 2020 年 6 月 22 日
回答済み: Stefanie Schwarz 2020 年 7 月 2 日
Hello everyone,
I have already connected my BLE device with Matlab. I can read the heart rate. My problem ist, that I want to use the heart rate in desktop real time sumulation. How can I import this data in Simulink?
Thank you for your help.
Lucas

回答 (1 件)

Stefanie Schwarz
Stefanie Schwarz 2020 年 7 月 2 日
Hi Lucas,
as far as I am aware, there is currently no Simulink block that can directly read from a BLE device using the host PC interface.
What you can do instead is use a MATLAB Function Block that leverages the ble() MATLAB function. The code would be along the lines of:
function y = fcn()
persistent b; %automatically initialized to []
persistent hr; %automatically initialized to []
%% extrinsic declarations
coder.extrinsic('ble');
coder.extrinsic('characteristic');
coder.extrinsic('read');
if(isempty(b))
b = ble("UA E39 MODULE");
hr = characteristic(b, "heart rate", "heart rate measurement");
end
%% initialize output
y = zeros(...)
%% read data from BLE device
data = read(hr);
%% post-process the data
y = ...
end
Note that the 'ble'-related functions do not support code generation and therefore need to be declared as extrinsic. Because of this, I am afraid you will not be able to run your model in a Simulink Desktop Real-Time (SLDRT) external mode simulation. However, you can run a SLDRT normal mode simulation which is a little different. To learn more about the differences between the two SLDRT simulation modes, see the following article:
Another option if you are only looking for a simulation running at an approximation of the wall clock time would be Simulation Pacing:

カテゴリ

Help Center および File ExchangeMultirate Signal Processing についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by