Disconnect from ble device in app designer

Hi everyone,
I am trying to disconnect from a ble device in app desginer, but somehow "clear app.ble" or "clear ble" does not work. I am still connected after that. Does anybody know how to disconnect properly?

4 Comments

@Niklas Maximilian Busse - can you disconnect from the ble device outside of App Designer (like from the command line)? Can you show us the code where you create the connection? Is the variable/member really named ble like the ble function?
In the function ConnectButtonPushed I connect to the ble device and assign it to the app property app.Device:
% Button pushed function: ConnectButton
function ConnectButtonPushed(app, event)
printOut(app, "Try to connect...")
app.ConnectButton.Enable = "off"
try
clear app.Device
catch
end
index = app.DevicesListBox.Value
address = app.DeviceList.addresses(index)
name = app.DeviceList.names(index)
try
device = ble(address)
app.Device = device
msg = 'Connected to device ' + name + ' with address: ' + address
showConnectedButtons(app)
app.DeviceInfo.Value = [msg]
catch exception
msg = getReport(exception, 'basic', 'hyperlinks','off')
end
printOut(app, msg)
app.ConnectButton.Enable = "on"
end
Property:
properties (Access = private)
Device ble % Description
And here I want to clear the variable but I think it does not get the right variable:
% Button pushed function: DisconnectButton
function DisconnectButtonPushed(app, event)
clear app.Device
printOut(app, "Disconnected")
app.DevicesListBox.Items = [""]
app.SelectedTextArea.Value = [""]
showNotConnectedButtons(app)
end
I dont know how to address the right variable, its the same problem for the console.
properties (Access = private)
Device ble % Description
? Are you defining two properties, one called Device and the other ble? I see the code
clear app.Device
but you indicate that it doesn't work. Is that because when you try to re-connect, you get an error saying "already connected" (or something similar)? Have you tried just setting
app.Device = [];
which I've seen in the forum but I'm not sure if that will work as expected.
I was able to connect to a device (from the command line) and the clear seemed to work (in that I could then re-connect to the same device). I didn't try from within an app though.
Thanks for your replies, I think I found a solution which is similar to your proposal. in the declaration of the property, I dont define the data type
properties (Access = private)
Device
so I can set it to "" when I want to disconnect:
function onDeviceDisconnect(app)
app.Device = "";

Sign in to comment.

Answers (0)

Categories

Find more on Data Acquisition Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!