Esempio n. 1
0
        /// <summary>
        /// Reads a property from the object
        /// </summary>
        /// <typeparam name="T1">The type of property to read</typeparam>
        /// <param name="property1Expr">The property expression</param>
        public async Task <Tuple <T1> > ReadPropertiesAsync <T1>(Expression <Func <TObj, T1> > property1Expr)
        {
            var values = await Client.SendRPMAsync(DeviceInstance, ObjectIdentifier,
                                                   ObjectHelpers.GetPropertyReference(property1Expr));

            return(new Tuple <T1>(values[0].As <T1>()));
        }
Esempio n. 2
0
        /// <summary>
        /// Reads a property from the object
        /// </summary>
        /// <typeparam name="T1">The type of property to read</typeparam>
        /// <param name="property1Expr">The property expression</param>
        public async Task <Tuple <ErrorOr <T1> > > ReadPropertiesSafeAsync <T1>(Expression <Func <TObj, T1> > property1Expr)
        {
            var results = await Client.SendRPMForReadResultsAsync(DeviceInstance,
                                                                  ObjectHelpers.GetObjectPropertyReference(ObjectIdentifier, property1Expr));

            return(new Tuple <ErrorOr <T1> >(
                       Client.FromReadResult <T1>(results[0])));
        }
Esempio n. 3
0
        /// <summary>
        /// Reads a single property from the object
        /// </summary>
        /// <typeparam name="T">The type of the property to read</typeparam>
        /// <param name="propertyExpr">The property expression</param>
        /// <returns>The property value</returns>
        public async Task <T> ReadPropertyAsync <T>(Expression <Func <TObj, T> > propertyExpr)
        {
            var reference = ObjectHelpers.GetPropertyReference(propertyExpr);
            var request   = new ReadPropertyRequest(ObjectIdentifier, reference.PropertyIdentifier, reference.PropertyArrayIndex);
            var ack       = await Client.SendRequestAsync <ReadPropertyAck>(
                DeviceInstance,
                request);

            return(ack.PropertyValue.As <T>());
        }
Esempio n. 4
0
        /// <summary>
        /// Sets a property to be updated
        /// </summary>
        /// <typeparam name="TProp">The type of the property</typeparam>
        /// <param name="propertyExpr">The property expression</param>
        /// <param name="value">The new value of the property</param>
        /// <param name="priority">The priority to write at</param>
        public void Set <TProp>(Expression <Func <TObj, TProp> > propertyExpr, TProp value, Option <uint> priority = default(Option <uint>))
        {
            var reference     = ObjectHelpers.GetPropertyReference(propertyExpr);
            var propertyValue = new PropertyValue(
                reference.PropertyIdentifier,
                reference.PropertyArrayIndex,
                Tagging.Tags.Encode(value),
                priority);

            this._properties.Add(propertyValue);
        }
Esempio n. 5
0
            /// <summary>
            /// Enqueues a property for reading
            /// </summary>
            /// <typeparam name="TProp">The type of property to read</typeparam>
            /// <param name="expression">The expression of the property to read</param>
            /// <param name="onValue">The action to invoke when a value is read</param>
            /// <param name="onError">The action to invoke when an error results</param>
            public void Enqueue <TProp>(Expression <Func <TObj, TProp> > expression, Action <TProp> onValue, Action <Error> onError = null)
            {
                var reference = ObjectHelpers.GetObjectPropertyReference(ObjectIdentifier, expression);
                var request   = new PropertyRequest <TProp>(
                    DeviceInstance,
                    reference,
                    onValue,
                    onError);

                Queue._requests.Add(request);
            }
Esempio n. 6
0
        /// <summary>
        /// Writes a property on the object
        /// </summary>
        /// <typeparam name="T">The type of property to write</typeparam>
        /// <param name="propertyExpr">The property expression</param>
        /// <param name="propertyValue">The property value</param>
        public Task WritePropertyAsync <T>(Expression <Func <TObj, T> > propertyExpr, T propertyValue)
        {
            var reference = ObjectHelpers.GetPropertyReference(propertyExpr);

            var request = new WritePropertyRequest(
                ObjectIdentifier,
                reference.PropertyIdentifier,
                reference.PropertyArrayIndex,
                TaggedGenericValue.Encode(propertyValue)
                );

            return(Client.SendRequestAsync(DeviceInstance, request));
        }
Esempio n. 7
0
        /// <summary>
        /// Reads three properties from the object
        /// </summary>
        /// <typeparam name="T1">The type of the first property</typeparam>
        /// <typeparam name="T2">The type of the second property</typeparam>
        /// <typeparam name="T3">The type of the third property</typeparam>
        /// <param name="property1Expr">The expression for the first property</param>
        /// <param name="property2Expr">The expression for the second property</param>
        /// <param name="property3Expr">The expression for the third property</param>
        /// <returns>The three property tuple</returns>
        public async Task <Tuple <ErrorOr <T1>, ErrorOr <T2>, ErrorOr <T3> > > ReadPropertiesSafeAsync <T1, T2, T3>(
            Expression <Func <TObj, T1> > property1Expr,
            Expression <Func <TObj, T2> > property2Expr,
            Expression <Func <TObj, T3> > property3Expr)
        {
            var values = await Client.SendRPMForReadResultsAsync(DeviceInstance,
                                                                 ObjectHelpers.GetObjectPropertyReference(ObjectIdentifier, property1Expr),
                                                                 ObjectHelpers.GetObjectPropertyReference(ObjectIdentifier, property2Expr),
                                                                 ObjectHelpers.GetObjectPropertyReference(ObjectIdentifier, property3Expr));

            return(new Tuple <ErrorOr <T1>, ErrorOr <T2>, ErrorOr <T3> >(
                       Client.FromReadResult <T1>(values[0]),
                       Client.FromReadResult <T2>(values[1]),
                       Client.FromReadResult <T3>(values[2])));
        }
Esempio n. 8
0
        /// <summary>
        /// Reads an entire range of an array from the object
        /// </summary>
        /// <typeparam name="T">The element type of the array</typeparam>
        /// <param name="propertyExpr">The expression of the array</param>
        /// <param name="range">The range to read, or None for the entire array</param>
        /// <returns>The resulting array range</returns>
        public async Task <ReadOnlyArray <T> > ReadRangeAsync <T>(
            Expression <Func <TObj, ReadOnlyArray <T> > > propertyExpr,
            Option <ReadRangeRequest.RangeType> range = default(Option <ReadRangeRequest.RangeType>))
        {
            var reference = ObjectHelpers.GetPropertyReference(propertyExpr);

            var request = new ReadRangeRequest(
                ObjectIdentifier,
                reference.PropertyIdentifier,
                reference.PropertyArrayIndex,
                range
                );

            var ack = await Client.SendRequestAsync <ReadRangeAck <T> >(DeviceInstance, request);

            return(ack.ItemData);
        }
Esempio n. 9
0
        /// <summary>
        /// Reads five properties from the object
        /// </summary>
        /// <typeparam name="T1">The type of the first property</typeparam>
        /// <typeparam name="T2">The type of the second property</typeparam>
        /// <typeparam name="T3">The type of the third property</typeparam>
        /// <typeparam name="T4">The type of the fourth property</typeparam>
        /// <typeparam name="T5">The type of the fifth property</typeparam>
        /// <param name="property1Expr">The expression for the first property</param>
        /// <param name="property2Expr">The expression for the second property</param>
        /// <param name="property3Expr">The expression for the third property</param>
        /// <param name="property4Expr">The expression for the fourth property</param>
        /// <param name="property5Expr">The expression for the fifth property</param>
        /// <returns>The five property tuple</returns>
        public async Task <Tuple <T1, T2, T3, T4, T5> > ReadPropertiesAsync <T1, T2, T3, T4, T5>(
            Expression <Func <TObj, T1> > property1Expr,
            Expression <Func <TObj, T2> > property2Expr,
            Expression <Func <TObj, T3> > property3Expr,
            Expression <Func <TObj, T4> > property4Expr,
            Expression <Func <TObj, T5> > property5Expr)
        {
            var values = await Client.SendRPMAsync(DeviceInstance, ObjectIdentifier,
                                                   ObjectHelpers.GetPropertyReference(property1Expr),
                                                   ObjectHelpers.GetPropertyReference(property2Expr),
                                                   ObjectHelpers.GetPropertyReference(property3Expr),
                                                   ObjectHelpers.GetPropertyReference(property4Expr),
                                                   ObjectHelpers.GetPropertyReference(property5Expr));

            return(new Tuple <T1, T2, T3, T4, T5>(
                       values[0].As <T1>(),
                       values[1].As <T2>(),
                       values[2].As <T3>(),
                       values[3].As <T4>(),
                       values[4].As <T5>()));
        }