Exemplo n.º 1
0
        public byte[] GetBytes()
        {
            ArrayList res = new ArrayList();

            res.Add((byte)((byte)BacNetEnums.BACNET_PDU_TYPE.PDU_TYPE_CONFIRMED_SERVICE_REQUEST | (1 << 1)));
            res.Add((byte)84);

            res.Add((byte)InvokeId);
            res.Add((byte)BacNetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY);

            //Object ID
            BacNetTag objectTag = new BacNetTag {
                Class = true, Length = 4, Number = 0
            };

            res.AddRange(objectTag.GetBytes());
            res.AddRange(ObjectId.GetObjectBytes());

            //Property ID
            BacNetTag propertyIdTag = new BacNetTag {
                Class = true, Length = (byte)PropertyId.GetLength(), Number = 1
            };

            res.AddRange(propertyIdTag.GetBytes());
            res.AddRange(PropertyId.GetBytes());

            if (ArrayIndex != null)
            {
                BacNetTag arrayIndexTag = new BacNetTag {
                    Class = true, Length = (byte)ArrayIndex.GetLength(), Number = 2
                };
                res.AddRange(arrayIndexTag.GetBytes());
                res.AddRange(ArrayIndex.GetBytes());
            }

            return((byte[])res.ToArray(typeof(byte)));
        }
Exemplo n.º 2
0
        public byte[] GetBytes()
        {
            ArrayList res = new ArrayList();

            res.Add((byte)BacNetEnums.BACNET_PDU_TYPE.PDU_TYPE_CONFIRMED_SERVICE_REQUEST);
            res.Add((byte)3);

            res.Add((byte)InvokeId);
            res.Add((byte)BacNetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_WRITE_PROPERTY);

            //Object ID
            BacNetTag objectTag = new BacNetTag {
                Class = true, Length = 4, Number = 0
            };

            res.AddRange(objectTag.GetBytes());
            res.AddRange(ObjectId.GetObjectBytes());

            //Property ID
            BacNetTag propertyIdTag = new BacNetTag {
                Class = true, Length = (byte)PropertyId.GetLength(), Number = 1
            };

            res.AddRange(propertyIdTag.GetBytes());
            res.AddRange(PropertyId.GetBytes());

            if (ArrayIndex != null)
            {
                BacNetTag arrayIndexTag = new BacNetTag {
                    Class = true, Length = (byte)ArrayIndex.GetLength(), Number = 2
                };
                res.AddRange(arrayIndexTag.GetBytes());
                res.AddRange(ArrayIndex.GetBytes());
            }

            //Opening Tag
            BacNetTag openingTag = new BacNetTag {
                Class = true, Length = 6, Number = 3
            };

            res.AddRange(openingTag.GetBytes());

            BacNetTag metaTag = new BacNetTag();

            foreach (var value in ValueList)
            {
                int    type;
                byte[] valueBytes = ByteConverter.GetPropertyValueBytes(value, out type);
                if (type != 0)
                {
                    metaTag = new BacNetTag {
                        Class = false, Length = (byte)valueBytes.Length, Number = (byte)type
                    };
                    res.AddRange(metaTag.GetBytes());
                }
                res.AddRange(valueBytes);
            }

            //Closing Tag
            BacNetTag closingTag = new BacNetTag {
                Class = true, Length = 7, Number = 3
            };

            res.AddRange(closingTag.GetBytes());

            BacNetTag priorityTag = new BacNetTag {
                Class = true, Number = 4, Length = 1
            };

            res.AddRange(priorityTag.GetBytes());
            res.Add((byte)0xA);


            return((byte[])res.ToArray(typeof(byte)));
        }