Пример #1
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);
        }
Пример #2
0
        /*****************************************************************************************************/
        static void StartActivity()
        {
            // Bacnet on UDP/IP/Ethernet
            // to bind to a specific network interface such as 100.75.35.6
            // bacnet_client = new BacnetClient(new BacnetIpUdpProtocolTransport(0xBAC0, false, false, 1472, "100.75.35.6"));
            // otherwise the default interface is open ... sometimes OK, sometimes not !
            bacnet_client = new BacnetClient(new BacnetIpUdpProtocolTransport(0xBAC0, false));

            // Or Bacnet Ethernet
            // bacnet_client = new BacnetClient(new BacnetEthernetProtocolTransport("Connexion au réseau local"));
            // Or Bacnet on IPV6, default interface
            // bacnet_client = new BacnetClient(new BacnetIpV6UdpProtocolTransport(0xBAC0));

            // If BacnetTransportSerial.cs is added to this project one can use for instance :
            // Bacnet Mstp on COM4 à 38400 bps, own master id 8
            // m_bacnet_client = new BacnetClient(new BacnetMstpProtocolTransport("COM4", 38400, 8);

            bacnet_client.Start();    // go

            // Send WhoIs in order to get back all the Iam responses :
            bacnet_client.OnIam += new BacnetClient.IamHandler(handler_OnIam);

            bacnet_client.WhoIs();

            /* Optional Remote Registration as A Foreign Device on a BBMD at @192.168.1.1 on the default 0xBAC0 port
             *
             * bacnet_client.RegisterAsForeignDevice("192.168.1.1", 60);
             * Thread.Sleep(20);
             * bacnet_client.RemoteWhoIs("192.168.1.1");
             */
        }
Пример #3
0
        /*****************************************************************************************************/
        static void StartActivity()
        {
            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(port: 0xBAC0, loggerFactory: loggerFactory, useExclusivePort: false), loggerFactory: loggerFactory);
            }
            // 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.Start();    // go

            // Send WhoIs in order to get back all the Iam responses :
            bacnet_client.OnIam += new BacnetClient.IamHandler(handler_OnIam);

            bacnet_client.WhoIs();

            /* Optional Remote Registration as A Foreign Device on a BBMD at @192.168.1.1 on the default 0xBAC0 port
             *
             * bacnet_client.RegisterAsForeignDevice("192.168.1.1", 60);
             * Thread.Sleep(20);
             * bacnet_client.RemoteWhoIs("192.168.1.1");
             */
        }
Пример #4
0
        /*****************************************************************************************************/
        static void StartActivity()
        {
            // Load the device descriptor from the embedded resource file
            // Get myId as own device id
            m_storage = DeviceStorage.Load("BasicAlarmListener.DeviceDescriptor.xml", myId);
            // A fast way to change the PROP_OBJECT_LIST
            Property Prop = Array.Find <Property>(m_storage.Objects[0].Properties, p => p.Id == BacnetPropertyIds.PROP_OBJECT_LIST);

            Prop.Value[0] = "OBJECT_DEVICE:" + myId.ToString();

            // 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);

            bacnet_client.OnWhoIs       += new BacnetClient.WhoIsHandler(handler_OnWhoIs);
            bacnet_client.OnEventNotify += new BacnetClient.EventNotificationCallbackHandler(handler_OnEventNotify);

            // ReadProperties handlers are not absolutly required. Only whois (... and event !) handlers could be used,
            // and m_storage object could be removed in this case.
            bacnet_client.OnReadPropertyRequest         += new BacnetClient.ReadPropertyRequestHandler(handler_OnReadPropertyRequest);
            bacnet_client.OnReadPropertyMultipleRequest += new BacnetClient.ReadPropertyMultipleRequestHandler(handler_OnReadPropertyMultipleRequest);

            bacnet_client.Start();    // go
        }
Пример #5
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());
        }
Пример #6
0
        /*****************************************************************************************************/
        static void StartActivity()
        {
            // 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.Start();    // go

            // Send WhoIs in order to get back all the Iam responses :
            bacnet_client.OnIam += new BacnetClient.IamHandler(handler_OnIam);

            bacnet_client.WhoIs();

            /* Optional Remote Registration as A Foreign Device on a BBMD at @192.168.1.1 on the default 0xBAC0 port
             *
             * bacnet_client.RegisterAsForeignDevice("192.168.1.1", 60);
             * Thread.Sleep(20);
             * bacnet_client.RemoteWhoIs("192.168.1.1");
             */
        }
Пример #7
0
        static void Main(string[] args)
        {
            Bacnet_client        = new BacnetClient(new BacnetIpUdpProtocolTransport(47808));
            Bacnet_client.OnIam += new BacnetClient.IamHandler(handler_OnIam);
            Bacnet_client.Start();
            Bacnet_client.WhoIs();
            Console.Read();
            Console.WriteLine("Begin Scan Device");

            foreach (var device in DevicesList)
            {
                var count = GetDeviceArrayIndexCount(device);
                ScanPointsBatch(device, count);
            }


            foreach (var device in DevicesList)
            {
                System.IO.File.WriteAllText($"{device.DeviceId}.json", Newtonsoft.Json.JsonConvert.SerializeObject(device));
            }



            Console.WriteLine("Begin Scan Properties");
            foreach (var device in DevicesList)
            {
                ScanSubProperties(device);
            }
            foreach (var device in DevicesList)
            {
                System.IO.File.WriteAllText($"{device.DeviceId}pppp.json", Newtonsoft.Json.JsonConvert.SerializeObject(device));
            }
            Console.WriteLine("Scan Finished");
        }
Пример #8
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;
            }
        }
Пример #9
0
        public static BacnetClient NewBackNetClient()
        {
            BacnetIpUdpProtocolTransport newPort = new BacnetIpUdpProtocolTransport(0xBAC0, false);

            bacNetClient = new BacnetClient(newPort);
            bacNetClient.Start();
            return(bacNetClient);
        }
        public Main()
        {
            InitializeComponent();

            // Bacnet on UDP/IP/Ethernet
            bacnet_client        = new BacnetClient(new BacnetIpUdpProtocolTransport(0xBAC0, false));
            bacnet_client.OnIam += new BacnetClient.IamHandler(bacnet_client_OnIam);
            bacnet_client.Start();
        }
Пример #11
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;
            }
        }
Пример #12
0
        private static void Main()
        {
            var transport = new BacnetIpUdpProtocolTransport(0xBAC0, true);
            var client    = new BacnetClient(transport);

            client.OnIam += OnIAm;
            client.Start();
            client.WhoIs();
            Console.ReadLine();
        }
        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
            {
            }
        }
Пример #14
0
        public Main()
        {
            InitializeComponent();

            // Bacnet on UDP/IP/Ethernet
            _bacnet_client        = new BacnetClient(new BacnetIpUdpProtocolTransport(0xBAC0, loggerFactory: NullLoggerFactory.Instance, useExclusivePort: false), NullLoggerFactory.Instance);
            _bacnet_client.OnIam += new BacnetClient.IamHandler(bacnet_client_OnIam);
            _bacnet_client.Start();

            _contextOptionsBuilder.UseSqlite($"Data Source={Path.Combine(Environment.CurrentDirectory, _dbName)}");
        }
        void StartActivity()
        {
            if (bacnet_client != null)
            {
                return;
            }

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

            bacnet_client.Start();                // go
        }
Пример #16
0
        /// <summary>
        /// Start bacnet client and setup handler
        /// </summary>
        static void StartBACnetServerActivity()
        {
            //// Bacnet on UDP/IP/Ethernet
            moBacnetClient = 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);

            moBacnetClient.Start();  // go

            //// Send WhoIs in order to get back all the Iam responses :
            moBacnetClient.OnIam += new BacnetClient.IamHandler(handler_OnIam);
            moBacnetClient.WhoIs();
        }
        /*****************************************************************************************************/
        static void StartActivity()
        {
            // Bacnet on UDP/IP/Ethernet
            bacnet_client = new BacnetClient(new BacnetIpUdpProtocolTransport(0xBAC0, false));
            // or Bacnet Mstp on COM4 à 38400 bps, own master id 8 : BacnetTransportSerial.cs must be added to this project
            // m_bacnet_client = new BacnetClient(new BacnetMstpProtocolTransport("COM4", 38400, 8);

            bacnet_client.Start();    // go

            // Send WhoIs in order to get back all the Iam responses :
            bacnet_client.OnIam += new BacnetClient.IamHandler(handler_OnIam);
            bacnet_client.WhoIs();
        }
        public static void StartActivity()
        {
            // Bacnet on UDP/IP/Ethernet
            bacnet_client = new BacnetClient(new BacnetIpUdpProtocolTransport(0xBAC0, false), 3000, 3);
            // 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"));

            bacnet_client.Start();//go
            // Send WhoIs in order to get back all the Iam responses :
            bacnet_client.OnIam += new BacnetClient.IamHandler(handler_OnIam);
            bacnet_client.WhoIs();
        }
Пример #19
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)
            {
            }
        }
Пример #20
0
 private void BACnetControl_Load(object sender, EventArgs e)
 {
     Bacnet_client        = new BacnetClient(new BacnetIpUdpProtocolTransport(47808, false));
     Bacnet_client.OnIam -= new BacnetClient.IamHandler(handler_OnIam);
     Bacnet_client.OnIam += new BacnetClient.IamHandler(handler_OnIam);
     Bacnet_client.Start();
     Bacnet_client.WhoIs();
     Task.Run(async() =>
     {
         for (int i = 0; i < 10; i++)
         {
             await Task.Delay(100);
             Log($"等待扫描...[{9 - i}]");
         }
         Scan();
     });
 }
Пример #21
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
            }
        }
        /// <summary>
        /// InIt bacnet and UI
        /// </summary>
        public LutronLightFloor()
        {
            InitializeComponent();

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

            //// Below 2 are needed for alarm event
            moBacnetClient.OnEventNotify         += new BacnetClient.EventNotificationCallbackHandler(handler_OnEventNotify);
            moBacnetClient.OnWhoIs               += new BacnetClient.WhoIsHandler(handler_OnWhoIs);
            moBacnetClient.OnCreateObjectRequest += new BacnetClient.CreateObjectRequestHandler(handler_OnCreateObjectRequest);

            moBacnetClient.Start();    // go
            moBacnetClient.WhoIs();    // go

            FillDropDown();
            FillAvailableDevicesForSchedule();
        }
Пример #23
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 ?");
                }
            }
        }
Пример #24
0
        private static void Main()
        {
            using (var loggerFactory = LoggerFactory.Create(b =>
            {
                b.AddConsole(c =>
                {
                    c.TimestampFormat = "[yyyy-MM-dd HH:mm:ss] ";
                });
            }))
            {
                var transport = new BacnetIpUdpProtocolTransport(port: 0xBAC0, loggerFactory: loggerFactory, useExclusivePort: true);
                var client    = new BacnetClient(transport, loggerFactory: loggerFactory);

                client.OnIam += OnIAm;
                client.Start();
                client.WhoIs();
                Console.ReadLine();
            }
        }
Пример #25
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            this.m_backgroundTaskDeferral = taskInstance.GetDeferral();
            taskInstance.Canceled        += TaskInstance_Canceled;

            this.m_azureDeviceClient = DeviceClient.CreateFromConnectionString(deviceConnectionString, TransportType.Amqp);

            // Set-up COV Subscription - Create a timer that run each second and changes the value
            subscriptionRenewalTimer = ThreadPoolTimer.CreatePeriodicTimer(subscriptionRenewalTimer_Tick, TimeSpan.FromSeconds(Subscriptions_ReplacementPollingPeriod / 2));

            m_bacnetClient = new BacnetClient(new BacnetIpUdpProtocolTransport(0xBAC0, false, false, 1472, "192.168.1.117"), 1000, 3);
            m_bacnetClient.Start();
            // Send WhoIs in order to get back all the Iam responses :
            m_bacnetClient.OnIam             += handler_OnIam;
            m_bacnetClient.OnCOVNotification += handler_OnCOVNotification;

            m_bacnetClient.WhoIs();

            ThreadPoolTimer.CreateTimer(DelayLoadSubscriptions, TimeSpan.FromSeconds(5));
        }
Пример #26
0
        private void InitCOVClient_Click(object sender, RoutedEventArgs e)
        {
            UiLogItem("Init Client");

            var selectedLocalHost = (LocalHostItem)AdapterList.SelectedItem;

            if (selectedLocalHost == null)
            {
                UiLogItem("Please select an address / adapter.");
                return;
            }

            bacnet_client = new BacnetClient(new BacnetIpUdpProtocolTransport(0xBAC0, false, false, 1472, selectedLocalHost.LocalHost.CanonicalName), 1000, 3);
            bacnet_client.Start();
            // Send WhoIs in order to get back all the Iam responses :
            bacnet_client.OnIam             += handler_OnIam;
            bacnet_client.OnCOVNotification += handler_OnCOVNotification;

            bacnet_client.WhoIs();
        }
        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);
        }
Пример #28
0
        /*****************************************************************************************************/

        private async void StartActivity()
        {
            // Bacnet on UDP/IP/Ethernet
            //bacnet_client = new BacnetClient(new BacnetIpUdpProtocolTransport(0xBAC0, false));
            // Replaced ConnectionString for UDP local adapter
            //            bacnet_client = new BacnetClient(new BacnetIpUdpProtocolTransport(0xBAC0, false, false, 1472, "192.168.127.1"), 1000, 3);
            bacnet_client = new BacnetClient(new BACNetLib.IO.BACnet.BacnetIpUdpProtocolTransport(0xBAC0, false, false, 1472, "192.168.1.21"), 1000, 3);
            // 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.Start();    // go

            // Send WhoIs in order to get back all the Iam responses :
            bacnet_client.OnIam += new BacnetClient.IamHandler(handler_OnIam);

            bacnet_client.WhoIs();
            await PutTaskDelay();
        }
Пример #29
0
        public static void Start()
        {
            Config();
            Stop();
            if (bacnetClient == null)
            {
                // Bacnet on UDP/IP/Ethernet
                bacnetClient = 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
                // bacnetClient = new BacnetClient(new BacnetEthernetProtocolTransport("Connexion au réseau local"));
                // Or Bacnet on IPV6
                // bacnetClient = new BacnetClient(new BacnetIpV6UdpProtocolTransport(0xBAC0));
            }

            bacnetClient.OnIam += Handler_OnIam;
            bacnetClient.Start();
            bacnetClient.WhoIs();
            LogHelper.Log("bacnetClient start IpUdpProtocol 0xBAC0: " + bacnetClient.ToString());
        }
Пример #30
0
        /// <summary>
        /// Start Bacnet protocol.
        /// </summary>
        public static void StartBackNetService()
        {
            if (bacNetClient == null)
            {
                BacnetIpUdpProtocolTransport newPort = new BacnetIpUdpProtocolTransport(0xBAC0, false);
                bacNetClient = new BacnetClient(newPort);

                //bacNetClient.Dispose();
                //   Thread.Sleep(1000);
                bacNetClient.Start();
                bacNetClient.OnIam   += new BacnetClient.IamHandler(BacNetService.Handler_OmIam);
                bacNetClient.OnWhoIs += new BacnetClient.WhoIsHandler(BacNetService.handler_OnWhoIs);

                bacNetClient.WhoIs();
            }
            else
            {
                bacNetClient.OnIam   -= new BacnetClient.IamHandler(BacNetService.Handler_OmIam);
                bacNetClient.OnWhoIs -= new BacnetClient.WhoIsHandler(BacNetService.handler_OnWhoIs);
            }
            Thread.Sleep(5000);
        }