Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • F firmware
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 74
    • Issues 74
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 29
    • Merge requests 29
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • External wiki
    • External wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • card10
  • firmware
  • Issues
  • #220

Closed
Open
Created Nov 14, 2020 by Sven Knebel@sknebel

non-blocking reads from serial?

I'd like to write an app that talks to a program on my PC bidirectionally (kind of as a remote and utility display: send key presses and sensor values from the card10 to the PC, allow the PC to ask the card10 to blink LEDs/update display contents). The obvious way seems to be the USB-serial.

With print() I can send text to the PC, but I would like a non-blocking way to check for data being sent from the PC, so that in an app main loop that reads sensors, controls LED blinking, ... this is just another step that checks for commands coming in.

I'm flexible in what this specifically looks like, some ideas:

  • micropython seems to have a streams abstraction that maybe could wrap the serial input and seems to support this: http://docs.micropython.org/en/latest/library/uio.html (referenced from https://firmware.card10.badge.events.ccc.de/pycardium/stdlib.html#uio)
  • it could be a function specific to the "standard output" matching print(), e.g. a try_input() that returns whatever is in the input buffer without waiting or a function to check if there is anything in the input buffer.

Possible workaround: I assume with input() I can do a blocking read of a line of text (haven't tested this yet), but that would rely on the PC-side constantly sending newlines to not block the app in that call, which doesn't seem ideal.

Assignee
Assign to
Time tracking