Exemplo n.º 1
0
        static async void bacnet_client_OnIam(BacnetClient sender, BacnetAddress adr, uint device_id, uint max_apdu, BacnetSegmentations segmentation, ushort vendor_id)
        {
            if (device_id != 12345)
            {
                bacnet_client.Log.AddCustomEvent(LagoVista.Core.PlatformSupport.LogLevel.Message, "Program", $"Device Id {device_id} connected");

                var deviceObjId  = new BacnetObjectId(BacnetObjectTypes.OBJECT_DEVICE, device_id);
                var objectIdList = await sender.ReadPropertyAsync(adr, deviceObjId, BacnetPropertyIds.PROP_OBJECT_LIST);

                foreach (var objId in objectIdList)
                {
                    Console.WriteLine($"\t\t{objId}");

                    LinkedList <BacnetObjectId> object_list = new LinkedList <BacnetObjectId>();

                    if (Enum.IsDefined(typeof(BacnetObjectTypes), ((BacnetObjectId)objId.Value).Type))
                    {
                        var val = (BacnetObjectId)objId.Value;
                        object_list.AddLast(val);
                    }

                    foreach (var objectId in object_list)
                    {
                        var props = new List <BacnetPropertyIds>();

                        if (objectId.type == BacnetObjectTypes.OBJECT_DEVICE)
                        {
                            props.Add(BacnetPropertyIds.PROP_DESCRIPTION);
                            props.Add(BacnetPropertyIds.PROP_SERIAL_NUMBER);
                            props.Add(BacnetPropertyIds.PROP_MODEL_NAME);
                            props.Add(BacnetPropertyIds.PROP_APPLICATION_SOFTWARE_VERSION);
                            props.Add(BacnetPropertyIds.PROP_OUT_OF_SERVICE);
                            props.Add(BacnetPropertyIds.PROP_LOCATION);
                            props.Add(BacnetPropertyIds.PROP_OBJECT_NAME);
                            props.Add(BacnetPropertyIds.PROP_OBJECT_IDENTIFIER);
                        }
                        else
                        {
                            props.Add(BacnetPropertyIds.PROP_PRESENT_VALUE);
                            props.Add(BacnetPropertyIds.PROP_NUMBER_OF_STATES);
                            props.Add(BacnetPropertyIds.PROP_OUT_OF_SERVICE);
                            props.Add(BacnetPropertyIds.PROP_STATE_TEXT);
                            props.Add(BacnetPropertyIds.PROP_RELIABILITY);
                            props.Add(BacnetPropertyIds.PROP_DESCRIPTION);
                            props.Add(BacnetPropertyIds.PROP_UNITS);
                        }

                        var results = await sender.ReadPropertyMultipleAsync(adr, objectId, props.ToArray());

                        var description = results.Where(prop => prop.property.GetPropertyId() == BacnetPropertyIds.PROP_DESCRIPTION).FirstOrDefault();
                        Console.WriteLine($"\t\t\tProperty {description.value[0]}:");


                        foreach (var child in results)
                        {
                            if (child.property.GetPropertyId() != BacnetPropertyIds.PROP_DESCRIPTION)
                            {
                                foreach (var value in child.value)
                                {
                                    if (value.Tag != BacnetApplicationTags.BACNET_APPLICATION_TAG_ERROR)
                                    {
                                        if (child.property.GetPropertyId() == BacnetPropertyIds.PROP_UNITS)
                                        {
                                            var unitInt = int.Parse(value.Value.ToString());
                                            var unit    = (BacnetUnitsId)unitInt;
                                            Console.WriteLine($"\t\t\t\t{child.property.GetPropertyId()}:  {unit}");
                                        }
                                        else
                                        {
                                            Console.WriteLine($"\t\t\t\t{child.property.GetPropertyId()}:  {value.Value}");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            //ignore Iams from other devices. (Also loopbacks)
        }