solax-py-library 1.0.0.15__py3-none-any.whl → 1.0.0.16__py3-none-any.whl

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.
Files changed (29) hide show
  1. solax_py_library/__init__.py +1 -1
  2. solax_py_library/snap_shot/__init__.py +4 -4
  3. solax_py_library/snap_shot/address.py +299 -67
  4. solax_py_library/snap_shot/base_modbus.py +14 -14
  5. solax_py_library/snap_shot/core.py +249 -219
  6. solax_py_library/snap_shot/exceptions.py +6 -4
  7. solax_py_library/snap_shot/parser.py +226 -224
  8. solax_py_library/snap_shot/untils.py +20 -17
  9. solax_py_library/upload/__init__.py +3 -3
  10. solax_py_library/upload/api/__init__.py +3 -3
  11. solax_py_library/upload/api/service.py +24 -24
  12. solax_py_library/upload/core/__init__.py +3 -3
  13. solax_py_library/upload/core/data_adapter/__init__.py +5 -5
  14. solax_py_library/upload/core/data_adapter/base.py +9 -9
  15. solax_py_library/upload/core/data_adapter/csv.py +26 -26
  16. solax_py_library/upload/core/upload_service/__init__.py +15 -15
  17. solax_py_library/upload/core/upload_service/base.py +43 -43
  18. solax_py_library/upload/core/upload_service/ftp.py +97 -86
  19. solax_py_library/upload/errors/__init__.py +10 -10
  20. solax_py_library/upload/errors/base.py +10 -10
  21. solax_py_library/upload/errors/upload_error.py +21 -21
  22. solax_py_library/upload/test/test_ftp.py +81 -40
  23. solax_py_library/upload/types/__init__.py +11 -11
  24. solax_py_library/upload/types/client.py +19 -19
  25. solax_py_library/upload/types/ftp.py +37 -37
  26. {solax_py_library-1.0.0.15.dist-info → solax_py_library-1.0.0.16.dist-info}/METADATA +4 -4
  27. solax_py_library-1.0.0.16.dist-info/RECORD +29 -0
  28. {solax_py_library-1.0.0.15.dist-info → solax_py_library-1.0.0.16.dist-info}/WHEEL +1 -1
  29. solax_py_library-1.0.0.15.dist-info/RECORD +0 -29
@@ -1,219 +1,249 @@
1
- from typing import Dict, Optional, List
2
- import asyncio
3
-
4
- from .base_modbus import ModbusClientBase
5
- from .address import *
6
- from .untils import retry
7
-
8
-
9
- class SnapshotCore:
10
- def __init__(self, modbus_client: ModbusClientBase, snap_except=None):
11
- self.modbus = modbus_client
12
- self.all_snap_shot_data: Dict[int, List[int]] = {}
13
- self.snap_except = snap_except
14
-
15
- def __getitem__(self, index: int) -> Optional[List[int]]:
16
- return self.all_snap_shot_data.get(index)
17
-
18
- async def __aiter__(self):
19
- for key in self.all_snap_shot_data:
20
- yield key, self.all_snap_shot_data[key]
21
-
22
- @property
23
- def all_snap_data(self):
24
- return self.all_snap_shot_data.copy()
25
-
26
- @retry(max_attempts=3, delay=0.5)
27
- async def _set_MCU_source(self):
28
- print("step 1 设置芯片源")
29
- result = await self.modbus.write_registers(SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_MCUSOURCE.value,
30
- [SnapshotMCUSource.MCU_SOURCE_MDSP.value])
31
- print(f'step 1 设置芯片源回复:0x{result[0]:04x}')
32
-
33
- @retry(max_attempts=3, delay=0.5)
34
- async def _set_export_device(self): # 设置输出设备
35
- print("setp 2 设置导出设备")
36
-
37
- result = await self.modbus.write_registers(SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_EXPORTDEVICE.value,
38
- [SnapshotExportDevice.EXPORT_DEVICE_UART.value])
39
- print(f'setp 2 设置导出设备:0x{result[0]:04x}')
40
-
41
- @retry(max_attempts=3, delay=0.5)
42
- async def _get_snapshot_total_number(self) -> int: # 取得快照总数
43
- print("step 3 获取快照总数")
44
- try_number = 3
45
- number = 0
46
- result = [0]
47
- while number < try_number:
48
- result = await self.modbus.read_registers(
49
- SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_TOTALNUMBER.value, 1)
50
- print(f"step 3 获取快照总数 :{result}")
51
- if result[0] > 0:
52
- break
53
- number += 1
54
- return result[0]
55
-
56
- @retry(max_attempts=3, delay=0.5)
57
- async def _start_snap_shot(self): # 获取快照开始结果
58
- print("第4步 录播开始")
59
- result = False
60
- readresultcnt = 0
61
- while readresultcnt < 3:
62
- result = await self.modbus.write_registers(
63
- SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_START.value,
64
- [SnapshotStartResult.SNAPSHOT_START_START.value])
65
- print(f' 设置录播开始{result}')
66
- await asyncio.sleep(1)
67
- response = await self.modbus.read_registers(
68
- SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_START.value, 1)
69
- print(f'录波读取设置变量:{response}')
70
-
71
- if response[0] == SnapshotStartResult.SNAPSHOT_START_SUCCESS.value:
72
- print(f'设置录播开始成功')
73
- result = True
74
- break
75
- else:
76
- print(f'设置录播开始失败')
77
- result = False
78
- readresultcnt += 1
79
-
80
- return result
81
-
82
- @retry(max_attempts=3, delay=0.5)
83
- async def _get_snapshot_dataPara(self): # 取得快照数据参数 数据总数 通道数 通道数据深度
84
- print("step 5 获取快照数据参数")
85
- result = await self.modbus.read_registers(SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_DATASIZE.value, 3)
86
- print(f"step 5 获取快照数据参数:{result}")
87
- return result[0]
88
-
89
- @retry(max_attempts=3, delay=0.5)
90
- async def _get_Single_snap_shot_data(self, index: int, DataNumber: int): # 获取单个快照数据
91
- readdatanum = 0
92
- packindex = 0
93
-
94
- await self._set_snap_shot_data_index(index) # 设置快照索引
95
- while readdatanum < DataNumber:
96
- if await self._get_data_pack_read_state() == False: # 获取数据包读取状态
97
- raise self.snap_except('读取数据包错误')
98
-
99
- siglepackdatanum = DataNumber - readdatanum
100
- if siglepackdatanum > 256:
101
- siglepackdatanum = 256
102
- print(f"第{index}次快照,第{packindex}包,读取数据个数:{siglepackdatanum}")
103
-
104
- await self._get_data_pack_index() # 取得数据包索引
105
- once_data = await self._get_data_pack(siglepackdatanum) # 获取快照数据的单个pack
106
- self.all_snap_shot_data.setdefault(index, []).extend(once_data)
107
-
108
- await self._clear_data_pack_read_state() # 清除数据包读取状态 让下位机切pack
109
- readdatanum += siglepackdatanum
110
- packindex += 1
111
- # print(f'self.all_snap_shot_data:{self.all_snap_shot_data}')
112
-
113
- @retry(max_attempts=3, delay=0.5) #
114
- async def _set_snap_shot_data_index(self, index: int): # 设置快照数据索引
115
- print("step 6 设置快照索引")
116
- result = await self.modbus.write_registers(
117
- SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_SNAPSHOTINDEX.value, [index])
118
- print(f'step 6 设置快照索引返回值:0x{result[0]:04x}')
119
-
120
- @retry(max_attempts=3, delay=0.5)
121
- async def _get_data_pack_read_state(self): # 取得数据包就绪状态
122
- #print(f'取得数据包就绪状态')
123
- readcnt = 0
124
- result = False
125
- while readcnt < 100:
126
- result = await self.modbus.read_registers(
127
- SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_PACKDATASTATUS.value, 1)
128
- status = result[0]
129
- if (status == 1):
130
- #print(f'数据包就绪状态为:{status},数据包就绪')
131
- result = True
132
- break
133
- else:
134
- #print(f'数据包就绪状态为:{status},数据包未就绪')
135
- readcnt += 1
136
- await asyncio.sleep(0.5)
137
- return result
138
-
139
- @retry(max_attempts=5, delay=0.2)
140
- async def _get_data_pack_index(self): # 取得数据包索引
141
- # print(f'获取数据包索引')
142
- result = await self.modbus.read_registers(
143
- SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_PACKINDEX.value, 1)
144
- packnum = result[0]
145
- # print(f'当前数据包的索引:{packnum}')
146
- return packnum
147
-
148
- @retry(max_attempts=3, delay=0.5)
149
- async def _get_data_pack(self, register_num: int) -> List: # 取得快照数据包
150
- #print(f'取得快照数据包')
151
- DataPack = []
152
- if register_num >= 256:
153
- response = await self.get_data_pack_h_address(64)
154
- DataPack.extend(response)
155
- response = await self._get_data_pack_l_address(64)
156
- DataPack.extend(response)
157
- elif register_num >= 64 and register_num < 256:
158
- response = await self.get_data_pack_h_address(64)
159
- DataPack.extend(response)
160
- response = await self._get_data_pack_l_address((register_num - 128) // 2)
161
- DataPack.extend(response)
162
- else:
163
- response = await self.get_data_pack_h_address(register_num // 2)
164
- DataPack.extend(response)
165
-
166
- # print(f'获取快照数据包返回值:{DataPack}')
167
- return DataPack
168
-
169
- @retry(max_attempts=3, delay=0.5)
170
- async def get_data_pack_h_address(self, register_num: int) -> List: # 取得数据包大小
171
- data = await self.modbus.read_registers(
172
- SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_PACKDATA.value, register_num)
173
- return data
174
-
175
- @retry(max_attempts=3, delay=0.5)
176
- async def _get_data_pack_l_address(self, register_num: int) -> List: # 取得数据包大小
177
- data = await self.modbus.read_registers(
178
- SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_PACKDATA.value + 64, register_num)
179
- return data
180
-
181
- @retry(max_attempts=5, delay=0.2)
182
- async def _clear_data_pack_read_state(self): # 清除数据包读取状态
183
- # print(f'清除数据包读取状态')
184
- response = await self.modbus.write_registers(
185
- SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_PACKDATASTATUS.value, [0])
186
- # print(f'清除数据包就绪状态返回值:{response}')
187
-
188
- @classmethod
189
- async def start(cls, modbus_client, snap_shot_index: int = 0, snap_exception=None):
190
- """启动故障录波
191
- snap_shot_index : 代表第几个故障 如果传0 就默认读取所有故障
192
- """
193
- #print'start.................................')
194
- instance = cls(modbus_client, snap_exception)
195
- try:
196
- # 第一步 设置快照芯片源
197
- await instance._set_MCU_source()
198
- # 第二步 设置导出设备
199
- await instance._set_export_device()
200
- # 第三步 获取设备总数
201
- total_number = await instance._get_snapshot_total_number()
202
- if total_number < 1:
203
- return instance.snap_except("无效的故障录波总数")
204
- # 第四步 开始录波
205
- await instance._start_snap_shot()
206
- # 第5步 获取快照数据参数
207
- total_data_length = await instance._get_snapshot_dataPara()
208
- # 第六步 读数据
209
- # for index in range(1, total_number + 1):
210
- # await instance._get_Single_snap_shot_data(index, total_data_length)
211
- await instance._get_Single_snap_shot_data(1, total_data_length)
212
-
213
- return instance.all_snap_data
214
-
215
- except Exception as e:
216
- return instance.snap_except(f"故障录波失败:{e}")
217
-
218
- async def __aenter__(self):
219
- return self
1
+ from typing import Dict, Optional, List
2
+ import asyncio
3
+
4
+ from .base_modbus import ModbusClientBase
5
+ from .address import *
6
+ from .untils import retry
7
+
8
+
9
+ class SnapshotCore:
10
+ def __init__(self, modbus_client: ModbusClientBase, snap_except=None):
11
+ self.modbus = modbus_client
12
+ self.all_snap_shot_data: Dict[int, List[int]] = {}
13
+ self.snap_except = snap_except
14
+
15
+ def __getitem__(self, index: int) -> Optional[List[int]]:
16
+ return self.all_snap_shot_data.get(index)
17
+
18
+ async def __aiter__(self):
19
+ for key in self.all_snap_shot_data:
20
+ yield key, self.all_snap_shot_data[key]
21
+
22
+ @property
23
+ def all_snap_data(self):
24
+ return self.all_snap_shot_data.copy()
25
+
26
+ @retry(max_attempts=3, delay=0.5)
27
+ async def _set_MCU_source(self):
28
+ print("step 1 设置芯片源")
29
+ result = await self.modbus.write_registers(
30
+ SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_MCUSOURCE.value,
31
+ [SnapshotMCUSource.MCU_SOURCE_MDSP.value],
32
+ )
33
+ print(f"step 1 设置芯片源回复:0x{result[0]:04x}")
34
+
35
+ @retry(max_attempts=3, delay=0.5)
36
+ async def _set_export_device(self): # 设置输出设备
37
+ print("setp 2 设置导出设备")
38
+
39
+ result = await self.modbus.write_registers(
40
+ SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_EXPORTDEVICE.value,
41
+ [SnapshotExportDevice.EXPORT_DEVICE_UART.value],
42
+ )
43
+ print(f"setp 2 设置导出设备:0x{result[0]:04x}")
44
+
45
+ @retry(max_attempts=3, delay=0.5)
46
+ async def _get_snapshot_total_number(self) -> int: # 取得快照总数
47
+ print("step 3 获取快照总数")
48
+ try_number = 3
49
+ number = 0
50
+ result = [0]
51
+ while number < try_number:
52
+ result = await self.modbus.read_registers(
53
+ SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_TOTALNUMBER.value, 1
54
+ )
55
+ print(f"step 3 获取快照总数 :{result}")
56
+ if result[0] > 0:
57
+ break
58
+ number += 1
59
+ return result[0]
60
+
61
+ @retry(max_attempts=3, delay=0.5)
62
+ async def _start_snap_shot(self): # 获取快照开始结果
63
+ print("第4步 录播开始")
64
+ result = False
65
+ readresultcnt = 0
66
+ while readresultcnt < 3:
67
+ result = await self.modbus.write_registers(
68
+ SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_START.value,
69
+ [SnapshotStartResult.SNAPSHOT_START_START.value],
70
+ )
71
+ print(f" 设置录播开始{result}")
72
+ await asyncio.sleep(1)
73
+ response = await self.modbus.read_registers(
74
+ SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_START.value, 1
75
+ )
76
+ print(f"录波读取设置变量:{response}")
77
+
78
+ if response[0] == SnapshotStartResult.SNAPSHOT_START_SUCCESS.value:
79
+ print("设置录播开始成功")
80
+ result = True
81
+ break
82
+ else:
83
+ print("设置录播开始失败")
84
+ result = False
85
+ readresultcnt += 1
86
+
87
+ return result
88
+
89
+ @retry(max_attempts=3, delay=0.5)
90
+ async def _get_snapshot_dataPara(
91
+ self
92
+ ): # 取得快照数据参数 数据总数 通道数 通道数据深度
93
+ print("step 5 获取快照数据参数")
94
+ result = await self.modbus.read_registers(
95
+ SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_DATASIZE.value, 3
96
+ )
97
+ print(f"step 5 获取快照数据参数:{result}")
98
+ return result[0]
99
+
100
+ @retry(max_attempts=3, delay=0.5)
101
+ async def _get_Single_snap_shot_data(
102
+ self, index: int, DataNumber: int
103
+ ): # 获取单个快照数据
104
+ readdatanum = 0
105
+ packindex = 0
106
+
107
+ await self._set_snap_shot_data_index(index) # 设置快照索引
108
+ while readdatanum < DataNumber:
109
+ if await self._get_data_pack_read_state() is False: # 获取数据包读取状态
110
+ raise self.snap_except("读取数据包错误")
111
+
112
+ siglepackdatanum = DataNumber - readdatanum
113
+ if siglepackdatanum > 256:
114
+ siglepackdatanum = 256
115
+ print(f"第{index}次快照,第{packindex}包,读取数据个数:{siglepackdatanum}")
116
+
117
+ await self._get_data_pack_index() # 取得数据包索引
118
+ once_data = await self._get_data_pack(
119
+ siglepackdatanum
120
+ ) # 获取快照数据的单个pack
121
+ self.all_snap_shot_data.setdefault(index, []).extend(once_data)
122
+
123
+ await (
124
+ self._clear_data_pack_read_state()
125
+ ) # 清除数据包读取状态 让下位机切pack
126
+ readdatanum += siglepackdatanum
127
+ packindex += 1
128
+ # print(f'self.all_snap_shot_data:{self.all_snap_shot_data}')
129
+
130
+ @retry(max_attempts=3, delay=0.5) #
131
+ async def _set_snap_shot_data_index(self, index: int): # 设置快照数据索引
132
+ print("step 6 设置快照索引")
133
+ result = await self.modbus.write_registers(
134
+ SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_SNAPSHOTINDEX.value,
135
+ [index],
136
+ )
137
+ print(f"step 6 设置快照索引返回值:0x{result[0]:04x}")
138
+
139
+ @retry(max_attempts=3, delay=0.5)
140
+ async def _get_data_pack_read_state(self): # 取得数据包就绪状态
141
+ # print(f'取得数据包就绪状态')
142
+ readcnt = 0
143
+ result = False
144
+ while readcnt < 100:
145
+ result = await self.modbus.read_registers(
146
+ SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_PACKDATASTATUS.value, 1
147
+ )
148
+ status = result[0]
149
+ if status == 1:
150
+ # print(f'数据包就绪状态为:{status},数据包就绪')
151
+ result = True
152
+ break
153
+ else:
154
+ # print(f'数据包就绪状态为:{status},数据包未就绪')
155
+ readcnt += 1
156
+ await asyncio.sleep(0.5)
157
+ return result
158
+
159
+ @retry(max_attempts=5, delay=0.2)
160
+ async def _get_data_pack_index(self): # 取得数据包索引
161
+ # print(f'获取数据包索引')
162
+ result = await self.modbus.read_registers(
163
+ SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_PACKINDEX.value, 1
164
+ )
165
+ packnum = result[0]
166
+ # print(f'当前数据包的索引:{packnum}')
167
+ return packnum
168
+
169
+ @retry(max_attempts=3, delay=0.5)
170
+ async def _get_data_pack(self, register_num: int) -> List: # 取得快照数据包
171
+ # print(f'取得快照数据包')
172
+ DataPack = []
173
+ if register_num >= 256:
174
+ response = await self.get_data_pack_h_address(64)
175
+ DataPack.extend(response)
176
+ response = await self._get_data_pack_l_address(64)
177
+ DataPack.extend(response)
178
+ elif register_num >= 64 and register_num < 256:
179
+ response = await self.get_data_pack_h_address(64)
180
+ DataPack.extend(response)
181
+ response = await self._get_data_pack_l_address((register_num - 128) // 2)
182
+ DataPack.extend(response)
183
+ else:
184
+ response = await self.get_data_pack_h_address(register_num // 2)
185
+ DataPack.extend(response)
186
+
187
+ # print(f'获取快照数据包返回值:{DataPack}')
188
+ return DataPack
189
+
190
+ @retry(max_attempts=3, delay=0.5)
191
+ async def get_data_pack_h_address(
192
+ self, register_num: int
193
+ ) -> List: # 取得数据包大小
194
+ data = await self.modbus.read_registers(
195
+ SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_PACKDATA.value,
196
+ register_num,
197
+ )
198
+ return data
199
+
200
+ @retry(max_attempts=3, delay=0.5)
201
+ async def _get_data_pack_l_address(
202
+ self, register_num: int
203
+ ) -> List: # 取得数据包大小
204
+ data = await self.modbus.read_registers(
205
+ SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_PACKDATA.value + 64,
206
+ register_num,
207
+ )
208
+ return data
209
+
210
+ @retry(max_attempts=5, delay=0.2)
211
+ async def _clear_data_pack_read_state(self): # 清除数据包读取状态
212
+ # print(f'清除数据包读取状态')
213
+ await self.modbus.write_registers(
214
+ SnapshotRegisterAddress.SNAPSHOT_REGISTERADDRESS_PACKDATASTATUS.value, [0]
215
+ )
216
+ # print(f'清除数据包就绪状态返回值:{response}')
217
+
218
+ @classmethod
219
+ async def start(cls, modbus_client, snap_shot_index: int = 0, snap_exception=None):
220
+ """启动故障录波
221
+ snap_shot_index : 代表第几个故障 如果传0 就默认读取所有故障
222
+ """
223
+ # print'start.................................')
224
+ instance = cls(modbus_client, snap_exception)
225
+ try:
226
+ # 第一步 设置快照芯片源
227
+ await instance._set_MCU_source()
228
+ # 第二步 设置导出设备
229
+ await instance._set_export_device()
230
+ # 第三步 获取设备总数
231
+ total_number = await instance._get_snapshot_total_number()
232
+ if total_number < 1:
233
+ return instance.snap_except("无效的故障录波总数")
234
+ # 第四步 开始录波
235
+ await instance._start_snap_shot()
236
+ # 第5步 获取快照数据参数
237
+ total_data_length = await instance._get_snapshot_dataPara()
238
+ # 第六步 读数据
239
+ # for index in range(1, total_number + 1):
240
+ # await instance._get_Single_snap_shot_data(index, total_data_length)
241
+ await instance._get_Single_snap_shot_data(1, total_data_length)
242
+
243
+ return instance.all_snap_data
244
+
245
+ except Exception as e:
246
+ return instance.snap_except(f"故障录波失败:{e}")
247
+
248
+ async def __aenter__(self):
249
+ return self
@@ -1,4 +1,6 @@
1
- class SnapshotError(Exception):
2
- ...
3
- class SnapshotTimeoutError(SnapshotError):
4
- ...
1
+ class SnapshotError(Exception):
2
+ ...
3
+
4
+
5
+ class SnapshotTimeoutError(SnapshotError):
6
+ ...