Exemplo n.º 1
0
        /*****************************************************************************************************/
        static void StartActivity()
        {
            // Load the device descriptor from the embedded resource file
            // Get myId as own device id
            m_storage = DeviceStorage.Load("BasicServer.DeviceDescriptor.xml");

            // Bacnet on UDP/IP/Ethernet
            bacnet_client = new BacnetClient(new BacnetIpUdpProtocolTransport(0xBAC0, false));
            // or Bacnet Mstp on COM4 à 38400 bps, own master id 8
            // m_bacnet_client = new BacnetClient(new BacnetMstpProtocolTransport("COM4", 38400, 8);
            // Or Bacnet Ethernet
            // bacnet_client = new BacnetClient(new BacnetEthernetProtocolTransport("Connexion au réseau local"));
            // Or Bacnet on IPV6
            // bacnet_client = new BacnetClient(new BacnetIpV6UdpProtocolTransport(0xBAC0));

            bacnet_client.OnWhoIs += new BacnetClient.WhoIsHandler(handler_OnWhoIs);
            bacnet_client.OnIam   += new BacnetClient.IamHandler(bacnet_client_OnIam);
            bacnet_client.OnReadPropertyRequest         += new BacnetClient.ReadPropertyRequestHandler(handler_OnReadPropertyRequest);
            bacnet_client.OnReadPropertyMultipleRequest += new BacnetClient.ReadPropertyMultipleRequestHandler(handler_OnReadPropertyMultipleRequest);
            bacnet_client.OnWritePropertyRequest        += new BacnetClient.WritePropertyRequestHandler(handler_OnWritePropertyRequest);

            bacnet_client.Start();    // go
            // Send Iam
            bacnet_client.Iam(m_storage.DeviceId, new BacnetSegmentations());
        }
Exemplo n.º 2
0
        /*****************************************************************************************************/
        static void StartActivity()
        {
            // Load the device descriptor from the external file
            m_storage = DeviceStorage.Load("DeviceDescriptor.xml");

            RaspberryGpioConfig();

            // Bacnet on UDP/IP/Ethernet
            bacnet_client = new BacnetClient(new BacnetIpUdpProtocolTransport(0xBAC0, false));

            // Bacnet Mstp using an Usb to Rs485 adapter :
            //      bacnet_client = new BacnetClient(new BacnetMstpProtocolTransport("/dev/ttyUSB0", 38400,4,10));
            // Master id 4, Max master 10, usb adapter attached on ttyUSB0
            // For MSTP, you should :
            //      1) avoid using the JIT compiler (since token passing timing will be unpredicable when accessing the first time bacnet objects)
            //      for that provide a native code in place of the CLI one using this command line :
            //           mono --aot ./RaspberrySample.exe
            //      this will create a file RaspberrySample.exe.so, let it close to the original CLI .exe code
            //      2) launch the process with a high priority :
            //          sudo nice --20 mono ./RaspberrySample.exe or LANG="en-US.UTF8" sudo nice --20 mono ./RaspberrySample.exe
            // Tested with Ftdi Usb/Rs485 adapter, Trane UC800 devices & Contemporary Control Bacnet router
            // ... sometimes Rs845 activity is lost ! So not fiable today, only for learing purpose.

            bacnet_client.OnWhoIs += new BacnetClient.WhoIsHandler(handler_OnWhoIs);
            bacnet_client.OnReadPropertyRequest         += new BacnetClient.ReadPropertyRequestHandler(handler_OnReadPropertyRequest);
            bacnet_client.OnReadPropertyMultipleRequest += new BacnetClient.ReadPropertyMultipleRequestHandler(handler_OnReadPropertyMultipleRequest);
            bacnet_client.OnWritePropertyRequest        += new BacnetClient.WritePropertyRequestHandler(handler_OnWritePropertyRequest);
            bacnet_client.OnTimeSynchronize             += new BacnetClient.TimeSynchronizeHandler(handler_OnTimeSynchronize);

            bacnet_client.Start();    // go
            // Send Iam
            bacnet_client.Iam(m_storage.DeviceId);
        }
Exemplo n.º 3
0
        // Quite all the code here came from DemoServer
        // Only COV, Write & Files operations have been commented
        // To activate BBMD services and Foreign Devices Acceptation
        // the only thinks to do is to call udp_transport.Bvlc.AddBBMDPeer(BBMD, Mask);
        // at least one time
        static BacnetActivity()
        {
            try
            {
                // resource is embedded in the project
                m_storage = DeviceStorage.Load("DemoBBMD.DeviceStorage.xml");

                m_storage.ChangeOfValue += new DeviceStorage.ChangeOfValueHandler(m_storage_ChangeOfValue);
                m_storage.ReadOverride  += new DeviceStorage.ReadOverrideHandler(m_storage_ReadOverride);

                // create udp service point
                // certainly here exclusive_port usage could be set to true
                // in order to be sure to be accepted by all the BBMD who are checking the
                // endpoint where the requests are arriving and or sending to preconfigured port
                // Needed with Wago 750-830, Contemporary Controls, Newron, ...

                // not specifying the local_endpoint_ip is a little bugy problem for broadcast when exists multiple active interfaces
                // with some chance it's Ok !

                using (var loggerFactory = LoggerFactory.Create(b =>
                {
                    b.AddConsole(c =>
                    {
                        c.TimestampFormat = "[yyyy-MM-dd HH:mm:ss] ";
                    });
                }))
                {
                    udp_transport = new BacnetIpUdpProtocolTransport(port: 0xBAC0, loggerFactory: loggerFactory, useExclusivePort: true);

                    // For IPV6, uncomment this, and comment out the previous line
                    // 187 is the device id : see DeviceStorage.xml
                    //udp_transportV6 = new BacnetIpV6UdpProtocolTransport(0xBAC0, 187, true);


                    m_ip_server = new BacnetClient(udp_transport, loggerFactory: loggerFactory);
                }

                m_ip_server.OnWhoIs += new BacnetClient.WhoIsHandler(OnWhoIs);
                m_ip_server.OnReadPropertyRequest += new BacnetClient.ReadPropertyRequestHandler(OnReadPropertyRequest);
                //m_ip_server.OnWritePropertyRequest += new BacnetClient.WritePropertyRequestHandler(OnWritePropertyRequest);
                m_ip_server.OnReadPropertyMultipleRequest += new BacnetClient.ReadPropertyMultipleRequestHandler(OnReadPropertyMultipleRequest);
                //m_ip_server.OnWritePropertyMultipleRequest += new BacnetClient.WritePropertyMultipleRequestHandler(OnWritePropertyMultipleRequest);
                //m_ip_server.OnAtomicWriteFileRequest += new BacnetClient.AtomicWriteFileRequestHandler(OnAtomicWriteFileRequest);
                //m_ip_server.OnAtomicReadFileRequest += new BacnetClient.AtomicReadFileRequestHandler(OnAtomicReadFileRequest);
                //m_ip_server.OnSubscribeCOV += new BacnetClient.SubscribeCOVRequestHandler(OnSubscribeCOV);
                //m_ip_server.OnSubscribeCOVProperty += new BacnetClient.SubscribeCOVPropertyRequestHandler(OnSubscribeCOVProperty);
                m_ip_server.OnTimeSynchronize            += new BacnetClient.TimeSynchronizeHandler(OnTimeSynchronize);
                m_ip_server.OnDeviceCommunicationControl += new BacnetClient.DeviceCommunicationControlRequestHandler(OnDeviceCommunicationControl);
                m_ip_server.OnReinitializedDevice        += new BacnetClient.ReinitializedRequestHandler(OnReinitializedDevice);
                m_ip_server.Start();

                //send greeting
                m_ip_server.Iam(m_storage.DeviceId, m_supported_segmentation);
            }
            catch
            {
                OpenError = true;
            }
        }
Exemplo n.º 4
0
        static BacnetActivity()
        {
            try
            {
                //init

                PhysicalAddress macAddr =
                    (
                        from netiface in NetworkInterface.GetAllNetworkInterfaces()
                        where ((netiface.OperationalStatus == OperationalStatus.Up) && ((netiface.NetworkInterfaceType == NetworkInterfaceType.Ethernet) || (netiface.NetworkInterfaceType == NetworkInterfaceType.Wireless80211)))
                        select netiface.GetPhysicalAddress()
                    ).FirstOrDefault();

                if (macAddr != null)
                {
                    byte[] mac = macAddr.GetAddressBytes();
                    DeviceId = ((uint)mac[5] + (uint)((mac[4] << 8) & 0x3F)) << 6;
                }

                if (App.Current.CurrentCulture == "fr")
                {
                    Storage = DeviceStorage.Load("RoomSimulator.DeviceStorage.xml", DeviceId);
                }
                else
                {
                    Storage = DeviceStorage.Load("RoomSimulator.DeviceStorageUs.xml", DeviceId);
                }

                Storage.ChangeOfValue += new DeviceStorage.ChangeOfValueHandler(m_storage_ChangeOfValue);
                Storage.ReadOverride  += new DeviceStorage.ReadOverrideHandler(m_storage_ReadOverride);

                //create udp service point
                var udp_transport = new BacnetIpUdpProtocolTransport(0xBAC0, false);       //set to true to force "single socket" usage
                udp_transport.Log = new DebugLogger();
                m_ip_server       = new BacnetClient(udp_transport);
                m_ip_server.Log   = new DebugLogger();

                m_ip_server.OnWhoIs += new BacnetClient.WhoIsHandler(OnWhoIs);
                m_ip_server.OnReadPropertyRequest         += new BacnetClient.ReadPropertyRequestHandler(OnReadPropertyRequest);
                m_ip_server.OnWritePropertyRequest        += new BacnetClient.WritePropertyRequestHandler(OnWritePropertyRequest);
                m_ip_server.OnReadPropertyMultipleRequest += new BacnetClient.ReadPropertyMultipleRequestHandler(OnReadPropertyMultipleRequest);
                m_ip_server.OnSubscribeCOV               += new BacnetClient.SubscribeCOVRequestHandler(OnSubscribeCOV);
                m_ip_server.OnSubscribeCOVProperty       += new BacnetClient.SubscribeCOVPropertyRequestHandler(OnSubscribeCOVProperty);
                m_ip_server.OnTimeSynchronize            += new BacnetClient.TimeSynchronizeHandler(OnTimeSynchronize);
                m_ip_server.OnDeviceCommunicationControl += new BacnetClient.DeviceCommunicationControlRequestHandler(OnDeviceCommunicationControl);
                m_ip_server.OnReinitializedDevice        += new BacnetClient.ReinitializedRequestHandler(OnReinitializedDevice);
                m_ip_server.Start();

                //send greeting
                m_ip_server.Iam(Storage.DeviceId, m_supported_segmentation);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        static BacnetActivity()
        {
            try
            {
                //init

                PhysicalAddress macAddr =
                    (
                        from netiface in NetworkInterface.GetAllNetworkInterfaces()
                        where ((netiface.OperationalStatus == OperationalStatus.Up) && ((netiface.NetworkInterfaceType == NetworkInterfaceType.Ethernet) || (netiface.NetworkInterfaceType == NetworkInterfaceType.Wireless80211)))
                        select netiface.GetPhysicalAddress()
                    ).FirstOrDefault();

                if (macAddr != null)
                {
                    byte[] mac = macAddr.GetAddressBytes();
                    deviceId = (uint)mac[5] + (uint)((mac[4] << 8) << 6);
                }
                // Un bricollage du dimanche vite fait ici !
                deviceId = deviceId + ((uint)(Program.Count & 0x3F));

                if (Application.CurrentCulture.TwoLetterISOLanguageName == "fr")
                {
                    m_storage = DeviceStorage.Load("Bacnet.Room.Simulator.DeviceStorage.xml", deviceId);
                }
                else
                {
                    m_storage = DeviceStorage.Load("Bacnet.Room.Simulator.DeviceStorageUs.xml", deviceId);
                }

                m_storage.ChangeOfValue += new DeviceStorage.ChangeOfValueHandler(m_storage_ChangeOfValue);
                m_storage.ReadOverride  += new DeviceStorage.ReadOverrideHandler(m_storage_ReadOverride);

                //create udp service point
                BacnetIpUdpProtocolTransport udp_transport = new BacnetIpUdpProtocolTransport(0xBAC0, false);       //set to true to force "single socket" usage
                m_ip_server = new BacnetClient(udp_transport);

                m_ip_server.OnWhoIs += new BacnetClient.WhoIsHandler(OnWhoIs);
                m_ip_server.OnReadPropertyRequest         += new BacnetClient.ReadPropertyRequestHandler(OnReadPropertyRequest);
                m_ip_server.OnWritePropertyRequest        += new BacnetClient.WritePropertyRequestHandler(OnWritePropertyRequest);
                m_ip_server.OnReadPropertyMultipleRequest += new BacnetClient.ReadPropertyMultipleRequestHandler(OnReadPropertyMultipleRequest);
                m_ip_server.OnSubscribeCOV               += new BacnetClient.SubscribeCOVRequestHandler(OnSubscribeCOV);
                m_ip_server.OnSubscribeCOVProperty       += new BacnetClient.SubscribeCOVPropertyRequestHandler(OnSubscribeCOVProperty);
                m_ip_server.OnTimeSynchronize            += new BacnetClient.TimeSynchronizeHandler(OnTimeSynchronize);
                m_ip_server.OnDeviceCommunicationControl += new BacnetClient.DeviceCommunicationControlRequestHandler(OnDeviceCommunicationControl);
                m_ip_server.OnReinitializedDevice        += new BacnetClient.ReinitializedRequestHandler(OnReinitializedDevice);
                m_ip_server.Start();

                //send greeting
                m_ip_server.Iam(m_storage.DeviceId, m_supported_segmentation);
            }
            catch
            {
            }
        }
Exemplo n.º 6
0
 /*****************************************************************************************************/
 static void handler_OnWhoIs(BacnetClient sender, BacnetAddress adr, int low_limit, int high_limit)
 {
     if (low_limit != -1 && m_storage.DeviceId < low_limit)
     {
         return;
     }
     else if (high_limit != -1 && m_storage.DeviceId > high_limit)
     {
         return;
     }
     sender.Iam(m_storage.DeviceId, new BacnetSegmentations());
 }
Exemplo n.º 7
0
 /*****************************************************************************************************/
 static void handler_OnWhoIs(BacnetClient sender, BacnetAddress adr, int low_limit, int high_limit)
 {
     if (low_limit != -1 && myId < low_limit)
     {
         return;
     }
     else if (high_limit != -1 && myId > high_limit)
     {
         return;
     }
     sender.Iam(myId, BacnetSegmentations.SEGMENTATION_BOTH, 61440);
 }
Exemplo n.º 8
0
        /// <summary>
        /// 启动服务
        /// </summary>
        public void Start()
        {
            try
            {
                //init

                PhysicalAddress macAddr =
                    (
                        from netiface in NetworkInterface.GetAllNetworkInterfaces()
                        where ((netiface.OperationalStatus == OperationalStatus.Up) && ((netiface.NetworkInterfaceType == NetworkInterfaceType.Ethernet) || (netiface.NetworkInterfaceType == NetworkInterfaceType.Wireless80211)))
                        select netiface.GetPhysicalAddress()
                    ).FirstOrDefault();

                if (macAddr != null)
                {
                    byte[] mac = macAddr.GetAddressBytes();
                    deviceId = ((uint)mac[5] + (uint)((mac[4] << 8) & 0x3F)) << 6;
                }
                // Un bricollage du dimanche vite fait ici !
                deviceId = deviceId + increaseId++;

                m_storage = DeviceStorage.Load("IoTServer.DeviceStorage.xml", deviceId);

                var str = JsonConvert.SerializeObject(m_storage);

                m_storage.ChangeOfValue += new DeviceStorage.ChangeOfValueHandler(m_storage_ChangeOfValue);
                m_storage.ReadOverride  += new DeviceStorage.ReadOverrideHandler(m_storage_ReadOverride);

                //create udp service point
                BacnetIpUdpProtocolTransport udp_transport = new BacnetIpUdpProtocolTransport(47808, false);       //set to true to force "single socket" usage
                m_ip_server = new BacnetClient(udp_transport);

                m_ip_server.OnWhoIs += new BacnetClient.WhoIsHandler(OnWhoIs);
                m_ip_server.OnReadPropertyRequest         += new BacnetClient.ReadPropertyRequestHandler(OnReadPropertyRequest);
                m_ip_server.OnWritePropertyRequest        += new BacnetClient.WritePropertyRequestHandler(OnWritePropertyRequest);
                m_ip_server.OnReadPropertyMultipleRequest += new BacnetClient.ReadPropertyMultipleRequestHandler(OnReadPropertyMultipleRequest);
                m_ip_server.OnSubscribeCOV               += new BacnetClient.SubscribeCOVRequestHandler(OnSubscribeCOV);
                m_ip_server.OnSubscribeCOVProperty       += new BacnetClient.SubscribeCOVPropertyRequestHandler(OnSubscribeCOVProperty);
                m_ip_server.OnTimeSynchronize            += new BacnetClient.TimeSynchronizeHandler(OnTimeSynchronize);
                m_ip_server.OnDeviceCommunicationControl += new BacnetClient.DeviceCommunicationControlRequestHandler(OnDeviceCommunicationControl);
                m_ip_server.OnReinitializedDevice        += new BacnetClient.ReinitializedRequestHandler(OnReinitializedDevice);
                m_ip_server.Start();

                //send greeting
                m_ip_server.Iam(m_storage.DeviceId, m_supported_segmentation);
            }
            catch (Exception e)
            {
            }
        }
Exemplo n.º 9
0
        public void OnWhoIs(BacnetClient sender, BacnetAddress adr, int low_limit, int high_limit)
        {
            //Don't really get what this is doing...not sure this is device instance like we need to filter on
            uint myId = (uint)Yabe.Properties.Settings.Default.YabeDeviceId;    //is this reliable?  Can this be changed from multiple places?

            if (low_limit != -1 && myId < low_limit)
            {
                return;
            }
            else if (high_limit != -1 && myId > high_limit)
            {
                return;
            }
            sender.Iam(myId, BacnetSegmentations.SEGMENTATION_BOTH, 61440);
        }
Exemplo n.º 10
0
        public static void StartActivity(DeviceObject _device)
        {
            deviceId = _device.PROP_OBJECT_IDENTIFIER.Instance;
            device   = _device;

            using (var loggerFactory = LoggerFactory.Create(b =>
            {
                b.AddConsole(c =>
                {
                    c.TimestampFormat = "[yyyy-MM-dd HH:mm:ss] ";
                });
            }))
            {
                // Bacnet on UDP/IP/Ethernet
                bacnet_client = new BacnetClient(new BacnetIpUdpProtocolTransport(0xBAC0, loggerFactory: loggerFactory), loggerFactory: loggerFactory);
            }

            bacnet_client.OnIam += new BacnetClient.IamHandler(handler_OnIam);
            bacnet_client.OnReadPropertyRequest         += new BacnetClient.ReadPropertyRequestHandler(handler_OnReadPropertyRequest);
            bacnet_client.OnReadPropertyMultipleRequest += new BacnetClient.ReadPropertyMultipleRequestHandler(handler_OnReadPropertyMultipleRequest);
            bacnet_client.OnWritePropertyRequest        += new BacnetClient.WritePropertyRequestHandler(handler_OnWritePropertyRequest);
            bacnet_client.OnSubscribeCOV           += new BacnetClient.SubscribeCOVRequestHandler(handler_OnSubscribeCOV);
            bacnet_client.OnSubscribeCOVProperty   += new BacnetClient.SubscribeCOVPropertyRequestHandler(handler_OnSubscribeCOVProperty);
            bacnet_client.OnReadRange              += new BacnetClient.ReadRangeHandler(handler_OnReadRange);
            bacnet_client.OnAtomicWriteFileRequest += new BacnetClient.AtomicWriteFileRequestHandler(handler_OnAtomicWriteFileRequest);
            bacnet_client.OnAtomicReadFileRequest  += new BacnetClient.AtomicReadFileRequestHandler(handler_OnAtomicReadFileRequest);
            // A sample to shows CreateObject & DeleteObject
            bacnet_client.OnCreateObjectRequest      += new BacnetClient.CreateObjectRequestHandler(handler_OnCreateObjectRequest);
            device.m_PROP_PROTOCOL_SERVICES_SUPPORTED = device.m_PROP_PROTOCOL_SERVICES_SUPPORTED.SetBit((byte)BacnetServicesSupported.SERVICE_SUPPORTED_CREATE_OBJECT, true);
            bacnet_client.OnDeleteObjectRequest      += new BacnetClient.DeleteObjectRequestHandler(handler_OnDeleteObjectRequest);
            device.m_PROP_PROTOCOL_SERVICES_SUPPORTED = device.m_PROP_PROTOCOL_SERVICES_SUPPORTED.SetBit((byte)BacnetServicesSupported.SERVICE_SUPPORTED_DELETE_OBJECT, true);

            BaCSharpObject.OnExternalCOVNotify += new BaCSharpObject.WriteNotificationCallbackHandler(handler_OnCOVManagementNotify);

            bacnet_client.Start();    // go
            // Send Iam
            bacnet_client.Iam(deviceId, new BacnetSegmentations());
            bacnet_client.OnWhoIs += new BacnetClient.WhoIsHandler(handler_OnWhoIs);

            if ((_device.FindBacnetObjectType(BacnetObjectTypes.OBJECT_NOTIFICATION_CLASS)) || (_device.FindBacnetObjectType(BacnetObjectTypes.OBJECT_SCHEDULE)))
            {
                bacnet_client.WhoIs();                          // Send WhoIs : needed BY Notification & Schedule for deviceId<->IP endpoint
                device.SetIpEndpoint(bacnet_client);            // Register the endpoint for IP Notification usage with IP:Port
            }
        }
Exemplo n.º 11
0
 private static void OnWhoIs(BacnetClient sender, BacnetAddress adr, int low_limit, int high_limit)
 {
     lock (m_lockObject)
     {
         if (low_limit != -1 && m_storage.DeviceId < low_limit)
         {
             return;
         }
         else if (high_limit != -1 && m_storage.DeviceId > high_limit)
         {
             return;
         }
         else
         {
             sender.Iam(m_storage.DeviceId, m_supported_segmentation);
         }
     }
 }
Exemplo n.º 12
0
        public void StartActivity(DeviceObject _device)
        {
            deviceId = _device.PROP_OBJECT_IDENTIFIER.instance;
            device   = _device;

            // Bacnet on UDP/IP/Ethernet
            bacnet_client = new BacnetClient(new BacnetIpUdpProtocolTransport(0xBAC0, false));

            bacnet_client.OnIam += new BacnetClient.IamHandler(handler_OnIam);
            bacnet_client.OnReadPropertyRequest         += new BacnetClient.ReadPropertyRequestHandler(handler_OnReadPropertyRequest);
            bacnet_client.OnReadPropertyMultipleRequest += new BacnetClient.ReadPropertyMultipleRequestHandler(handler_OnReadPropertyMultipleRequest);
            bacnet_client.OnWritePropertyRequest        += new BacnetClient.WritePropertyRequestHandler(handler_OnWritePropertyRequest);
            bacnet_client.OnSubscribeCOV         += new BacnetClient.SubscribeCOVRequestHandler(handler_OnSubscribeCOV);
            bacnet_client.OnSubscribeCOVProperty += new BacnetClient.SubscribeCOVPropertyRequestHandler(handler_OnSubscribeCOVProperty);
            bacnet_client.OnReadRange            += new BacnetClient.ReadRangeHandler(handler_OnReadRange);
            // A sample to shows CreateObject & DeleteObject
            bacnet_client.OnCreateObjectRequest += new BacnetClient.CreateObjectRequestHandler(handler_OnCreateObjectRequest);
            device.m_PROP_PROTOCOL_SERVICES_SUPPORTED.SetBit((byte)BacnetServicesSupported.SERVICE_SUPPORTED_CREATE_OBJECT, true);
            bacnet_client.OnDeleteObjectRequest += new BacnetClient.DeleteObjectRequestHandler(handler_OnDeleteObjectRequest);
            device.m_PROP_PROTOCOL_SERVICES_SUPPORTED.SetBit((byte)BacnetServicesSupported.SERVICE_SUPPORTED_DELETE_OBJECT, true);

            BaCSharpObject.OnExternalCOVNotify += new BaCSharpObject.WriteNotificationCallbackHandler(handler_OnCOVManagementNotify);

            try
            {
                bacnet_client.Start();    // go
                // Send Iam
                bacnet_client.Iam(deviceId, BacnetSegmentations.SEGMENTATION_BOTH, 61440);
                bacnet_client.OnWhoIs += new BacnetClient.WhoIsHandler(handler_OnWhoIs);

                if ((_device.FindBacnetObjectType(BacnetObjectTypes.OBJECT_NOTIFICATION_CLASS)) || (_device.FindBacnetObjectType(BacnetObjectTypes.OBJECT_SCHEDULE)))
                {
                    bacnet_client.WhoIs();                          // Send WhoIs : needed BY Notification & Schedule for deviceId<->IP endpoint
                    device.SetIpEndpoint(bacnet_client);            // Register the endpoint for IP Notification usage with IP:Port
                }
            }
            catch
            {
                if (Environment.UserInteractive)
                {
                    Console.WriteLine("\nSocket Error, Udp Port already in used in exclusive mode ?");
                }
            }
        }
        private static void StartActivity()
        {
            m_storage = DeviceStorage.Load("Ths_BTLServer.DeviceDescriptor.xml", null);
            m_storage.ChangeOfValue                     += new DeviceStorage.ChangeOfValueHandler(Program.m_storage_ChangeOfValue);
            m_subscriptions                              = new Dictionary <BacnetObjectId, List <Subscription> >();
            bacnet_client                                = new BacnetClient(new BacnetIpUdpProtocolTransport(0xBAC0, false));
            bacnet_client.OnWhoIs                       += new BacnetClient.WhoIsHandler(Program.handler_OnWhoIs);
            bacnet_client.OnIam                         += new BacnetClient.IamHandler(bacnet_client_OnIam);
            bacnet_client.OnWhoHas                      += new BacnetClient.WhoHasHandler(Program.bacnet_client_OnWhoHas);
            bacnet_client.OnReadPropertyRequest         += new BacnetClient.ReadPropertyRequestHandler(Program.handler_OnReadPropertyRequest);
            bacnet_client.OnReadPropertyMultipleRequest += new BacnetClient.ReadPropertyMultipleRequestHandler(Program.handler_OnReadPropertyMultipleRequest);
            bacnet_client.OnWritePropertyRequest        += new BacnetClient.WritePropertyRequestHandler(Program.handler_OnWritePropertyRequest);
            bacnet_client.OnSubscribeCOV                += new BacnetClient.SubscribeCOVRequestHandler(Program.bacnet_client_OnSubscribeCOV);
            bacnet_client.OnSubscribeCOVProperty        += new BacnetClient.SubscribeCOVPropertyRequestHandler(Program.bacnet_client_OnSubscribeCOVProperty);
            bacnet_client.Retries                        = 10;
            bacnet_client.Start();
            uint deviceId = m_storage.DeviceId;

            bacnet_client.WhoIs(-1, -1, null);
            bacnet_client.Iam(m_storage.DeviceId, BacnetSegmentations.SEGMENTATION_BOTH);
        }
        /// <summary>
        /// handler to assign alarm enrolment instance on event notification
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="adr"></param>
        /// <param name="low_limit"></param>
        /// <param name="high_limit"></param>
        static void handler_OnWhoIs(BacnetClient sender, BacnetAddress adr, int low_limit, int high_limit)
        {
            if (low_limit != -1 && 1 < low_limit)
            {
                return;
            }
            else if (high_limit != -1 && 1 > high_limit)
            {
                return;
            }

            using (var loESDLutronEntities = new ESDLutronEntities())
            {
                Int32?liAlarmEnrolment = loESDLutronEntities.BACnetDevices
                                         .Where(x => x.device_id == 1 &&
                                                x.object_type.ToUpper() == LutronFloorObjectType.ALERT_ENROLLMENT)
                                         .Select(x => x.object_instance).FirstOrDefault();

                if (liAlarmEnrolment != null)
                {
                    sender.Iam((uint)liAlarmEnrolment, new BacnetSegmentations());
                }
            }
        }