pySerial works fine in Python interpreter, but not standalone

后端 未结 4 1883
我在风中等你
我在风中等你 2020-12-15 23:06

Good morning! Recently I bought an Arduino board to make sort of \"light control\" in my room. Here is the code of the firmware I wrote:

int control = 0;
int         


        
4条回答
  •  渐次进展
    2020-12-16 00:01

    My guess is it has something to with the environment.

    import os
    print os.environ['PS1']
    

    From a script that will not be set. (And maybe something else too.)

    tty's will buffer differently depending on whether or not they think the terminal is interactive. That should be the only difference between the way your two methods work. A lot applications decide this on whether or not PS1 (your terminal prompt) is set. If you set this in you environment manually it may start behaving the same way as it does interactively.

    Also, I would call the call the pyserial flush command manually in your script. (And this would be the preferred way to do it. Instead of masquerading as an interactive terminal.)

提交回复
热议问题