Coder Social home page Coder Social logo

Comments (7)

bastian2001 avatar bastian2001 commented on June 17, 2024 1

because the read is blocking

That's actually a different issue than mine. This is about the write function. You should be able to use the fork by LukaOber that I linked above. It fixes the read function. In this case, it's the write function that stalls separately from the read function. I've had stalled reads on mine too, but they were resolved when I just used the fork (there's already a merge request for this fork).

from serialport-rs.

bastian2001 avatar bastian2001 commented on June 17, 2024 1

For different reasons, I reinstalled Windows on my PC. Since then, it works. I don't think there was a bug fix related to this, so AFAIK it's not fixed

from serialport-rs.

bastian2001 avatar bastian2001 commented on June 17, 2024

To give some context: this is my code, with different timeouts specified, all of which stalling the program:

use serialport::new;
use std::io;

fn main() {
    let mut port = new("COM8", 38400)
        .timeout(std::time::Duration::from_millis(100))
        .open()
        .expect("Failed to open port");
    let mut serial_buf: Vec<u8> = vec![0; 100];
    loop {
        println!("Reading");
        let mut s = String::new();
        let res = io::stdin().read_line(&mut s);
        match res {
            Ok(_) => {
                println!("Read {} bytes from stdin", s.len());
                println!("Content: {}", s);
                let s = s.as_bytes();
                port.write(s).expect("Write failed");
                //^^^^^^^^ stalls here
                println!("Wrote {} bytes to Serial", s.len());
            }
            Err(e) => eprintln!("{:?}", e),
        }
    }
}

from serialport-rs.

FrankLaterza avatar FrankLaterza commented on June 17, 2024

I'm having the same issue. I have two threads for reading and writing using a clone of the serial port. I can't write anything on the port because the read is blocking and waiting for a response. This is not an issue on my Linux machine.

from serialport-rs.

FrankLaterza avatar FrankLaterza commented on June 17, 2024

After I changed my crate to the fork by LukaOber it worked great! I had to change some code, but this solution works for me. Thanks for sharing!

from serialport-rs.

Resonanz avatar Resonanz commented on June 17, 2024

So.... is this fixed now ?

from serialport-rs.

nskartoredjo avatar nskartoredjo commented on June 17, 2024

I've encountered a similar issue, and with a bit of digging, it turns out that the write timeout is never set for Windows machines. I've created a pull request to resolve the issue

from serialport-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.