This package includes the .NET System.Device.Model for .NET nanoFramework C# projects.
$ dotnet add package nanoFramework.System.Device.ModelThis library is experimental, it may change and it may be moved to a different package in the future. Avoid taking direct dependency on it.
This library provides a set of attributes which allow to annotate devices.
They can be used for:
Model is representing language independent description of the device. The attributes represent a C# mapping from C# types into the model.
Every class producing telemetry or exposing some commands should put a telemetry attribute on it
[Interface("LPS25H - Piezoresistive pressure and thermometer sensor")]
public class Lps25h : IDisposable
[Interface(...)] attribute:
Every method or property producing telemetry should have [Telemetry] attribute on it.
For properties providing name of the Telemetry is optional as it can be deduced from the property name.
Telemetry can be put on:
out argument
out arguments are currently out of scope but are considered [Telemetry]
public Temperature Temperature => Temperature.FromDegreesCelsius(42.5f + ReadInt16(Register.Temperature) / 480f);
[Telemetry("Humidity")]
public bool TryReadHumidity(out RelativeHumidity humidity) => TryReadHumidityCore(out humidity);
[Telemetry("Pressure")]
public Pressure ReadPressure() { /*...*/ }
Vector3) it should have additional displayName providedTelemetry attribute with the same name on the same InterfaceProperties should be put on properties or methods which describe the device or change its functioning. They should only be used on things which don't change value between calls (unless it's been written to or a command has been executed on the device). Specifially reading (telemetry) from the device should not change the state of the property.
Usage is similar to Telemetry with some additions:
PowerMode) is used on i.e. SetPowerMode and ReadPowerMode they will be merged into a single model property[Property]
public Sampling HumiditySampling { get { /*...*/ } set { /* ... */ } }
[Property("PowerMode")]
public void SetPowerMode(Bme680PowerMode powerMode) { /*...*/ }
[Property("PowerMode")]
public Bme680PowerMode ReadPowerMode() { /*...*/ }Components represent references to other (instances) of interfaces.
They can only be put on the properties, the return type of the property or its ancestor class should have an Interface attribute.
[Component]
public SenseHatTemperatureAndHumidity TemperatureAndHumidity { get; private set; }
// ...
public class SenseHatTemperatureAndHumidity : Hts221.Hts221 { /* ... */ }
// ...
[Interface("HTS221 - Capacitive digital sensor for relative humidity and temperature")]
public class Hts221 : IDisposable { /* ... */ }Commands can be something which can be executed on the device and they can be put only on methods.
[Command]
public void PlayTone(double frequency, int duraton) { /* ... */ }
[Command]
protected override void SetDefaultConfiguration() { /* ... */ }Only simple types can be serialized: