Code: |
{ Copyright (C) 2006 Mike B. Petrichenko Этот адрес электронной почты защищён от спам-ботов. У вас должен быть включен JavaScript для просмотра. Этот адрес электронной почты защищён от спам-ботов. У вас должен быть включен JavaScript для просмотра. ICQ: 190812766 Phone: +7 (928) 324-58-24 +7 (928) 819-46-40
All Rights Reserved.
Only for non commercial purpose. } unit BTRadio;
interface
uses Windows, BluetoothAPI;
type TBTAddrArray = array of BTH_ADDR;
TBTRadio = class private FAddress: BTH_ADDR; FClassOfDevice: cardinal; FHandle: THandle; FManufacturer: word; FName: string; FSubversion: word;
function GetConnectable: boolean; function GetDiscoverable: boolean;
procedure SetConnectable(const Value: boolean); procedure SetDiscoverable(const Value: boolean);
public constructor Create(const AHandle: THandle); destructor Destroy; override;
property Address: BTH_ADDR read FAddress; property ClassOfDevice: cardinal read FClassOfDevice; property Connectable: boolean read GetConnectable write SetConnectable; property Discoverable: boolean read GetDiscoverable write SetDiscoverable; property Handle: THandle read FHandle; property Manufacturer: word read FManufacturer; property Name: string read FName; property Subversion: word read FSubversion; end;
function BTGetRadioByAddr(const Addr: BTH_ADDR): TBTRadio;
procedure BTEnumRadios(var Radios: TBTAddrArray);
implementation
uses SysUtils, BTStrings, BTExceptions;
function BTGetRadioByAddr(const Addr: BTH_ADDR): TBTRadio; var hFind: HBLUETOOTH_RADIO_FIND; SearchParams: BLUETOOTH_FIND_RADIO_PARAMS; hRadio: THandle; RadioInfo: BLUETOOTH_RADIO_INFO; RadioInfoSize: dword; begin Result := nil;
SearchParams.dwSize := SizeOf(BLUETOOTH_FIND_RADIO_PARAMS);
hFind := BluetoothFindFirstRadio(@SearchParams, hRadio); if (hFind <> 0) then begin repeat RadioInfoSize := SizeOf(BLUETOOTH_RADIO_INFO); FillChar(RadioInfo, RadioInfoSize, 0); RadioInfo.dwSize := RadioInfoSize;
if (BluetoothGetRadioInfo(hRadio, RadioInfo) = ERROR_SUCCESS) then if (RadioInfo.address.ullLong = Addr) then begin Result := TBTRadio.Create(hRadio); Break; end;
CloseHandle(hRadio); until (not BluetoothFindNextRadio(hFind, hRadio));
BluetoothFindRadioClose(hFind); end; end;
procedure BTEnumRadios(var Radios: TBTAddrArray); var hFind: HBLUETOOTH_RADIO_FIND; SearchParams: BLUETOOTH_FIND_RADIO_PARAMS; hRadio: THandle; Ndx: word; RadioInfo: BLUETOOTH_RADIO_INFO; RadioInfoSize: dword; begin Radios := nil; Ndx := 0;
SearchParams.dwSize := SizeOf(BLUETOOTH_FIND_RADIO_PARAMS);
hFind := BluetoothFindFirstRadio(@SearchParams, hRadio); if (hFind <> 0) then begin repeat RadioInfoSize := SizeOf(BLUETOOTH_RADIO_INFO); FillChar(RadioInfo, RadioInfoSize, 0); RadioInfo.dwSize := RadioInfoSize;
if (BluetoothGetRadioInfo(hRadio, RadioInfo) = ERROR_SUCCESS) then begin Inc(Ndx); SetLength(Radios, Ndx); CopyMemory(@Radios[Ndx - 1], @RadioInfo, RadioInfoSize); end;
CloseHandle(hRadio); until (not BluetoothFindNextRadio(hFind, hRadio));
BluetoothFindRadioClose(hFind); end; end;
function TBTRadio.GetConnectable: boolean; begin Result := BluetoothIsConnectable(FHandle); end;
function TBTRadio.GetDiscoverable: boolean; begin Result := BluetoothIsDiscoverable(FHandle); end;
procedure TBTRadio.SetConnectable(const Value: boolean); begin if (not BluetoothEnableIncomingConnections(FHandle, Value)) then raise BTException.Create(STR_ERROR_ENABLE_CONNECTION); end;
procedure TBTRadio.SetDiscoverable(const Value: boolean); begin if (not BluetoothEnableDiscovery(FHandle, Value)) then raise BTException.Create(STR_ERROR_ENABLE_DISCOVERY); end;
constructor TBTRadio.Create(const AHandle: THandle); var RadioInfo: BLUETOOTH_RADIO_INFO; RadioInfoSize: dword; Res: dword; begin FHandle := AHandle;
RadioInfoSize := SizeOf(BLUETOOTH_RADIO_INFO); FillChar(RadioInfo, RadioInfoSize, 0); RadioInfo.dwSize := RadioInfoSize;
Res := BluetoothGetRadioInfo(FHandle, RadioInfo); if (Res = ERROR_SUCCESS) then begin FAddress := RadioInfo.address.ullLong; FClassOfDevice := RadioInfo.ulClassofDevice; FManufacturer := RadioInfo.manufacturer; FName := string(widestring(RadioInfo.szName)); FSubversion := RadioInfo.lmpSubversion;
end else case Res of ERROR_INVALID_PARAMETER: raise BTException.Create(STR_ERROR_INVALID_PARAMETER); ERROR_REVISION_MISMATCH: raise BTException.Create(STR_ERROR_REVISION_MISMATCH);
else RaiseLastOSError; end; end;
destructor TBTRadio.Destroy; begin CloseHandle(FHandle);
inherited; end;
end.
|
Просьба писать ваши замечания, наблюдения и все остальное,
что поможет улучшить предоставляемую информацию на этом сайте.
ВСЕ КОММЕНТАРИИ МОДЕРИРУЮТСЯ ВРУЧНУЮ, ТАК ЧТО СПАМИТЬ БЕСПОЛЕЗНО!