Creating a manual timeout for bluetooth connection in MATLAB App Designer
10 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have created a wireless signal analyzing application using MATLAB App Designer, a HC-06 Bluetooth module, and an Arduino. The application is basically complete and I am now coding in as much error detection as possible so the app does not crash if used incorrectly.
Given the device is connected using bluetooth, there are certain instances where the application is unable to esablish a connection. If this occurs, an error is shown in the code view of the App Designer, and the app crashes. Is there any way to create a sort of timeout in the code to keep the app from crashing while in use?
Attached is a picture of the UI I've created as well as the code used to create the bluetooth connection. When the user clicks the 'Connect' button, the shown code runs to pair the bluetooth device. This is where I'd like to be able to catch a failed connection before the app crashes. Normally the error occurs at the "fopen(app.bt);" line indicating the device cannot connect.
Note: The "Message Board" area of the UI is used to display error messages to the user

% Button pushed function: ConnectButton
function ConnectButtonPushed(app, event)
% Initialization and setup of BT device
if(app.connectFlag == 0 && app.inputSelectFlag == 1 && app.wirelessSelectFlag == 1)
% Clear message board
app.MessageBoardLabelText.Text = '';
instrreset; % clear and reset any existing instrument object
app.bt = Bluetooth(app.btName,1); % create bluetooth object using user selected device
fopen(app.bt); % Open BT connection
% Lamps indicating successful connection
app.ConnectLamp.Color = [0,1,0]; % Green
app.ConnectLabel.Text = 'Connection Successful!';
app.DisconnectLamp.Color = [0.9,0.9,0.9]; % Grey
app.DisconnectLabel.Text = '';
% Update Flags
app.connectFlag = 1;
app.disconnectFlag = 0;
app.wirelessSelectFlag = 0;
% app.inputSelectFlag = 0;
% app.transmissionSelectFlag = 0;
app.signalAnalysisFlag = 0;
app.resetFlag = 0;
app.setupAxesFlag = 0;
elseif(app.connectFlag == 0 && app.inputSelectFlag == 0 && app.wirelessSelectFlag == 1)
app.MessageBoardLabelText.Text = 'Please select input device!';
app.MessageBoardLabelText.FontColor = [1.0,0.0,0.0]; % red text
elseif(app.connectFlag == 0 && app.inputSelectFlag == 1 && app.wirelessSelectFlag == 0)
app.MessageBoardLabelText.Text = 'Please select wireless device!';
app.MessageBoardLabelText.FontColor = [1.0,0.0,0.0]; % red text
elseif(app.connectFlag == 0 && app.inputSelectFlag == 0 && app.wirelessSelectFlag == 0)
app.MessageBoardLabelText.Text = 'Please select input and wireless device before connecting!';
app.MessageBoardLabelText.FontColor = [1.0,0.0,0.0]; % red text
else
app.MessageBoardLabelText.Text = 'Device is already connected!';
app.MessageBoardLabelText.FontColor = [1.0,0.0,0.0]; % red text
end
end
1 Commento
Motaz Kaoud
il 26 Mag 2021
Hi, Has it work? i'm working in a simmilar project to receive data from a Bluetooth device using App designer tool.
Risposte (2)
epzolo
il 26 Mag 2021
2 Commenti
Motaz Kaoud
il 26 Mag 2021
Great, Can you guide me in using App Designer to receive data from a such Bluetooth device? what's the libraries or functions should i use to read/write a stream of data with a Bluetooth on microcontroller using app designer thanks for advance
Maty
il 8 Mar 2024
Bonjour, je travail sur un projet de robot et j'aimerais faire la connexion de matlab app designer avec un module bluetooth,alors j'aimerais que vous m'expliquiez la procedure a suivre.
0 Commenti
Vedere anche
Categorie
Scopri di più su MATLAB Support Package for Arduino Hardware in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!