berkowski / tokio-serial

A serial port implementation for tokio
MIT License
205 stars 67 forks source link

resource busy on OSX with exclusive=true #74

Open HerrMuellerluedenscheid opened 2 weeks ago

HerrMuellerluedenscheid commented 2 weeks ago

Hi, I'm on OSX. The device I'm trying to connect to responds fine using e.g. screen. When using tokio-serial I'm getting the response:

called `Result::unwrap()` on an `Err` value: Error { kind: Unknown, description: "Device or resource busy" }

What I tried and what works fine os linux:

    let port = "/dev/tty.usbserial-AB0LMQX8";
    let mut serial_stream = tokio_serial::new(port, 9600)
        .open_native_async().unwrap();
HerrMuellerluedenscheid commented 6 days ago

It turned out that the exclusive flag was preventing access. I cross-checked with pySerial where the exclusive flag works. Under the hood they use different flags as a colleague of mine found out (Thanks Sebastian 👍) :

pyserial uses flock(…, LOCK_EX) while serialport-rs uses ioctl(…, TIOCEXCL). Probably thats why one works while the other doesnt. For now, I'm using exclusive=false under OSX.