pybricks / pybricksdev

pybricksdev: Python Package with Pybricks developer tools
https://pypi.org/project/pybricksdev/
MIT License
48 stars 15 forks source link

Reading the stdout info from hub instead of printing it? #62

Closed johnscary-ev3 closed 1 year ago

johnscary-ev3 commented 1 year ago

Hi guys, I am using prybricksdev to communicate with my Inventor Hub. This is working fine. However, the stdout from the hub just gets printed to my terminal, but I would like to process it now in my PC side program. Documentation shows some options in the hub.run method but is not too clear on how I should read this data into my program. I guess I should set print_output rag to False but what are calls to get this data? Looks like line_handler arg True will give me one line at a time which is great but then how do I get the lines of data into a variable in my program? Do you have some docs on this or a simple example?

Thanks.

def run(
    py_path: str | None = None,
    wait: bool = True,
    print_output: bool = True,
    line_handler: bool = True
) -> Coroutine[Any, Any, None]:
"""
Compiles and runs a user program.

Args:
    py_path: The path to the .py file to compile. If None, runs a
        previously downloaded program.
    wait: If true, wait for the user program to stop before returning.
    print_output: If true, echo stdout of the hub to sys.stdout.
    line_handler: If true enable hub stdout line handler features.
"""
dlech commented 1 year ago

I made some example code recently at https://github.com/orgs/pybricks/discussions/1182#discussioncomment-6544876

Also FYI, using discussions instead of issues is a better way to ask questions. Issues are better for bug reports and feature requests.

johnscary-ev3 commented 1 year ago

Thanks for example code. I think that hub.read_line() call is what I need. Will use discussions for questions next time.