Skip to content

Make resetting optional when opening a device #251

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions pyftdi/ftdi.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,8 @@ def open_from_url(self, url: str) -> None:
def open(self, vendor: int, product: int, bus: Optional[int] = None,
address: Optional[int] = None, index: int = 0,
serial: Optional[str] = None,
interface: int = 1) -> None:
interface: int = 1,
reset: bool = True) -> None:
"""Open a new interface to the specified FTDI device.

If several FTDI devices of the same kind (vid, pid) are connected
Expand All @@ -525,18 +526,21 @@ def open(self, vendor: int, product: int, bus: Optional[int] = None,
:param str serial: optional selector, specified the FTDI device
by its serial number
:param str interface: FTDI interface/port
:param bool reset: If set, reset the device on open
"""
devdesc = UsbDeviceDescriptor(vendor, product, bus, address, serial,
index, None)
device = UsbTools.get_device(devdesc)
self.open_from_device(device, interface)
self.open_from_device(device, interface, reset=reset)

def open_from_device(self, device: UsbDevice,
interface: int = 1) -> None:
interface: int = 1,
reset: bool = True) -> None:
"""Open a new interface from an existing USB device.

:param device: FTDI USB device (PyUSB instance)
:param interface: FTDI interface to use (integer starting from 1)
:param reset: If set, reset the device on open
"""
if not isinstance(device, UsbDevice):
raise FtdiError("Device '%s' is not a PyUSB device" % device)
Expand All @@ -556,10 +560,11 @@ def open_from_device(self, device: UsbDevice,
self._readbuffer = bytearray()
# Drain input buffer
self.purge_buffers()
# Shallow reset
self._reset_device()
# Reset feature mode
self.set_bitmode(0, Ftdi.BitMode.RESET)
if reset:
# Shallow reset
self._reset_device()
# Reset feature mode
self.set_bitmode(0, Ftdi.BitMode.RESET)
# Init latency
self._latency_threshold = None
self.set_latency_timer(self.LATENCY_MIN)
Expand Down