Main Content

bluetoothlist

扫描附近的 Bluetooth 经典设备

自 R2020b 起

说明

示例

devlist = bluetoothlist 扫描附近的 Bluetooth® 经典设备。使用 bluetooth 连接到设备。

示例

devlist = bluetoothlist("Timeout",time) 扫描时间最长为 time 秒。Windows® 的默认超时期限为 35 秒,macOS 的默认超时期限为 20 秒。time 的值必须等于或大于 5。

示例

全部折叠

扫描附近的蓝牙经典设备,并检查其连接状态。

使用 bluetoothlist 列出所有附近的设备。如果设备已连接到另一个设备或应用程序,则该设备可能不会出现在此列表中。您可先断开设备与任何其他设备或应用程序的连接,以便 MATLAB® 发现它。

devlist = bluetoothlist
devlist=5×4 table
        Name            Address        Channel          Status      
    _____________    ______________    _______    __________________

    "Pixel 3"        "3C286DD533CA"    8          "Ready to connect"         
    "HC-06"          "98D331FB3B77"    1          "Requires pairing"
    "mjin-maci"      "A886DDA44062"    3          "Requires pairing"
    "DMTDevice"      "B0B448F47A4C"    Unknown    "Unknown"         

NameAddress 列用于标识设备。Channel 列指示设备 SPP 通道。Status 列说明当前设备连接状态。

您还可以指定超时值,该值在 Windows 上小于默认的 35 秒,在 macOS 上小于默认的 20 秒。

devlist = bluetoothlist("Timeout",10)
devlist=3×4 table
        Name            Address        Channel          Status      
    _____________    ______________    _______    __________________

    "Pixel 3"        "3C286DD533CA"    8          "Ready to connect"         
    "mjin-maci"      "A886DDA44062"    3          "Requires pairing"

输出参量

全部折叠

附近的 Bluetooth 设备的列表,以表形式返回。该表包含以下列。

设备名称,以字符串标量形式返回。多个设备可以共享同一个名称。

数据类型: string

设备标识符,以字符串标量形式返回。

数据类型: string

设备 SPP 通道,以分类标量形式返回。如果通道未知,则此列中的值为 Unknown

数据类型: categorical

设备连接状态,以字符串形式返回。仅当 Bluetooth 设备的状态为 "Ready to connect" 时,才能使用 bluetooth 连接到它。可能的值如下。

描述
"Ready to connect"设备支持 SPP,已配对,但未连接到任何位置。
"Requires pairing"设备支持 SPP,但未配对。
"Connected"设备支持 SPP 且已连接。
"Unsupported"设备不支持 SPP。
"Unknown"不知道设备是否支持 SPP。设备已关闭或无法响应扫描请求。

数据类型: string

版本历史记录

在 R2020b 中推出

另请参阅