Esempio n. 1
0
        private void SendBinaryOutput(bool OnState)
        {
            TestWriteLabel.Text = "...";

            // Assume just Binary Output for now ...
            BACnetEnums.BACNET_OBJECT_TYPE objtype = BACnetEnums.BACNET_OBJECT_TYPE.OBJECT_BINARY_OUTPUT;
            BACnetEnums.BACNET_PROPERTY_ID propid  = BACnetEnums.BACNET_PROPERTY_ID.PROP_PRESENT_VALUE;
            int idx = ObjectList.SelectedIndex;

            if (idx >= 0)
            {
                string s  = ObjectList.Items[idx].ToString();
                string s1 = s.Substring(15);
                if (s1.Length > 0)
                {
                    uint     objinst  = Convert.ToUInt32(s1);
                    Property property = new Property();
                    property.Tag = BACnetEnums.BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_ENUMERATED;
                    if (OnState)
                    {
                        property.ValueEnum = 1; // Turn it on
                    }
                    else
                    {
                        property.ValueEnum = 0; // Turn it off
                    }
                    if (BACStack.SendWriteProperty(
                            BACnetData.DeviceIndex,
                            (uint)objinst,
                            -1,
                            objtype,
                            propid,
                            property,
                            1))
                    {
                        TestWriteLabel.Text = "Binary Output " + (OnState ? "On" : "Off");
                    }
                    else
                    {
                        TestWriteLabel.Text = "Binary Output On Error";
                    }
                }
            }
        }
Esempio n. 2
0
        private void ReadPresentValueBtn_Click(object sender, EventArgs e)
        {
            PresentValueLabel.Text = "...";

            // Assume just Binary Output for now ...
            BACnetEnums.BACNET_OBJECT_TYPE objtype = BACnetEnums.BACNET_OBJECT_TYPE.OBJECT_BINARY_OUTPUT;
            BACnetEnums.BACNET_PROPERTY_ID propid  = BACnetEnums.BACNET_PROPERTY_ID.PROP_PRESENT_VALUE;
            int idx = ObjectList.SelectedIndex;

            if (idx >= 0)
            {
                string s  = ObjectList.Items[idx].ToString();
                string s1 = s.Substring(15);
                if (s1.Length > 0)
                {
                    uint     objinst  = Convert.ToUInt32(s1);
                    Property property = new Property();

                    if (!BACStack.SendReadProperty(BACnetData.DeviceIndex,
                                                   (uint)objinst,
                                                   -1,
                                                   objtype,
                                                   propid,
                                                   property))
                    {
                        PresentValueLabel.Text = "Read Present Value Error (1)";
                        return;
                    }
                    if (property.Tag != BACnetEnums.BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_ENUMERATED)
                    {
                        PresentValueLabel.Text = "Read Present Value Error (2)";
                        return;
                    }
                    if (property.ValueEnum == 1)
                    {
                        PresentValueLabel.Text = "Binary Output On";
                    }
                    else
                    {
                        PresentValueLabel.Text = "Binary Output Off";
                    }
                }
            }
        }
Esempio n. 3
0
        public dynamic ReadValue(Device device, BACnetEnums.BACNET_OBJECT_TYPE bacnetObjectType, uint instance,
                                 BACnetEnums.BACNET_PROPERTY_ID bacnetPropertyId = BACnetEnums.BACNET_PROPERTY_ID.PROP_PRESENT_VALUE)
        {
            BACnetEnums.BACNET_OBJECT_TYPE objtype = bacnetObjectType;
            BACnetEnums.BACNET_PROPERTY_ID propid  = bacnetPropertyId;

            uint     objinst  = instance;
            Property property = new Property();

            if (!BACStack.SendReadProperty(device,
                                           (uint)objinst,
                                           -1,
                                           objtype,
                                           propid,
                                           property))
            {
                return(-1);
            }

            return(property);
        }
Esempio n. 4
0
        private void DecodeConfirmedService(byte[] apdu_buf)
        {
            if ((apdu_buf[0] & 0x08) != 0)
            {
                _apm.MessageTodo("m0002 Need to implement confirmed service types with seg=1 still");
                return;
            }

            int iptr = 3;

            confirmedServiceChoice       = (BACnetEnums.BACNET_CONFIRMED_SERVICE)apdu_buf[iptr++];
            apduConfirmedServiceTypeFlag = true;

            switch (confirmedServiceChoice)
            {
            case BACnetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY:
                // Expecting 2-3 context tags.
                // First, mandatory, context 0, object ID
                objectID = new BACnetObjectIdentifier();
                objectID.DecodeContextTag(apdu_buf, ref iptr);

                // Second, mandatory, Property ID
                propertyID = (BACnetEnums.BACNET_PROPERTY_ID)BACnetEncoding.DecodeTagContextUint(apdu_buf, ref iptr, 1);

                // Third, Array Index, Optional
                if (iptr < apdu_length)
                {
                    arrayIndex        = (int)BACnetEncoding.DecodeTagContextUint(apdu_buf, ref iptr, 2);
                    arrayIndexDecoded = true;
                }
                break;

            default:
                _apm.MessageTodo("m0024 all the other service types");
                break;
            }
        }
Esempio n. 5
0
        void DecodeComplexACK(byte[] buf, int offset)
        {
            if ((buf[offset] & 0x0f) != 0)
            {
                throw new Exception("m0020 - Not ready to handle segmented messages yet");
            }

            // invoke ID - ignoring for now

            // Service ACK choice

            BACnetEnums.BACNET_CONFIRMED_SERVICE sc = (BACnetEnums.BACNET_CONFIRMED_SERVICE)buf[offset + 2];
            switch (sc)
            {
            case BACnetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY:
                offset += 3;

                // Decode Object ID of the object whos property we are reading

                BACnetObjectIdentifier oid = new BACnetObjectIdentifier(buf, ref offset, BACnetEnums.TAG.CONTEXT, 0);

                // Decode the property ID
                propertyID = (BACnetEnums.BACNET_PROPERTY_ID)BACnetEncoding.DecodeTagContextUint(buf, ref offset, 1);

                // Now decode the Property Value itself. Variable encoding, variable length, etc....

                switch (oid.objectType)
                {
                case BACnetEnums.BACNET_OBJECT_TYPE.OBJECT_DEVICE:
                    switch (propertyID)
                    {
                    case BACnetEnums.BACNET_PROPERTY_ID.PROP_OBJECT_LIST:
                        // decode the list of objects
                        // process the opening context tag, 0x3e
                        if (buffer[offset++] != 0x3e)
                        {
                            throw new Exception("m0033 - Opening context tag not found " + buffer[offset - 1].ToString());
                        }

                        objectList = new List <BACnetObjectIdentifier>();

                        // now loop until closing tag found
                        while (buffer[offset] != 0x3f)
                        {
                            // we should get a list of object IDs, add these to our backnet packet object as they are discovered.

                            objectList.Add(new BACnetObjectIdentifier(buffer, ref offset, BACnetEnums.TAG.APPLICATION, BACnetEnums.BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_OBJECT_ID));
                        }
                        break;

                    case BACnetEnums.BACNET_PROPERTY_ID.PROP_OBJECT_NAME:
                        _apm.MessageTodo("m0032 - Decode object name");
                        break;

                    default:
                        _apm.MessageTodo("m0026 Unimplemented Property ID " + propertyID.ToString());
                        break;
                    }
                    break;

                default:
                    _apm.MessageTodo("m0061 Unhandled object type " + oid.objectType.ToString());
                    break;
                }
                break;

            default:
                _apm.MessageTodo("m0028 - Not ready to deal with this service yet " + sc.ToString());
                return;
            }
        }
Esempio n. 6
0
        // Build the 'header' part of the BACnet Packet
        private static int InsertReadPropertyResponse(AppManager apm, BACnetPacket requestBACpkt, BACnetPacket responseCRP, byte[] outbuf, BACnetEnums.BACNET_PROPERTY_ID pID)
        {
            int optr;

            optr = responseCRP.apdu_offset;

            // build APDU to provide services supported.

            responseCRP.EncodeNPDU(outbuf, ref optr);

            BACnetLibraryCL.InsertPDU(outbuf, ref optr, BACnetEnums.BACNET_PDU_TYPE.PDU_TYPE_COMPLEX_ACK, requestBACpkt.invokeID, requestBACpkt.confirmedServiceChoice);

            requestBACpkt.objectID.EncodeContextTag(outbuf, ref optr, 0);

            BACnetLibraryCL.InsertContextTag(outbuf, ref optr, 1, (int)pID);

            return(optr);
        }