0

I have the following code for my IOS implementation, the problem is that the WroteCharacteristicValue event is never fired. Is is being fired on the android side when I connect to the same module. Any ideas what to do?

    public void StartUpdates ()
    {
        // TODO: should be bool RequestValue? compare iOS API for commonality
        bool successful = false;
        if(CanRead) {
            Console.WriteLine ("** Characteristic.RequestValue, PropertyType = Read, requesting read");
            _parentDevice.UpdatedCharacterteristicValue += UpdatedRead;

            _parentDevice.ReadValue (_nativeCharacteristic);

            successful = true;
        }
        if (CanUpdate) {
            Console.WriteLine ("** Characteristic.RequestValue, PropertyType = Notify, requesting updates");
            _parentDevice.UpdatedCharacterteristicValue += UpdatedNotify;

            _parentDevice.WroteCharacteristicValue += Wrote; // -DP here??

            _parentDevice.SetNotifyValue (true, _nativeCharacteristic);

            successful = true;
        }

        Console.WriteLine ("** RequestValue, Succesful: " + successful.ToString());
    }
    void Wrote(object sender, CBCharacteristicEventArgs e) {

        System.Diagnostics.Debug.WriteLine("Characteristic Write Complete!");

        this.WriteComplete (this, new CharacteristicReadEventArgs () {
            Characteristic = new Characteristic(e.Characteristic, _parentDevice)
        });
    } 
4

1 回答 1

1

仅当WroteCharacteristic特征写入响应时才会触发。

您可以通过以下方式进行检查:

var prop = _nativeCharacteristic.Properties;
if(prop.HasFlag(CBCharacteristicProperties.Write))
{
    // Event can be used
}
else if(prop.HasFlag(CBCharacteristicProperties.WriteWithoutResponse))
{
    // Event will not fire if WriteWithoutResponse
}

顺便说一句:我们为 BLE 提供了一个插件,所以你不必关心平台特定的东西 ;) http://smstuebe.de/2016/05/13/blev1.0/

于 2016-06-09T07:28:30.733 回答