ponkan-python 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ponkan_python-0.1.0.dist-info/METADATA +157 -0
- ponkan_python-0.1.0.dist-info/RECORD +39 -0
- ponkan_python-0.1.0.dist-info/WHEEL +4 -0
- ponkan_python-0.1.0.dist-info/entry_points.txt +5 -0
- ponkan_python-0.1.0.dist-info/licenses/LICENSE +22 -0
- ponkan_python-0.1.0.dist-info/licenses/NOTICE.md +14 -0
- py3dscapture/__init__.py +36 -0
- py3dscapture/artifacts.py +66 -0
- py3dscapture/capture.py +599 -0
- py3dscapture/devices/__init__.py +1 -0
- py3dscapture/devices/n3dsxl_ftd3.py +238 -0
- py3dscapture/errors.py +120 -0
- py3dscapture/hardware_gate.py +143 -0
- py3dscapture/image/__init__.py +1 -0
- py3dscapture/image/frame.py +166 -0
- py3dscapture/protocol/__init__.py +1 -0
- py3dscapture/protocol/layout_3ds.py +60 -0
- py3dscapture/protocol/n3dsxl.py +249 -0
- py3dscapture/protocol/sizes.py +128 -0
- py3dscapture/py.typed +1 -0
- py3dscapture/streaming/__init__.py +1 -0
- py3dscapture/streaming/buffers.py +156 -0
- py3dscapture/streaming/engine.py +285 -0
- py3dscapture/streaming/policies.py +157 -0
- py3dscapture/streaming/stats.py +254 -0
- py3dscapture/tools/__init__.py +1 -0
- py3dscapture/tools/capture_raw.py +44 -0
- py3dscapture/tools/list_devices.py +68 -0
- py3dscapture/tools/raw_to_png.py +251 -0
- py3dscapture/tools/stream_n3dsxl.py +152 -0
- py3dscapture/transport/__init__.py +1 -0
- py3dscapture/transport/d3xx_backend.py +850 -0
- py3dscapture/transport/d3xx_native.py +268 -0
- py3dscapture/transport/d3xx_native_streaming.py +306 -0
- py3dscapture/transport/d3xx_streaming.py +202 -0
- py3dscapture/transport/ftd3_backend.py +275 -0
- py3dscapture/transport/ftd3_pipe.py +387 -0
- py3dscapture/transport/libusb_async.py +134 -0
- py3dscapture/transport/libusb_backend.py +357 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"""D3XX-backed async transfer adapter for streaming."""
|
|
2
|
+
|
|
3
|
+
import time
|
|
4
|
+
from concurrent.futures import Future, ThreadPoolExecutor, wait
|
|
5
|
+
from threading import Event, Lock
|
|
6
|
+
from typing import Protocol
|
|
7
|
+
|
|
8
|
+
from py3dscapture.protocol.sizes import N3DSXL_BULK_IN_ENDPOINT
|
|
9
|
+
from py3dscapture.streaming.buffers import RawFrameSlot
|
|
10
|
+
from py3dscapture.transport.d3xx_backend import D3XX_DEFAULT_TIMEOUT_MS, D3xxBackendError
|
|
11
|
+
from py3dscapture.transport.libusb_async import AsyncTransferCallback
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class D3xxAsyncBackendConfigError(ValueError):
|
|
15
|
+
"""Raised when D3XX async backend configuration is invalid.
|
|
16
|
+
|
|
17
|
+
Currently this is used for non-positive worker counts.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class D3xxAsyncBackendReleasedError(RuntimeError):
|
|
22
|
+
"""Raised when submitting to a released D3XX async backend.
|
|
23
|
+
|
|
24
|
+
Once released, the backend has closed its executor and handle.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class D3xxAsyncBackendCancellingError(RuntimeError):
|
|
29
|
+
"""Raised when submitting while D3XX async backend cancellation is in progress.
|
|
30
|
+
|
|
31
|
+
Submissions are rejected after cancellation starts so shutdown cannot race
|
|
32
|
+
with new reads.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class D3xxStreamHandle(Protocol):
|
|
37
|
+
"""D3XX handle surface needed by the streaming adapter.
|
|
38
|
+
|
|
39
|
+
The handle is normally a ``D3xxHandle`` opened by the fallback backend, but
|
|
40
|
+
tests may inject a smaller fake.
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
def read_pipe(self, pipe: int, length: int, timeout_ms: int) -> bytes:
|
|
44
|
+
"""Read one stream payload.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
pipe: D3XX pipe ID to read.
|
|
48
|
+
length: Maximum number of bytes to read.
|
|
49
|
+
timeout_ms: Read timeout in milliseconds.
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
Bytes returned by the handle.
|
|
53
|
+
"""
|
|
54
|
+
...
|
|
55
|
+
|
|
56
|
+
def close(self) -> None:
|
|
57
|
+
"""Close the D3XX handle.
|
|
58
|
+
|
|
59
|
+
Implementations release the native device handle and should make repeat
|
|
60
|
+
calls harmless where possible.
|
|
61
|
+
"""
|
|
62
|
+
...
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class D3xxAsyncBackend:
|
|
66
|
+
"""Adapt blocking D3XX stream reads to the StreamingEngine async boundary.
|
|
67
|
+
|
|
68
|
+
Reads run in a worker executor and copy bytes into preallocated raw slots.
|
|
69
|
+
Completion callbacks are invoked only after the worker read returns.
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
def __init__(
|
|
73
|
+
self,
|
|
74
|
+
handle: D3xxStreamHandle,
|
|
75
|
+
*,
|
|
76
|
+
pipe: int = N3DSXL_BULK_IN_ENDPOINT,
|
|
77
|
+
timeout_ms: int = D3XX_DEFAULT_TIMEOUT_MS,
|
|
78
|
+
max_workers: int = 1,
|
|
79
|
+
) -> None:
|
|
80
|
+
"""Create a sequential D3XX read worker backend.
|
|
81
|
+
|
|
82
|
+
Args:
|
|
83
|
+
handle: Open D3XX handle that owns pipe reads and close.
|
|
84
|
+
pipe: D3XX pipe ID used for streaming reads.
|
|
85
|
+
timeout_ms: Read timeout passed to the handle.
|
|
86
|
+
max_workers: Number of read worker threads.
|
|
87
|
+
|
|
88
|
+
Raises:
|
|
89
|
+
D3xxAsyncBackendConfigError: ``max_workers`` is not positive.
|
|
90
|
+
"""
|
|
91
|
+
if max_workers <= 0:
|
|
92
|
+
raise D3xxAsyncBackendConfigError
|
|
93
|
+
self._handle = handle
|
|
94
|
+
self._pipe = pipe
|
|
95
|
+
self._timeout_ms = timeout_ms
|
|
96
|
+
self._executor = ThreadPoolExecutor(
|
|
97
|
+
max_workers=max_workers,
|
|
98
|
+
thread_name_prefix="py3dscapture-d3xx-stream",
|
|
99
|
+
)
|
|
100
|
+
self._cancel_requested = Event()
|
|
101
|
+
self._lock = Lock()
|
|
102
|
+
self._futures: set[Future[None]] = set()
|
|
103
|
+
self._released = False
|
|
104
|
+
|
|
105
|
+
def submit_read(
|
|
106
|
+
self,
|
|
107
|
+
slot: RawFrameSlot,
|
|
108
|
+
*,
|
|
109
|
+
length: int,
|
|
110
|
+
callback: AsyncTransferCallback,
|
|
111
|
+
) -> None:
|
|
112
|
+
"""Submit one read into a preallocated slot.
|
|
113
|
+
|
|
114
|
+
Args:
|
|
115
|
+
slot: Checked-out raw slot whose buffer receives bytes.
|
|
116
|
+
length: Maximum read length in bytes.
|
|
117
|
+
callback: Completion callback invoked from the worker after read
|
|
118
|
+
completion.
|
|
119
|
+
|
|
120
|
+
Raises:
|
|
121
|
+
ValueError: ``length`` is larger than the slot buffer.
|
|
122
|
+
D3xxAsyncBackendReleasedError: The backend has already been
|
|
123
|
+
released.
|
|
124
|
+
D3xxAsyncBackendCancellingError: Cancellation is in progress.
|
|
125
|
+
"""
|
|
126
|
+
if length > len(slot.buffer):
|
|
127
|
+
raise ValueError
|
|
128
|
+
with self._lock:
|
|
129
|
+
if self._released:
|
|
130
|
+
raise D3xxAsyncBackendReleasedError
|
|
131
|
+
if self._cancel_requested.is_set():
|
|
132
|
+
raise D3xxAsyncBackendCancellingError
|
|
133
|
+
future = self._executor.submit(self._read_into_slot, slot, length, callback)
|
|
134
|
+
self._futures.add(future)
|
|
135
|
+
future.add_done_callback(self._forget_future)
|
|
136
|
+
|
|
137
|
+
def cancel_all(self) -> None:
|
|
138
|
+
"""Request cancellation and cancel pending worker jobs.
|
|
139
|
+
|
|
140
|
+
Running D3XX reads may still finish according to backend timeout
|
|
141
|
+
behavior; completions after cancellation are ignored.
|
|
142
|
+
"""
|
|
143
|
+
self._cancel_requested.set()
|
|
144
|
+
with self._lock:
|
|
145
|
+
futures = tuple(self._futures)
|
|
146
|
+
for future in futures:
|
|
147
|
+
future.cancel()
|
|
148
|
+
|
|
149
|
+
def drain(self) -> None:
|
|
150
|
+
"""Wait for submitted worker jobs to settle.
|
|
151
|
+
|
|
152
|
+
The method blocks until all submitted futures are done or cancelled.
|
|
153
|
+
"""
|
|
154
|
+
while True:
|
|
155
|
+
with self._lock:
|
|
156
|
+
futures = tuple(self._futures)
|
|
157
|
+
pending = tuple(future for future in futures if not future.done())
|
|
158
|
+
if not pending:
|
|
159
|
+
return
|
|
160
|
+
wait(pending)
|
|
161
|
+
|
|
162
|
+
def release(self) -> None:
|
|
163
|
+
"""Cancel workers, close the executor, and close the D3XX handle.
|
|
164
|
+
|
|
165
|
+
The method is idempotent. It requests cancellation, drains worker jobs,
|
|
166
|
+
shuts down the executor, and then closes the handle.
|
|
167
|
+
"""
|
|
168
|
+
with self._lock:
|
|
169
|
+
if self._released:
|
|
170
|
+
return
|
|
171
|
+
self._released = True
|
|
172
|
+
self.cancel_all()
|
|
173
|
+
self.drain()
|
|
174
|
+
self._executor.shutdown(wait=True, cancel_futures=True)
|
|
175
|
+
self._handle.close()
|
|
176
|
+
|
|
177
|
+
def _read_into_slot(
|
|
178
|
+
self,
|
|
179
|
+
slot: RawFrameSlot,
|
|
180
|
+
length: int,
|
|
181
|
+
callback: AsyncTransferCallback,
|
|
182
|
+
) -> None:
|
|
183
|
+
transferred = 0
|
|
184
|
+
status = 0
|
|
185
|
+
slot.backend_started_ns = time.monotonic_ns()
|
|
186
|
+
try:
|
|
187
|
+
payload = self._handle.read_pipe(self._pipe, length, self._timeout_ms)
|
|
188
|
+
payload = payload[:length]
|
|
189
|
+
transferred = len(payload)
|
|
190
|
+
slot.buffer[:transferred] = payload
|
|
191
|
+
except D3xxBackendError as exc:
|
|
192
|
+
status = 1 if exc.status is None else exc.status
|
|
193
|
+
except (OSError, RuntimeError):
|
|
194
|
+
status = 1
|
|
195
|
+
completed_ns = time.monotonic_ns()
|
|
196
|
+
if self._cancel_requested.is_set():
|
|
197
|
+
return
|
|
198
|
+
callback(slot.index, transferred, status, completed_ns)
|
|
199
|
+
|
|
200
|
+
def _forget_future(self, future: Future[None]) -> None:
|
|
201
|
+
with self._lock:
|
|
202
|
+
self._futures.discard(future)
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
"""FTD3 transport selection across libusb and D3XX backends."""
|
|
2
|
+
|
|
3
|
+
from typing import Literal, Protocol, cast
|
|
4
|
+
|
|
5
|
+
from py3dscapture.devices.n3dsxl_ftd3 import DeviceCandidate, N3DSXLDevice
|
|
6
|
+
from py3dscapture.errors import DeviceOpenError
|
|
7
|
+
from py3dscapture.transport.ftd3_pipe import FTD3_COMMAND_TIMEOUT_MS, Ftd3Pipe
|
|
8
|
+
from py3dscapture.transport.libusb_backend import LibusbBackend
|
|
9
|
+
|
|
10
|
+
BackendKind = Literal["libusb", "d3xx"]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Ftd3Transport(Protocol):
|
|
14
|
+
"""Transport operations needed by FTD3/N3DSXL protocol code.
|
|
15
|
+
|
|
16
|
+
The protocol is shared by libusb command-pipe transport and the optional
|
|
17
|
+
native D3XX fallback.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
backend_kind: BackendKind
|
|
21
|
+
candidate: DeviceCandidate
|
|
22
|
+
|
|
23
|
+
def close(self) -> None:
|
|
24
|
+
"""Close the transport.
|
|
25
|
+
|
|
26
|
+
Implementations release any owned USB or D3XX handle resources.
|
|
27
|
+
"""
|
|
28
|
+
...
|
|
29
|
+
|
|
30
|
+
def create_pipe(self) -> None:
|
|
31
|
+
"""Create the command pipe.
|
|
32
|
+
|
|
33
|
+
Raises:
|
|
34
|
+
Ftd3CommandError: The backend cannot create or emulate the command
|
|
35
|
+
pipe.
|
|
36
|
+
"""
|
|
37
|
+
...
|
|
38
|
+
|
|
39
|
+
def abort_pipe(self, pipe: int) -> None:
|
|
40
|
+
"""Abort one pipe.
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
pipe: Pipe or endpoint ID to abort.
|
|
44
|
+
"""
|
|
45
|
+
...
|
|
46
|
+
|
|
47
|
+
def set_stream_pipe(self, pipe: int, length: int) -> None:
|
|
48
|
+
"""Configure a stream pipe.
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
pipe: Pipe or endpoint ID to configure.
|
|
52
|
+
length: Stream transfer length in bytes.
|
|
53
|
+
"""
|
|
54
|
+
...
|
|
55
|
+
|
|
56
|
+
def read_pipe(
|
|
57
|
+
self,
|
|
58
|
+
pipe: int,
|
|
59
|
+
length: int,
|
|
60
|
+
timeout_ms: int = FTD3_COMMAND_TIMEOUT_MS,
|
|
61
|
+
) -> bytes:
|
|
62
|
+
"""Read bytes from one pipe.
|
|
63
|
+
|
|
64
|
+
Args:
|
|
65
|
+
pipe: Pipe or endpoint ID to read.
|
|
66
|
+
length: Maximum number of bytes to read.
|
|
67
|
+
timeout_ms: Read timeout in milliseconds.
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
Bytes returned by the backend.
|
|
71
|
+
"""
|
|
72
|
+
...
|
|
73
|
+
|
|
74
|
+
def write_pipe(
|
|
75
|
+
self,
|
|
76
|
+
pipe: int,
|
|
77
|
+
payload: bytes,
|
|
78
|
+
timeout_ms: int = FTD3_COMMAND_TIMEOUT_MS,
|
|
79
|
+
) -> int:
|
|
80
|
+
"""Write bytes to one pipe.
|
|
81
|
+
|
|
82
|
+
Args:
|
|
83
|
+
pipe: Pipe or endpoint ID to write.
|
|
84
|
+
payload: Bytes to transfer.
|
|
85
|
+
timeout_ms: Write timeout in milliseconds.
|
|
86
|
+
|
|
87
|
+
Returns:
|
|
88
|
+
Number of bytes transferred.
|
|
89
|
+
"""
|
|
90
|
+
...
|
|
91
|
+
|
|
92
|
+
def reconnect_after_drain(self) -> None:
|
|
93
|
+
"""Reconnect after drain if the backend requires it.
|
|
94
|
+
|
|
95
|
+
D3XX closes and reopens to match cc3dsfs; libusb keeps the active
|
|
96
|
+
session.
|
|
97
|
+
"""
|
|
98
|
+
...
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class D3xxFallbackBackend(Protocol):
|
|
102
|
+
"""D3XX backend surface needed by fallback selection.
|
|
103
|
+
|
|
104
|
+
The fallback is used only when libusb open fails with a driver/backend
|
|
105
|
+
mismatch signal.
|
|
106
|
+
"""
|
|
107
|
+
|
|
108
|
+
def iter_device_candidates(self) -> tuple[object, ...]:
|
|
109
|
+
"""Return D3XX candidates.
|
|
110
|
+
|
|
111
|
+
Returns:
|
|
112
|
+
Candidate objects accepted by the concrete D3XX backend.
|
|
113
|
+
"""
|
|
114
|
+
...
|
|
115
|
+
|
|
116
|
+
def open(self, candidate: object) -> object:
|
|
117
|
+
"""Open a D3XX candidate.
|
|
118
|
+
|
|
119
|
+
Args:
|
|
120
|
+
candidate: Candidate object returned by ``iter_device_candidates``.
|
|
121
|
+
|
|
122
|
+
Returns:
|
|
123
|
+
Transport-compatible D3XX handle.
|
|
124
|
+
"""
|
|
125
|
+
...
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
class LibusbFtd3Transport:
|
|
129
|
+
"""FTD3 transport adapter over the existing libusb session.
|
|
130
|
+
|
|
131
|
+
The adapter delegates command-pipe payload work to ``Ftd3Pipe`` and owns the
|
|
132
|
+
underlying ``N3DSXLDevice`` session close.
|
|
133
|
+
"""
|
|
134
|
+
|
|
135
|
+
backend_kind: BackendKind = "libusb"
|
|
136
|
+
|
|
137
|
+
def __init__(self, session: N3DSXLDevice) -> None:
|
|
138
|
+
"""Create a transport adapter from an opened libusb session.
|
|
139
|
+
|
|
140
|
+
Args:
|
|
141
|
+
session: Open N3DSXL libusb session.
|
|
142
|
+
"""
|
|
143
|
+
self.session = session
|
|
144
|
+
self._pipe = Ftd3Pipe(session)
|
|
145
|
+
|
|
146
|
+
@property
|
|
147
|
+
def candidate(self) -> DeviceCandidate:
|
|
148
|
+
"""Return the accepted N3DSXL candidate for protocol metadata.
|
|
149
|
+
|
|
150
|
+
Returns:
|
|
151
|
+
Candidate associated with the underlying libusb session.
|
|
152
|
+
"""
|
|
153
|
+
return self.session.candidate
|
|
154
|
+
|
|
155
|
+
def close(self) -> None:
|
|
156
|
+
"""Close the underlying libusb session.
|
|
157
|
+
|
|
158
|
+
This releases claimed interfaces and closes the USB handle.
|
|
159
|
+
"""
|
|
160
|
+
self.session.close()
|
|
161
|
+
|
|
162
|
+
def create_pipe(self) -> None:
|
|
163
|
+
"""Create the FTD3 command pipe through libusb command wrapper.
|
|
164
|
+
|
|
165
|
+
Raises:
|
|
166
|
+
Ftd3CommandError: The command write fails or transfers only a
|
|
167
|
+
partial payload.
|
|
168
|
+
"""
|
|
169
|
+
self._pipe.create_pipe()
|
|
170
|
+
|
|
171
|
+
def abort_pipe(self, pipe: int) -> None:
|
|
172
|
+
"""Abort one FTD3 pipe through libusb command wrapper.
|
|
173
|
+
|
|
174
|
+
Args:
|
|
175
|
+
pipe: Pipe or endpoint ID to abort.
|
|
176
|
+
"""
|
|
177
|
+
self._pipe.abort_pipe(pipe)
|
|
178
|
+
|
|
179
|
+
def set_stream_pipe(self, pipe: int, length: int) -> None:
|
|
180
|
+
"""Set stream pipe through libusb command wrapper.
|
|
181
|
+
|
|
182
|
+
Args:
|
|
183
|
+
pipe: Pipe or endpoint ID to configure.
|
|
184
|
+
length: Transfer length in bytes.
|
|
185
|
+
"""
|
|
186
|
+
self._pipe.set_stream_pipe(pipe, length)
|
|
187
|
+
|
|
188
|
+
def read_pipe(
|
|
189
|
+
self,
|
|
190
|
+
pipe: int,
|
|
191
|
+
length: int,
|
|
192
|
+
timeout_ms: int = FTD3_COMMAND_TIMEOUT_MS,
|
|
193
|
+
) -> bytes:
|
|
194
|
+
"""Read one FTD3 pipe through libusb command wrapper.
|
|
195
|
+
|
|
196
|
+
Args:
|
|
197
|
+
pipe: Pipe or endpoint ID to read.
|
|
198
|
+
length: Maximum number of bytes to read.
|
|
199
|
+
timeout_ms: Read timeout in milliseconds.
|
|
200
|
+
|
|
201
|
+
Returns:
|
|
202
|
+
Bytes read from the pipe.
|
|
203
|
+
"""
|
|
204
|
+
return self._pipe.read_pipe(pipe, length, timeout_ms)
|
|
205
|
+
|
|
206
|
+
def write_pipe(
|
|
207
|
+
self,
|
|
208
|
+
pipe: int,
|
|
209
|
+
payload: bytes,
|
|
210
|
+
timeout_ms: int = FTD3_COMMAND_TIMEOUT_MS,
|
|
211
|
+
) -> int:
|
|
212
|
+
"""Write one FTD3 pipe through libusb command wrapper.
|
|
213
|
+
|
|
214
|
+
Args:
|
|
215
|
+
pipe: Pipe or endpoint ID to write.
|
|
216
|
+
payload: Bytes to transfer.
|
|
217
|
+
timeout_ms: Write timeout in milliseconds.
|
|
218
|
+
|
|
219
|
+
Returns:
|
|
220
|
+
Number of bytes transferred.
|
|
221
|
+
"""
|
|
222
|
+
return self._pipe.write_pipe(pipe, payload, timeout_ms)
|
|
223
|
+
|
|
224
|
+
def reconnect_after_drain(self) -> None:
|
|
225
|
+
"""Keep libusb behavior unchanged after the initial drain.
|
|
226
|
+
|
|
227
|
+
The libusb path keeps the current claimed session instead of closing and
|
|
228
|
+
reopening like the D3XX fallback.
|
|
229
|
+
"""
|
|
230
|
+
self._pipe.reconnect_after_drain()
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def open_ftd3_transport(
|
|
234
|
+
candidate: DeviceCandidate,
|
|
235
|
+
libusb_backend: LibusbBackend,
|
|
236
|
+
d3xx_backend: D3xxFallbackBackend,
|
|
237
|
+
) -> Ftd3Transport:
|
|
238
|
+
"""Open libusb first, then use D3XX only for driver/backend mismatch.
|
|
239
|
+
|
|
240
|
+
Args:
|
|
241
|
+
candidate: Accepted N3DSXL candidate to open.
|
|
242
|
+
libusb_backend: Primary libusb backend.
|
|
243
|
+
d3xx_backend: Fallback backend used when libusb reports a driver
|
|
244
|
+
mismatch.
|
|
245
|
+
|
|
246
|
+
Returns:
|
|
247
|
+
Open transport compatible with ``N3DSXLProtocol``.
|
|
248
|
+
|
|
249
|
+
Raises:
|
|
250
|
+
DeviceOpenError: libusb open fails for reasons other than driver/backend
|
|
251
|
+
mismatch, or D3XX fallback has no candidates.
|
|
252
|
+
"""
|
|
253
|
+
try:
|
|
254
|
+
return LibusbFtd3Transport(N3DSXLDevice.open(candidate, backend=libusb_backend))
|
|
255
|
+
except DeviceOpenError as exc:
|
|
256
|
+
if not _is_libusb_driver_mismatch(exc):
|
|
257
|
+
raise
|
|
258
|
+
d3xx_candidates = d3xx_backend.iter_device_candidates()
|
|
259
|
+
if not d3xx_candidates:
|
|
260
|
+
raise
|
|
261
|
+
return cast("Ftd3Transport", d3xx_backend.open(d3xx_candidates[0]))
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def _is_libusb_driver_mismatch(error: DeviceOpenError) -> bool:
|
|
265
|
+
text = _error_chain_text(error)
|
|
266
|
+
return "LIBUSB_ERROR_NOT_FOUND" in text or "LIBUSB_ERROR_NOT_SUPPORTED" in text
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def _error_chain_text(error: BaseException) -> str:
|
|
270
|
+
parts: list[str] = []
|
|
271
|
+
current: BaseException | None = error
|
|
272
|
+
while current is not None:
|
|
273
|
+
parts.append(str(current))
|
|
274
|
+
current = current.__cause__
|
|
275
|
+
return " ".join(parts)
|