Skip to content

Commit 8bf5f71

Browse files
committed
EV3: Fix flashing on Windows.
Windows requires a reportid byte at the front of each sent message for an HID device, even if the device doesn't use reportids. Adding this synthetic 0x00 to the front of the message enables successful EV3 flashing on Windows.
1 parent a1a9a71 commit 8bf5f71

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

pybricksdev/connections/ev3.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import asyncio
55
import enum
66
import itertools
7+
import platform
78
import struct
89
from typing import Callable
910

@@ -97,6 +98,14 @@ def _send_command(self, command: Command, payload: bytes | None = None) -> int:
9798
if payload is not None:
9899
message += payload
99100

101+
if platform.system() == "Windows":
102+
# On Windows, HID reports require an extra leading byte for the
103+
# report ID, even if it's zero. Note that although Windows would
104+
# add a synthetic 0x00 HID byte to the front of reads as well,
105+
# we don't have to handle it because hidapi.dll strips that byte
106+
# in hid_read().
107+
message = b'\x00' + message
108+
100109
self._device.write(message)
101110

102111
return message_number

0 commit comments

Comments
 (0)