Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Adding timeout to sys.stdin.read(1)

    Scheduled Pinned Locked Moved MicroPython
    uartread datatelnetselect
    3 Posts 2 Posters 45 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B Offline
      berni
      last edited by

      I am trying to read from the serial and telnet using sys.stdin.read(1). Since the function is blocking, I tried some suggested options with uselect:

      import sys, uselect
      
      spoll=uselect.poll()
      spoll.register(sys.stdin, uselect.POLLIN)
      
      def read1():
          return(sys.stdin.read(1) if spoll.poll(0) else None)
      

      However, I get the following error: OSError: stream operation not supported on the following line: spoll.register(sys.stdin, uselect.POLLIN)

      Any suggestion for non-blocking read of UART and Telnet using non-blocking calls?

      Thank you in advance!

      J 1 Reply Last reply Reply Quote 0
      • J Offline
        jcaron @berni
        last edited by

        @berni have you tried setting it to non-blocking?

        If using the UART directly there is an any method which tells you if there’s data available, not sure if that is available via the stdin interface nor if that would work with telnet.

        1 Reply Last reply Reply Quote 0
        • B Offline
          berni
          last edited by

          @jcaron unfortunately, there is any method with the stdin and I haven't found any way to interact directly with the telnet server.

          My previous implementation used the UART, but then I realized that I was able to read from Telnet, but no way to type anything. Also, the telnet connection was quite slow and unreliable for some reason (time out when login/password). With stdin it works much better, but not typing anything will block the application forever.

          1 Reply Last reply Reply Quote 0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • 1 / 1
          • First post
            Last post

          Pycom on Twitter

          Pycom