paulvha / scd30_on_raspberry

Program to set and read SCD30 on a raspberry Pi
GNU General Public License v3.0
7 stars 2 forks source link

stdout delay when capturing output #3

Closed lukvmil closed 5 years ago

lukvmil commented 5 years ago

I'm trying to integrate your program into a python application by capturing the stdout from the console. For some reason, after displaying the starting message, individual readings will not be outputted until all readings are complete. For example, the default command ./scd30 displays 10 readings in 2 second increments. The readings will not go to stdout until all 10 have completed. This is an issue as I would like to run the program continuously ./scd30 -l 0 and use the readings from there. Here is my code:

import subprocess, shlex
def run_command(command):
    process = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE)
    while True:
        output = process.stdout.readline()
        if output == '' and process.poll() is not None:
            break
        if output:
            print(output.strip())
    rc = process.poll()
    return rc

run_command("./scd30")
paulvha commented 5 years ago

I currently have no time to reproduce, but I did look at the code. The only difference in the output, is that that welcome message is using p_printf() and the values are displayed using printf. You could try to change in the do_output() routine the 5 'printf(' to 'p_printf(WHITE,' and see what happens.

lukvmil commented 5 years ago

I'll give that a try. Would I need to modify the code before running make?

paulvha commented 5 years ago

Yes.. change the printf and indicated in de do-output() and then run make.

Outlook voor Androidhttps://aka.ms/ghei36 downloaden


From: Aeolus1364 notifications@github.com Sent: Wednesday, January 9, 2019 4:22:03 PM To: paulvha/scd30_on_raspberry Cc: paulvha; Comment Subject: Re: [paulvha/scd30_on_raspberry] stdout delay when capturing output (#3)

I'll give that a try. Would I need to modify the code before running make?

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fpaulvha%2Fscd30_on_raspberry%2Fissues%2F3%23issuecomment-452734397&data=02%7C01%7C%7C68c98e18d55b4c9fb06b08d676463703%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636826441266057107&sdata=82Jc3GtnHyfSTZl1KccJ61BrUgnPoICoQCIYtR2e1xM%3D&reserved=0, or mute the threadhttps://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAPRgvNZav4FP2xJH2QdmXoJdvKBPqTllks5vBgkbgaJpZM4Z3me4&data=02%7C01%7C%7C68c98e18d55b4c9fb06b08d676463703%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636826441266057107&sdata=R1PGnfTGXGDJ7CLU5u8vB4mKdyOT8ReuBk4WjjnODF4%3D&reserved=0.

lukvmil commented 5 years ago

That seems to have worked, here is the change I made on line 404 in scd30.cpp:

p_printf(WHITE, (char *) "CO2: %4d PPM\tHumidity: %3.2f %%RH Temperature: %3.2f *%c ",co2, hum,temp,t);

lukvmil commented 5 years ago

I've submitted a pull request

paulvha commented 5 years ago

Weird.. but good to know...

Outlook voor Androidhttps://aka.ms/ghei36 downloaden


From: Aeolus1364 notifications@github.com Sent: Wednesday, January 9, 2019 4:48:54 PM To: paulvha/scd30_on_raspberry Cc: paulvha; Comment Subject: Re: [paulvha/scd30_on_raspberry] stdout delay when capturing output (#3)

That seems to have worked, here is the change I made on line 404 in scd30.cpp:

p_printf(WHITE, (char ) "CO2: %4d PPM\tHumidity: %3.2f %%RH Temperature: %3.2f %c ",co2, hum,temp,t);

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fpaulvha%2Fscd30_on_raspberry%2Fissues%2F3%23issuecomment-452744620&data=02%7C01%7C%7Cef9fbf9db9404310b7d508d67649f5bc%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636826457351546938&sdata=K5wKtiBYL5To6seTycd9HkVF1xqDjqpFDsYLQbgYjbE%3D&reserved=0, or mute the threadhttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAPRgvHKTX-9xYLqxpFwnZebaYV2Clj9_ks5vBg9mgaJpZM4Z3me4&data=02%7C01%7C%7Cef9fbf9db9404310b7d508d67649f5bc%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636826457351546938&sdata=Ru1I2cfd3R1a0fpmcLjyai%2Ffc82m4eXYBy6DZLW0yS0%3D&reserved=0.

paulvha commented 5 years ago

I will need to change more places (in case other options were requested) and post the code today. Want to add your code in the appendix of the .odt file as an example how to include in Python.

paulvha commented 5 years ago

closed after making changes to the source to handle this