hid 1.0.5__tar.gz → 1.0.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
hid-1.0.7/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Austin Morton
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1 +1,2 @@
1
- include README.md
1
+ include README.md
2
+ include LICENSE
hid-1.0.7/PKG-INFO ADDED
@@ -0,0 +1,106 @@
1
+ Metadata-Version: 2.1
2
+ Name: hid
3
+ Version: 1.0.7
4
+ Summary: ctypes bindings for hidapi
5
+ Home-page: https://github.com/apmorton/pyhidapi
6
+ Author: Austin Morton
7
+ Author-email: amorton@juvsoft.com
8
+ License: MIT
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python
13
+ Classifier: Programming Language :: Python :: 3
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+
17
+ # Installing pyhidapi
18
+ pyhidapi is available on [PyPI](https://pypi.org/project/hid/) and can be installed using pip.
19
+ ```
20
+ pip install hid
21
+ ```
22
+
23
+ pyhidapi is dependant upon the [hidapi library](https://github.com/libusb/hidapi), which must be installed separately.
24
+
25
+ # Installing hidapi
26
+
27
+ ## Linux
28
+ Installation procedures vary depending on your distribution.
29
+
30
+ ### Arch Linux
31
+ Binary distributions are available in the community repository.
32
+
33
+ 1. Enable the community repository in `/etc/pacman.conf`
34
+ ```
35
+ [community]
36
+ Include = /etc/pacman.d/mirrorlist
37
+ ```
38
+ 2. Install hidapi
39
+ ```
40
+ pacman -Sy hidapi
41
+ ```
42
+
43
+ ### CentOS/RHEL
44
+ Binary distributions are available through [EPEL](https://fedoraproject.org/wiki/EPEL).
45
+ ```
46
+ yum install hidapi
47
+ ```
48
+
49
+ ### Fedora
50
+ Binary distributions are available.
51
+ ```
52
+ dnf install hidapi
53
+ ```
54
+
55
+ ### Ubuntu/Debian
56
+ Binary distributions are available.
57
+
58
+ ```
59
+ apt install libhidapi-hidraw0
60
+ ```
61
+ or
62
+ ```
63
+ apt install libhidapi-libusb0
64
+ ```
65
+
66
+ ### Others
67
+ Binary distributions may be available in your package repositories. If not, you can build from source as described [in the libusb/hidapi README](https://github.com/libusb/hidapi#build-instructions).
68
+
69
+ ## Windows
70
+ Installation procedure for Windows is described [in the libusb/hidapi README](https://github.com/libusb/hidapi#building-on-windows)
71
+
72
+ Binary distributions are provided by [libusb/hidapi](https://github.com/libusb/hidapi/releases)
73
+
74
+ ## OSX
75
+ There are currently no official binary distributions for Mac, so you must build hidapi yourself.
76
+
77
+ Installation instructions are described [in the libusb/hidapi README](https://github.com/libusb/hidapi#mac)
78
+
79
+ You can also use brew:
80
+ ```
81
+ brew install hidapi
82
+ ```
83
+
84
+ ## FreeBSD
85
+ Binary distributions are available.
86
+
87
+ ```
88
+ pkg install -g 'py3*-hid'
89
+ ```
90
+
91
+ # Sample usage code
92
+
93
+ The details about a HID device can be printed with following code:
94
+
95
+ ```python
96
+ import hid
97
+
98
+ vid = 0x046d # Change it for your device
99
+ pid = 0xc534 # Change it for your device
100
+
101
+ with hid.Device(vid, pid) as h:
102
+ print(f'Device manufacturer: {h.manufacturer}')
103
+ print(f'Product: {h.product}')
104
+ print(f'Serial Number: {h.serial}')
105
+ ```
106
+
@@ -1,90 +1,90 @@
1
- # Installing pyhidapi
2
- pyhidapi is available on [PyPI](https://pypi.org/project/hid/) and can be installed using pip.
3
- ```
4
- pip install hid
5
- ```
6
-
7
- pyhidapi is dependant upon the [hidapi library](https://github.com/libusb/hidapi), which must be installed separately.
8
-
9
- # Installing hidapi
10
-
11
- ## Linux
12
- Installation procedures vary depending on your distribution.
13
-
14
- ### Arch Linux
15
- Binary distributions are available in the community repository.
16
-
17
- 1. Enable the community repository in `/etc/pacman.conf`
18
- ```
19
- [community]
20
- Include = /etc/pacman.d/mirrorlist
21
- ```
22
- 2. Install hidapi
23
- ```
24
- pacman -Sy hidapi
25
- ```
26
-
27
- ### CentOS/RHEL
28
- Binary distributions are available through [EPEL](https://fedoraproject.org/wiki/EPEL).
29
- ```
30
- yum install hidapi
31
- ```
32
-
33
- ### Fedora
34
- Binary distributions are available.
35
- ```
36
- dnf install hidapi
37
- ```
38
-
39
- ### Ubuntu/Debian
40
- Binary distributions are available.
41
-
42
- ```
43
- apt install libhidapi-hidraw0
44
- ```
45
- or
46
- ```
47
- apt install libhidapi-libusb0
48
- ```
49
-
50
- ### Others
51
- Binary distributions may be available in your package repositories. If not, you can build from source as described [in the libusb/hidapi README](https://github.com/libusb/hidapi#build-instructions).
52
-
53
- ## Windows
54
- Installation procedure for Windows is described [in the libusb/hidapi README](https://github.com/libusb/hidapi#building-on-windows)
55
-
56
- Binary distributions are provided by [libusb/hidapi](https://github.com/libusb/hidapi/releases)
57
-
58
- ## OSX
59
- There are currently no official binary distributions for Mac, so you must build hidapi yourself.
60
-
61
- Installation instructions are described [in the libusb/hidapi README](https://github.com/libusb/hidapi#mac)
62
-
63
- You can also use brew:
64
- ```
65
- brew install hidapi
66
- ```
67
-
68
- ## FreeBSD
69
- Binary distributions are available.
70
-
71
- ```
72
- pkg install -g 'py3*-hid'
73
- ```
74
-
75
- # Sample usage code
76
-
77
- The details about a HID device can be printed with following code:
78
-
79
- ```python
80
- import hid
81
-
82
- vid = 0x046d # Change it for your device
83
- pid = 0xc534 # Change it for your device
84
-
85
- with hid.Device(vid, pid) as h:
86
- print(f'Device manufacturer: {h.manufacturer}')
87
- print(f'Product: {h.product}')
88
- print(f'Serial Number: {h.serial}')
89
- ```
90
-
1
+ # Installing pyhidapi
2
+ pyhidapi is available on [PyPI](https://pypi.org/project/hid/) and can be installed using pip.
3
+ ```
4
+ pip install hid
5
+ ```
6
+
7
+ pyhidapi is dependant upon the [hidapi library](https://github.com/libusb/hidapi), which must be installed separately.
8
+
9
+ # Installing hidapi
10
+
11
+ ## Linux
12
+ Installation procedures vary depending on your distribution.
13
+
14
+ ### Arch Linux
15
+ Binary distributions are available in the community repository.
16
+
17
+ 1. Enable the community repository in `/etc/pacman.conf`
18
+ ```
19
+ [community]
20
+ Include = /etc/pacman.d/mirrorlist
21
+ ```
22
+ 2. Install hidapi
23
+ ```
24
+ pacman -Sy hidapi
25
+ ```
26
+
27
+ ### CentOS/RHEL
28
+ Binary distributions are available through [EPEL](https://fedoraproject.org/wiki/EPEL).
29
+ ```
30
+ yum install hidapi
31
+ ```
32
+
33
+ ### Fedora
34
+ Binary distributions are available.
35
+ ```
36
+ dnf install hidapi
37
+ ```
38
+
39
+ ### Ubuntu/Debian
40
+ Binary distributions are available.
41
+
42
+ ```
43
+ apt install libhidapi-hidraw0
44
+ ```
45
+ or
46
+ ```
47
+ apt install libhidapi-libusb0
48
+ ```
49
+
50
+ ### Others
51
+ Binary distributions may be available in your package repositories. If not, you can build from source as described [in the libusb/hidapi README](https://github.com/libusb/hidapi#build-instructions).
52
+
53
+ ## Windows
54
+ Installation procedure for Windows is described [in the libusb/hidapi README](https://github.com/libusb/hidapi#building-on-windows)
55
+
56
+ Binary distributions are provided by [libusb/hidapi](https://github.com/libusb/hidapi/releases)
57
+
58
+ ## OSX
59
+ There are currently no official binary distributions for Mac, so you must build hidapi yourself.
60
+
61
+ Installation instructions are described [in the libusb/hidapi README](https://github.com/libusb/hidapi#mac)
62
+
63
+ You can also use brew:
64
+ ```
65
+ brew install hidapi
66
+ ```
67
+
68
+ ## FreeBSD
69
+ Binary distributions are available.
70
+
71
+ ```
72
+ pkg install -g 'py3*-hid'
73
+ ```
74
+
75
+ # Sample usage code
76
+
77
+ The details about a HID device can be printed with following code:
78
+
79
+ ```python
80
+ import hid
81
+
82
+ vid = 0x046d # Change it for your device
83
+ pid = 0xc534 # Change it for your device
84
+
85
+ with hid.Device(vid, pid) as h:
86
+ print(f'Device manufacturer: {h.manufacturer}')
87
+ print(f'Product: {h.product}')
88
+ print(f'Serial Number: {h.serial}')
89
+ ```
90
+
@@ -1,224 +1,266 @@
1
- import os
2
- import ctypes
3
- import atexit
4
-
5
- __all__ = ['HIDException', 'DeviceInfo', 'Device', 'enumerate']
6
-
7
-
8
- hidapi = None
9
- library_paths = (
10
- 'libhidapi-hidraw.so',
11
- 'libhidapi-hidraw.so.0',
12
- 'libhidapi-libusb.so',
13
- 'libhidapi-libusb.so.0',
14
- 'libhidapi-iohidmanager.so',
15
- 'libhidapi-iohidmanager.so.0',
16
- 'libhidapi.dylib',
17
- 'hidapi.dll',
18
- 'libhidapi-0.dll'
19
- )
20
-
21
- for lib in library_paths:
22
- try:
23
- hidapi = ctypes.cdll.LoadLibrary(lib)
24
- break
25
- except OSError:
26
- pass
27
- else:
28
- error = "Unable to load any of the following libraries:{}"\
29
- .format(' '.join(library_paths))
30
- raise ImportError(error)
31
-
32
-
33
- hidapi.hid_init()
34
- atexit.register(hidapi.hid_exit)
35
-
36
-
37
- class HIDException(Exception):
38
- pass
39
-
40
-
41
- class DeviceInfo(ctypes.Structure):
42
- def as_dict(self):
43
- ret = {}
44
- for name, type in self._fields_:
45
- if name == 'next':
46
- continue
47
- ret[name] = getattr(self, name, None)
48
-
49
- return ret
50
-
51
- DeviceInfo._fields_ = [
52
- ('path', ctypes.c_char_p),
53
- ('vendor_id', ctypes.c_ushort),
54
- ('product_id', ctypes.c_ushort),
55
- ('serial_number', ctypes.c_wchar_p),
56
- ('release_number', ctypes.c_ushort),
57
- ('manufacturer_string', ctypes.c_wchar_p),
58
- ('product_string', ctypes.c_wchar_p),
59
- ('usage_page', ctypes.c_ushort),
60
- ('usage', ctypes.c_ushort),
61
- ('interface_number', ctypes.c_int),
62
- ('next', ctypes.POINTER(DeviceInfo)),
63
- ]
64
-
65
- hidapi.hid_init.argtypes = []
66
- hidapi.hid_init.restype = ctypes.c_int
67
- hidapi.hid_exit.argtypes = []
68
- hidapi.hid_exit.restype = ctypes.c_int
69
- hidapi.hid_enumerate.argtypes = [ctypes.c_ushort, ctypes.c_ushort]
70
- hidapi.hid_enumerate.restype = ctypes.POINTER(DeviceInfo)
71
- hidapi.hid_free_enumeration.argtypes = [ctypes.POINTER(DeviceInfo)]
72
- hidapi.hid_free_enumeration.restype = None
73
- hidapi.hid_open.argtypes = [ctypes.c_ushort, ctypes.c_ushort, ctypes.c_wchar_p]
74
- hidapi.hid_open.restype = ctypes.c_void_p
75
- hidapi.hid_open_path.argtypes = [ctypes.c_char_p]
76
- hidapi.hid_open_path.restype = ctypes.c_void_p
77
- hidapi.hid_write.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_size_t]
78
- hidapi.hid_write.restype = ctypes.c_int
79
- hidapi.hid_read_timeout.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_size_t, ctypes.c_int]
80
- hidapi.hid_read_timeout.restype = ctypes.c_int
81
- hidapi.hid_read.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_size_t]
82
- hidapi.hid_read.restype = ctypes.c_int
83
- hidapi.hid_get_input_report.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_size_t]
84
- hidapi.hid_get_input_report.restype = ctypes.c_int
85
- hidapi.hid_set_nonblocking.argtypes = [ctypes.c_void_p, ctypes.c_int]
86
- hidapi.hid_set_nonblocking.restype = ctypes.c_int
87
- hidapi.hid_send_feature_report.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_int]
88
- hidapi.hid_send_feature_report.restype = ctypes.c_int
89
- hidapi.hid_get_feature_report.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_size_t]
90
- hidapi.hid_get_feature_report.restype = ctypes.c_int
91
- hidapi.hid_close.argtypes = [ctypes.c_void_p]
92
- hidapi.hid_close.restype = None
93
- hidapi.hid_get_manufacturer_string.argtypes = [ctypes.c_void_p, ctypes.c_wchar_p, ctypes.c_size_t]
94
- hidapi.hid_get_manufacturer_string.restype = ctypes.c_int
95
- hidapi.hid_get_product_string.argtypes = [ctypes.c_void_p, ctypes.c_wchar_p, ctypes.c_size_t]
96
- hidapi.hid_get_product_string.restype = ctypes.c_int
97
- hidapi.hid_get_serial_number_string.argtypes = [ctypes.c_void_p, ctypes.c_wchar_p, ctypes.c_size_t]
98
- hidapi.hid_get_serial_number_string.restype = ctypes.c_int
99
- hidapi.hid_get_indexed_string.argtypes = [ctypes.c_void_p, ctypes.c_int, ctypes.c_wchar_p, ctypes.c_size_t]
100
- hidapi.hid_get_indexed_string.restype = ctypes.c_int
101
- hidapi.hid_error.argtypes = [ctypes.c_void_p]
102
- hidapi.hid_error.restype = ctypes.c_wchar_p
103
-
104
-
105
- def enumerate(vid=0, pid=0):
106
- ret = []
107
- info = hidapi.hid_enumerate(vid, pid)
108
- c = info
109
-
110
- while c:
111
- ret.append(c.contents.as_dict())
112
- c = c.contents.next
113
-
114
- hidapi.hid_free_enumeration(info)
115
-
116
- return ret
117
-
118
-
119
- class Device(object):
120
- def __init__(self, vid=None, pid=None, serial=None, path=None):
121
- if path:
122
- self.__dev = hidapi.hid_open_path(path)
123
- elif serial:
124
- serial = ctypes.create_unicode_buffer(serial)
125
- self.__dev = hidapi.hid_open(vid, pid, serial)
126
- elif vid and pid:
127
- self.__dev = hidapi.hid_open(vid, pid, None)
128
- else:
129
- raise ValueError('specify vid/pid or path')
130
-
131
- if not self.__dev:
132
- raise HIDException('unable to open device')
133
-
134
- def __enter__(self):
135
- return self
136
-
137
- def __exit__(self, exc_type, exc_value, exc_traceback):
138
- self.close()
139
-
140
- def __hidcall(self, function, *args, **kwargs):
141
- if not self.__dev:
142
- raise HIDException('device closed')
143
-
144
- ret = function(*args, **kwargs)
145
-
146
- if ret == -1:
147
- err = hidapi.hid_error(self.__dev)
148
- raise HIDException(err)
149
- return ret
150
-
151
- def __readstring(self, function, max_length=255):
152
- buf = ctypes.create_unicode_buffer(max_length)
153
- self.__hidcall(function, self.__dev, buf, max_length)
154
- return buf.value
155
-
156
- def write(self, data):
157
- return self.__hidcall(hidapi.hid_write, self.__dev, data, len(data))
158
-
159
- def read(self, size, timeout=None):
160
- data = ctypes.create_string_buffer(size)
161
-
162
- if timeout is None:
163
- size = self.__hidcall(hidapi.hid_read, self.__dev, data, size)
164
- else:
165
- size = self.__hidcall(
166
- hidapi.hid_read_timeout, self.__dev, data, size, timeout)
167
-
168
- return data.raw[:size]
169
-
170
- def get_input_report(self, report_id, size):
171
- data = ctypes.create_string_buffer(size)
172
-
173
- # Pass the id of the report to be read.
174
- data[0] = bytearray((report_id,))
175
-
176
- size = self.__hidcall(
177
- hidapi.hid_get_input_report, self.__dev, data, size)
178
- return data.raw[:size]
179
-
180
- def send_feature_report(self, data):
181
- return self.__hidcall(hidapi.hid_send_feature_report,
182
- self.__dev, data, len(data))
183
-
184
- def get_feature_report(self, report_id, size):
185
- data = ctypes.create_string_buffer(size)
186
-
187
- # Pass the id of the report to be read.
188
- data[0] = bytearray((report_id,))
189
-
190
- size = self.__hidcall(
191
- hidapi.hid_get_feature_report, self.__dev, data, size)
192
- return data.raw[:size]
193
-
194
- def close(self):
195
- if self.__dev:
196
- hidapi.hid_close(self.__dev)
197
- self.__dev = None
198
-
199
- @property
200
- def nonblocking(self):
201
- return getattr(self, '_nonblocking', 0)
202
-
203
- @nonblocking.setter
204
- def nonblocking(self, value):
205
- self.__hidcall(hidapi.hid_set_nonblocking, self.__dev, value)
206
- setattr(self, '_nonblocking', value)
207
-
208
- @property
209
- def manufacturer(self):
210
- return self.__readstring(hidapi.hid_get_manufacturer_string)
211
-
212
- @property
213
- def product(self):
214
- return self.__readstring(hidapi.hid_get_product_string)
215
-
216
- @property
217
- def serial(self):
218
- return self.__readstring(hidapi.hid_get_serial_number_string)
219
-
220
- def get_indexed_string(self, index, max_length=255):
221
- buf = ctypes.create_unicode_buffer(max_length)
222
- self.__hidcall(hidapi.hid_get_indexed_string,
223
- self.__dev, index, buf, max_length)
224
- return buf.value
1
+ import os
2
+ import ctypes
3
+ import atexit
4
+ import enum
5
+
6
+ __all__ = ['HIDException', 'DeviceInfo', 'Device', 'enumerate', 'BusType']
7
+
8
+
9
+ hidapi = None
10
+ library_paths = (
11
+ 'libhidapi-hidraw.so',
12
+ 'libhidapi-hidraw.so.0',
13
+ 'libhidapi-libusb.so',
14
+ 'libhidapi-libusb.so.0',
15
+ 'libhidapi-iohidmanager.so',
16
+ 'libhidapi-iohidmanager.so.0',
17
+ 'libhidapi.dylib',
18
+ 'hidapi.dll',
19
+ 'libhidapi-0.dll'
20
+ )
21
+
22
+ for lib in library_paths:
23
+ try:
24
+ hidapi = ctypes.cdll.LoadLibrary(lib)
25
+ break
26
+ except OSError:
27
+ pass
28
+ else:
29
+ error = "Unable to load any of the following libraries:{}"\
30
+ .format(' '.join(library_paths))
31
+ raise ImportError(error)
32
+
33
+
34
+ hidapi.hid_init()
35
+ atexit.register(hidapi.hid_exit)
36
+
37
+
38
+ class HIDException(Exception):
39
+ pass
40
+
41
+ class APIVersion(ctypes.Structure):
42
+ _fields_ = [
43
+ ('major', ctypes.c_int),
44
+ ('minor', ctypes.c_int),
45
+ ('patch', ctypes.c_int),
46
+ ]
47
+
48
+ try:
49
+ hidapi.hid_version.argtypes = []
50
+ hidapi.hid_version.restype = ctypes.POINTER(APIVersion)
51
+
52
+ version = hidapi.hid_version()
53
+ version = (
54
+ version.contents.major,
55
+ version.contents.minor,
56
+ version.contents.patch,
57
+ )
58
+ except AttributeError:
59
+ #
60
+ # hid_version API was added in
61
+ # https://github.com/libusb/hidapi/commit/8f72236099290345928e646d2f2c48f0187ac4af
62
+ # so if it is missing we are dealing with hidapi 0.8.0 or older
63
+ #
64
+ version = (0, 8, 0)
65
+
66
+ if version >= (0, 13, 0):
67
+ bus_type = [
68
+ ('bus_type', ctypes.c_int),
69
+ ]
70
+ else:
71
+ bus_type = []
72
+
73
+ class BusType(enum.Enum):
74
+ UNKNOWN = 0x00
75
+ USB = 0x01
76
+ BLUETOOTH = 0x02
77
+ I2C = 0x03
78
+ SPI = 0x04
79
+
80
+ class DeviceInfo(ctypes.Structure):
81
+ def as_dict(self):
82
+ ret = {}
83
+ for name, type in self._fields_:
84
+ if name == 'next':
85
+ continue
86
+ ret[name] = getattr(self, name, None)
87
+
88
+ if name == 'bus_type':
89
+ ret[name] = BusType(ret[name])
90
+
91
+ return ret
92
+
93
+ DeviceInfo._fields_ = [
94
+ ('path', ctypes.c_char_p),
95
+ ('vendor_id', ctypes.c_ushort),
96
+ ('product_id', ctypes.c_ushort),
97
+ ('serial_number', ctypes.c_wchar_p),
98
+ ('release_number', ctypes.c_ushort),
99
+ ('manufacturer_string', ctypes.c_wchar_p),
100
+ ('product_string', ctypes.c_wchar_p),
101
+ ('usage_page', ctypes.c_ushort),
102
+ ('usage', ctypes.c_ushort),
103
+ ('interface_number', ctypes.c_int),
104
+ ('next', ctypes.POINTER(DeviceInfo)),
105
+ ] + bus_type
106
+
107
+ hidapi.hid_init.argtypes = []
108
+ hidapi.hid_init.restype = ctypes.c_int
109
+ hidapi.hid_exit.argtypes = []
110
+ hidapi.hid_exit.restype = ctypes.c_int
111
+ hidapi.hid_enumerate.argtypes = [ctypes.c_ushort, ctypes.c_ushort]
112
+ hidapi.hid_enumerate.restype = ctypes.POINTER(DeviceInfo)
113
+ hidapi.hid_free_enumeration.argtypes = [ctypes.POINTER(DeviceInfo)]
114
+ hidapi.hid_free_enumeration.restype = None
115
+ hidapi.hid_open.argtypes = [ctypes.c_ushort, ctypes.c_ushort, ctypes.c_wchar_p]
116
+ hidapi.hid_open.restype = ctypes.c_void_p
117
+ hidapi.hid_open_path.argtypes = [ctypes.c_char_p]
118
+ hidapi.hid_open_path.restype = ctypes.c_void_p
119
+ hidapi.hid_write.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_size_t]
120
+ hidapi.hid_write.restype = ctypes.c_int
121
+ hidapi.hid_read_timeout.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_size_t, ctypes.c_int]
122
+ hidapi.hid_read_timeout.restype = ctypes.c_int
123
+ hidapi.hid_read.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_size_t]
124
+ hidapi.hid_read.restype = ctypes.c_int
125
+ hidapi.hid_get_input_report.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_size_t]
126
+ hidapi.hid_get_input_report.restype = ctypes.c_int
127
+ hidapi.hid_set_nonblocking.argtypes = [ctypes.c_void_p, ctypes.c_int]
128
+ hidapi.hid_set_nonblocking.restype = ctypes.c_int
129
+ hidapi.hid_send_feature_report.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_int]
130
+ hidapi.hid_send_feature_report.restype = ctypes.c_int
131
+ hidapi.hid_get_feature_report.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_size_t]
132
+ hidapi.hid_get_feature_report.restype = ctypes.c_int
133
+ hidapi.hid_close.argtypes = [ctypes.c_void_p]
134
+ hidapi.hid_close.restype = None
135
+ hidapi.hid_get_manufacturer_string.argtypes = [ctypes.c_void_p, ctypes.c_wchar_p, ctypes.c_size_t]
136
+ hidapi.hid_get_manufacturer_string.restype = ctypes.c_int
137
+ hidapi.hid_get_product_string.argtypes = [ctypes.c_void_p, ctypes.c_wchar_p, ctypes.c_size_t]
138
+ hidapi.hid_get_product_string.restype = ctypes.c_int
139
+ hidapi.hid_get_serial_number_string.argtypes = [ctypes.c_void_p, ctypes.c_wchar_p, ctypes.c_size_t]
140
+ hidapi.hid_get_serial_number_string.restype = ctypes.c_int
141
+ hidapi.hid_get_indexed_string.argtypes = [ctypes.c_void_p, ctypes.c_int, ctypes.c_wchar_p, ctypes.c_size_t]
142
+ hidapi.hid_get_indexed_string.restype = ctypes.c_int
143
+ hidapi.hid_error.argtypes = [ctypes.c_void_p]
144
+ hidapi.hid_error.restype = ctypes.c_wchar_p
145
+
146
+
147
+ def enumerate(vid=0, pid=0):
148
+ ret = []
149
+ info = hidapi.hid_enumerate(vid, pid)
150
+ c = info
151
+
152
+ while c:
153
+ ret.append(c.contents.as_dict())
154
+ c = c.contents.next
155
+
156
+ hidapi.hid_free_enumeration(info)
157
+
158
+ return ret
159
+
160
+
161
+ class Device(object):
162
+ def __init__(self, vid=None, pid=None, serial=None, path=None):
163
+ if path:
164
+ self.__dev = hidapi.hid_open_path(path)
165
+ elif serial:
166
+ serial = ctypes.create_unicode_buffer(serial)
167
+ self.__dev = hidapi.hid_open(vid, pid, serial)
168
+ elif vid and pid is not None:
169
+ self.__dev = hidapi.hid_open(vid, pid, None)
170
+ else:
171
+ raise ValueError('specify vid/pid or path')
172
+
173
+ if not self.__dev:
174
+ raise HIDException('unable to open device')
175
+
176
+ def __enter__(self):
177
+ return self
178
+
179
+ def __exit__(self, exc_type, exc_value, exc_traceback):
180
+ self.close()
181
+
182
+ def __hidcall(self, function, *args, **kwargs):
183
+ if not self.__dev:
184
+ raise HIDException('device closed')
185
+
186
+ ret = function(*args, **kwargs)
187
+
188
+ if ret == -1:
189
+ err = hidapi.hid_error(self.__dev)
190
+ raise HIDException(err)
191
+ return ret
192
+
193
+ def __readstring(self, function, max_length=255):
194
+ buf = ctypes.create_unicode_buffer(max_length)
195
+ self.__hidcall(function, self.__dev, buf, max_length)
196
+ return buf.value
197
+
198
+ def write(self, data):
199
+ return self.__hidcall(hidapi.hid_write, self.__dev, data, len(data))
200
+
201
+ def read(self, size, timeout=None):
202
+ data = ctypes.create_string_buffer(size)
203
+
204
+ if timeout is None:
205
+ size = self.__hidcall(hidapi.hid_read, self.__dev, data, size)
206
+ else:
207
+ size = self.__hidcall(
208
+ hidapi.hid_read_timeout, self.__dev, data, size, timeout)
209
+
210
+ return data.raw[:size]
211
+
212
+ def get_input_report(self, report_id, size):
213
+ data = ctypes.create_string_buffer(size)
214
+
215
+ # Pass the id of the report to be read.
216
+ data[0] = bytearray((report_id,))
217
+
218
+ size = self.__hidcall(
219
+ hidapi.hid_get_input_report, self.__dev, data, size)
220
+ return data.raw[:size]
221
+
222
+ def send_feature_report(self, data):
223
+ return self.__hidcall(hidapi.hid_send_feature_report,
224
+ self.__dev, data, len(data))
225
+
226
+ def get_feature_report(self, report_id, size):
227
+ data = ctypes.create_string_buffer(size)
228
+
229
+ # Pass the id of the report to be read.
230
+ data[0] = bytearray((report_id,))
231
+
232
+ size = self.__hidcall(
233
+ hidapi.hid_get_feature_report, self.__dev, data, size)
234
+ return data.raw[:size]
235
+
236
+ def close(self):
237
+ if self.__dev:
238
+ hidapi.hid_close(self.__dev)
239
+ self.__dev = None
240
+
241
+ @property
242
+ def nonblocking(self):
243
+ return getattr(self, '_nonblocking', 0)
244
+
245
+ @nonblocking.setter
246
+ def nonblocking(self, value):
247
+ self.__hidcall(hidapi.hid_set_nonblocking, self.__dev, value)
248
+ setattr(self, '_nonblocking', value)
249
+
250
+ @property
251
+ def manufacturer(self):
252
+ return self.__readstring(hidapi.hid_get_manufacturer_string)
253
+
254
+ @property
255
+ def product(self):
256
+ return self.__readstring(hidapi.hid_get_product_string)
257
+
258
+ @property
259
+ def serial(self):
260
+ return self.__readstring(hidapi.hid_get_serial_number_string)
261
+
262
+ def get_indexed_string(self, index, max_length=255):
263
+ buf = ctypes.create_unicode_buffer(max_length)
264
+ self.__hidcall(hidapi.hid_get_indexed_string,
265
+ self.__dev, index, buf, max_length)
266
+ return buf.value
@@ -0,0 +1,106 @@
1
+ Metadata-Version: 2.1
2
+ Name: hid
3
+ Version: 1.0.7
4
+ Summary: ctypes bindings for hidapi
5
+ Home-page: https://github.com/apmorton/pyhidapi
6
+ Author: Austin Morton
7
+ Author-email: amorton@juvsoft.com
8
+ License: MIT
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python
13
+ Classifier: Programming Language :: Python :: 3
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+
17
+ # Installing pyhidapi
18
+ pyhidapi is available on [PyPI](https://pypi.org/project/hid/) and can be installed using pip.
19
+ ```
20
+ pip install hid
21
+ ```
22
+
23
+ pyhidapi is dependant upon the [hidapi library](https://github.com/libusb/hidapi), which must be installed separately.
24
+
25
+ # Installing hidapi
26
+
27
+ ## Linux
28
+ Installation procedures vary depending on your distribution.
29
+
30
+ ### Arch Linux
31
+ Binary distributions are available in the community repository.
32
+
33
+ 1. Enable the community repository in `/etc/pacman.conf`
34
+ ```
35
+ [community]
36
+ Include = /etc/pacman.d/mirrorlist
37
+ ```
38
+ 2. Install hidapi
39
+ ```
40
+ pacman -Sy hidapi
41
+ ```
42
+
43
+ ### CentOS/RHEL
44
+ Binary distributions are available through [EPEL](https://fedoraproject.org/wiki/EPEL).
45
+ ```
46
+ yum install hidapi
47
+ ```
48
+
49
+ ### Fedora
50
+ Binary distributions are available.
51
+ ```
52
+ dnf install hidapi
53
+ ```
54
+
55
+ ### Ubuntu/Debian
56
+ Binary distributions are available.
57
+
58
+ ```
59
+ apt install libhidapi-hidraw0
60
+ ```
61
+ or
62
+ ```
63
+ apt install libhidapi-libusb0
64
+ ```
65
+
66
+ ### Others
67
+ Binary distributions may be available in your package repositories. If not, you can build from source as described [in the libusb/hidapi README](https://github.com/libusb/hidapi#build-instructions).
68
+
69
+ ## Windows
70
+ Installation procedure for Windows is described [in the libusb/hidapi README](https://github.com/libusb/hidapi#building-on-windows)
71
+
72
+ Binary distributions are provided by [libusb/hidapi](https://github.com/libusb/hidapi/releases)
73
+
74
+ ## OSX
75
+ There are currently no official binary distributions for Mac, so you must build hidapi yourself.
76
+
77
+ Installation instructions are described [in the libusb/hidapi README](https://github.com/libusb/hidapi#mac)
78
+
79
+ You can also use brew:
80
+ ```
81
+ brew install hidapi
82
+ ```
83
+
84
+ ## FreeBSD
85
+ Binary distributions are available.
86
+
87
+ ```
88
+ pkg install -g 'py3*-hid'
89
+ ```
90
+
91
+ # Sample usage code
92
+
93
+ The details about a HID device can be printed with following code:
94
+
95
+ ```python
96
+ import hid
97
+
98
+ vid = 0x046d # Change it for your device
99
+ pid = 0xc534 # Change it for your device
100
+
101
+ with hid.Device(vid, pid) as h:
102
+ print(f'Device manufacturer: {h.manufacturer}')
103
+ print(f'Product: {h.product}')
104
+ print(f'Serial Number: {h.serial}')
105
+ ```
106
+
@@ -1,3 +1,4 @@
1
+ LICENSE
1
2
  MANIFEST.in
2
3
  README.md
3
4
  setup.cfg
File without changes
File without changes
File without changes
@@ -1,33 +1,31 @@
1
- from setuptools import setup, find_packages
2
- import os
3
-
4
- here = os.path.abspath(os.path.dirname(__file__))
5
- README = open(os.path.join(here, 'README.md')).read()
6
-
7
-
8
- version = '1.0.5'
9
-
10
- setup(
11
- name='hid',
12
- version=version,
13
- description='ctypes bindings for hidapi',
14
- long_description=README,
15
- long_description_content_type='text/markdown',
16
- classifiers=[
17
- 'Intended Audience :: Developers',
18
- 'License :: OSI Approved :: MIT License',
19
- 'Operating System :: OS Independent',
20
- 'Programming Language :: Python',
21
- 'Programming Language :: Python :: 2.6',
22
- 'Programming Language :: Python :: 2.7',
23
- 'Programming Language :: Python :: 3',
24
- ],
25
- keywords='',
26
- author='Austin Morton',
27
- author_email='amorton@juvsoft.com',
28
- url='https://github.com/apmorton/pyhidapi',
29
- license='MIT',
30
- packages=find_packages(),
31
- zip_safe=False,
32
- test_suite='nose.collector'
33
- )
1
+ from setuptools import setup, find_packages
2
+ import os
3
+
4
+ here = os.path.abspath(os.path.dirname(__file__))
5
+ README = open(os.path.join(here, 'README.md')).read()
6
+
7
+
8
+ version = '1.0.7'
9
+
10
+ setup(
11
+ name='hid',
12
+ version=version,
13
+ description='ctypes bindings for hidapi',
14
+ long_description=README,
15
+ long_description_content_type='text/markdown',
16
+ classifiers=[
17
+ 'Intended Audience :: Developers',
18
+ 'License :: OSI Approved :: MIT License',
19
+ 'Operating System :: OS Independent',
20
+ 'Programming Language :: Python',
21
+ 'Programming Language :: Python :: 3',
22
+ ],
23
+ keywords='',
24
+ author='Austin Morton',
25
+ author_email='amorton@juvsoft.com',
26
+ url='https://github.com/apmorton/pyhidapi',
27
+ license='MIT',
28
+ packages=find_packages(),
29
+ zip_safe=False,
30
+ test_suite='nose.collector'
31
+ )
hid-1.0.5/PKG-INFO DELETED
@@ -1,108 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: hid
3
- Version: 1.0.5
4
- Summary: ctypes bindings for hidapi
5
- Home-page: https://github.com/apmorton/pyhidapi
6
- Author: Austin Morton
7
- Author-email: amorton@juvsoft.com
8
- License: MIT
9
- Description: # Installing pyhidapi
10
- pyhidapi is available on [PyPI](https://pypi.org/project/hid/) and can be installed using pip.
11
- ```
12
- pip install hid
13
- ```
14
-
15
- pyhidapi is dependant upon the [hidapi library](https://github.com/libusb/hidapi), which must be installed separately.
16
-
17
- # Installing hidapi
18
-
19
- ## Linux
20
- Installation procedures vary depending on your distribution.
21
-
22
- ### Arch Linux
23
- Binary distributions are available in the community repository.
24
-
25
- 1. Enable the community repository in `/etc/pacman.conf`
26
- ```
27
- [community]
28
- Include = /etc/pacman.d/mirrorlist
29
- ```
30
- 2. Install hidapi
31
- ```
32
- pacman -Sy hidapi
33
- ```
34
-
35
- ### CentOS/RHEL
36
- Binary distributions are available through [EPEL](https://fedoraproject.org/wiki/EPEL).
37
- ```
38
- yum install hidapi
39
- ```
40
-
41
- ### Fedora
42
- Binary distributions are available.
43
- ```
44
- dnf install hidapi
45
- ```
46
-
47
- ### Ubuntu/Debian
48
- Binary distributions are available.
49
-
50
- ```
51
- apt install libhidapi-hidraw0
52
- ```
53
- or
54
- ```
55
- apt install libhidapi-libusb0
56
- ```
57
-
58
- ### Others
59
- Binary distributions may be available in your package repositories. If not, you can build from source as described [in the libusb/hidapi README](https://github.com/libusb/hidapi#build-instructions).
60
-
61
- ## Windows
62
- Installation procedure for Windows is described [in the libusb/hidapi README](https://github.com/libusb/hidapi#building-on-windows)
63
-
64
- Binary distributions are provided by [libusb/hidapi](https://github.com/libusb/hidapi/releases)
65
-
66
- ## OSX
67
- There are currently no official binary distributions for Mac, so you must build hidapi yourself.
68
-
69
- Installation instructions are described [in the libusb/hidapi README](https://github.com/libusb/hidapi#mac)
70
-
71
- You can also use brew:
72
- ```
73
- brew install hidapi
74
- ```
75
-
76
- ## FreeBSD
77
- Binary distributions are available.
78
-
79
- ```
80
- pkg install -g 'py3*-hid'
81
- ```
82
-
83
- # Sample usage code
84
-
85
- The details about a HID device can be printed with following code:
86
-
87
- ```python
88
- import hid
89
-
90
- vid = 0x046d # Change it for your device
91
- pid = 0xc534 # Change it for your device
92
-
93
- with hid.Device(vid, pid) as h:
94
- print(f'Device manufacturer: {h.manufacturer}')
95
- print(f'Product: {h.product}')
96
- print(f'Serial Number: {h.serial}')
97
- ```
98
-
99
-
100
- Platform: UNKNOWN
101
- Classifier: Intended Audience :: Developers
102
- Classifier: License :: OSI Approved :: MIT License
103
- Classifier: Operating System :: OS Independent
104
- Classifier: Programming Language :: Python
105
- Classifier: Programming Language :: Python :: 2.6
106
- Classifier: Programming Language :: Python :: 2.7
107
- Classifier: Programming Language :: Python :: 3
108
- Description-Content-Type: text/markdown
@@ -1,108 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: hid
3
- Version: 1.0.5
4
- Summary: ctypes bindings for hidapi
5
- Home-page: https://github.com/apmorton/pyhidapi
6
- Author: Austin Morton
7
- Author-email: amorton@juvsoft.com
8
- License: MIT
9
- Description: # Installing pyhidapi
10
- pyhidapi is available on [PyPI](https://pypi.org/project/hid/) and can be installed using pip.
11
- ```
12
- pip install hid
13
- ```
14
-
15
- pyhidapi is dependant upon the [hidapi library](https://github.com/libusb/hidapi), which must be installed separately.
16
-
17
- # Installing hidapi
18
-
19
- ## Linux
20
- Installation procedures vary depending on your distribution.
21
-
22
- ### Arch Linux
23
- Binary distributions are available in the community repository.
24
-
25
- 1. Enable the community repository in `/etc/pacman.conf`
26
- ```
27
- [community]
28
- Include = /etc/pacman.d/mirrorlist
29
- ```
30
- 2. Install hidapi
31
- ```
32
- pacman -Sy hidapi
33
- ```
34
-
35
- ### CentOS/RHEL
36
- Binary distributions are available through [EPEL](https://fedoraproject.org/wiki/EPEL).
37
- ```
38
- yum install hidapi
39
- ```
40
-
41
- ### Fedora
42
- Binary distributions are available.
43
- ```
44
- dnf install hidapi
45
- ```
46
-
47
- ### Ubuntu/Debian
48
- Binary distributions are available.
49
-
50
- ```
51
- apt install libhidapi-hidraw0
52
- ```
53
- or
54
- ```
55
- apt install libhidapi-libusb0
56
- ```
57
-
58
- ### Others
59
- Binary distributions may be available in your package repositories. If not, you can build from source as described [in the libusb/hidapi README](https://github.com/libusb/hidapi#build-instructions).
60
-
61
- ## Windows
62
- Installation procedure for Windows is described [in the libusb/hidapi README](https://github.com/libusb/hidapi#building-on-windows)
63
-
64
- Binary distributions are provided by [libusb/hidapi](https://github.com/libusb/hidapi/releases)
65
-
66
- ## OSX
67
- There are currently no official binary distributions for Mac, so you must build hidapi yourself.
68
-
69
- Installation instructions are described [in the libusb/hidapi README](https://github.com/libusb/hidapi#mac)
70
-
71
- You can also use brew:
72
- ```
73
- brew install hidapi
74
- ```
75
-
76
- ## FreeBSD
77
- Binary distributions are available.
78
-
79
- ```
80
- pkg install -g 'py3*-hid'
81
- ```
82
-
83
- # Sample usage code
84
-
85
- The details about a HID device can be printed with following code:
86
-
87
- ```python
88
- import hid
89
-
90
- vid = 0x046d # Change it for your device
91
- pid = 0xc534 # Change it for your device
92
-
93
- with hid.Device(vid, pid) as h:
94
- print(f'Device manufacturer: {h.manufacturer}')
95
- print(f'Product: {h.product}')
96
- print(f'Serial Number: {h.serial}')
97
- ```
98
-
99
-
100
- Platform: UNKNOWN
101
- Classifier: Intended Audience :: Developers
102
- Classifier: License :: OSI Approved :: MIT License
103
- Classifier: Operating System :: OS Independent
104
- Classifier: Programming Language :: Python
105
- Classifier: Programming Language :: Python :: 2.6
106
- Classifier: Programming Language :: Python :: 2.7
107
- Classifier: Programming Language :: Python :: 3
108
- Description-Content-Type: text/markdown