python-snap7 3.3.0__py3-none-any.whl → 3.3.1__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.
- {python_snap7-3.3.0.dist-info → python_snap7-3.3.1.dist-info}/METADATA +1 -1
- {python_snap7-3.3.0.dist-info → python_snap7-3.3.1.dist-info}/RECORD +7 -7
- {python_snap7-3.3.0.dist-info → python_snap7-3.3.1.dist-info}/WHEEL +1 -1
- snap7/server/__init__.py +114 -2
- {python_snap7-3.3.0.dist-info → python_snap7-3.3.1.dist-info}/entry_points.txt +0 -0
- {python_snap7-3.3.0.dist-info → python_snap7-3.3.1.dist-info}/licenses/LICENSE +0 -0
- {python_snap7-3.3.0.dist-info → python_snap7-3.3.1.dist-info}/top_level.txt +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
python_snap7-3.3.
|
|
1
|
+
python_snap7-3.3.1.dist-info/licenses/LICENSE,sha256=PIihE_yP-8gc-ff9ikvQQPOa0biOCZ6Bc-6h3G3xRUQ,1097
|
|
2
2
|
s7/__init__.py,sha256=q6E4rA1BDx36PPkJS55xv7XCxwlaQeEK6HNotFjLeYo,1096
|
|
3
3
|
snap7/__init__.py,sha256=2NAAE1oaSSd7DqPl0dx7jNXtsM2PRBWRm9X-bkmgC6U,1275
|
|
4
4
|
snap7/async_client.py,sha256=SxIf2W-mimITD6P0cL3J66vpEr1SeCHne645lwkmbPU,66346
|
|
@@ -21,14 +21,14 @@ snap7/s7protocol.py,sha256=gPfU4BL3S4iicKgDrqksSTjPuRnVmHmrrMDzcLSBiDY,70946
|
|
|
21
21
|
snap7/szl.py,sha256=952lFvuTTE4nBlG2Lvn_3SaS_hazkM0ZfboIPgTwFM8,7999
|
|
22
22
|
snap7/tags.py,sha256=TmbNRHNWZVe3Yl_1L5WXE3Qb0lxIEW-veoCRGt0giZQ,26987
|
|
23
23
|
snap7/type.py,sha256=EiXqU0ayYYxlM-5fUcPL7psgL1EGNNqAa7JXH4QlAnU,9752
|
|
24
|
-
snap7/server/__init__.py,sha256=
|
|
24
|
+
snap7/server/__init__.py,sha256=4e-D2pz60BI751dIkmFi2ivDc7f4K0Xxc0DQB2PWUYY,117955
|
|
25
25
|
snap7/server/__main__.py,sha256=OdOgyMmFThjSe2jSgvlbkquGYnZcBW6wubs2ldhNSOE,1206
|
|
26
26
|
snap7/util/__init__.py,sha256=d6n2oy7tNYke1ia0TUyWz_ni3l0XN1qvilM5sW0T-Es,1874
|
|
27
27
|
snap7/util/db.py,sha256=geesYS2oyOuTADOJa2me1p1rqJVzPuLTCfye6JIeav0,27120
|
|
28
28
|
snap7/util/getters.py,sha256=UjojRLazJECrngor_8BI38R8VMEMdXusC95zqNEErJg,25767
|
|
29
29
|
snap7/util/setters.py,sha256=BpFqVxxUbhqarV6Gzt4ZuxycHljtDYsONCr6e9G33Ms,27226
|
|
30
|
-
python_snap7-3.3.
|
|
31
|
-
python_snap7-3.3.
|
|
32
|
-
python_snap7-3.3.
|
|
33
|
-
python_snap7-3.3.
|
|
34
|
-
python_snap7-3.3.
|
|
30
|
+
python_snap7-3.3.1.dist-info/METADATA,sha256=QyJmylhZmd0a0mS7LnETGAkonGCeizCDmr6HHigft6k,4669
|
|
31
|
+
python_snap7-3.3.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
32
|
+
python_snap7-3.3.1.dist-info/entry_points.txt,sha256=IPZyYr1lKyavXXpAc4xO505afTGwTY8GmNFuy5lsSiM,75
|
|
33
|
+
python_snap7-3.3.1.dist-info/top_level.txt,sha256=PTgDoDG45QNL2XIE9RM7S_ZCdWQjtMMuXNyrI2UdnbU,9
|
|
34
|
+
python_snap7-3.3.1.dist-info/RECORD,,
|
snap7/server/__init__.py
CHANGED
|
@@ -1070,8 +1070,12 @@ class Server:
|
|
|
1070
1070
|
return (0x01, bytearray())
|
|
1071
1071
|
|
|
1072
1072
|
def _handle_write_area(self, request: Dict[str, Any], client_address: Tuple[str, int]) -> bytes:
|
|
1073
|
-
"""Handle write area request."""
|
|
1073
|
+
"""Handle write area request (single or multi-item)."""
|
|
1074
1074
|
try:
|
|
1075
|
+
params = request.get("parameters", {})
|
|
1076
|
+
if params.get("item_count", 1) > 1 and "address_specs" in params:
|
|
1077
|
+
return self._handle_multi_write_area(request, client_address)
|
|
1078
|
+
|
|
1075
1079
|
# Parse address specification from request parameters
|
|
1076
1080
|
addr_info = self._parse_write_address(request)
|
|
1077
1081
|
if not addr_info:
|
|
@@ -1122,6 +1126,70 @@ class Server:
|
|
|
1122
1126
|
logger.error(f"Error handling write request: {e}")
|
|
1123
1127
|
return self._build_error_response(request, 0x8000)
|
|
1124
1128
|
|
|
1129
|
+
def _handle_multi_write_area(self, request: Dict[str, Any], client_address: Tuple[str, int]) -> bytes:
|
|
1130
|
+
"""Handle multi-item write area request.
|
|
1131
|
+
|
|
1132
|
+
Splits the data section into one block per address specification, writes
|
|
1133
|
+
each item to its own area, and returns one return code per item.
|
|
1134
|
+
"""
|
|
1135
|
+
params = request["parameters"]
|
|
1136
|
+
address_specs: List[Dict[str, Any]] = params["address_specs"]
|
|
1137
|
+
item_count = len(address_specs)
|
|
1138
|
+
data_section: bytes = request.get("raw_data", b"")
|
|
1139
|
+
|
|
1140
|
+
return_codes = bytearray()
|
|
1141
|
+
offset = 0
|
|
1142
|
+
for i, addr in enumerate(address_specs):
|
|
1143
|
+
if offset + 4 > len(data_section):
|
|
1144
|
+
# Data section is missing this item
|
|
1145
|
+
return_codes.append(0x07)
|
|
1146
|
+
continue
|
|
1147
|
+
|
|
1148
|
+
transport_size = data_section[offset + 1]
|
|
1149
|
+
length = struct.unpack(">H", data_section[offset + 2 : offset + 4])[0]
|
|
1150
|
+
# BIT, REAL and OCTET STRING lengths are in bytes, the others in bits
|
|
1151
|
+
byte_length = length if transport_size in (0x03, 0x07, 0x09) else length // 8
|
|
1152
|
+
write_data = data_section[offset + 4 : offset + 4 + byte_length]
|
|
1153
|
+
offset += 4 + byte_length
|
|
1154
|
+
# Fill byte for even alignment (not after last item)
|
|
1155
|
+
if i < item_count - 1 and byte_length % 2 != 0:
|
|
1156
|
+
offset += 1
|
|
1157
|
+
|
|
1158
|
+
if len(write_data) != byte_length:
|
|
1159
|
+
return_codes.append(0x07)
|
|
1160
|
+
continue
|
|
1161
|
+
|
|
1162
|
+
area = addr.get("area", S7Area.DB)
|
|
1163
|
+
db_number = addr.get("db_number", 0)
|
|
1164
|
+
start = addr.get("start", 0)
|
|
1165
|
+
return_code = self._write_item_to_memory_area(area, db_number, start, bytearray(write_data))
|
|
1166
|
+
return_codes.append(return_code)
|
|
1167
|
+
if return_code == 0xFF:
|
|
1168
|
+
self._emit_event(
|
|
1169
|
+
EVC_DATA_WRITE,
|
|
1170
|
+
param1=self._event_area(area),
|
|
1171
|
+
param2=db_number,
|
|
1172
|
+
param3=start,
|
|
1173
|
+
param4=len(write_data),
|
|
1174
|
+
sender=self._event_sender(client_address),
|
|
1175
|
+
)
|
|
1176
|
+
|
|
1177
|
+
header = struct.pack(
|
|
1178
|
+
">BBHHHHBB",
|
|
1179
|
+
0x32,
|
|
1180
|
+
S7PDUType.ACK_DATA,
|
|
1181
|
+
0x0000,
|
|
1182
|
+
request["sequence"],
|
|
1183
|
+
0x0002, # param length
|
|
1184
|
+
len(return_codes),
|
|
1185
|
+
0x00,
|
|
1186
|
+
0x00,
|
|
1187
|
+
)
|
|
1188
|
+
|
|
1189
|
+
parameters = struct.pack(">BB", S7Function.WRITE_AREA, item_count)
|
|
1190
|
+
|
|
1191
|
+
return header + parameters + bytes(return_codes)
|
|
1192
|
+
|
|
1125
1193
|
def _handle_plc_control(self, request: Dict[str, Any], client_address: Tuple[str, int]) -> bytes:
|
|
1126
1194
|
"""Handle PLC control request (start, compress, copy_ram_to_rom)."""
|
|
1127
1195
|
try:
|
|
@@ -1236,6 +1304,38 @@ class Server:
|
|
|
1236
1304
|
logger.error(f"Error parsing write address: {e}")
|
|
1237
1305
|
return None
|
|
1238
1306
|
|
|
1307
|
+
def _write_item_to_memory_area(self, area: S7Area, db_number: int, start: int, write_data: bytearray) -> int:
|
|
1308
|
+
"""
|
|
1309
|
+
Write one item to a registered memory area.
|
|
1310
|
+
|
|
1311
|
+
Returns:
|
|
1312
|
+
Item return code: ``0xFF`` on success, ``0x0A`` when the area is not
|
|
1313
|
+
registered, and ``0x05`` when the range is outside the registered area.
|
|
1314
|
+
Nothing is written unless the whole item fits.
|
|
1315
|
+
"""
|
|
1316
|
+
try:
|
|
1317
|
+
area_key = (area, db_number)
|
|
1318
|
+
|
|
1319
|
+
if area_key not in self.memory_areas:
|
|
1320
|
+
logger.warning(f"Memory area {area}#{db_number} not registered for write")
|
|
1321
|
+
return 0x0A
|
|
1322
|
+
|
|
1323
|
+
with self.area_locks[area_key]:
|
|
1324
|
+
area_data = self.memory_areas[area_key]
|
|
1325
|
+
|
|
1326
|
+
if start < 0 or start + len(write_data) > len(area_data):
|
|
1327
|
+
logger.warning(f"Write range [{start}, {start + len(write_data)}) exceeds area size {len(area_data)}")
|
|
1328
|
+
return 0x05
|
|
1329
|
+
|
|
1330
|
+
area_data[start : start + len(write_data)] = write_data
|
|
1331
|
+
|
|
1332
|
+
logger.debug(f"Wrote {len(write_data)} bytes to {area}#{db_number} at offset {start}")
|
|
1333
|
+
return 0xFF
|
|
1334
|
+
|
|
1335
|
+
except Exception as e:
|
|
1336
|
+
logger.error(f"Error writing to memory area: {e}")
|
|
1337
|
+
return 0x01
|
|
1338
|
+
|
|
1239
1339
|
def _write_to_memory_area(self, area: S7Area, db_number: int, start: int, write_data: bytearray) -> bool:
|
|
1240
1340
|
"""
|
|
1241
1341
|
Write data to registered memory area.
|
|
@@ -1339,6 +1439,7 @@ class Server:
|
|
|
1339
1439
|
raise S7ProtocolError("Data section extends beyond PDU")
|
|
1340
1440
|
|
|
1341
1441
|
data_section = pdu[offset : offset + data_len]
|
|
1442
|
+
request["raw_data"] = data_section
|
|
1342
1443
|
request["data"] = self._parse_data_section(data_section)
|
|
1343
1444
|
offset += data_len
|
|
1344
1445
|
|
|
@@ -1393,9 +1494,20 @@ class Server:
|
|
|
1393
1494
|
elif function_code == S7Function.WRITE_AREA:
|
|
1394
1495
|
# Parse write area parameters (same format as read)
|
|
1395
1496
|
if len(param_data) >= 14: # Minimum for write area request
|
|
1396
|
-
# Function code (1) + item count (1) + address spec (12)
|
|
1497
|
+
# Function code (1) + item count (1) + N * address spec (12 each)
|
|
1397
1498
|
item_count = param_data[1]
|
|
1398
1499
|
|
|
1500
|
+
if item_count > 1:
|
|
1501
|
+
# Multi-item write: parse all address specs
|
|
1502
|
+
write_specs: List[Dict[str, Any]] = []
|
|
1503
|
+
offset = 2
|
|
1504
|
+
for _ in range(item_count):
|
|
1505
|
+
if offset + 12 > len(param_data):
|
|
1506
|
+
break
|
|
1507
|
+
write_specs.append(self._parse_address_specification(param_data[offset : offset + 12]))
|
|
1508
|
+
offset += 12
|
|
1509
|
+
return {"function_code": function_code, "item_count": item_count, "address_specs": write_specs}
|
|
1510
|
+
|
|
1399
1511
|
# Parse address specification starting at byte 2
|
|
1400
1512
|
if len(param_data) >= 14:
|
|
1401
1513
|
addr_spec = param_data[2:14] # 12 bytes of address specification
|
|
File without changes
|
|
File without changes
|
|
File without changes
|