Core
slmp.core
Core codec/types/helpers for SLMP 4E binary.
Classes
BlockReadResult
dataclass
Result of block device read.
Source code in slmp\core.py
166 167 168 169 170 171 | |
DeviceBlockResult
dataclass
Result of a single device block in block access.
Source code in slmp\core.py
158 159 160 161 162 163 | |
DeviceRef
dataclass
Device reference.
Attributes:
| Name | Type | Description |
|---|---|---|
code |
str
|
Device code string (e.g. 'D', 'X'). |
number |
int
|
Device address number. |
Source code in slmp\core.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
Functions
__str__()
Return the string representation of the device (e.g., 'D100', 'X1F').
Source code in slmp\core.py
84 85 86 87 88 | |
ExtendedDevice
dataclass
Extended Device text plus optional qualified extension-specification override.
Source code in slmp\core.py
242 243 244 245 246 247 248 | |
ExtensionSpec
dataclass
Extended Device extension fields (binary, 0080..0083).
Source code in slmp\core.py
231 232 233 234 235 236 237 238 239 | |
LabelArrayReadPoint
dataclass
Request point for array label read.
Source code in slmp\core.py
115 116 117 118 119 120 121 | |
LabelArrayReadResult
dataclass
Result of array label read.
Source code in slmp\core.py
187 188 189 190 191 192 193 194 | |
LabelArrayWritePoint
dataclass
Request point for array label write.
Source code in slmp\core.py
124 125 126 127 128 129 130 131 | |
LabelRandomReadResult
dataclass
Result of random label read.
Source code in slmp\core.py
197 198 199 200 201 202 203 204 | |
LabelRandomWritePoint
dataclass
Request point for random label write.
Source code in slmp\core.py
134 135 136 137 138 139 | |
LongTimerResult
dataclass
Result of long timer read.
Source code in slmp\core.py
174 175 176 177 178 179 180 181 182 183 184 | |
MonitorResult
dataclass
Result of registered monitor device read.
Source code in slmp\core.py
150 151 152 153 154 155 | |
RandomReadResult
dataclass
Result of random device read.
Source code in slmp\core.py
142 143 144 145 146 147 | |
SlmpResponse
dataclass
Decoded SLMP response frame.
Attributes:
| Name | Type | Description |
|---|---|---|
serial |
int
|
Serial number matching the request. |
target |
SlmpTarget
|
Source station routing information. |
end_code |
int
|
Response end code (0x0000 for success). |
data |
bytes
|
Command-specific response payload. |
raw |
bytes
|
Full raw binary response frame. |
Source code in slmp\core.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
Attributes
is_success
property
Return True if the response end_code is 0.
SlmpTarget
dataclass
SLMP frame destination fields.
Attributes:
| Name | Type | Description |
|---|---|---|
network |
int
|
Network number (0x00 for local network). |
station |
int
|
Station number (0xFF for control CPU). |
module_io |
int | ModuleIONo | str
|
Module I/O number (0x03FF for own station). |
multidrop |
int
|
Multidrop station number (0x00 for no multidrop). |
Source code in slmp\core.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
Functions
__post_init__()
Resolve module_io from enum name or value.
Source code in slmp\core.py
58 59 60 61 62 63 64 65 66 67 68 69 | |
SlmpTraceFrame
dataclass
A single SLMP transaction captured by a trace hook.
Source code in slmp\core.py
216 217 218 219 220 221 222 223 224 225 226 227 228 | |
TypeNameInfo
dataclass
Result of READ_TYPE_NAME command.
Source code in slmp\core.py
207 208 209 210 211 212 213 | |
Functions
build_device_modification_flags(*, series, use_indirect_specification=False, register_mode='none')
Build device_modification_flags from Extended Device semantics.
register_mode
- "none"
- "z"
- "lz" (iQ-R/iQ-L only)
Source code in slmp\core.py
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 | |
decode_3e_response(frame)
Decode a 3E response frame.
Source code in slmp\core.py
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 | |
decode_4e_response(frame)
Decode a 4E response frame.
Source code in slmp\core.py
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 | |
decode_device_dwords(data)
Decode a byte array into a list of 32-bit double-word values.
Source code in slmp\core.py
715 716 717 718 719 | |
decode_device_words(data)
Decode a byte array into a list of 16-bit word values.
Source code in slmp\core.py
708 709 710 711 712 | |
decode_response(frame, *, frame_type)
Decode an SLMP response frame based on frame_type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
bytes
|
Full raw binary response frame. |
required |
frame_type
|
FrameType
|
Expected frame format (3E or 4E). |
required |
Returns:
| Type | Description |
|---|---|
SlmpResponse
|
A decoded |
Raises:
| Type | Description |
|---|---|
SlmpError
|
If the frame is malformed or the subheader does not match. |
Source code in slmp\core.py
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 | |
encode_3e_request(*, target, monitoring_timer, command, subcommand, data=b'')
Encode a full 3E request frame.
Source code in slmp\core.py
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 | |
encode_4e_request(*, serial, target, monitoring_timer, command, subcommand, data=b'')
Encode a full 4E request frame.
Source code in slmp\core.py
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 | |
encode_device_spec(device, *, series)
Encode a device specification into bytes based on the PLC series.
Source code in slmp\core.py
565 566 567 568 569 570 571 572 573 574 575 576 577 578 | |
encode_extended_device_spec(device, *, series, extension, include_direct_memory_at_end=True)
Encode an Extended Device extended device specification into bytes.
Source code in slmp\core.py
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 | |
encode_extension_spec(spec)
Encode an Extended Device extension specification into bytes.
Source code in slmp\core.py
581 582 583 584 585 586 587 588 589 | |
encode_request(*, frame_type, serial, target, monitoring_timer, command, subcommand, data=b'')
Encode an SLMP request frame based on frame_type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame_type
|
FrameType
|
SLMP frame format (3E or 4E). |
required |
serial
|
int
|
Serial number for 4E frames (ignored for 3E). |
required |
target
|
SlmpTarget
|
Target station routing information. |
required |
monitoring_timer
|
int
|
Timeout value in multiples of 250ms. |
required |
command
|
int
|
SLMP command code. |
required |
subcommand
|
int
|
SLMP subcommand code. |
required |
data
|
bytes
|
Command-specific binary payload. |
b''
|
Returns:
| Type | Description |
|---|---|
bytes
|
The full binary request frame. |
Source code in slmp\core.py
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 | |
pack_bit_values(values)
Pack a sequence of bit values into binary format.
In SLMP binary bit-unit access, each byte contains two points. The high nibble stores the first point, and the low nibble stores the second.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Iterable[bool | int]
|
An iterable of boolean or integer (0/1) values. |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
Packed binary data. |
Source code in slmp\core.py
722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 | |
parse_device(value)
Parse a device string into a DeviceRef.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str | DeviceRef
|
Device string (e.g. 'D100', 'X1F') or |
required |
Returns:
| Type | Description |
|---|---|
DeviceRef
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the device format is invalid or the code is unknown. |
Source code in slmp\core.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
parse_extended_device(value)
Parse an Extended Device string (e.g., 'U01\G10', 'J2\SW10') or return ExtendedDevice as-is.
Source code in slmp\core.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | |
resolve_device_subcommand(*, bit_unit, series, extension=False)
Resolve the SLMP subcommand for device read/write operations.
Source code in slmp\core.py
549 550 551 552 553 554 555 556 557 558 559 560 561 562 | |
resolve_extended_device_and_extension(device, extension)
Resolve device and extension specification, prioritizing explicit qualification in the device string.
Source code in slmp\core.py
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | |
unpack_bit_values(data, count)
Unpack binary bit data into a list of booleans.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
Binary data received from the PLC. |
required |
count
|
int
|
The number of bit points to extract. |
required |
Returns:
| Type | Description |
|---|---|
list[bool]
|
A list of boolean values. |
Raises:
| Type | Description |
|---|---|
SlmpError
|
If the data length is insufficient for the requested count. |
Source code in slmp\core.py
743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 | |