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

Unable to access battery information #63

Closed
mkoakintomiwa opened this issue Jun 20, 2020 · 2 comments
Closed

Unable to access battery information #63

mkoakintomiwa opened this issue Jun 20, 2020 · 2 comments

Comments

@mkoakintomiwa
Copy link

Operating system: Windows

I got Unable to access battery information Error: Error { source: Kind(InvalidData), description: Some("Device rate value is unknown") } error: process didn't exit successfully: target\debug\battery.exe (exit code: 1) When i ran this:

extern crate battery;

use std::io;
use std::thread;
use std::time::Duration;

fn main() -> battery::Result<()> {
    let manager = battery::Manager::new()?;
    let mut battery = match manager.batteries()?.next() {
        Some(Ok(battery)) => battery,
        Some(Err(e)) => {
            eprintln!("Unable to access battery information");
            return Err(e);
        }
        None => {
            eprintln!("Unable to find any batteries");
            return Err(io::Error::from(io::ErrorKind::NotFound).into());
        }
    };

    loop {
        println!("{:?}", battery);
        thread::sleep(Duration::from_secs(1));
        manager.refresh(&mut battery)?;
    }
}
@svartalf
Copy link
Owner

svartalf commented Jun 27, 2020

Hi, @mkoakintomiwa! Thank you for the bug report!

I managed to write a fix for it, can you test it? It's in the git branch right now, so you need to temporary replace your battery dependency in Cargo.toml with the following dependency:

[dependencies]
battery = { git = "https://github.com/svartalf/rust-battery.git", branch = "issue-63" }

From what I understand, it can be reproduced when your laptop battery is fully charged and AC is plugged on, so your battery neither charging nor discharging.

@svartalf
Copy link
Owner

svartalf commented Jul 1, 2020

I'm going to assume that 0d7b9e4 fixes this bug, so this issue is closed now. Thank you once again for the bug report!

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

2 participants