Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PySerial only working from interactive python, not from script in windows #735

Open
leonhardpetzel opened this issue Jan 30, 2024 · 2 comments

Comments

@leonhardpetzel
Copy link

Hello,

I found a really strange issue on Windows 10 Pro using python 3.12.1 with PySerial 3.5.

I have an arduino board with MEGA2560 connected via USB and the firmware on the board will reply to a "*IDN?\r" command with some version string.

If I send the commands in an interactive python promt, all works fine:
Python Bug 0

Also from the debug console (in VS Code) all works fine:
Python Bug 1

However, when I run the commands from a script, it seems like nothing is sent to the board:
Python Bug 2

I tried to put time.sleep() everywhere, but it did not change anything. It really seems like the difference is, if the call comes from an interactive session, or not.

I am not sure, if the issue originates from PySerial, from python or from Windows.
Does somebody here have an idea, where this could come from?

Thanks and BR

@paratim
Copy link

paratim commented Feb 7, 2024

Yes, I'm seeing an issue similar to yours. In my case a sleep(5) after the serial port creation seemed to be a workaround.

@leonhardpetzel
Copy link
Author

Yes, I'm seeing an issue similar to yours. In my case a sleep(5) after the serial port creation seemed to be a workaround.

Thanks for the information! A 2 second sleep works for me. Amazing! I only tried 100ms sleep, which I thought was super long, but apparently not enough.

I also found that writing to the .timeout member is a very bad idea. As soon as I try to change the timeout, the next send transaction just sends garbage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants