From eb5395dee4a37f915f24be3046e10942cb3235a3 Mon Sep 17 00:00:00 2001 From: Ferd Chen Date: Wed, 16 Dec 2015 16:26:38 +0000 Subject: [PATCH] make it support python2.7, by providing conversion from int list to byte stream --- quick2wire/i2c.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/quick2wire/i2c.py b/quick2wire/i2c.py index 0b6b9fe..4fa0495 100644 --- a/quick2wire/i2c.py +++ b/quick2wire/i2c.py @@ -7,7 +7,15 @@ from ctypes import create_string_buffer, sizeof, c_int, byref, pointer, addressof, string_at from quick2wire.board_revision import revision -assert sys.version_info.major >= 3, __name__ + " is only supported on Python 3" +#assert sys.version_info.major >= 3, __name__ + " is only supported on Python 3" + +def toBytes(seq): + v = "" + if sys.version_info.major >= 3: + v = bytes(seq) + else: + v = ''.join([chr(d) for d in seq]) + return v default_bus = 1 if revision() > 1 else 0 @@ -101,7 +109,8 @@ def writing(addr, byte_seq): The bytes are passed to this function as a sequence. """ - buf = bytes(byte_seq) + #buf = bytes(byte_seq) + buf = toBytes(byte_seq) return _new_i2c_msg(addr, 0, create_string_buffer(buf, len(buf)))