Пример #1
0
 public void Dispose()
 {
     if (m_comm == null)
     {
         return;
     }
     m_comm.OnComplexAck -= m_comm_OnComplexAck;
     m_comm.OnError      -= m_comm_OnError;
     m_comm.OnAbort      -= m_comm_OnAbort;
     m_comm.OnSimpleAck  -= m_comm_OnSimpleAck;
     m_comm.OnSegment    -= m_comm_OnSegment;
     m_comm = null;
 }
Пример #2
0
 private void m_comm_OnComplexAck(BacnetClient sender, BacnetAddress adr, BacnetPduTypes type, BacnetConfirmedServices service, byte invoke_id, byte[] buffer, int offset, int length)
 {
     if (invoke_id == m_wait_invoke_id)
     {
         Segmented = false;
         m_result  = new byte[length];
         if (length > 0)
         {
             Array.Copy(buffer, offset, m_result, 0, length);
         }
         ((System.Threading.ManualResetEvent)AsyncWaitHandle).Set();     //notify waiter even if segmented
     }
 }
Пример #3
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());
        }
Пример #4
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);

            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();
        }
Пример #5
0
        private void m_AddEthernetButton_Click(object sender, EventArgs e)
        {
            try
            {
                String[] s = m_EthernetInterfaceCombo.Text.Split(':');

                m_result     = new BacnetClient(new BacnetEthernetProtocolTransport(s[0]), (int)m_TimeoutValue.Value, (int)m_RetriesValue.Value);
                DialogResult = DialogResult.OK;
            }
            catch {}

            Close();
        }
Пример #6
0
        private void m_AddEthernetButton_Click(object sender, EventArgs e)
        {
            try
            {
                string s = ethernet_interfaces.Find(o => o.Item1 == m_EthernetInterfaceCombo.Text).Item3;

                m_result          = new BacnetClient(new BacnetEthernetProtocolTransport(s), (int)m_TimeoutValue.Value, (int)m_RetriesValue.Value);
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            catch {}

            this.Close();
        }
Пример #7
0
        void handler_OnIam(BacnetClient sender, BacnetAddress adr, uint device_id, uint max_apdu, BacnetSegmentations segmentation, ushort vendor_id)
        {
            // Device already registred ?
            foreach (BacNode bn in NetworkDevices)
            {
                if (bn.getAdd(device_id) != null)
                {
                    return;
                }
            }

            var ignore = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => NetworkDevices.Add(new BacNode(adr, device_id)));
        }
Пример #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)
            {
            }
        }
Пример #9
0
        void handler_OnCOVNotification(BacnetClient sender, BacnetAddress adr, byte invoke_id, uint subscriberProcessIdentifier, BacnetObjectId initiatingDeviceIdentifier, BacnetObjectId monitoredObjectIdentifier, uint timeRemaining, bool need_confirm, ICollection <BacnetPropertyValue> values, BacnetMaxSegments max_segments)
        {
            foreach (BacnetPropertyValue value in values)
            {
                switch ((BacnetPropertyIds)value.property.propertyIdentifier)
                {
                case BacnetPropertyIds.PROP_PRESENT_VALUE:
                    Debug.WriteLine($"Got {value.value[0].Value} from {monitoredObjectIdentifier}");
                    this.SendTelemtry(value, monitoredObjectIdentifier);
                    break;

                case BacnetPropertyIds.PROP_STATUS_FLAGS:
                    string status_text = "";
                    if (value.value != null && value.value.Count > 0)
                    {
                        BacnetStatusFlags status = (BacnetStatusFlags)((BacnetBitString)value.value[0].Value).ConvertToInt();
                        if ((status & BacnetStatusFlags.STATUS_FLAG_FAULT) == BacnetStatusFlags.STATUS_FLAG_FAULT)
                        {
                            status_text += "FAULT,";
                        }
                        else if ((status & BacnetStatusFlags.STATUS_FLAG_IN_ALARM) == BacnetStatusFlags.STATUS_FLAG_IN_ALARM)
                        {
                            status_text += "ALARM,";
                        }
                        else if ((status & BacnetStatusFlags.STATUS_FLAG_OUT_OF_SERVICE) == BacnetStatusFlags.STATUS_FLAG_OUT_OF_SERVICE)
                        {
                            status_text += "OOS,";
                        }
                        else if ((status & BacnetStatusFlags.STATUS_FLAG_OVERRIDDEN) == BacnetStatusFlags.STATUS_FLAG_OVERRIDDEN)
                        {
                            status_text += "OR,";
                        }
                    }
                    if (status_text != "")
                    {
                        Debug.WriteLine(status_text);
                    }
                    break;

                default:
                    //got something else? ignore it
                    break;
                }
            }

            if (need_confirm)
            {
                sender.SimpleAckResponse(adr, BacnetConfirmedServices.SERVICE_CONFIRMED_COV_NOTIFICATION, invoke_id);
            }
        }
Пример #10
0
        private static void OnAtomicReadFileRequest(BacnetClient sender, BacnetAddress adr, byte invoke_id, bool is_stream, BacnetObjectId object_id, int position, uint count, BacnetMaxSegments max_segments)
        {
            lock (m_lockObject)
            {
                try
                {
                    if (object_id.Type != BacnetObjectTypes.OBJECT_FILE)
                    {
                        throw new Exception("File Reading on non file objects ... bah!");
                    }
                    else if (object_id.Instance != 0)
                    {
                        throw new Exception("Don't know this file");
                    }

                    //this is a test file for performance measuring
                    int  filesize    = m_storage.ReadPropertyValue(object_id, BacnetPropertyIds.PROP_FILE_SIZE);    //test file is ~10mb
                    bool end_of_file = (position + count) >= filesize;
                    count = (uint)Math.Min(count, filesize - position);
                    int max_filebuffer_size = sender.GetFileBufferMaxSize();
                    if (count > max_filebuffer_size && max_segments > 0)
                    {
                        //create segmented message!!!
                    }
                    else
                    {
                        count = (uint)Math.Min(count, max_filebuffer_size);     //trim
                    }

                    //fill file with bogus content
                    byte[] file_buffer = new byte[count];
                    byte[] bogus       = new byte[] { (byte)'F', (byte)'I', (byte)'L', (byte)'L' };
                    for (int i = 0; i < count; i += bogus.Length)
                    {
                        Array.Copy(bogus, 0, file_buffer, i, Math.Min(bogus.Length, count - i));
                    }

                    //send
                    HandleSegmentationResponse(sender, adr, invoke_id, max_segments, (seg) =>
                    {
                        sender.ReadFileResponse(adr, invoke_id, seg, position, count, end_of_file, file_buffer);
                    });
                }
                catch (Exception)
                {
                    sender.ErrorResponse(adr, BacnetConfirmedServices.SERVICE_CONFIRMED_ATOMIC_READ_FILE, invoke_id, BacnetErrorClasses.ERROR_CLASS_DEVICE, BacnetErrorCodes.ERROR_CODE_OTHER);
                }
            }
        }
        // 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 !
                udp_transport = new BacnetIpUdpProtocolTransport(0xBAC0, 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);

                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;
            }
        }
Пример #12
0
        public void DownloadFileByBlocking(BacnetClient comm, BacnetAddress adr, BacnetObjectId object_id, string filename, Action <int> progress_action)
        {
            Cancel = false;

            //open file
            System.IO.FileStream fs = null;
            try
            {
                fs = System.IO.File.OpenWrite(filename);
            }
            catch (Exception ex)
            {
                throw new System.IO.IOException("Couldn't open file", ex);
            }

            int  position    = 0;
            uint count       = (uint)comm.GetFileBufferMaxSize();
            bool end_of_file = false;

            byte[] buffer;
            int    buffer_offset;

            try
            {
                while (!end_of_file && !Cancel)
                {
                    //read from device
                    if (!comm.ReadFileRequest(adr, object_id, ref position, ref count, out end_of_file, out buffer, out buffer_offset))
                    {
                        throw new System.IO.IOException("Couldn't read file");
                    }
                    position += (int)count;

                    //write to file
                    if (count > 0)
                    {
                        fs.Write(buffer, buffer_offset, (int)count);
                        if (progress_action != null)
                        {
                            progress_action(position);
                        }
                    }
                }
            }
            finally
            {
                fs.Close();
            }
        }
        public AlarmSummary(ImageList img_List, BacnetClient comm, BacnetAddress adr, uint device_id, Dictionary <Tuple <String, BacnetObjectId>, String> DevicesObjectsName)
        {
            InitializeComponent();
            this.Text = "Active Alarms on Device Id " + device_id.ToString();
            this.comm = comm;
            this.adr  = adr;

            this.DevicesObjectsName = DevicesObjectsName;

            TAlarmList.ImageList = img_List;

            Application.UseWaitCursor = true;

            Application.DoEvents();
        }
Пример #14
0
        public BBMDEditor(BacnetClient comm, BacnetAddress adr)
        {
            InitializeComponent();

            DataGridViewCellStyle dgv = new DataGridViewCellStyle();

            dgv.Alignment = DataGridViewContentAlignment.MiddleCenter;

            BBMDTable.ColumnHeadersDefaultCellStyle = FDRTable.ColumnHeadersDefaultCellStyle = dgv;

            transport = (BacnetIpUdpProtocolTransport)comm.Transport;
            BBMDep    = new IPEndPoint(System.Net.IPAddress.Parse(adr.ToString().Split(':')[0]), Convert.ToInt32(adr.ToString().Split(':')[1]));

            transport.Bvlc.MessageReceived += new System.IO.BACnet.Serialize.BVLC.BVLCMessageReceiveHandler(Bvlc_MessageReceived);
        }
Пример #15
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);
        }
Пример #16
0
 private static void OnWritePropertyMultipleRequest(BacnetClient sender, BacnetAddress adr, byte invoke_id, BacnetObjectId object_id, ICollection <BacnetPropertyValue> values, BacnetMaxSegments max_segments)
 {
     lock (m_lockObject)
     {
         try
         {
             m_storage.WritePropertyMultiple(object_id, values);
             sender.SimpleAckResponse(adr, BacnetConfirmedServices.SERVICE_CONFIRMED_WRITE_PROP_MULTIPLE, invoke_id);
         }
         catch (Exception)
         {
             sender.ErrorResponse(adr, BacnetConfirmedServices.SERVICE_CONFIRMED_WRITE_PROP_MULTIPLE, invoke_id, BacnetErrorClasses.ERROR_CLASS_DEVICE, BacnetErrorCodes.ERROR_CODE_OTHER);
         }
     }
 }
Пример #17
0
        private static async void OnIAm(BacnetClient sender, BacnetAddress adr,
                                        uint deviceid, uint maxapdu, BacnetSegmentations segmentation, ushort vendorid)
        {
            Console.WriteLine($"Detected device {deviceid} at {adr}");

            // In theory each bacnet device should have object of type OBJECT_DEVICE with property PROP_OBJECT_LIST
            // This property is a list of all bacnet objects (ids) of that device

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

            foreach (var objId in objectIdList)
            {
                Console.WriteLine($"{objId}");
            }
        }
        private void bacnet_client_OnIam(BacnetClient sender, BacnetAddress adr, uint device_id, uint max_apdu, BacnetSegmentations segmentation, ushort vendor_id)
        {
            this.Invoke((MethodInvoker) delegate
            {
                ListViewItem itm = m_list.Items.Add(adr.ToString());
                itm.Tag          = new KeyValuePair <BacnetAddress, uint>(adr, device_id);
                itm.SubItems.Add("");

                //read name
                IList <BacnetValue> values;
                if (bacnet_client.ReadPropertyRequest(adr, new BacnetObjectId(BacnetObjectTypes.OBJECT_DEVICE, device_id), BacnetPropertyIds.PROP_OBJECT_NAME, out values))
                {
                    itm.SubItems[1].Text = (string)values[0].Value;
                }
            }, null);
        }
 /*****************************************************************************************************/
 static void handler_OnIam(BacnetClient sender, BacnetAddress adr, uint device_id, uint max_apdu, BacnetSegmentations segmentation, ushort vendor_id)
 {
     lock (DevicesList)
     {
         // Device already registred ?
         foreach (BacNode bn in DevicesList)
         {
             if (bn.getAdd(device_id) != null)
             {
                 return;                                 // Yes
             }
         }
         // Not already in the list
         DevicesList.Add(new BacNode(adr, device_id));   // add it
     }
 }
Пример #20
0
 public BacnetAsyncResult(BacnetClient comm, BacnetAddress adr, byte invokeId, byte[] transmitBuffer, int transmitLength, bool waitForTransmit, int transmitTimeout)
 {
     _transmitTimeout    = transmitTimeout;
     _addr               = adr;
     _waitForTransmit    = waitForTransmit;
     _transmitBuffer     = transmitBuffer;
     _transmitLength     = transmitLength;
     _comm               = comm;
     _waitInvokeId       = invokeId;
     _comm.OnComplexAck += OnComplexAck;
     _comm.OnError      += OnError;
     _comm.OnAbort      += OnAbort;
     _comm.OnSimpleAck  += OnSimpleAck;
     _comm.OnSegment    += OnSegment;
     _waitHandle         = new ManualResetEvent(false);
 }
Пример #21
0
 public BacnetAsyncResult(BacnetClient comm, BacnetAddress adr, byte invoke_id, byte[] transmit_buffer, int transmit_length, bool wait_for_transmit, int transmit_timeout)
 {
     m_transmit_timeout = transmit_timeout;
     m_adr = adr;
     m_wait_for_transmit = wait_for_transmit;
     m_transmit_buffer   = transmit_buffer;
     m_transmit_length   = transmit_length;
     AsyncWaitHandle     = new System.Threading.ManualResetEvent(false);
     m_comm               = comm;
     m_wait_invoke_id     = invoke_id;
     m_comm.OnComplexAck += new BacnetClient.ComplexAckHandler(m_comm_OnComplexAck);
     m_comm.OnError      += new BacnetClient.ErrorHandler(m_comm_OnError);
     m_comm.OnAbort      += new BacnetClient.AbortHandler(m_comm_OnAbort);
     m_comm.OnSimpleAck  += new BacnetClient.SimpleAckHandler(m_comm_OnSimpleAck);
     m_comm.OnSegment    += new BacnetClient.SegmentHandler(m_comm_OnSegment);
 }
Пример #22
0
        //TODO: just put in network.
        public void OnIam(BacnetClient sender, BacnetAddress adr, uint device_id, uint max_apdu, BacnetSegmentations segmentation, ushort vendor_id)
        {
            if (BacnetDevices.ContainsKey(device_id))       //may happen since multiple WhoIs's are sent out...
            {
                return;
            }

            if (BacnetGlobalNetwork.FilterDeviceInstance && (device_id < BacnetGlobalNetwork.DeviceInstanceMin || device_id > BacnetGlobalNetwork.DeviceInstanceMax))
            {
                return;
            }

            var device = new BACnetDevice(this, adr, device_id, Instance);

            BacnetDevices.Add(device_id, device);
        }
Пример #23
0
        private void m_SearchIpButton_Click(object sender, EventArgs e)
        {
            String adr = Properties.Settings.Default.DefaultUdpIp;

            if (adr.Contains(':'))
            {
                m_result = new BacnetClient(new BacnetIpV6UdpProtocolTransport((int)m_PortValue.Value, Properties.Settings.Default.YabeDeviceId, Properties.Settings.Default.Udp_ExclusiveUseOfSocket, Properties.Settings.Default.Udp_DontFragment, Properties.Settings.Default.Udp_MaxPayload, adr), (int)m_TimeoutValue.Value, (int)m_RetriesValue.Value);
            }
            else
            {
                m_result = new BacnetClient(new BacnetIpUdpProtocolTransport((int)m_PortValue.Value, Properties.Settings.Default.Udp_ExclusiveUseOfSocket, Properties.Settings.Default.Udp_DontFragment, Properties.Settings.Default.Udp_MaxPayload, adr), (int)m_TimeoutValue.Value, (int)m_RetriesValue.Value);
            }

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }
Пример #24
0
        public ScheduleDisplay(ImageList img_List, BacnetClient comm, BacnetAddress adr, BacnetObjectId object_id)
        {
            InitializeComponent();
            this.comm        = comm;
            this.adr         = adr;
            this.schedule_id = object_id;

            // Get the Present_Value data Type, used for new value in the schedule
            // ... replaced if some other values found in the scheduling
            try
            {
                IList <BacnetValue> value;
                comm.ReadPropertyRequest(adr, object_id, BacnetPropertyIds.PROP_PRESENT_VALUE, out value);

                if ((value != null) && (value.Count != 0) && (value[0].Tag != BacnetApplicationTags.BACNET_APPLICATION_TAG_NULL))
                {
                    ScheduleType = value[0].Tag;
                }
            }
            catch { }


            for (int i = 1; i < 12; i++)
            {
                ScheduleDataType.Items.Add(GetNiceName((BacnetApplicationTags)i));
            }

            ReadEffectivePeriod();
            ReadEffectiveWeeklySchedule();
            ReadExceptionSchedule();
            ReadObjectsPropertiesReferences();

            ToolTip t1 = new ToolTip();

            t1.AutomaticDelay = 0;
            t1.SetToolTip(TxtStartDate, "A wrong value set this to Always");
            ToolTip t2 = new ToolTip();

            t2.AutomaticDelay = 0;
            t2.SetToolTip(TxtEndDate, "A wrong value set this to Always");

            // get the ImageList from MainDialog
            listReferences.SmallImageList = img_List;

            ScheduleDataType.Text = GetNiceName(ScheduleType);
        }
        /// <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>
        public 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;
            }

            //int? alaramEnrollmentVal = _LutronLightRepository.GetAlaramEnrollment();
            //if (alaramEnrollmentVal != null)
            //{
            //    sender.Iam((uint)alaramEnrollmentVal, new BacnetSegmentations());
            //}
        }
Пример #26
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();
     });
 }
        // Only for MULTIPLE TREND LOG
        private int ReadNumberofCurves(BacnetClient comm, BacnetAddress adr, BacnetObjectId object_id)
        {
            IList <BacnetValue> value;

            try
            {
                if (!comm.ReadPropertyRequest(adr, object_id, BacnetPropertyIds.PROP_LOG_DEVICE_OBJECT_PROPERTY, out value))
                {
                    return(0);
                }
                return(value == null ? 0 : value.Count);
            }
            catch
            {
                return(0);
            }
        }
Пример #28
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
            }
        }
Пример #29
0
 private void handler_OnIam(BacnetClient sender, BacnetAddress adr, uint deviceId, uint maxAPDU, BacnetSegmentations segmentation, ushort vendorId)
 {
     BeginInvoke(new Action(() =>
     {
         lock (devicesList)
         {
             foreach (BacNode bn in devicesList)
             {
                 if (bn.GetAdd(deviceId) != null)
                 {
                     return;                                // Yes
                 }
             }
             devicesList.Add(new BacNode(adr, deviceId));   // add it
             listBox1.Items.Add(adr.ToString() + " " + deviceId);
         }
     }));
 }
        /// <summary>
        /// Handler to get COV notification and process further
        /// </summary>
        private void handler_OnCOVNotification(BacnetClient foBacnetClient, BacnetAddress foBacnetAddress, byte foInvokeid,
                                               uint fisubscriberProcessIdentifier, BacnetObjectId foInitiatingDeviceIdentifier, BacnetObjectId foMonitoredObjectIdentifier,
                                               uint fiTimeRemaining, bool fbNeedConfirm, ICollection <BacnetPropertyValue> foBacnetPropertyValue, BacnetMaxSegments foBacnetMaxSegments)
        {
            foreach (BacnetPropertyValue value in foBacnetPropertyValue)
            {
                switch ((BacnetPropertyIds)value.property.propertyIdentifier)
                {
                case BacnetPropertyIds.PROP_PRESENT_VALUE:
                    COVChangesToUI(value.value[0].ToString());
                    break;

                default:
                    ////got something else? ignore it
                    break;
                }
            }
        }