ifxusb010 0.1.4__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.
@@ -0,0 +1,2 @@
1
+ .env*/
2
+ __pycache__/
@@ -0,0 +1 @@
1
+ 3.12
@@ -0,0 +1,207 @@
1
+ Metadata-Version: 2.4
2
+ Name: ifxusb010
3
+ Version: 0.1.4
4
+ Summary: python for Infineon USB010
5
+ Author-email: a9202507 <a9202507@gmail.com>
6
+ Requires-Python: >=3.12
7
+ Requires-Dist: bitarray>=3.8.0
8
+ Requires-Dist: libusb-package>=1.0.26.3
9
+ Requires-Dist: pyusb>=1.3.1
10
+ Requires-Dist: pywinusb>=0.4.2
11
+ Requires-Dist: wmi>=1.5.1
12
+ Provides-Extra: dev
13
+ Requires-Dist: mypy>=1.19.1; extra == 'dev'
14
+ Description-Content-Type: text/markdown
15
+
16
+ # ifxusb010
17
+
18
+ Python library for Infineon USB010 I2C dongle.
19
+
20
+ ## Installation
21
+
22
+ ```bash
23
+ pip install ifxusb010
24
+ ```
25
+
26
+ Or install from TestPyPI:
27
+
28
+ ```bash
29
+ pip install -i https://test.pypi.org/simple/ ifxusb010
30
+ ```
31
+
32
+ > **Note:** Windows 使用者需先用 [Zadig](https://zadig.akeo.ie/) 將 USB010 dongle 的驅動程式替換為 WinUSB。
33
+
34
+ ---
35
+
36
+ ## Quick Start
37
+
38
+ ```python
39
+ import ifxusb010
40
+
41
+ # 連接 USB010 dongle
42
+ dev = ifxusb010.connect_device()
43
+ ```
44
+
45
+ ---
46
+
47
+ ## API Reference
48
+
49
+ ### `connect_device(vendor_id=0x058B, product_id=0x0230)`
50
+
51
+ 連接 USB010 dongle,回傳 USB device 物件。
52
+
53
+ | 參數 | 型別 | 預設值 | 說明 |
54
+ |------|------|--------|------|
55
+ | `vendor_id` | int | `0x058B` | USB Vendor ID |
56
+ | `product_id` | int | `0x0230` | USB Product ID |
57
+
58
+ **回傳值:** `usb.core.Device` 物件
59
+
60
+ ---
61
+
62
+ ### `search_I2C(dev, start_address, end_address, debug, enable_8bit_mode)`
63
+
64
+ 掃描 I2C bus 上的裝置。
65
+
66
+ | 參數 | 型別 | 預設值 | 說明 |
67
+ |------|------|--------|------|
68
+ | `dev` | Device | `None` | USB device 物件,`None` 會自動連接 |
69
+ | `start_address` | int | `0x20` | 掃描起始地址 (8-bit) |
70
+ | `end_address` | int | `0xFE` | 掃描結束地址 (8-bit) |
71
+ | `debug` | bool | `False` | 印出 debug 資訊 |
72
+ | `enable_8bit_mode` | bool | `True` | `True` 回傳 8-bit 地址,`False` 回傳 7-bit 地址 |
73
+
74
+ **回傳值:** `list` — 找到的裝置地址列表
75
+
76
+ ```python
77
+ dev = ifxusb010.connect_device()
78
+ devices = ifxusb010.search_I2C(dev=dev)
79
+ # avaliable device found at 8bits address 0x40
80
+ # devices = [0x40]
81
+ ```
82
+
83
+ ---
84
+
85
+ ### `multiReadWriteFunction(dev, device_address, write_command_code_list, read_number_length, debug)`
86
+
87
+ 通用 I2C 讀寫函式,支援**純寫入**和**寫入後讀取**兩種模式。
88
+
89
+ | 參數 | 型別 | 預設值 | 說明 |
90
+ |------|------|--------|------|
91
+ | `dev` | Device | `None` | USB device 物件,`None` 會自動連接 |
92
+ | `device_address` | int | `0x40` | I2C 裝置寫地址 (8-bit,偶數) |
93
+ | `write_command_code_list` | list | `None` | 要寫入的資料列表 |
94
+ | `read_number_length` | int | `0` | 要讀取的 byte 數,`0` 表示純寫入 |
95
+ | `debug` | bool | `False` | 印出 debug 資訊 |
96
+
97
+ **回傳值:**
98
+
99
+ ```python
100
+ {
101
+ "transactionErrorCode": int, # 0 表示成功
102
+ "readData": list # 讀回的資料(純寫入時為空列表 [])
103
+ }
104
+ ```
105
+
106
+ #### 模式說明
107
+
108
+ | `read_number_length` | 模式 | I2C 地址 | 行為 |
109
+ |---|---|---|---|
110
+ | `0` | 純寫入 | 偶數地址 (e.g. `0x40`) | 只寫入資料,不讀回 |
111
+ | `> 0` | 寫入 + 讀取 | 奇數地址 (e.g. `0x41`) | 寫入後讀取指定數量的 byte |
112
+
113
+ #### 範例 1:純寫入 (Write Only)
114
+
115
+ ```python
116
+ import ifxusb010
117
+
118
+ dev = ifxusb010.connect_device()
119
+
120
+ # 寫入 6 bytes 到 I2C 裝置 0x40
121
+ ifxusb010.multiReadWriteFunction(
122
+ dev=dev,
123
+ device_address=0x40,
124
+ write_command_code_list=[0xFD, 0x04, 0x00, 0x00, 0x00, 0x00],
125
+ read_number_length=0
126
+ )
127
+ # I2C write to 0x40 success
128
+ ```
129
+
130
+ #### 範例 2:寫入後讀取 (Write + Read)
131
+
132
+ ```python
133
+ import ifxusb010
134
+
135
+ dev = ifxusb010.connect_device()
136
+
137
+ # 寫入 1 byte (register address),然後讀回 5 bytes
138
+ result = ifxusb010.multiReadWriteFunction(
139
+ dev=dev,
140
+ device_address=0x40,
141
+ write_command_code_list=[0xFD],
142
+ read_number_length=5
143
+ )
144
+
145
+ print(result["transactionErrorCode"]) # 0 = 成功
146
+ print([hex(x) for x in result["readData"]])
147
+ # ['0x4', '0xf9', '0x57', '0xe9', '0x73']
148
+ ```
149
+
150
+ #### 範例 3:連續多筆 I2C 操作
151
+
152
+ 共用同一個 `dev` 物件,連續執行多筆 I2C 指令:
153
+
154
+ ```python
155
+ import ifxusb010
156
+
157
+ dev = ifxusb010.connect_device()
158
+
159
+ # Step 1: 寫入設定暫存器
160
+ ifxusb010.multiReadWriteFunction(
161
+ dev=dev,
162
+ device_address=0x40,
163
+ write_command_code_list=[0xFD, 0x04, 0x00, 0x00, 0x00, 0x00],
164
+ read_number_length=0
165
+ )
166
+
167
+ # Step 2: 寫入觸發指令
168
+ ifxusb010.multiReadWriteFunction(
169
+ dev=dev,
170
+ device_address=0x40,
171
+ write_command_code_list=[0xFE, 0x2D],
172
+ read_number_length=0
173
+ )
174
+
175
+ # Step 3: 讀回結果 (5 bytes)
176
+ result = ifxusb010.multiReadWriteFunction(
177
+ dev=dev,
178
+ device_address=0x40,
179
+ write_command_code_list=[0xFD],
180
+ read_number_length=5
181
+ )
182
+
183
+ if result["transactionErrorCode"] == 0:
184
+ print(f"讀回的資料: {[hex(x) for x in result['readData']]}")
185
+ else:
186
+ print(f"交易失敗,錯誤碼: {result['transactionErrorCode']}")
187
+ ```
188
+
189
+ ---
190
+
191
+ ### `mrw(dev, device_address, data, debug)`
192
+
193
+ 簡化版的寫入函式,內部呼叫 `multiReadWriteFunction`。
194
+
195
+ | 參數 | 型別 | 預設值 | 說明 |
196
+ |------|------|--------|------|
197
+ | `dev` | Device | `None` | USB device 物件 |
198
+ | `device_address` | int | `0x40` | I2C 裝置寫地址 (8-bit) |
199
+ | `data` | list | `[0xFD, 0x04, 0x00, 0x00, 0x00, 0x00]` | 要寫入的資料 |
200
+ | `debug` | bool | `False` | 印出 debug 資訊 |
201
+
202
+ **回傳值:** `int` — `transactionErrorCode`(0 表示成功)
203
+
204
+ ```python
205
+ dev = ifxusb010.connect_device()
206
+ error_code = ifxusb010.mrw(dev=dev, device_address=0x40, data=[0xFD, 0x04, 0x00, 0x00, 0x00, 0x00])
207
+ ```
@@ -0,0 +1,192 @@
1
+ # ifxusb010
2
+
3
+ Python library for Infineon USB010 I2C dongle.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install ifxusb010
9
+ ```
10
+
11
+ Or install from TestPyPI:
12
+
13
+ ```bash
14
+ pip install -i https://test.pypi.org/simple/ ifxusb010
15
+ ```
16
+
17
+ > **Note:** Windows 使用者需先用 [Zadig](https://zadig.akeo.ie/) 將 USB010 dongle 的驅動程式替換為 WinUSB。
18
+
19
+ ---
20
+
21
+ ## Quick Start
22
+
23
+ ```python
24
+ import ifxusb010
25
+
26
+ # 連接 USB010 dongle
27
+ dev = ifxusb010.connect_device()
28
+ ```
29
+
30
+ ---
31
+
32
+ ## API Reference
33
+
34
+ ### `connect_device(vendor_id=0x058B, product_id=0x0230)`
35
+
36
+ 連接 USB010 dongle,回傳 USB device 物件。
37
+
38
+ | 參數 | 型別 | 預設值 | 說明 |
39
+ |------|------|--------|------|
40
+ | `vendor_id` | int | `0x058B` | USB Vendor ID |
41
+ | `product_id` | int | `0x0230` | USB Product ID |
42
+
43
+ **回傳值:** `usb.core.Device` 物件
44
+
45
+ ---
46
+
47
+ ### `search_I2C(dev, start_address, end_address, debug, enable_8bit_mode)`
48
+
49
+ 掃描 I2C bus 上的裝置。
50
+
51
+ | 參數 | 型別 | 預設值 | 說明 |
52
+ |------|------|--------|------|
53
+ | `dev` | Device | `None` | USB device 物件,`None` 會自動連接 |
54
+ | `start_address` | int | `0x20` | 掃描起始地址 (8-bit) |
55
+ | `end_address` | int | `0xFE` | 掃描結束地址 (8-bit) |
56
+ | `debug` | bool | `False` | 印出 debug 資訊 |
57
+ | `enable_8bit_mode` | bool | `True` | `True` 回傳 8-bit 地址,`False` 回傳 7-bit 地址 |
58
+
59
+ **回傳值:** `list` — 找到的裝置地址列表
60
+
61
+ ```python
62
+ dev = ifxusb010.connect_device()
63
+ devices = ifxusb010.search_I2C(dev=dev)
64
+ # avaliable device found at 8bits address 0x40
65
+ # devices = [0x40]
66
+ ```
67
+
68
+ ---
69
+
70
+ ### `multiReadWriteFunction(dev, device_address, write_command_code_list, read_number_length, debug)`
71
+
72
+ 通用 I2C 讀寫函式,支援**純寫入**和**寫入後讀取**兩種模式。
73
+
74
+ | 參數 | 型別 | 預設值 | 說明 |
75
+ |------|------|--------|------|
76
+ | `dev` | Device | `None` | USB device 物件,`None` 會自動連接 |
77
+ | `device_address` | int | `0x40` | I2C 裝置寫地址 (8-bit,偶數) |
78
+ | `write_command_code_list` | list | `None` | 要寫入的資料列表 |
79
+ | `read_number_length` | int | `0` | 要讀取的 byte 數,`0` 表示純寫入 |
80
+ | `debug` | bool | `False` | 印出 debug 資訊 |
81
+
82
+ **回傳值:**
83
+
84
+ ```python
85
+ {
86
+ "transactionErrorCode": int, # 0 表示成功
87
+ "readData": list # 讀回的資料(純寫入時為空列表 [])
88
+ }
89
+ ```
90
+
91
+ #### 模式說明
92
+
93
+ | `read_number_length` | 模式 | I2C 地址 | 行為 |
94
+ |---|---|---|---|
95
+ | `0` | 純寫入 | 偶數地址 (e.g. `0x40`) | 只寫入資料,不讀回 |
96
+ | `> 0` | 寫入 + 讀取 | 奇數地址 (e.g. `0x41`) | 寫入後讀取指定數量的 byte |
97
+
98
+ #### 範例 1:純寫入 (Write Only)
99
+
100
+ ```python
101
+ import ifxusb010
102
+
103
+ dev = ifxusb010.connect_device()
104
+
105
+ # 寫入 6 bytes 到 I2C 裝置 0x40
106
+ ifxusb010.multiReadWriteFunction(
107
+ dev=dev,
108
+ device_address=0x40,
109
+ write_command_code_list=[0xFD, 0x04, 0x00, 0x00, 0x00, 0x00],
110
+ read_number_length=0
111
+ )
112
+ # I2C write to 0x40 success
113
+ ```
114
+
115
+ #### 範例 2:寫入後讀取 (Write + Read)
116
+
117
+ ```python
118
+ import ifxusb010
119
+
120
+ dev = ifxusb010.connect_device()
121
+
122
+ # 寫入 1 byte (register address),然後讀回 5 bytes
123
+ result = ifxusb010.multiReadWriteFunction(
124
+ dev=dev,
125
+ device_address=0x40,
126
+ write_command_code_list=[0xFD],
127
+ read_number_length=5
128
+ )
129
+
130
+ print(result["transactionErrorCode"]) # 0 = 成功
131
+ print([hex(x) for x in result["readData"]])
132
+ # ['0x4', '0xf9', '0x57', '0xe9', '0x73']
133
+ ```
134
+
135
+ #### 範例 3:連續多筆 I2C 操作
136
+
137
+ 共用同一個 `dev` 物件,連續執行多筆 I2C 指令:
138
+
139
+ ```python
140
+ import ifxusb010
141
+
142
+ dev = ifxusb010.connect_device()
143
+
144
+ # Step 1: 寫入設定暫存器
145
+ ifxusb010.multiReadWriteFunction(
146
+ dev=dev,
147
+ device_address=0x40,
148
+ write_command_code_list=[0xFD, 0x04, 0x00, 0x00, 0x00, 0x00],
149
+ read_number_length=0
150
+ )
151
+
152
+ # Step 2: 寫入觸發指令
153
+ ifxusb010.multiReadWriteFunction(
154
+ dev=dev,
155
+ device_address=0x40,
156
+ write_command_code_list=[0xFE, 0x2D],
157
+ read_number_length=0
158
+ )
159
+
160
+ # Step 3: 讀回結果 (5 bytes)
161
+ result = ifxusb010.multiReadWriteFunction(
162
+ dev=dev,
163
+ device_address=0x40,
164
+ write_command_code_list=[0xFD],
165
+ read_number_length=5
166
+ )
167
+
168
+ if result["transactionErrorCode"] == 0:
169
+ print(f"讀回的資料: {[hex(x) for x in result['readData']]}")
170
+ else:
171
+ print(f"交易失敗,錯誤碼: {result['transactionErrorCode']}")
172
+ ```
173
+
174
+ ---
175
+
176
+ ### `mrw(dev, device_address, data, debug)`
177
+
178
+ 簡化版的寫入函式,內部呼叫 `multiReadWriteFunction`。
179
+
180
+ | 參數 | 型別 | 預設值 | 說明 |
181
+ |------|------|--------|------|
182
+ | `dev` | Device | `None` | USB device 物件 |
183
+ | `device_address` | int | `0x40` | I2C 裝置寫地址 (8-bit) |
184
+ | `data` | list | `[0xFD, 0x04, 0x00, 0x00, 0x00, 0x00]` | 要寫入的資料 |
185
+ | `debug` | bool | `False` | 印出 debug 資訊 |
186
+
187
+ **回傳值:** `int` — `transactionErrorCode`(0 表示成功)
188
+
189
+ ```python
190
+ dev = ifxusb010.connect_device()
191
+ error_code = ifxusb010.mrw(dev=dev, device_address=0x40, data=[0xFD, 0x04, 0x00, 0x00, 0x00, 0x00])
192
+ ```
@@ -0,0 +1,18 @@
1
+ from pywinusb import hid
2
+ import wmi
3
+
4
+ def find_specific_device():
5
+ # search USB through wmi
6
+ c = wmi.WMI()
7
+ usb_devices = c.Win32_PnPEntity(ConfigManagerErrorCode=0)
8
+
9
+ for device in usb_devices:
10
+ # search 058b
11
+ if device.DeviceID and '058B' in device.DeviceID.upper(): ## 058B means Infineon
12
+ print("found device:")
13
+ print(f"device name: {device.Name}")
14
+
15
+ print(f"device ID: {device.DeviceID}")
16
+ print(f"manufacturer : {device.Manufacturer}")
17
+
18
+ find_specific_device()
@@ -0,0 +1,41 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "ifxusb010"
7
+ version = "0.1.4"
8
+ description = "python for Infineon USB010"
9
+ readme = "README.md"
10
+ requires-python = ">=3.12"
11
+ dependencies = [
12
+ "bitarray>=3.8.0",
13
+ "libusb-package>=1.0.26.3",
14
+ "pyusb>=1.3.1",
15
+ "pywinusb>=0.4.2",
16
+ "wmi>=1.5.1",
17
+ ]
18
+ authors = [
19
+ {name = "a9202507", email = "a9202507@gmail.com"},
20
+ ]
21
+
22
+ [project.optional-dependencies]
23
+ dev = [
24
+ "mypy>=1.19.1",
25
+ ]
26
+
27
+ [tool.hatch.build.targets.sdist]
28
+ exclude = [
29
+ ".git",
30
+ "__pycache__",
31
+ "*.pyc",
32
+ "dist",
33
+ ".env*",
34
+ ".pypi_test_token",
35
+ "test_module.py",
36
+ "usb010_*.py",
37
+ "*.log",
38
+ ".DS_Store",
39
+ "Thumbs.db",
40
+ "libusb-1.0.29", # 加入這個
41
+ ]
@@ -0,0 +1,11 @@
1
+ docutils==0.21.2
2
+ importlib_metadata==8.5.0
3
+ libusb==1.0.27.post3
4
+ packaging==24.2
5
+ pkg_about==1.2.5
6
+ pywin32==308
7
+ pywinusb==0.4.2
8
+ setuptools==75.6.0
9
+ uv==0.5.6
10
+ WMI==1.5.1
11
+ zipp==3.21.0
@@ -0,0 +1,10 @@
1
+ #from .scanner import search_I2C, connect_device, mrw, multiReadWriteFunction
2
+ #from .scanner import Dongle
3
+ from .dongle import dongle
4
+ from .pmbus import PMBusDevice
5
+ from . import mckinley
6
+
7
+
8
+ __all__ = ["dongle","scan_I2C","connect_device","multi_readr_write","PMBusDevice","mckinley","rainier"]
9
+
10
+