JoelBender / bacpypes

BACpypes provides a BACnet application layer and network layer written in Python for daemons, scripting, and graphical interfaces.
MIT License
298 stars 128 forks source link

Strange error in apdu.encode(xpdu) #489

Open mayeranalytics opened 1 year ago

mayeranalytics commented 1 year ago

Hi Joel,

I'm getting a very strange error in apdu.encode(xpdu):

Traceback (most recent call last):
  File "/home/pi/miniconda3/lib/python3.4/site-packages/bacpypes/appservice.py", line 1486, in sap_indication
    apdu.encode(xpdu)
  File "/home/pi/miniconda3/lib/python3.4/site-packages/bacpypes/apdu.py", line 695, in encode
    Sequence.encode(self, self._tag_list)
  File "/home/pi/miniconda3/lib/python3.4/site-packages/bacpypes/constructeddata.py", line 115, in encode
    helper.encode(tag)
  File "/home/pi/miniconda3/lib/python3.4/site-packages/bacpypes/primitivedata.py", line 1810, in encode
    tag.set_app_data(Tag.objectIdentifierAppTag, struct.pack('>L', self.get_long()))
struct.error: argument out of range

get_long returns a number that is too large to pack into ">L" (32 bits). I have no clue what's going on. Do you have any ideas?

Many thanks

JoelBender commented 1 year ago

Inside get_long() is this:

        objType, objInstance = self.get_tuple()

        # pack the components together
        return ((objType << 22) + objInstance)

So this error is (a) the object instance is greater than 4294967295, or (b) the object type is greater than 1023.

mayeranalytics commented 1 year ago

Yeah.... the dear user switched object instance and object type 🤨 - safety measures added. Thanks for the pointer!