私はBluetoothLEについて勉強中です。あなたが私を助けることができない場合は、私にいくつかの助言を与えることができますか?
Windows 10でBluetoothLEのサンプルソースを学習するユニバーサルWindows:Character_ValueChanged()はCharacteristic関数に応答しません。サンプルソースでは、値の変更は関数呼び出しと呼ばれますが、WinFormには応答しません。 してください。
private GattCharacteristic registeredCharacteristic; こんにちは。 私はBluetoothLEを勉強しています。そして、私はそのデータを見て、私はそのブログを見ました。あなたが私を助けることができない場合は、私にいくつかの助言を与えることができますか?
Windows 10でBluetoothLEのサンプルソースを学習するユニバーサルWindows:Character_ValueChanged()はCharacteristic関数に応答しません。サンプルソースでは、値の変更は関数呼び出しと呼ばれますが、WinFormには応答しません。 してください。
private GattCharacteristic registeredCharacteristic;
.
.
private async void BTN_Change_SubscribeToggle_Click(object sender, EventArgs e)
{
if (!subscribedForNotifications)
{
// initialize status
GattCommunicationStatus status = GattCommunicationStatus.Unreachable;
var cccdValue = GattClientCharacteristicConfigurationDescriptorValue.None;
if (selectedCharacteristic.CharacteristicProperties.HasFlag(GattCharacteristicProperties.Indicate))
{
cccdValue = GattClientCharacteristicConfigurationDescriptorValue.Indicate;
}
else if (selectedCharacteristic.CharacteristicProperties.HasFlag(GattCharacteristicProperties.Notify))
{
cccdValue = GattClientCharacteristicConfigurationDescriptorValue.Notify;
}
Debug.WriteLine("[ cccdValue = {0} ]", cccdValue);
try
{
// BT_Code: Must write the CCCD in order for server to send indications.
// We receive them in the ValueChanged event handler.
status = await selectedCharacteristic.WriteClientCharacteristicConfigurationDescriptorAsync(cccdValue);
Debug.WriteLine("[ status = {0} ]", status);
if (status == GattCommunicationStatus.Success)
{
AddValueChangedHandler();
Notify_User("Successfully subscribed for value changes", NotifyType.StatusMessage);
}
else
{
Notify_User("Error registering for value changes : " + status.ToString(), NotifyType.ErrorMessage);
}
}
catch (UnauthorizedAccessException ex)
{
// This usually happens when a device reports that it support indicate, but it actually doesn't.
Notify_User(ex.Message, NotifyType.ErrorMessage);
}
} // if(!subscribedForNotifications)
else
{
try
{
// BT_Code: Must write the CCCD in order for server to send notifications.
// We receive them in the ValueChanged event handler.
// Note that this sample configures either Indicate or Notify, but not both.
var result = await
selectedCharacteristic.WriteClientCharacteristicConfigurationDescriptorAsync(
GattClientCharacteristicConfigurationDescriptorValue.None);
Debug.WriteLine("[ result = {0} ]", result);
if (result == GattCommunicationStatus.Success)
{
subscribedForNotifications = false;
RemoveValueChangedHandler();
Notify_User("Successfully un-registered for notifications", NotifyType.StatusMessage);
}
else
{
Notify_User("Error un-registered for notifications : " + result, NotifyType.ErrorMessage);
}
}
catch (UnauthorizedAccessException ex)
{
Notify_User(ex.Message, NotifyType.ErrorMessage);
}
} // else
}
private void AddValueChangedHandler()
{
Debug.WriteLine("[ AddValueChangedHandler() ]");
Debug.WriteLine("[ subscribedForNotifications = {0} ]", subscribedForNotifications);
BTN_Change_SubscribeToggle.Text = "Unsubscribe from value changes";
if (!subscribedForNotifications)
{
registeredCharacteristic = selectedCharacteristic;
registeredCharacteristic.ValueChanged += Characteristic_ValueChanged;
subscribedForNotifications = true;
CTR_Update_Visible(LB_Value, true);
CTR_Update_Msg(LB_Value, "test");
}
}
private async void Characteristic_ValueChanged(GattCharacteristic sender, GattValueChangedEventArgs args)
{
// BT_Code: An Indicate or Notify reported that the value has changed.
// Display the new value with a timestamp.
//var reader = DataReader.FromBuffer(args.CharacteristicValue);
Debug.WriteLine("[ Characteristic_ValueChanged ]");
var newValue = FormatValueByPresentation(args.CharacteristicValue, presentationFormat);
var message = string.Format("Value at {0} : \r\n\t {1}", DateTime.Now.ToString("HH:mm:ss.FFF"), newValue);
}
こんにちは、スタックオーバーフローを歓迎します。質問をして質問を更新する方法の詳細については、 の[ask]リンクを参照してください。たとえば、重複するテキストを削除します。 –