Ejemplo n.º 1
0
    /// <summary>
    /// Set property value.
    /// </summary>
    /// <param name="index">Zero-based property index.</param>
    /// <param name="value">Value</param>
    /// <returns>Indicator when the property is set.</returns>
    protected internal AsyncReply <object> _Set(byte index, object value)
    {
        if (index >= properties.Length)
        {
            return(null);
        }

        var reply = new AsyncReply <object>();

        var parameters = Codec.Compose(value, connection);

        connection.SendRequest(Packets.IIPPacket.IIPPacketAction.SetProperty)
        .AddUInt32(instanceId)
        .AddUInt8(index)
        .AddUInt8Array(parameters)
        .Done()
        .Then((res) =>
        {
            // not really needed, server will always send property modified,
            // this only happens if the programmer forgot to emit in property setter
            properties[index] = value;
            reply.Trigger(null);
        });

        return(reply);
    }