chairmanPC
Active member
- Joined
 - Apr 19, 2021
 
- Messages
 - 38
 
- Programming Experience
 - 10+
 
The WIndows .NET Framework form version of the BLE Watcher is running fine, so I am making a ASP.NET version of the BLE Watcher, but I kept getting this error:
Here are the codes below:
	
	
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
And this is my C# code.
	
	
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
Did I do something wrong here?
It's a ASP.NET project (non-Core), running .NET Framework 4.7.2.
	
		
			
		
		
	
				
			The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG)).
Note that the code in Form_Load is straight from the Windows Form version of the Watcher. In fact, all of the code came from this site: Bluetooth GATT Client - UWP applications.Here are the codes below:
			
				Webpage file:
			
		
		
		<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="BLE_Device_Watcher.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
        <div>
        </div>
    </form>
</body>
</html>
	And this is my C# code.
			
				WebForm1.aspx.cs:
			
		
		
		using System;
namespace BLE_Device_Watcher
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        //Device Data
        BluetoothLEDevice bluetoothLeDevice;
        GattDeviceServicesResult result;
        static DeviceInformation device = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            
            // Query for extra properties you want returned
            string[] requestedProperties = { "System.Devices.Aep.DeviceAddress", "System.Devices.Aep.IsConnected" };
            DeviceWatcher deviceWatcher =
                        DeviceInformation.CreateWatcher(
                                BluetoothLEDevice.GetDeviceSelectorFromPairingState(false),
                                requestedProperties,
                                DeviceInformationKind.AssociationEndpoint);
            // Register event handlers before starting the watcher.
            // Added, Updated and Removed are required to get all nearby devices
            deviceWatcher.Added += DeviceWatcher_Added;
            deviceWatcher.Updated += DeviceWatcher_Updated;
            deviceWatcher.Removed += DeviceWatcher_Removed;
            // EnumerationCompleted and Stopped are optional to implement.
            deviceWatcher.EnumerationCompleted += DeviceWatcher_EnumerationCompleted;
            deviceWatcher.Stopped += DeviceWatcher_Stopped;
            // Start the watcher.
            deviceWatcher.Start();
        }                <<---- The offending line
        protected void Button1_Click(object sender, EventArgs e)
        {
        }
        //Other
        private static void DeviceWatcher_Updated(DeviceWatcher sender, DeviceInformationUpdate args)
        {
            //throw new NotImplementedException();
        }
        private static void DeviceWatcher_Added(DeviceWatcher sender, DeviceInformation args)
        {
            if (args.Name == "myDevice")
            {
                device = args;
            }
        }
        private static void DeviceWatcher_Stopped(DeviceWatcher sender, object args)
        {
            //throw new NotImplementedException();
        }
        private static void DeviceWatcher_EnumerationCompleted(DeviceWatcher sender, object args)
        {
            //throw new NotImplementedException();
        }
        private static void DeviceWatcher_Removed(DeviceWatcher sender, DeviceInformationUpdate args)
        {
            //throw new NotImplementedException();
        }
    }
}
	Did I do something wrong here?
It's a ASP.NET project (non-Core), running .NET Framework 4.7.2.