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

ByteIndicator Does not display negative numbers #970

Open
jozamudi opened this issue Feb 13, 2023 · 5 comments
Open

ByteIndicator Does not display negative numbers #970

jozamudi opened this issue Feb 13, 2023 · 5 comments
Assignees

Comments

@jozamudi
Copy link

Describe the bug

When the value of the ByteIndicator widget is a negative the byte indicator displays all bits are off.

Expected behavior

The byteIndicator should display the bits regardless if the value is signed or unsigned.

Steps to Reproduce

Set the value of the ByteIndicator negative.

Possible Solution

In the ByteIndicator class, the function update_indicators. There is an 'if' statement that sets the value to zero if the value is negative. Removing this 'if' statement fixes the issue.

My Platform

Additional context

@YektaY
Copy link
Collaborator

YektaY commented Feb 15, 2023

Hello,

The PyDM team is assessing which route to approach this change and were wondering if something like this new widget request #922 work for your needs?

@jozamudi
Copy link
Author

Hi,

I dont' think a new widget would be necessary to solve the issue. But if there is something that would prohibit the use of a negative value, then sure. Otherwise just allowing the byte indicator to display the bits of a value without limiting the value to be positive would be great.

@YektaY YektaY removed their assignment Aug 3, 2023
@nstelter-slac nstelter-slac self-assigned this Aug 10, 2023
@nstelter-slac
Copy link
Collaborator

Hi,

initial draft up here: #1025

if we want to err on the side of caution, we could enable this feature with a QtDesigner option for the widget. Something like "displayNegatives" that is toggled off by default.

@klauer
Copy link
Collaborator

klauer commented Aug 17, 2023

What do you expect that the bits of a negative value should be in your application?

I think the ByteIndicator doesn't support (negative) signed values because they don't make much sense from the perspective of displaying a bit mask as a string of on/off LEDs.

For a bit of background - when it comes to representing negative numbers on a computer, it could be through one's/two's complement or even just the most significant bit could represent the sign (see here). Additionally, there's a matter of the bit width - if we are to sign extend the negative number to show it in the byte indicator, are we talking 32-bit integers in every case? Most likely not. PyDM (to my recollection) doesn't retain the bit width of integer values from the control system, so does the byte indicator need a bit width setting for negative numbers?

@nstelter-slac
Copy link
Collaborator

nstelter-slac commented Aug 17, 2023

hi,

agree that two's complement for negative numbers doesn't make much sense here,
seems difficult to interpret compared to unsigned binary and positive numbers in two's representation would be confusing. (beyond the mentioned bit-width issues)

not super familiar with all the use cases of this widget, but seems reasonable to drop the sign and display the absolute value of negative numbers. (what i interpreted jozamudi's ask to be, but please clarify if not), especially if added as toggleable option for the widget (off by default) and possibly some visual indication that its displaying negative.

currently negative numbers display nothing in the widget, so think that toggle adds additional functionality without compromising original usage.

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

4 participants