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

Behaviour when no ESP device connected using esptool as a module (ESPTOOL-980) #1044

Open
mbastida123 opened this issue Dec 20, 2024 · 1 comment

Comments

@mbastida123
Copy link

mbastida123 commented Dec 20, 2024

Operating System

Debian GNU/Linux 12 (bookworm)

Esptool Version

esptool==4.8.1

Python Version

Python 3.11.2

Full Esptool Command Line that Was Run

No response

Esptool Output

I'm making a script on python to program some ESP devices via a GUI.

The line:

    esp= esptool.get_default_connected_device(serial_list=['/dev/ttyUSB1'], 
                                                                port=None, 
                                                                connect_attempts=1, 
                                                                initial_baud=921600)

Correctly returns an instance if the ESP device is connected.

However, if there is no ESP device attached to the ESP-PROG the function timeouts and raises FatalError.

This is totally expected behaviour.

The problem is that when this happens the serial port is not correctly closed and so if get_default_connected_device() is placed inside a loop the following calls to said function will never work. Even if you connect an ESP device.
/dev/ttyUSB1 failed to connect: Could not open /dev/ttyUSB1, the port is busy or doesn't exist.

I have tried numerous ways to manually close the port. But the serial instance is not available to me.

Is this an issue or am I doing something wrong?

@github-actions github-actions bot changed the title Behaviour when no ESP device connected using esptool as a module Behaviour when no ESP device connected using esptool as a module (ESPTOOL-980) Dec 20, 2024
@Dzarda7
Copy link
Contributor

Dzarda7 commented Dec 20, 2024

Hi @mbastida123, the esptool as python package can be used with context manager. We recently added the section into the documentation, so you can take a look here. It should ensure that port is properly closed afterwards. Hope it helps.

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

No branches or pull requests

2 participants