コード例 #1
0
ファイル: SensorRead.cs プロジェクト: vinmenn/HBus.DotNet
        public SensorRead(byte[] array)
        {
            var stack = new SimpleStack(array);

            Name = stack.PopName();
            Time = stack.PopUInt32();
            Value = stack.PopSingle();
        }
コード例 #2
0
ファイル: NodeStatusInfo.cs プロジェクト: vinmenn/HBus.DotNet
        public NodeStatusInfo(byte[] data)
        {
            var stack = new SimpleStack(data);
            //Bit Mask:
            //----------
            //00: Inputs
            //01: Outputs
            //02: Analogs
            //04: Counters
            //08: Pwms
            //16: Devices
            //32: Sensors
            Mask = stack.PopByte();

            //Node global status
            Time = stack.PopUInt32();

            NodeStatus = (NodeStatusValues)stack.PopByte();
            BusStatus = (BusStatus)stack.PopByte();

            LastError = (NodeErrorCodes)stack.PopByte();
            TotalErrors = stack.PopUInt32();
            
            var size = stack.PopByte(); Inputs = size > 0 ? new byte[size] : null;
            size = stack.PopByte(); Outputs = size > 0 ? new byte[size] : null;
            size = stack.PopByte(); Analogs = size > 0 ? new ushort[size] : null;
            size = stack.PopByte(); Counters = size > 0 ? new uint[size] : null;
            size = stack.PopByte(); Pwms = size > 0 ? new ushort[size] : null;
            size = stack.PopByte(); Devices = size > 0 ? new string[size] : null;
            size = stack.PopByte(); Sensors = size > 0 ? new float[size] : null;

            LastActivatedInput = stack.PopName();
            LastActivatedOutput = stack.PopName();

            //Inputs
            if ((Mask & 0x01) != 0 && Inputs!=null)
                for (var i = 0; i < Inputs.Length; i++)
                    Inputs[i] = stack.PopByte();
            //Outputs
            if ((Mask & 0x02) != 0 && Outputs != null)
                for (var i = 0; i < Outputs.Length; i++)
                    Outputs[i] = stack.PopByte();
            //Analogs
            if ((Mask & 0x04) != 0 && Analogs != null)
                for (var i = 0; i < Analogs.Length; i++)
                    Analogs[i] = stack.PopUInt16();
            //Counters
            if ((Mask & 0x08) != 0 && Counters != null)
                for (var i = 0; i < Counters.Length; i++)
                    Counters[i] = stack.PopUInt32();
            //Pwms
            if ((Mask & 0x10) != 0 && Pwms != null)
                for (var i = 0; i < Pwms.Length; i++)
                    Pwms[i] = stack.PopUInt16();
            //Devices
            if ((Mask & 0x20) != 0 && Devices!= null)
                for (var i = 0; i < Devices.Length; i++)
                    //Get status string
                    Devices[i] = stack.PopString();
            //Sensors
            if ((Mask & 0x40) != 0 && Sensors != null)
                for (var i = 0; i < Sensors.Length; i++)
                    //Get last sensor read
                    Sensors[i] = stack.PopSingle();
        }