Giter Site home page Giter Site logo

Comments (2)

mlsvrts avatar mlsvrts commented on June 16, 2024

Reproduced this on my system (not including the baudrate failures; those are likely unrelated):

$ lsusb
0403:6001 Future Technology Devices International, Ltd FT232 Serial (UART) IC

$ uname -ar
5.13.0-27-generic #29~20.04.1-Ubuntu

from serialport-rs.

mlsvrts avatar mlsvrts commented on June 16, 2024

The issue can be trivially fixed by setting the port timeout on my system:

diff --git a/examples/hardware_check.rs b/examples/hardware_check.rs
index 881b680..2107e50 100644
--- a/examples/hardware_check.rs
+++ b/examples/hardware_check.rs
@@ -247,11 +247,13 @@ fn test_single_port(port: &mut dyn serialport::SerialPort, loopback: bool) {
         .expect("Unable to write bytes.");
     println!("success");
 
-    print!("Testing data reception...");
     if loopback {
+        print!("Testing data reception...");
+        port.set_timeout(Duration::from_millis(1000)).ok();
+
         let mut buf = [0u8; 12];
-        if port.read_exact(&mut buf).is_err() {
-            println!("FAILED");
+        if let Err(e) = port.read_exact(&mut buf) {
+            println!("FAILED ({})", e);
         } else {
             assert_eq!(
                 str::from_utf8(&buf).unwrap(),

The default timeout is zero:

port.set_timeout(Duration::from_millis(0)).unwrap();

I'm not sure what the expected behavior of 'read_exact' with a zero-duration timeout is, however.

Edit:

The timeout duration is eventually consumed by either nix::poll::ppoll or nix::poll::poll on posix systems:

nix::poll::ppoll(slice::from_mut(&mut fd), Some(timespec), SigSet::empty())

Both of these functions support a format for specifying 'no timeout', however, serialport-rs can't currently express this as its timeout is not optional. I think that supporting Option<Duration> would be a nice feature for serialport-rs, but constitutes a fairly significant change.

For the scope of this issue, adding a non-zero timeout to the example seems reasonable.

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.