Esempio n. 1
0
        /// <summary> Reads string value from the given characteristic. </summary>
        /// <param name="Characteristic"> The GATT characteristic. </param>
        /// <param name="Value"> If the method completed with success contains the read value. </param>
        /// <returns> If the method completed with success the returning value is
        ///   <see cref="wclErrors.WCL_E_SUCCESS" />. If the method failed the returning value is
        ///   one of the Bluetooth Framework error code. </returns>
        protected Int32 ReadStringValue(wclGattCharacteristic?Characteristic, out String Value)
        {
            Value = "";

            if (!FConnected)
            {
                return(wclConnectionErrors.WCL_E_CONNECTION_NOT_ACTIVE);
            }
            if (Characteristic == null)
            {
                return(wclBluetoothErrors.WCL_E_BLUETOOTH_LE_ATTRIBUTE_NOT_FOUND);
            }

            Byte[] CharValue;
            Int32  Res = FClient.ReadCharacteristicValue(Characteristic.Value, wclGattOperationFlag.goNone,
                                                         out CharValue);

            if (Res == wclErrors.WCL_E_SUCCESS)
            {
                if (CharValue != null && CharValue.Length > 0)
                {
                    Value = Encoding.UTF8.GetString(CharValue);
                }
            }
            return(Res);
        }