diff --git a/chid.pxd b/chid.pxd index 516984e..a7bbf59 100644 --- a/chid.pxd +++ b/chid.pxd @@ -1,38 +1,38 @@ from libc.stddef cimport wchar_t, size_t cdef extern from "hidapi.h": - ctypedef struct hid_device: - pass + ctypedef struct hid_device: + pass - cdef struct hid_device_info: - char *path - unsigned short vendor_id - unsigned short product_id - wchar_t *serial_number - unsigned short release_number - wchar_t *manufacturer_string - wchar_t *product_string - unsigned short usage_page - unsigned short usage - int interface_number - hid_device_info *next + cdef struct hid_device_info: + char *path + unsigned short vendor_id + unsigned short product_id + wchar_t *serial_number + unsigned short release_number + wchar_t *manufacturer_string + wchar_t *product_string + unsigned short usage_page + unsigned short usage + int interface_number + hid_device_info *next - hid_device_info* hid_enumerate(unsigned short, unsigned short) nogil - void hid_free_enumeration(hid_device_info*) + hid_device_info* hid_enumerate(unsigned short, unsigned short) nogil + void hid_free_enumeration(hid_device_info*) - hid_device* hid_open(unsigned short, unsigned short, const wchar_t*) - hid_device* hid_open_path(char *path) - void hid_close(hid_device *) - int hid_write(hid_device* device, unsigned char *data, int length) nogil - int hid_read(hid_device* device, unsigned char* data, int max_length) nogil - int hid_read_timeout(hid_device* device, unsigned char* data, int max_length, int milliseconds) nogil - int hid_set_nonblocking(hid_device* device, int value) - int hid_send_feature_report(hid_device* device, unsigned char *data, int length) nogil - int hid_get_feature_report(hid_device* device, unsigned char *data, int length) nogil - int hid_get_input_report(hid_device* device, unsigned char *data, int length) nogil + hid_device* hid_open(unsigned short, unsigned short, const wchar_t*) + hid_device* hid_open_path(char *path) + void hid_close(hid_device *) + int hid_write(hid_device* device, unsigned char *data, int length) nogil + int hid_read(hid_device* device, unsigned char* data, int max_length) nogil + int hid_read_timeout(hid_device* device, unsigned char* data, int max_length, int milliseconds) nogil + int hid_set_nonblocking(hid_device* device, int value) + int hid_send_feature_report(hid_device* device, unsigned char *data, int length) nogil + int hid_get_feature_report(hid_device* device, unsigned char *data, int length) nogil + int hid_get_input_report(hid_device* device, unsigned char *data, int length) nogil - int hid_get_manufacturer_string(hid_device*, wchar_t *, size_t) - int hid_get_product_string(hid_device*, wchar_t *, size_t) - int hid_get_serial_number_string(hid_device*, wchar_t *, size_t) - int hid_get_indexed_string(hid_device*, int, wchar_t *, size_t) - wchar_t *hid_error(hid_device *) + int hid_get_manufacturer_string(hid_device*, wchar_t *, size_t) + int hid_get_product_string(hid_device*, wchar_t *, size_t) + int hid_get_serial_number_string(hid_device*, wchar_t *, size_t) + int hid_get_indexed_string(hid_device*, int, wchar_t *, size_t) + wchar_t *hid_error(hid_device *) diff --git a/hid.pyx b/hid.pyx index 34401b5..e920832 100644 --- a/hid.pyx +++ b/hid.pyx @@ -4,235 +4,235 @@ from libc.stddef cimport wchar_t, size_t from cpython.unicode cimport PyUnicode_FromUnicode cdef extern from "ctype.h": - int wcslen(wchar_t*) + int wcslen(wchar_t*) cdef extern from "stdlib.h": - void free(void* ptr) - void* malloc(size_t size) + void free(void* ptr) + void* malloc(size_t size) cdef extern from *: - object PyUnicode_FromWideChar(const wchar_t *w, Py_ssize_t size) - Py_ssize_t PyUnicode_AsWideChar(object unicode, wchar_t *w, Py_ssize_t size) + object PyUnicode_FromWideChar(const wchar_t *w, Py_ssize_t size) + Py_ssize_t PyUnicode_AsWideChar(object unicode, wchar_t *w, Py_ssize_t size) cdef object U(wchar_t *wcs): - if wcs == NULL: - return '' - cdef int n = wcslen(wcs) - return PyUnicode_FromWideChar(wcs, n) + if wcs == NULL: + return '' + cdef int n = wcslen(wcs) + return PyUnicode_FromWideChar(wcs, n) def enumerate(int vendor_id=0, int product_id=0): - cdef hid_device_info* info - with nogil: - info = hid_enumerate(vendor_id, product_id) - cdef hid_device_info* c = info - res = [] - while c: - res.append({ - 'path': c.path, - 'vendor_id': c.vendor_id, - 'product_id': c.product_id, - 'serial_number': U(c.serial_number), - 'release_number': c.release_number, - 'manufacturer_string': U(c.manufacturer_string), - 'product_string': U(c.product_string), - 'usage_page': c.usage_page, - 'usage': c.usage, - 'interface_number': c.interface_number, - }) - c = c.next - hid_free_enumeration(info) - return res + cdef hid_device_info* info + with nogil: + info = hid_enumerate(vendor_id, product_id) + cdef hid_device_info* c = info + res = [] + while c: + res.append({ + 'path': c.path, + 'vendor_id': c.vendor_id, + 'product_id': c.product_id, + 'serial_number': U(c.serial_number), + 'release_number': c.release_number, + 'manufacturer_string': U(c.manufacturer_string), + 'product_string': U(c.product_string), + 'usage_page': c.usage_page, + 'usage': c.usage, + 'interface_number': c.interface_number, + }) + c = c.next + hid_free_enumeration(info) + return res cdef class device: - cdef hid_device *_c_hid - - def open(self, int vendor_id=0, int product_id=0, unicode serial_number=None): - cdef wchar_t * cserial_number = NULL - cdef int serial_len - cdef Py_ssize_t result - try: - if serial_number is not None: - serial_len = len(serial_number) - cserial_number = malloc(sizeof(wchar_t) * (serial_len+1)) - if cserial_number == NULL: - raise MemoryError() - result = PyUnicode_AsWideChar(serial_number, cserial_number, serial_len) - if result == -1: - raise ValueError("invalid serial number string") - cserial_number[serial_len] = 0 # Must explicitly null-terminate - self._c_hid = hid_open(vendor_id, product_id, cserial_number) - finally: - if cserial_number != NULL: - free(cserial_number) - if self._c_hid == NULL: - raise IOError('open failed') - - def open_path(self, bytes path): - cdef char* cbuff = path - self._c_hid = hid_open_path(cbuff) - if self._c_hid == NULL: - raise IOError('open failed') - - def close(self): - if self._c_hid != NULL: - hid_close(self._c_hid) - self._c_hid = NULL - - def write(self, buff): - '''Accept a list of integers (0-255) and send them to the device''' - if self._c_hid == NULL: - raise ValueError('not open') - # convert to bytes - if sys.version_info < (3, 0): - buff = ''.join(map(chr, buff)) - else: - buff = bytes(buff) - cdef hid_device * c_hid = self._c_hid - cdef unsigned char* cbuff = buff # covert to c string - cdef size_t c_buff_len = len(buff) - cdef int result - with nogil: - result = hid_write(c_hid, cbuff, c_buff_len) - return result - - def set_nonblocking(self, int v): - '''Set the nonblocking flag''' - if self._c_hid == NULL: - raise ValueError('not open') - return hid_set_nonblocking(self._c_hid, v) - - def read(self, int max_length, int timeout_ms=0): - '''Return a list of integers (0-255) from the device up to max_length bytes.''' - if self._c_hid == NULL: - raise ValueError('not open') - cdef unsigned char lbuff[16] - cdef unsigned char* cbuff - cdef size_t c_max_length = max_length - cdef int c_timeout_ms = timeout_ms - cdef hid_device * c_hid = self._c_hid - if max_length <= 16: - cbuff = lbuff - else: - cbuff = malloc(max_length) - if timeout_ms > 0: + cdef hid_device *_c_hid + + def open(self, int vendor_id=0, int product_id=0, unicode serial_number=None): + cdef wchar_t * cserial_number = NULL + cdef int serial_len + cdef Py_ssize_t result + try: + if serial_number is not None: + serial_len = len(serial_number) + cserial_number = malloc(sizeof(wchar_t) * (serial_len+1)) + if cserial_number == NULL: + raise MemoryError() + result = PyUnicode_AsWideChar(serial_number, cserial_number, serial_len) + if result == -1: + raise ValueError("invalid serial number string") + cserial_number[serial_len] = 0 # Must explicitly null-terminate + self._c_hid = hid_open(vendor_id, product_id, cserial_number) + finally: + if cserial_number != NULL: + free(cserial_number) + if self._c_hid == NULL: + raise IOError('open failed') + + def open_path(self, bytes path): + cdef char* cbuff = path + self._c_hid = hid_open_path(cbuff) + if self._c_hid == NULL: + raise IOError('open failed') + + def close(self): + if self._c_hid != NULL: + hid_close(self._c_hid) + self._c_hid = NULL + + def write(self, buff): + '''Accept a list of integers (0-255) and send them to the device''' + if self._c_hid == NULL: + raise ValueError('not open') + # convert to bytes + if sys.version_info < (3, 0): + buff = ''.join(map(chr, buff)) + else: + buff = bytes(buff) + cdef hid_device * c_hid = self._c_hid + cdef unsigned char* cbuff = buff # covert to c string + cdef size_t c_buff_len = len(buff) + cdef int result with nogil: - n = hid_read_timeout(c_hid, cbuff, c_max_length, c_timeout_ms) - else: + result = hid_write(c_hid, cbuff, c_buff_len) + return result + + def set_nonblocking(self, int v): + '''Set the nonblocking flag''' + if self._c_hid == NULL: + raise ValueError('not open') + return hid_set_nonblocking(self._c_hid, v) + + def read(self, int max_length, int timeout_ms=0): + '''Return a list of integers (0-255) from the device up to max_length bytes.''' + if self._c_hid == NULL: + raise ValueError('not open') + cdef unsigned char lbuff[16] + cdef unsigned char* cbuff + cdef size_t c_max_length = max_length + cdef int c_timeout_ms = timeout_ms + cdef hid_device * c_hid = self._c_hid + if max_length <= 16: + cbuff = lbuff + else: + cbuff = malloc(max_length) + if timeout_ms > 0: + with nogil: + n = hid_read_timeout(c_hid, cbuff, c_max_length, c_timeout_ms) + else: + with nogil: + n = hid_read(c_hid, cbuff, c_max_length) + if n is -1: + raise IOError('read error') + res = [] + for i in range(n): + res.append(cbuff[i]) + if max_length > 16: + free(cbuff) + return res + + def get_manufacturer_string(self): + if self._c_hid == NULL: + raise ValueError('not open') + cdef wchar_t buff[255] + cdef int r = hid_get_manufacturer_string(self._c_hid, buff, 255) + if r < 0: + raise IOError('get manufacturer string error') + return U(buff) + + + def get_product_string(self): + if self._c_hid == NULL: + raise ValueError('not open') + cdef wchar_t buff[255] + cdef int r = hid_get_product_string(self._c_hid, buff, 255) + if r < 0: + raise IOError('get product string error') + return U(buff) + + def get_serial_number_string(self): + if self._c_hid == NULL: + raise ValueError('not open') + cdef wchar_t buff[255] + cdef int r = hid_get_serial_number_string(self._c_hid, buff, 255) + if r < 0: + raise IOError('get serial number string error') + return U(buff) + + def get_indexed_string(self, index): + if self._c_hid == NULL: + raise ValueError('not open') + cdef wchar_t buff[255] + cdef unsigned char c_index = index + cdef int r = hid_get_indexed_string(self._c_hid, c_index, buff, 255) + if r < 0: + raise IOError('get indexed string error') + return U(buff) + + def send_feature_report(self, buff): + if self._c_hid == NULL: + raise ValueError('not open') + '''Accept a list of integers (0-255) and send them to the device''' + # convert to bytes + if sys.version_info < (3, 0): + buff = ''.join(map(chr, buff)) + else: + buff = bytes(buff) + cdef hid_device * c_hid = self._c_hid + cdef unsigned char* cbuff = buff # covert to c string + cdef size_t c_buff_len = len(buff) + cdef int result with nogil: - n = hid_read(c_hid, cbuff, c_max_length) - if n is -1: - raise IOError('read error') - res = [] - for i in range(n): - res.append(cbuff[i]) - if max_length > 16: - free(cbuff) - return res - - def get_manufacturer_string(self): - if self._c_hid == NULL: - raise ValueError('not open') - cdef wchar_t buff[255] - cdef int r = hid_get_manufacturer_string(self._c_hid, buff, 255) - if r < 0: - raise IOError('get manufacturer string error') - return U(buff) - - - def get_product_string(self): - if self._c_hid == NULL: - raise ValueError('not open') - cdef wchar_t buff[255] - cdef int r = hid_get_product_string(self._c_hid, buff, 255) - if r < 0: - raise IOError('get product string error') - return U(buff) - - def get_serial_number_string(self): - if self._c_hid == NULL: - raise ValueError('not open') - cdef wchar_t buff[255] - cdef int r = hid_get_serial_number_string(self._c_hid, buff, 255) - if r < 0: - raise IOError('get serial number string error') - return U(buff) - - def get_indexed_string(self, index): - if self._c_hid == NULL: - raise ValueError('not open') - cdef wchar_t buff[255] - cdef unsigned char c_index = index - cdef int r = hid_get_indexed_string(self._c_hid, c_index, buff, 255) - if r < 0: - raise IOError('get indexed string error') - return U(buff) - - def send_feature_report(self, buff): - if self._c_hid == NULL: - raise ValueError('not open') - '''Accept a list of integers (0-255) and send them to the device''' - # convert to bytes - if sys.version_info < (3, 0): - buff = ''.join(map(chr, buff)) - else: - buff = bytes(buff) - cdef hid_device * c_hid = self._c_hid - cdef unsigned char* cbuff = buff # covert to c string - cdef size_t c_buff_len = len(buff) - cdef int result - with nogil: - result = hid_send_feature_report(c_hid, cbuff, c_buff_len) - return result - - def get_feature_report(self, int report_num, int max_length): - if self._c_hid == NULL: - raise ValueError('not open') - cdef hid_device * c_hid = self._c_hid - cdef unsigned char lbuff[16] - cdef unsigned char* cbuff - cdef size_t c_max_length = max_length - cdef int n - if max_length <= 16: - cbuff = lbuff - else: - cbuff = malloc(max_length) - cbuff[0] = report_num - with nogil: - n = hid_get_feature_report(c_hid, cbuff, c_max_length) - res = [] - if n < 0: - raise IOError('read error') - for i in range(n): - res.append(cbuff[i]) - if max_length > 16: - free(cbuff) - return res - - def get_input_report(self, int report_num, int max_length): - if self._c_hid == NULL: - raise ValueError('not open') - cdef hid_device * c_hid = self._c_hid - cdef unsigned char lbuff[16] - cdef unsigned char* cbuff - cdef size_t c_max_length = max_length - cdef int n - if max_length <= 16: - cbuff = lbuff - else: - cbuff = malloc(max_length) - cbuff[0] = report_num - with nogil: - n = hid_get_input_report(c_hid, cbuff, c_max_length) - res = [] - if n < 0: - raise IOError('read error') - for i in range(n): - res.append(cbuff[i]) - if max_length > 16: - free(cbuff) - return res - - def error(self): - if self._c_hid == NULL: - raise ValueError('not open') - return U(hid_error(self._c_hid)) + result = hid_send_feature_report(c_hid, cbuff, c_buff_len) + return result + + def get_feature_report(self, int report_num, int max_length): + if self._c_hid == NULL: + raise ValueError('not open') + cdef hid_device * c_hid = self._c_hid + cdef unsigned char lbuff[16] + cdef unsigned char* cbuff + cdef size_t c_max_length = max_length + cdef int n + if max_length <= 16: + cbuff = lbuff + else: + cbuff = malloc(max_length) + cbuff[0] = report_num + with nogil: + n = hid_get_feature_report(c_hid, cbuff, c_max_length) + res = [] + if n < 0: + raise IOError('read error') + for i in range(n): + res.append(cbuff[i]) + if max_length > 16: + free(cbuff) + return res + + def get_input_report(self, int report_num, int max_length): + if self._c_hid == NULL: + raise ValueError('not open') + cdef hid_device * c_hid = self._c_hid + cdef unsigned char lbuff[16] + cdef unsigned char* cbuff + cdef size_t c_max_length = max_length + cdef int n + if max_length <= 16: + cbuff = lbuff + else: + cbuff = malloc(max_length) + cbuff[0] = report_num + with nogil: + n = hid_get_input_report(c_hid, cbuff, c_max_length) + res = [] + if n < 0: + raise IOError('read error') + for i in range(n): + res.append(cbuff[i]) + if max_length > 16: + free(cbuff) + return res + + def error(self): + if self._c_hid == NULL: + raise ValueError('not open') + return U(hid_error(self._c_hid)) diff --git a/setup.py b/setup.py index 7bc3f13..53a928f 100755 --- a/setup.py +++ b/setup.py @@ -4,128 +4,124 @@ import sys import subprocess -hidapi_topdir = os.path.join('hidapi') -hidapi_include = os.path.join(hidapi_topdir, 'hidapi') +hidapi_topdir = os.path.join("hidapi") +hidapi_include = os.path.join(hidapi_topdir, "hidapi") system_hidapi = 0 -libs= [] -src = ['hid.pyx', 'chid.pxd'] +libs = [] +src = ["hid.pyx", "chid.pxd"] + def hidapi_src(platform): - return os.path.join(hidapi_topdir, platform, 'hid.c') + return os.path.join(hidapi_topdir, platform, "hid.c") + -if '--with-system-hidapi' in sys.argv: - sys.argv.remove('--with-system-hidapi') +if "--with-system-hidapi" in sys.argv: + sys.argv.remove("--with-system-hidapi") system_hidapi = 1 - hidapi_include = '/usr/include/hidapi' + hidapi_include = "/usr/include/hidapi" -if sys.platform.startswith('linux'): +if sys.platform.startswith("linux"): modules = [] - if '--without-libusb' in sys.argv: - sys.argv.remove('--without-libusb') - hidraw_module = 'hid' + if "--without-libusb" in sys.argv: + sys.argv.remove("--without-libusb") + hidraw_module = "hid" else: - hidraw_module = 'hidraw' - libs = ['usb-1.0', 'udev', 'rt'] + hidraw_module = "hidraw" + libs = ["usb-1.0", "udev", "rt"] if system_hidapi == 1: - libs.append('hidapi-libusb') + libs.append("hidapi-libusb") else: - src.append(hidapi_src('libusb')) + src.append(hidapi_src("libusb")) modules.append( - Extension('hid', - sources = src, - include_dirs = [hidapi_include, '/usr/include/libusb-1.0'], - libraries = libs, + Extension( + "hid", + sources=src, + include_dirs=[hidapi_include, "/usr/include/libusb-1.0"], + libraries=libs, ) ) - libs = ['udev', 'rt'] - src = ['hidraw.pyx', 'chid.pxd'] + libs = ["udev", "rt"] + src = ["hidraw.pyx", "chid.pxd"] if system_hidapi == 1: - libs.append('hidapi-hidraw') + libs.append("hidapi-hidraw") else: - src.append(hidapi_src('linux')) + src.append(hidapi_src("linux")) modules.append( - Extension(hidraw_module, - sources = src, - include_dirs = [hidapi_include], - libraries = libs, + Extension( + hidraw_module, sources=src, include_dirs=[hidapi_include], libraries=libs, ) ) -if sys.platform.startswith('darwin'): - macos_sdk_path = subprocess.check_output(['xcrun', '--show-sdk-path']).decode().strip() - os.environ['CFLAGS'] = '-isysroot "%s" -framework IOKit -framework CoreFoundation -framework AppKit' % macos_sdk_path - os.environ['LDFLAGS'] = '' +if sys.platform.startswith("darwin"): + macos_sdk_path = ( + subprocess.check_output(["xcrun", "--show-sdk-path"]).decode().strip() + ) + os.environ["CFLAGS"] = ( + '-isysroot "%s" -framework IOKit -framework CoreFoundation -framework AppKit' + % macos_sdk_path + ) + os.environ["LDFLAGS"] = "" if system_hidapi == True: - libs.append('hidapi') + libs.append("hidapi") else: - src.append(hidapi_src('mac')) + src.append(hidapi_src("mac")) modules = [ - Extension('hid', - sources = src, - include_dirs = [hidapi_include], - libraries = libs, - ) + Extension("hid", sources=src, include_dirs=[hidapi_include], libraries=libs,) ] -if sys.platform.startswith('win') or sys.platform.startswith('cygwin'): - libs = ['setupapi'] +if sys.platform.startswith("win") or sys.platform.startswith("cygwin"): + libs = ["setupapi"] if system_hidapi == True: - libs.append('hidapi') + libs.append("hidapi") else: - src.append(hidapi_src('windows')) + src.append(hidapi_src("windows")) modules = [ - Extension('hid', - sources = src, - include_dirs = [hidapi_include], - libraries = libs, - ) + Extension("hid", sources=src, include_dirs=[hidapi_include], libraries=libs,) ] -if 'bsd' in sys.platform: - if 'freebsd' in sys.platform: - libs = ['usb', 'hidapi'] - include_dirs_bsd = ['/usr/local/include/hidapi'] +if "bsd" in sys.platform: + if "freebsd" in sys.platform: + libs = ["usb", "hidapi"] + include_dirs_bsd = ["/usr/local/include/hidapi"] else: - libs = ['usb-1.0'] - include_dirs_bsd = [hidapi_include, - '/usr/include/libusb-1.0', - '/usr/local/include/libusb-1.0', - '/usr/local/include/'] + libs = ["usb-1.0"] + include_dirs_bsd = [ + hidapi_include, + "/usr/include/libusb-1.0", + "/usr/local/include/libusb-1.0", + "/usr/local/include/", + ] if system_hidapi == True: - libs.append('hidapi-libusb') + libs.append("hidapi-libusb") else: - src.append(hidapi_src('libusb')) + src.append(hidapi_src("libusb")) modules = [ - Extension('hid', - sources = src, - include_dirs = include_dirs_bsd, - libraries = libs, - ) - ] + Extension("hid", sources=src, include_dirs=include_dirs_bsd, libraries=libs,) + ] setup( - name = 'hidapi', - version = '0.10.1', - description = 'A Cython interface to the hidapi from https://github.com/libusb/hidapi', - author = 'Gary Bishop', - author_email = 'gb@cs.unc.edu', - maintainer = 'Pavol Rusnak', - maintainer_email = 'pavol@rusnak.io', - url = 'https://github.com/trezor/cython-hidapi', - package_dir = {'hid': 'hidapi/*'}, - classifiers = [ - 'Operating System :: MacOS :: MacOS X', - 'Operating System :: Microsoft :: Windows', - 'Operating System :: POSIX', - 'License :: OSI Approved :: BSD License', - 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', + name="hidapi", + version="0.10.1", + description="A Cython interface to the hidapi from https://github.com/libusb/hidapi", + author="Gary Bishop", + author_email="gb@cs.unc.edu", + maintainer="Pavol Rusnak", + maintainer_email="pavol@rusnak.io", + url="https://github.com/trezor/cython-hidapi", + package_dir={"hid": "hidapi/*"}, + classifiers=[ + "Operating System :: MacOS :: MacOS X", + "Operating System :: Microsoft :: Windows", + "Operating System :: POSIX", + "License :: OSI Approved :: BSD License", + "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", + "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", ], - ext_modules = modules, - setup_requires = ['Cython'], - install_requires = ['setuptools>=19.0'], + ext_modules=modules, + setup_requires=["Cython"], + install_requires=["setuptools>=19.0"], ) diff --git a/tests.py b/tests.py index 6ac48bc..c8310c6 100644 --- a/tests.py +++ b/tests.py @@ -8,5 +8,5 @@ def test_enumerate(self): self.assertTrue(len(hid.enumerate()) >= 0) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/try.py b/try.py index 0e9ab50..8ea672b 100644 --- a/try.py +++ b/try.py @@ -18,7 +18,7 @@ print("Opening the device") h = hid.device() - h.open(0x534c, 0x0001) # TREZOR VendorID/ProductID + h.open(0x534C, 0x0001) # TREZOR VendorID/ProductID print("Manufacturer: %s" % h.get_manufacturer_string()) print("Product: %s" % h.get_product_string()) @@ -48,7 +48,8 @@ except IOError as ex: print(ex) - print("You probably don't have the hard coded device. Update the hid.device line") - print("in this script with one from the enumeration list output above and try again.") + print("You probably don't have the hard-coded device.") + print("Update the h.open() line in this script with the one") + print("from the enumeration list output above and try again.") print("Done")