BAC0 icon indicating copy to clipboard operation
BAC0 copied to clipboard

'WritePropertyMultipleError' object has no attribute 'errorCode'

Open JerryXinhui opened this issue 1 year ago • 8 comments

When I try to use bacnet.writeMultiple to write a not exist object of the device, the error message is 'WritePropertyMultipleError' object has no attribute 'errorCode'. But in the wireshark I can see the clear reason "unknown object". How can I get the real reason. For sometimes, I need the real reason to do some judgment. And if I use bacnet.write to write a not exist object of the device, I can get the real reason. image

JerryXinhui avatar Jul 18 '22 06:07 JerryXinhui

I'm not someone to answer the question, but what are the use cases for writeMultiple versus just write? Would you have an example where this is used?

bbartling avatar Jul 18 '22 11:07 bbartling

I‘m not sure I understand your question correctly. But sometimes, we use writeMultiple to write multiple object to test the device works well under this condition. And also , we use writeMultiple to write a non-existent object to the device in order to test whether the device works well.

JerryXinhui avatar Jul 19 '22 01:07 JerryXinhui

I don't have a lot of experience with writeMultiple as few devices I use supports it.

I suspect that we will need to go back to the bacpypes internals to see the APdU error. I may have done something wrong in the implementation.

ChristianTremblay avatar Jul 19 '22 02:07 ChristianTremblay

@JoelBender would you be kind enough to comment on this ?

ChristianTremblay avatar Jul 19 '22 18:07 ChristianTremblay

In the ASN.1 of the standard, the WritePropertyMultiple-Error is described like this:

WritePropertyMultiple-Error ::= SEQUENCE {
    error-type [0] Error,
    first-failed-write-attempt [1] BACnetObjectPropertyReference
}

Which in BACpypes is translated to this:

class WritePropertyMultipleError(ErrorSequence):
    sequenceElements = \
        [ Element('errorType', ErrorType, 0)
        , Element('firstFailedWriteAttempt', ObjectPropertyReference, 1)
        ]

The first element of the sequence will be a context encoded ErrorType structure, which itself contains the errorClass and errorCode. The second element, also context encoded, is the reference to the first failed object and property (and possibly array index) that failed.

The weirdness is in Clause 21.4 where most Result(-) errors are just errors, but some provide additional information and "include" an error.

JoelBender avatar Jul 20 '22 02:07 JoelBender

@JoelBender I have same problem, so how to solve it? Can I define error code and error class by myself? I am looking forward to your reply.

Chris-Wang-bjc avatar Jul 28 '22 02:07 Chris-Wang-bjc

If you call apdu.debug_contents() you'll see all of the content that has been decoded. Check to make sure hasattr(apdu, 'errorType') and then apdu.errorType.errorClass and apdu.errorType.errorCode will have the rest of what you are looking for.

JoelBender avatar Jul 28 '22 02:07 JoelBender

Thanks for your reply, but sorry, I‘m not sure I understand your reply correctly. You can tell me more details about "hasattr(apdu, 'errorType')"? I hope the error message will return the real reason instead of "no attribute" error, thanks.

Chris-Wang-bjc avatar Jul 28 '22 04:07 Chris-Wang-bjc

This issue had no activity for a long period of time. If this issue is still required, please update the status or else, it will be closed. Please note that an issue can be reopened if required.

github-actions[bot] avatar Sep 27 '22 03:09 github-actions[bot]