/// <summary> /// Updates the object /// </summary> public Task UpdateAsync() { var spec = new WriteAccessSpecification(ObjectIdentifier, new ReadOnlyArray <PropertyValue>(_properties)); var request = new WritePropertyMultipleRequest(new ReadOnlyArray <WriteAccessSpecification>(false, spec)); return(Client.SendRequestAsync(DeviceInstance, request)); }
/// <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>()); }
/// <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)); }
/// <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); }
/// <summary> /// Creates the object /// </summary> public Task CreateAsync() { var request = new CreateObjectRequest(ObjectSpecifier, new ReadOnlyArray <PropertyValue>(_properties)); return(Client.SendRequestAsync(DeviceInstance, request)); }