I realized after I sent the earlier message that my thinking was a bit messed up. An unsigned byte of 255 (hex 0xff) would be interpreted as -1 if treated as signed (not -128 as I originally said); However an unsigned byte value 128 (hex 0x80) would be interpreted as -128 if it were treated as signed. Given that I still think I was on the right track even if my actual thinking was not entirely correct. On 3/23/12, Alex Hall <mehgcap@xxxxxxxxx> wrote: > Great point, I wonder if that's what is happening. The example I found > uses ctypes data structures to preserve the values, but Python's > inability to flip the sign using an if statement makes me wonder if it > is just not reading the byte value properly, as you said. I'll have to > test this on some other systems and see what happens there. > > On 3/23/12, Soronel Haetir <soronel.haetir@xxxxxxxxx> wrote: >> MSDN says that 255 is "Unknown status - unable to read the battery >> flag information", 255 and -128 are the same value after taking a >> possible sign conversion into account. >> >> I forget whether python offers unsigned types, especially explicitly >> sized unsigned types, which is what you would need to directly use the >> structure in the form it is given (with the values coming out as >> documented). >> >> On 3/23/12, Alex Hall <mehgcap@xxxxxxxxx> wrote: >>> Hi all, >>> I am writing a small plugin for nvda to read some system vitals at a >>> keypress, one of which is battery. I am on a desktop, but many users >>> have laptops, so the plugin will include battery information if it is >>> available. The problem, though, is that my BatteryFlag keeps coming >>> out to -128. Were it 128 I would be happy, since that is the constant >>> for there being no battery in the system (I have a desktop, so that >>> works). A negative, though, is not covered anywhere in the document I >>> found that explains this system_power_structure I am using. I hesitate >>> to just assume it is the right value but negated, since I am not sure >>> what will happen on other systems. Has anyone ever heard of this? >>> >>> As you may know, nvda plugins are to be written in Python. I found a >>> forum where someone uses ctypes to grab the system_power_status >>> structure and convert it to Python, so I am using that code. The >>> person who used this solution on the forum did not mention any >>> problems, so I wonder if it is just my system since I am running >>> Windows via Bootcamp? I really doubt this could be the case, however. >>> >>> The strangest part is that I tried to flip the value: >>> if sps.BatteryFlag<0: sps.BatteryFlag=sps.BatteryFlag*-1 >>> Yet it comes out as -128 whether or not I have that statement in >>> place. Either Python is not seeing the value (originally a >>> ctypes.c_byte, if that helps) as negative, or something is going on >>> that I don't understand. Any help or explanations would be great. >>> Thanks. >>> >>> >>> -- >>> Have a great day, >>> Alex (msg sent from GMail website) >>> mehgcap@xxxxxxxxx; http://www.facebook.com/mehgcap >>> ** To leave the list, click on the immediately-following link:- >>> ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe] >>> ** If this link doesn't work then send a message to: >>> ** program-l-request@xxxxxxxxxxxxx >>> ** and in the Subject line type >>> ** unsubscribe >>> ** For other list commands such as vacation mode, click on the >>> ** immediately-following link:- >>> ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq] >>> ** or send a message, to >>> ** program-l-request@xxxxxxxxxxxxx with the Subject:- faq >>> >> >> >> -- >> Soronel Haetir >> soronel.haetir@xxxxxxxxx >> ** To leave the list, click on the immediately-following link:- >> ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe] >> ** If this link doesn't work then send a message to: >> ** program-l-request@xxxxxxxxxxxxx >> ** and in the Subject line type >> ** unsubscribe >> ** For other list commands such as vacation mode, click on the >> ** immediately-following link:- >> ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq] >> ** or send a message, to >> ** program-l-request@xxxxxxxxxxxxx with the Subject:- faq >> > > > -- > Have a great day, > Alex (msg sent from GMail website) > mehgcap@xxxxxxxxx; http://www.facebook.com/mehgcap > ** To leave the list, click on the immediately-following link:- > ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe] > ** If this link doesn't work then send a message to: > ** program-l-request@xxxxxxxxxxxxx > ** and in the Subject line type > ** unsubscribe > ** For other list commands such as vacation mode, click on the > ** immediately-following link:- > ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq] > ** or send a message, to > ** program-l-request@xxxxxxxxxxxxx with the Subject:- faq > -- Soronel Haetir soronel.haetir@xxxxxxxxx ** To leave the list, click on the immediately-following link:- ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe] ** If this link doesn't work then send a message to: ** program-l-request@xxxxxxxxxxxxx ** and in the Subject line type ** unsubscribe ** For other list commands such as vacation mode, click on the ** immediately-following link:- ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq] ** or send a message, to ** program-l-request@xxxxxxxxxxxxx with the Subject:- faq