2012-08-17 45 views
1

我將來自Codeplex的託管WiFi網站的WLAN API集成到我的C#項目(Windows窗體應用程序)中。在API中,提供了不同的功能來檢索機器當前WiFi配置文件的各個方面。我只對檢索下面的函數中給出的RSSI強度感興趣。然後,我想要獲取該值並將其粘貼在表單上的文本框中。訪問同一應用程序中的兩個.csproj文件之間的功能

(Visual Studio 2008中)

在WlanAPI.cs文件,我感興趣的是函數存在這樣:

namespace NativeWifi 
{ 
    public class WlanClient 
{ 
    /// <summary> 
    /// Represents a Wifi network interface. 
    /// </summary> 
    public class WlanInterface 
    { 

        /// <summary> 
     /// Gets the RSSI. 
     /// </summary> 
     /// <value>The RSSI.</value> 
     /// <remarks>Not supported on Windows XP SP2.</remarks> 
     public int RSSI 
     { 
      get 
      { 
       return GetInterfaceInt(Wlan.WlanIntfOpcode.RSSI); 
      } 
     } 

在myApp.cs我有一個文本框,簡單地命名爲 '無線網絡連接' 那將顯示當前的RSSI。 我已經包括:在myApp.cs頭中使用NativeWifi,但似乎無法從WlanAPI.csproj中的RSSI函數中獲取數據。該項目建立並編譯得很好。我只是想獲得RSSI值。

在myApp.cs我有聲明的效果:

wifi.Text = (GetInterfaceInt(Wlan.WlanIntfOpcode.RSSI)); //app form txt_box=RSSI value 

我知道這是不正確的,但顯示了我想要做的事。

任何想法?

謝謝。

+0

什麼是錯誤消息,如果有的話?你能否確認你的項目中是否添加了對WlanAPI的引用? – 2012-08-17 11:46:02

+0

我得到的錯誤消息是:錯誤1名稱'GetInterfaceInt'在當前上下文中不存在。我有rssi函數存在於我的項目中的命名空間參考,但沒有直接引用WlanApi。 – 2012-08-17 11:59:11

+0

這裏似乎有一個斷開連接,你提到的錯誤是編譯錯誤(可以通過添加對WlanApi項目的引用來適當解決,假設你的實際代碼通過RSSI屬性使用GetInterfaceInt並通過使用通過使用WlanInterface對象獲得一個WlanClient對象的接口屬性),但同時你在你的問題中提到它正在構建和編譯好... – 2012-08-17 12:10:34

回答

2

您應該能夠通過

  1. 添加到WlanAPI.dll或WlanAPI項目(如果你把它添加到您的解決方案)
  2. 使用代碼像下面的參考解決你所面臨的問題:

    Using NativeWifi; 
    
    Class MyAPP : Form 
    { 
    
        public void PrintRSSI() 
        { 
    
         WlanClient client = new WlanClient(); 
         var interfaces = client.Interfaces; 
    
         //Now chose an interface out of all the available interfaces. Usually there would be zero or 1 interfaces available 
         if(interfaces.Length > 0) 
         { 
          //Select first available interface. A more complicated logic can present the list of available interfaces to the user and and then display RSSI for the selected interface 
          wifi.Text = interfaces[0].RSSI.ToString(); 
         } 
        } 
    
    //Other code for the class 
    } 
    
+0

我添加了對項目的引用並運行了你的代碼。我得到的錯誤是:錯誤無法將類型'int'隱式轉換爲字符串 – 2012-08-17 12:32:47

+0

我運行了int rssi = interfaces [0] .RSSI; wifi.Text = rssi.ToString();剛剛得到一個空格 – 2012-08-17 12:36:04

+0

'int'to string error was my fault,RSSI is int and should be converted to string before assign to it to text。我編輯了我的答案。關於獲得一個空白的框,嘗試把一個斷點,看看RSSI的價值,你越來越。 – 2012-08-20 05:41:21

相關問題