Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot set final bit of signed integers using set_attr_bit #1542

Open
DavideFigundio opened this issue Dec 28, 2023 · 0 comments
Open

Cannot set final bit of signed integers using set_attr_bit #1542

DavideFigundio opened this issue Dec 28, 2023 · 0 comments

Comments

@DavideFigundio
Copy link

When attempting to set or unset the final bit of signed integer values (sbyte, int16/32/64) I am getting an out of bounds error.

I am connecting to a third party server, getting the node that I require and running the following code:

def set_bit(node: SyncNode, bit: int, value: bool):
    '''Sets the value of the indicated bit for the given node.'''
    
    if value:
        node.set_attr_bit(asyncua.ua.AttributeIds.Value, bit)
    else:
        node.unset_attr_bit(asyncua.ua.AttributeIds.Value, bit)

This raises an exception for certain values of bit (7 for sbyte, 15 for int16...) giving the reason (int16 example):

struct.error: short format requires -32768 <= number <= 32767

However this does not fail if the function would not actually change the value of the bit, for example the following code would run without issues:

value = asyncua.ua.Variant(-32768, asyncua.ua.VariantType.Int16)
node.set_value(value)
node.set_attr_bit(asyncua.ua.AttributeIds.Value, 15)

Finally, there are no issues when using unsigned variable types (byte, uint16/32/64).

Python-Version: 3.12
opcua-asyncio Version: 1.0.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant