Skip to content

Commit bc6c75e

Browse files
Controller: Add an optional timeout parameter for the read call, fixes packets not received in VMs.
1 parent 0613cdc commit bc6c75e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/usbbluetooth/controller.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,19 +143,19 @@ def write(self, data: bytearray) -> int:
143143
else:
144144
raise ValueError(f"Unsupported HCI packet type: {type}")
145145

146-
def read(self, bufsize=1024):
146+
def read(self, bufsize=1024, timeout=500):
147147
if not self.is_open:
148148
raise DeviceClosedException()
149149
# Data endpoint
150150
try:
151-
data_acl = self._ep_acl_in.read(bufsize, timeout=1)
151+
data_acl = self._ep_acl_in.read(bufsize, timeout=timeout)
152152
if data_acl and len(data_acl) > 0:
153153
return b"\x02" + data_acl
154154
except usb.core.USBTimeoutError:
155155
pass
156156
# Event endpoint
157157
try:
158-
data_evt = self._ep_events.read(bufsize, timeout=1)
158+
data_evt = self._ep_events.read(bufsize, timeout=timeout)
159159
if data_evt and len(data_evt) > 0:
160160
return b"\x04" + data_evt
161161
except usb.core.USBTimeoutError:

0 commit comments

Comments
 (0)