如何用C#中的蓝牙低功耗称重机获得重量?

时间:2017-12-06 10:10:21

标签: c# visual-studio bluetooth bluetooth-lowenergy

我目前有一台BLE(蓝牙低功耗)称重机,当人站在上面时,它可以提供重量,BMI,温度和其他一些值。我想在我的桌面应用程序中获取这些值。我尝试检查BluetoothLEAdvertisement方法,但我仍然没有得到任何价值。如果有人能分享它的工作原理,那就太好了!

class Program
{
    static void Main(string[] args)
    {
        // Start the program
        var program = new Program();

        // Close on key press
        Console.ReadLine();
    }

    public Program()
    {
        // Create Bluetooth Listener
        var watcher = new BluetoothLEAdvertisementWatcher();

        watcher.ScanningMode = BluetoothLEScanningMode.Active;

        // Only activate the watcher when we're recieving values >= -80
        watcher.SignalStrengthFilter.InRangeThresholdInDBm = -80;

        // Stop watching if the value drops below -90 (user walked away)
        watcher.SignalStrengthFilter.OutOfRangeThresholdInDBm = -90;

        // Register callback for when we see an advertisements
        watcher.Received += OnAdvertisementReceived;

        // Wait 5 seconds to make sure the device is really out of range
        watcher.SignalStrengthFilter.OutOfRangeTimeout = TimeSpan.FromMilliseconds(5000);
        watcher.SignalStrengthFilter.SamplingInterval = TimeSpan.FromMilliseconds(2000);

        // Starting watching for advertisements
        watcher.Start();
    }

    private void OnAdvertisementReceived(BluetoothLEAdvertisementWatcher watcher, BluetoothLEAdvertisementReceivedEventArgs eventArgs)
    {
        // Tell the user we see an advertisement and print some properties
        Console.WriteLine(String.Format("Advertisement:"));
        Console.WriteLine(String.Format("  BT_ADDR: {0}", eventArgs.BluetoothAddress));
        Console.WriteLine(String.Format("  FR_NAME: {0}", eventArgs.Advertisement.LocalName));
        Console.WriteLine(String.Format("  FR_NAME: {0}", eventArgs.Advertisement.DataSections.ToString()));
        Console.WriteLine();
    }
}

这是我目前拥有的代码。有人请帮助我! :)

0 个答案:

没有答案