From b2ee837c57c652e4325af0c70c0623f8dd4d8229 Mon Sep 17 00:00:00 2001 From: Ben Bass Date: Wed, 3 Apr 2024 19:58:11 +0100 Subject: [PATCH 1/2] fix bitbang port value exceeding 8 bits --- src/pylibftdi/bitbang.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pylibftdi/bitbang.py b/src/pylibftdi/bitbang.py index 98b260f..95709c6 100644 --- a/src/pylibftdi/bitbang.py +++ b/src/pylibftdi/bitbang.py @@ -158,7 +158,9 @@ def port(self): @port.setter def port(self, value): + # restrict to a single byte + value &= 0xFF self._latch = value if self.sync: self.flush_output() - return super().write(chr(value)) + return super().write(value.to_bytes()) From 96d78a918ed4adbbefbcda692b7f9395406152d7 Mon Sep 17 00:00:00 2001 From: Ben Bass Date: Wed, 3 Apr 2024 20:03:00 +0100 Subject: [PATCH 2/2] fix to_bytes() for Python < 3.11 --- src/pylibftdi/bitbang.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pylibftdi/bitbang.py b/src/pylibftdi/bitbang.py index 95709c6..65cabbd 100644 --- a/src/pylibftdi/bitbang.py +++ b/src/pylibftdi/bitbang.py @@ -163,4 +163,5 @@ def port(self, value): self._latch = value if self.sync: self.flush_output() - return super().write(value.to_bytes()) + # note to_bytes() gets these as default args in Python3.11+ + return super().write(value.to_bytes(1, "big"))