我想编写一个简单的实用程序,将WiFi路由器的RSSI定期记录到文本文件中。是否有人知道使用Delphi库或API包装器读取无线路由器的RSSI值? 最佳答案 您可以使用Native Wifi API获取活动网络wifi连接的RSSI,在调用WlanOpenHandle和WlanEnumInterfaces函数之后,必须执行WlanQueryInterface方法,将wlan_intf_opcode_current_connection枚举值和指向结构,从这里必须访问WLAN_CONNECTION_ATTRIBUTES元素,并最终读取wlanAssociationAttributes字段的值。这是该字段的描述。 wlanSignalQualityA percentage value that represents the signal quality of the network. WLAN_SIGNAL_QUALITY是ULONG类型。该成员包含一个 值介于0到100之间。值0表示实际的RSSI信号 强度为-100 dbm。值100表示​​实际RSSI信号 强度为-50 dbm。您可以计算RSSI信号强度值 使用线性在1至99之间的wlanSignalQuality值 插值。试试这个示例代码uses Windows, SysUtils, nduWlanAPI in 'nduWlanAPI.pas', nduWlanTypes in 'nduWlanTypes.pas';procedure Scan();var hClient : THandle; dwVersion : DWORD; ResultInt : DWORD; pInterface : Pndu_WLAN_INTERFACE_INFO_LIST; i : Integer; pInterfaceGuid : TGUID; pdwDataSize, RSSI : DWORD; ppData : pndu_WLAN_CONNECTION_ATTRIBUTES;begin ResultInt:=WlanOpenHandle(1, nil, @dwVersion, @hClient); try if ResultInt<> ERROR_SUCCESS then begin WriteLn('Error Open CLient'+IntToStr(ResultInt)); Exit; end; ResultInt:=WlanEnumInterfaces(hClient, nil, @pInterface); if ResultInt<> ERROR_SUCCESS then begin WriteLn('Error Enum Interfaces '+IntToStr(ResultInt)); exit; end; for i := 0 to pInterface^.dwNumberOfItems - 1 do begin Writeln('Interface ' + pInterface^.InterfaceInfo[i].strInterfaceDescription); WriteLn('GUID ' + GUIDToString(pInterface^.InterfaceInfo[i].InterfaceGuid)); pInterfaceGuid:= pInterface^.InterfaceInfo[pInterface^.dwIndex].InterfaceGuid; ppData:=nil; pdwDataSize:=0; ResultInt:=WlanQueryInterface(hClient, @pInterfaceGuid, wlan_intf_opcode_current_connection, nil, @pdwDataSize, @ppData,nil); try if (ResultInt=ERROR_SUCCESS) and (pdwDataSize=SizeOf(Tndu_WLAN_CONNECTION_ATTRIBUTES)) then begin Writeln(Format('Profile %s',[ppData^.strProfileName])); Writeln(Format('Mac Address %.2x:%.2x:%.2x:%.2x:%.2x:%.2x',[ ppData^.wlanAssociationAttributes.dot11Bssid[0], ppData^.wlanAssociationAttributes.dot11Bssid[1], ppData^.wlanAssociationAttributes.dot11Bssid[2], ppData^.wlanAssociationAttributes.dot11Bssid[3], ppData^.wlanAssociationAttributes.dot11Bssid[4], ppData^.wlanAssociationAttributes.dot11Bssid[5]])); RSSI := (ppData^.wlanAssociationAttributes.wlanSignalQuality div 2) - 100; Writeln(Format('RSSI %d dbm',[RSSI])); end; finally if ppData<>nil then WlanFreeMemory(ppData); end; end; finally WlanCloseHandle(hClient, nil); end;end;begin try Scan(); except on E:Exception do Writeln(E.Classname, ': ', E.Message); end; Readln;end.注意:不幸的是,AFAIK不存在将Native Wifi API标头转换为Delphi的官方翻译,因此您可以使用wlanSignalQuality。关于delphi - Delphi例程读取无线连接的RSSI吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14324706/
10-11 15:40