在 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/