コード例 #1
0
ファイル: ModbusSensorDevice.cs プロジェクト: alljoyn/dsb
        internal ModbusSensorProperty(ModbusSensorProperty Other)
        {
            this.m_device      = Other.m_device;
            this.Name          = Other.Name;
            this.InterfaceHint = Other.InterfaceHint;

            try
            {
                this.Attributes = new List <IAdapterAttribute>(Other.Attributes);
            }
            catch (OutOfMemoryException ex)
            {
                throw;
            }
        }
コード例 #2
0
ファイル: ModbusSensorDevice.cs プロジェクト: alljoyn/dsb
        internal uint Initialize()
        {
            // Sensor property.
            ModbusSensorProperty sensorProperty = new ModbusSensorProperty(this, "T/H/CO2 Sensor", "");

            // Current Temperature Reading attribute.
            ModbusSensorAttribute tempAttr = new ModbusSensorAttribute(
                this,
                "Temperature",
                Windows.Foundation.PropertyValue.CreateDouble(0),
                E_ACCESS_TYPE.ACCESS_READ
                );

            tempAttr.COVBehavior = SignalBehavior.Always;
            sensorProperty.Attributes.Add(tempAttr);

            // Temperature Adjustment attribute.
            ModbusSensorAttribute tempAdjAttr = new ModbusSensorAttribute(
                this,
                "Temperature Adjustment",
                Windows.Foundation.PropertyValue.CreateDouble(0),
                E_ACCESS_TYPE.ACCESS_READ
                );

            tempAdjAttr.COVBehavior = SignalBehavior.Always;
            sensorProperty.Attributes.Add(tempAdjAttr);

            //Set Temperature Adjustment method.
            ModbusSensorMethod tempAdjCommand = new ModbusSensorMethod(
                this,
                "setTempAdj",
                "Sets the value of Temperature Adjustment to adjust the temperature reading. The input value must be between -20.0 to +20.0.",
                "Temperature Adjustment",
                0);
            var tempAdjParam = new AdapterValue("value", Windows.Foundation.PropertyValue.CreateDouble(0));

            tempAdjCommand.InputParams.Add(tempAdjParam);
            this.Methods.Add(tempAdjCommand);

            // Currernt Humidity Reading attribute.
            ModbusSensorAttribute humidAttr = new ModbusSensorAttribute(
                this,
                "Humidity",
                Windows.Foundation.PropertyValue.CreateDouble(0),
                E_ACCESS_TYPE.ACCESS_READ
                );

            humidAttr.COVBehavior = SignalBehavior.Always;
            sensorProperty.Attributes.Add(humidAttr);

            // Humidity Adjustment attribute.
            ModbusSensorAttribute humidAdjAttr = new ModbusSensorAttribute(
                this,
                "Humidity Adjustment",
                Windows.Foundation.PropertyValue.CreateDouble(0),
                E_ACCESS_TYPE.ACCESS_READ
                );

            humidAdjAttr.COVBehavior = SignalBehavior.Always;
            sensorProperty.Attributes.Add(humidAdjAttr);

            //Set Humidity Adjustment method.
            ModbusSensorMethod humidAdjCommand = new ModbusSensorMethod(
                this,
                "setHumidAdj",
                "Sets the value of Humidity Adjustment to adjust the humidity reading. The input value must be between -20.0 to +20.0.",
                "Humidity Adjustment",
                0);
            var humidAdjParam = new AdapterValue("value", Windows.Foundation.PropertyValue.CreateDouble(0));

            humidAdjCommand.InputParams.Add(humidAdjParam);
            this.Methods.Add(humidAdjCommand);

            // Temperature/Humidity Reading Interval attribute.
            ModbusSensorAttribute THIntervalAttr = new ModbusSensorAttribute(
                this,
                "T/H Reading Interval",
                Windows.Foundation.PropertyValue.CreateUInt16(1),
                E_ACCESS_TYPE.ACCESS_READ
                );

            THIntervalAttr.COVBehavior = SignalBehavior.Always;
            sensorProperty.Attributes.Add(THIntervalAttr);

            //Set Temperature/Humidity Reading Interval method.
            ModbusSensorMethod THIntervalCommand = new ModbusSensorMethod(
                this,
                "setTHInterval",
                "Sets the value of temperature and humidity reading interval. The input value must be between 1 to 10.",
                "T/H Reading Interval",
                0);
            var THIntervalParam = new AdapterValue("value", Windows.Foundation.PropertyValue.CreateUInt16(1));

            THIntervalCommand.InputParams.Add(THIntervalParam);
            this.Methods.Add(THIntervalCommand);


            // Current CO2 Concentration attribute.
            ModbusSensorAttribute CO2Attr = new ModbusSensorAttribute(
                this,
                "CO2 Concentration",
                Windows.Foundation.PropertyValue.CreateUInt16(0),
                E_ACCESS_TYPE.ACCESS_READ
                );

            CO2Attr.COVBehavior = SignalBehavior.Always;
            sensorProperty.Attributes.Add(CO2Attr);

            // CO2 Adjustment attribute.
            ModbusSensorAttribute CO2AdjAttr = new ModbusSensorAttribute(
                this,
                "CO2 Adjustment",
                Windows.Foundation.PropertyValue.CreateInt16(0),
                E_ACCESS_TYPE.ACCESS_READ
                );

            CO2AdjAttr.COVBehavior = SignalBehavior.Always;
            sensorProperty.Attributes.Add(CO2AdjAttr);

            //Set CO2 Concentration Adjustment method.
            ModbusSensorMethod CO2AdjCommand = new ModbusSensorMethod(
                this,
                "setCO2Adj",
                "Sets the value of CO2 concentration Adjustment to adjust the CO2 concentration reading. The input value must be between -1500 to +1500",
                "CO2 Adjustment",
                0);
            var CO2AdjParam = new AdapterValue("value", Windows.Foundation.PropertyValue.CreateInt16(0));

            CO2AdjCommand.InputParams.Add(CO2AdjParam);
            this.Methods.Add(CO2AdjCommand);

            // CO2 Reading Interval attribute.
            ModbusSensorAttribute CO2IntervalAttr = new ModbusSensorAttribute(
                this,
                "CO2 Reading Interval",
                Windows.Foundation.PropertyValue.CreateUInt16(1),
                E_ACCESS_TYPE.ACCESS_READ
                );

            CO2IntervalAttr.COVBehavior = SignalBehavior.Always;
            sensorProperty.Attributes.Add(CO2IntervalAttr);

            //Set CO2 Reading Interval method.
            ModbusSensorMethod CO2IntervalCommand = new ModbusSensorMethod(
                this,
                "setCO2Interval",
                "Sets the value of temperature and humidity reading interval. The input value must be between 1 to 10.",
                "CO2 Reading Interval",
                0);
            var CO2IntervalParam = new AdapterValue("value", Windows.Foundation.PropertyValue.CreateUInt16(1));

            CO2IntervalCommand.InputParams.Add(CO2IntervalParam);
            this.Methods.Add(CO2IntervalCommand);


            // Create Change of Value Signal for the Temperature Attribute
            AdapterSignal covSignal      = new AdapterSignal(Constants.CHANGE_OF_VALUE_SIGNAL);
            AdapterValue  propertyHandle = new AdapterValue(Constants.COV__PROPERTY_HANDLE, sensorProperty);
            AdapterValue  attrHandle     = new AdapterValue(Constants.COV__ATTRIBUTE_HANDLE, tempAttr.Value);

            covSignal.Params.Add(propertyHandle);
            covSignal.Params.Add(attrHandle);


            this.Signals.Add(covSignal);
            this.Properties.Add(sensorProperty);

            return(ERROR_SUCCESS);
        }