gpt4 book ai didi

windows - 如何使用 Delphi 列出蓝牙 radio /设备?

转载 作者:可可西里 更新时间:2023-11-01 11:30:24 34 4
gpt4 key购买 nike

在 Delphi 下使用蓝牙时,列出所有已连接的蓝牙设备到某个蓝牙 radio (主机设备)可能很方便。所以问题是:

如何使用 Delphi 列出蓝牙 radio /设备?

最佳答案

这可以通过 JEDI API JwaBluetoothAPIs(在这里找到它:http://sourceforge.net/projects/jedi-apilib/)和下面的代码片段来完成:

uses
JwaBluetoothAPIs;

procedure ScanBluetoothRadiosDevices;
var
RadioHandle, DeviceFindHandle: THandle;
FindHandle: HBLUETOOTH_RADIO_FIND;
BtFrp: TBlueToothFindRadioParams;
RadioInfo: BLUETOOTH_RADIO_INFO;
DeviceInfo: BLUETOOTH_DEVICE_INFO;
DeviceSearchParams: BLUETOOTH_DEVICE_SEARCH_PARAMS;
Err : integer;
begin
// specify record sizes
BtFrp.dwSize := SizeOf(BtFrp);
DeviceInfo.dwSize := SizeOf(DeviceInfo);
RadioInfo.dwSize := SizeOf(RadioInfo);

FindHandle := BluetoothFindFirstRadio(@BtFrp, RadioHandle);
if (FindHandle = 0) then
RaiseLastOSError;

repeat
BluetoothEnableDiscovery(RadioHandle, True);
if BluetoothGetRadioInfo(RadioHandle, RadioInfo) = ERROR_SUCCESS then
ShowMessage('Radio found: '+ RadioInfo.szName);

with DeviceSearchParams do
begin
dwSize := SizeOf(DeviceSearchParams);
fReturnUnknown := True;
fReturnRemembered := True;
hRadio := RadioHandle;
end;

DeviceFindHandle := BluetoothFindFirstDevice(DeviceSearchParams, DeviceInfo);
if DeviceFindHandle = 0 then
Continue;

repeat
if BluetoothGetDeviceInfo(RadioHandle, DeviceInfo) = ERROR_SUCCESS then
begin
BluetoothUpdateDeviceRecord(DeviceInfo);
if DeviceInfo.fConnected then
ShowMessageFmt('Device %s is connected', [DeviceInfo.szName])
else
ShowMessageFmt('Device %s is not connected', [DeviceInfo.szName]);
end;
until not BluetoothFindNextDevice(DeviceFindHandle, DeviceInfo);
BluetoothFindDeviceClose(DeviceFindHandle)
until not (BluetoothFindNextRadio(FindHandle, RadioHandle));
BluetoothFindRadioClose(FindHandle);
end;

从那时起,可以轻松替换 ShowMessageFmt(..) 调用并将其替换为自定义代码。

关于windows - 如何使用 Delphi 列出蓝牙 radio /设备?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21497453/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com