-
Notifications
You must be signed in to change notification settings - Fork 2
/
s7telegrams.py
743 lines (581 loc) · 15.7 KB
/
s7telegrams.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
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
284
285
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
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
388
389
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
426
427
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
468
469
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
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
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
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
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
678
679
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
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
import S7
ISO_CR = bytearray()
ISO_CR.append(0x03) # RFC 1006 ID (3)
ISO_CR.append(0x00) # Reserved, always 0
ISO_CR.append(0x00) # High part of packet length (entire frame, payload and TPDU included)
ISO_CR.append(0x16) # Low part of packet length (entire frame, payload and TPDU included)
# COTP (ISO 8073 Header)
ISO_CR.append(0x11) # PDU Size Length
ISO_CR.append(0xE0) # CR - Connection Request ID
ISO_CR.append(0x00) # Dst Reference HI
ISO_CR.append(0x00) # Dst Reference LO
ISO_CR.append(0x00) # Src Reference HI
ISO_CR.append(0x00) # Src Reference LO
ISO_CR.append(0x00) # Class + Options Flags
ISO_CR.append(0xC0) # PDU Max Length ID
ISO_CR.append(0x01) # PDU Max Length HI
ISO_CR.append(0x0A) # PDU Max Length LO
ISO_CR.append(0xC1) # Src TSAP Identifier
ISO_CR.append(0x02) # Src TSAP Length (2 bytes)
ISO_CR.append(0x01) # Src TSAP HI (will be overwritten)
ISO_CR.append(0x00) # Src TSAP LO (will be overwritten)
ISO_CR.append(0xC2) # Dst TSAP Identifier
ISO_CR.append(0x02) # Dst TSAP Length (2 bytes)
ISO_CR.append(0x01) # Dst TSAP HI (will be overwritten)
ISO_CR.append(0x02) # Dst TSAP LO (will be overwritten)
S7_PN = bytearray()
S7_PN.append(0x03)
S7_PN.append(0x00)
S7_PN.append(0x00)
S7_PN.append(0x19)
S7_PN.append(0x02)
S7_PN.append(0xf0)
S7_PN.append(0x80) # TPKT + COTP (see above for info)
S7_PN.append(0x32)
S7_PN.append(0x01)
S7_PN.append(0x00)
S7_PN.append(0x00)
S7_PN.append(0x04)
S7_PN.append(0x00)
S7_PN.append(0x00)
S7_PN.append(0x08)
S7_PN.append(0x00)
S7_PN.append(0x00)
S7_PN.append(0xf0)
S7_PN.append(0x00)
S7_PN.append(0x00)
S7_PN.append(0x01)
S7_PN.append(0x00)
S7_PN.append(0x01)
S7_PN.append(0x00)
S7_PN.append(0x1e) # PDU Length Requested = HI-LO Here Default 480 bytes
S7_RW = bytearray()
# TPKT
S7_RW.append(0x03)
S7_RW.append(0x00)
S7_RW.append(0x00)
S7_RW.append(0x1f) # Telegram Length (Data Size + 31 or 35)
# TPKT
# COTP
S7_RW.append(0x02)
S7_RW.append(0xf0)
S7_RW.append(0x80) # COTP (see above for info)
# COTP
# S7 PROTO
S7_RW.append(0x32) # S7 Protocol ID
S7_RW.append(0x01) # Job Type
S7_RW.append(0x00)
S7_RW.append(0x00) # Redundancy identification
S7_RW.append(0x05)
S7_RW.append(0x00) # PDU Reference
S7_RW.append(0x00)
S7_RW.append(0x0e) # Parameters Length
S7_RW.append(0x00)
S7_RW.append(0x00) # Data Length = Size(bytes) + 4
# S7 PROTO PAYLOAD
S7_RW.append(0x04) # Function 4 Read Var, 5 Write Var
S7_RW.append(0x01) # Items count
S7_RW.append(0x12) # Var spec.
S7_RW.append(0x0a) # Length of remaining bytes
S7_RW.append(0x10) # Syntax ID
S7_RW.append(S7.DataTypes.Byte) # Transport Size idx=22
S7_RW.append(0x00)
S7_RW.append(0x00) # Num Elements
S7_RW.append(0x00)
S7_RW.append(0x00) # DB Number
S7_RW.append(0x84) # Area Type
S7_RW.append(0x00)
S7_RW.append(0x00)
S7_RW.append(0x00) # Area Offset
# WR Area
S7_RW.append(0x00) # Reserved
S7_RW.append(0x04) # Transport Size
S7_RW.append(0x00) #
S7_RW.append(0x00) # Data Length * 8 (if not bit or timer or counter)
Size_RD = 31
Size_WR = 35
S7_MRD_HEADER = bytearray()
S7_MRD_HEADER.append(0x03)
S7_MRD_HEADER.append(0x00)
S7_MRD_HEADER.append(0x00)
S7_MRD_HEADER.append(0x1f) # Telegram Length
S7_MRD_HEADER.append(0x02)
S7_MRD_HEADER.append(0xf0)
S7_MRD_HEADER.append(0x80) # COTP
S7_MRD_HEADER.append(0x32) # S7 Protocol ID
S7_MRD_HEADER.append(0x01) # Job Type
S7_MRD_HEADER.append(0x00)
S7_MRD_HEADER.append(0x00) # Redundancy identification
S7_MRD_HEADER.append(0x05)
S7_MRD_HEADER.append(0x00) # PDU Reference
S7_MRD_HEADER.append(0x00)
S7_MRD_HEADER.append(0x0e) # Parameters Length
S7_MRD_HEADER.append(0x00)
S7_MRD_HEADER.append(0x00) # Data Length = Size(bytes) + 4
S7_MRD_HEADER.append(0x04) # Function 4 Read Var, 5 Write Var
S7_MRD_HEADER.append(0x01) # Items count (idx 18)
S7_MRD_ITEM = bytearray()
S7_MRD_ITEM.append(0x12) # Var Spec
S7_MRD_ITEM.append(0x0a) # Length of remaining bytes
S7_MRD_ITEM.append(0x10) # Syntax ID
S7_MRD_ITEM.append(S7.DataTypes.Byte) # Transport Size idx = 3
S7_MRD_ITEM.append(0x00) #
S7_MRD_ITEM.append(0x00) # Num Elements
S7_MRD_ITEM.append(0x00) #
S7_MRD_ITEM.append(0x00) # DB Number or 0
S7_MRD_ITEM.append(0x84) # Area Type
S7_MRD_ITEM.append(0x00) #
S7_MRD_ITEM.append(0x00) #
S7_MRD_ITEM.append(0x00) # Area Offset
S7_MWR_HEADER = bytearray()
S7_MWR_HEADER.append(0x03)
S7_MWR_HEADER.append(0x00)
S7_MWR_HEADER.append(0x00)
S7_MWR_HEADER.append(0x14) # Telegram Length
S7_MWR_HEADER.append(0x02)
S7_MWR_HEADER.append(0xf0)
S7_MWR_HEADER.append(0x80) # COTP
S7_MWR_HEADER.append(0x32) # S7 Protocol ID
S7_MWR_HEADER.append(0x01) # Job Type
S7_MWR_HEADER.append(0x00) #
S7_MWR_HEADER.append(0x00) # Redundancy identification
S7_MWR_HEADER.append(0x05) #
S7_MWR_HEADER.append(0x00) # PDU Reference
S7_MWR_HEADER.append(0x00) #
S7_MWR_HEADER.append(0x0e) # Parameters Length (idx 13)
S7_MWR_HEADER.append(0x00) #
S7_MWR_HEADER.append(0x00) # Data Length = Size(bytes) + 4 (idx 15)
S7_MWR_HEADER.append(0x05) # Function 5 Write Var
S7_MWR_HEADER.append(0x01) # Items count (idx 18)
S7_MWR_PARAM = bytearray()
S7_MWR_PARAM.append(0x12) # Var Spec.
S7_MWR_PARAM.append(0x0a) # Length of remaining bytes
S7_MWR_PARAM.append(0x10) # Syntax ID
S7_MWR_PARAM.append(S7.DataTypes.Byte) # Transport Size idx=3
S7_MWR_PARAM.append(0x00) #
S7_MWR_PARAM.append(0x00) # Num Elements
S7_MWR_PARAM.append(0x00) #
S7_MWR_PARAM.append(0x00) # DB Number (if any, else 0)
S7_MWR_PARAM.append(0x84) # Area Type
S7_MWR_PARAM.append(0x00) #
S7_MWR_PARAM.append(0x00) #
S7_MWR_PARAM.append(0x00) # Area Offset
S7_SZL_FIRST = bytearray()
S7_SZL_FIRST.append(0x03)
S7_SZL_FIRST.append(0x00)
S7_SZL_FIRST.append(0x00)
S7_SZL_FIRST.append(0x21)
S7_SZL_FIRST.append(0x02)
S7_SZL_FIRST.append(0xf0)
S7_SZL_FIRST.append(0x80)
S7_SZL_FIRST.append(0x32)
S7_SZL_FIRST.append(0x07)
S7_SZL_FIRST.append(0x00)
S7_SZL_FIRST.append(0x00)
S7_SZL_FIRST.append(0x05)
S7_SZL_FIRST.append(0x00) # Sequence out
S7_SZL_FIRST.append(0x00)
S7_SZL_FIRST.append(0x08)
S7_SZL_FIRST.append(0x00)
S7_SZL_FIRST.append(0x08)
S7_SZL_FIRST.append(0x00)
S7_SZL_FIRST.append(0x01)
S7_SZL_FIRST.append(0x12)
S7_SZL_FIRST.append(0x04)
S7_SZL_FIRST.append(0x11)
S7_SZL_FIRST.append(0x44)
S7_SZL_FIRST.append(0x01)
S7_SZL_FIRST.append(0x00)
S7_SZL_FIRST.append(0xff)
S7_SZL_FIRST.append(0x09)
S7_SZL_FIRST.append(0x00)
S7_SZL_FIRST.append(0x04)
S7_SZL_FIRST.append(0x00)
S7_SZL_FIRST.append(0x00) # ID (29)
S7_SZL_FIRST.append(0x00)
S7_SZL_FIRST.append(0x00) # Index (31)
S7_SZL_NEXT = bytearray()
S7_SZL_NEXT.append(0x03)
S7_SZL_NEXT.append(0x00)
S7_SZL_NEXT.append(0x00)
S7_SZL_NEXT.append(0x21)
S7_SZL_NEXT.append(0x02)
S7_SZL_NEXT.append(0xf0)
S7_SZL_NEXT.append(0x80)
S7_SZL_NEXT.append(0x32)
S7_SZL_NEXT.append(0x07)
S7_SZL_NEXT.append(0x00)
S7_SZL_NEXT.append(0x00)
S7_SZL_NEXT.append(0x06)
S7_SZL_NEXT.append(0x00)
S7_SZL_NEXT.append(0x00)
S7_SZL_NEXT.append(0x0c)
S7_SZL_NEXT.append(0x00)
S7_SZL_NEXT.append(0x04)
S7_SZL_NEXT.append(0x00)
S7_SZL_NEXT.append(0x01)
S7_SZL_NEXT.append(0x12)
S7_SZL_NEXT.append(0x08)
S7_SZL_NEXT.append(0x12)
S7_SZL_NEXT.append(0x44)
S7_SZL_NEXT.append(0x01)
S7_SZL_NEXT.append(0x01) # Sequence
S7_SZL_NEXT.append(0x00)
S7_SZL_NEXT.append(0x00)
S7_SZL_NEXT.append(0x00)
S7_SZL_NEXT.append(0x00)
S7_SZL_NEXT.append(0x00)
S7_SZL_NEXT.append(0x00)
S7_SZL_NEXT.append(0x00)
S7_SZL_NEXT.append(0x00)
# Get Date/Time request
S7_GET_DT = bytearray()
S7_GET_DT.append(0x03)
S7_GET_DT.append(0x00)
S7_GET_DT.append(0x00)
S7_GET_DT.append(0x1d)
S7_GET_DT.append(0x02)
S7_GET_DT.append(0xf0)
S7_GET_DT.append(0x80)
S7_GET_DT.append(0x32)
S7_GET_DT.append(0x07)
S7_GET_DT.append(0x00)
S7_GET_DT.append(0x00)
S7_GET_DT.append(0x38)
S7_GET_DT.append(0x00)
S7_GET_DT.append(0x00)
S7_GET_DT.append(0x08)
S7_GET_DT.append(0x00)
S7_GET_DT.append(0x04)
S7_GET_DT.append(0x00)
S7_GET_DT.append(0x01)
S7_GET_DT.append(0x12)
S7_GET_DT.append(0x04)
S7_GET_DT.append(0x11)
S7_GET_DT.append(0x47)
S7_GET_DT.append(0x01)
S7_GET_DT.append(0x00)
S7_GET_DT.append(0x0a)
S7_GET_DT.append(0x00)
S7_GET_DT.append(0x00)
S7_GET_DT.append(0x00)
# Set Date/Time command
S7_SET_DT = bytearray()
S7_SET_DT.append(0x03)
S7_SET_DT.append(0x00)
S7_SET_DT.append(0x00)
S7_SET_DT.append(0x27)
S7_SET_DT.append(0x02)
S7_SET_DT.append(0xf0)
S7_SET_DT.append(0x80)
S7_SET_DT.append(0x32)
S7_SET_DT.append(0x07)
S7_SET_DT.append(0x00)
S7_SET_DT.append(0x00)
S7_SET_DT.append(0x89)
S7_SET_DT.append(0x03)
S7_SET_DT.append(0x00)
S7_SET_DT.append(0x08)
S7_SET_DT.append(0x00)
S7_SET_DT.append(0x0e)
S7_SET_DT.append(0x00)
S7_SET_DT.append(0x01)
S7_SET_DT.append(0x12)
S7_SET_DT.append(0x04)
S7_SET_DT.append(0x11)
S7_SET_DT.append(0x47)
S7_SET_DT.append(0x02)
S7_SET_DT.append(0x00)
S7_SET_DT.append(0xff)
S7_SET_DT.append(0x09)
S7_SET_DT.append(0x00)
S7_SET_DT.append(0x0a)
S7_SET_DT.append(0x00)
S7_SET_DT.append(0x19) # Hi part of Year (idx=30)
S7_SET_DT.append(0x13) # Lo part of Year
S7_SET_DT.append(0x12) # Month
S7_SET_DT.append(0x06) # Day
S7_SET_DT.append(0x17) # Hour
S7_SET_DT.append(0x37) # Min
S7_SET_DT.append(0x13) # Sec
S7_SET_DT.append(0x00) # ms
S7_SET_DT.append(0x01) # Day Of Week
# S7 Set Session Password
S7_SET_PWD = bytearray()
S7_SET_PWD.append(0x03)
S7_SET_PWD.append(0x00)
S7_SET_PWD.append(0x00)
S7_SET_PWD.append(0x25)
S7_SET_PWD.append(0x02)
S7_SET_PWD.append(0xf0)
S7_SET_PWD.append(0x80)
S7_SET_PWD.append(0x32)
S7_SET_PWD.append(0x07)
S7_SET_PWD.append(0x00)
S7_SET_PWD.append(0x00)
S7_SET_PWD.append(0x27)
S7_SET_PWD.append(0x00)
S7_SET_PWD.append(0x00)
S7_SET_PWD.append(0x08)
S7_SET_PWD.append(0x00)
S7_SET_PWD.append(0x0c)
S7_SET_PWD.append(0x00)
S7_SET_PWD.append(0x01)
S7_SET_PWD.append(0x12)
S7_SET_PWD.append(0x04)
S7_SET_PWD.append(0x11)
S7_SET_PWD.append(0x45)
S7_SET_PWD.append(0x01)
S7_SET_PWD.append(0x00)
S7_SET_PWD.append(0xff)
S7_SET_PWD.append(0x09)
S7_SET_PWD.append(0x00)
S7_SET_PWD.append(0x08)
# 8 Char Encoded Password
S7_SET_PWD.append(0x00)
S7_SET_PWD.append(0x00)
S7_SET_PWD.append(0x00)
S7_SET_PWD.append(0x00)
S7_SET_PWD.append(0x00)
S7_SET_PWD.append(0x00)
S7_SET_PWD.append(0x00)
S7_SET_PWD.append(0x00)
# S7 Clear Session Password
S7_CLR_PWD = bytearray()
S7_CLR_PWD.append(0x03)
S7_CLR_PWD.append(0x00)
S7_CLR_PWD.append(0x00)
S7_CLR_PWD.append(0x1d)
S7_CLR_PWD.append(0x02)
S7_CLR_PWD.append(0xf0)
S7_CLR_PWD.append(0x80)
S7_CLR_PWD.append(0x32)
S7_CLR_PWD.append(0x07)
S7_CLR_PWD.append(0x00)
S7_CLR_PWD.append(0x00)
S7_CLR_PWD.append(0x29)
S7_CLR_PWD.append(0x00)
S7_CLR_PWD.append(0x00)
S7_CLR_PWD.append(0x08)
S7_CLR_PWD.append(0x00)
S7_CLR_PWD.append(0x04)
S7_CLR_PWD.append(0x00)
S7_CLR_PWD.append(0x01)
S7_CLR_PWD.append(0x12)
S7_CLR_PWD.append(0x04)
S7_CLR_PWD.append(0x11)
S7_CLR_PWD.append(0x45)
S7_CLR_PWD.append(0x02)
S7_CLR_PWD.append(0x00)
S7_CLR_PWD.append(0x0a)
S7_CLR_PWD.append(0x00)
S7_CLR_PWD.append(0x00)
S7_CLR_PWD.append(0x00)
# S7 STOP request
S7_STOP = bytearray()
#TPKT
S7_STOP.append(0x03)
S7_STOP.append(0x00)
S7_STOP.append(0x00)
S7_STOP.append(0x21)
#COTP
S7_STOP.append(0x02)
S7_STOP.append(0xf0)
S7_STOP.append(0x80)
#S7 HDR
S7_STOP.append(0x32)
S7_STOP.append(0x01)
S7_STOP.append(0x00)
S7_STOP.append(0x00)
S7_STOP.append(0x0e)
S7_STOP.append(0x00)
S7_STOP.append(0x00)
S7_STOP.append(0x10)
S7_STOP.append(0x00)
S7_STOP.append(0x00)
# ATF HDR
S7_STOP.append(0x29) # Elem Type
S7_STOP.append(0x00) # Elem Count
S7_STOP.append(0x00) # Elem Count
S7_STOP.append(0x00) # DB
S7_STOP.append(0x00) # DB
S7_STOP.append(0x00) # AREA
S7_STOP.append(0x09) # OFFSET
S7_STOP.append(0x50) # OFFSET
S7_STOP.append(0x5f) # OFFSET
S7_STOP.append(0x50)
S7_STOP.append(0x52)
S7_STOP.append(0x4f)
S7_STOP.append(0x47)
S7_STOP.append(0x52)
S7_STOP.append(0x41)
S7_STOP.append(0x4d)
# S7 HOT Start request
S7_HOT_START = bytearray()
S7_HOT_START.append(0x03)
S7_HOT_START.append(0x00)
S7_HOT_START.append(0x00)
S7_HOT_START.append(0x25)
S7_HOT_START.append(0x02)
S7_HOT_START.append(0xf0)
S7_HOT_START.append(0x80)
S7_HOT_START.append(0x32)
S7_HOT_START.append(0x01)
S7_HOT_START.append(0x00)
S7_HOT_START.append(0x00)
S7_HOT_START.append(0x0c)
S7_HOT_START.append(0x00)
S7_HOT_START.append(0x00)
S7_HOT_START.append(0x14)
S7_HOT_START.append(0x00)
S7_HOT_START.append(0x00)
S7_HOT_START.append(0x28)
S7_HOT_START.append(0x00)
S7_HOT_START.append(0x00)
S7_HOT_START.append(0x00)
S7_HOT_START.append(0x00)
S7_HOT_START.append(0x00)
S7_HOT_START.append(0x00)
S7_HOT_START.append(0xfd)
S7_HOT_START.append(0x00)
S7_HOT_START.append(0x00)
S7_HOT_START.append(0x09)
S7_HOT_START.append(0x50)
S7_HOT_START.append(0x5f)
S7_HOT_START.append(0x50)
S7_HOT_START.append(0x52)
S7_HOT_START.append(0x4f)
S7_HOT_START.append(0x47)
S7_HOT_START.append(0x52)
S7_HOT_START.append(0x41)
S7_HOT_START.append(0x4d)
# S7 COLD Start request
S7_COLD_START = bytearray()
S7_COLD_START.append(0x03)
S7_COLD_START.append(0x00)
S7_COLD_START.append(0x00)
S7_COLD_START.append(0x27)
S7_COLD_START.append(0x02)
S7_COLD_START.append(0xf0)
S7_COLD_START.append(0x80)
S7_COLD_START.append(0x32)
S7_COLD_START.append(0x01)
S7_COLD_START.append(0x00)
S7_COLD_START.append(0x00)
S7_COLD_START.append(0x0f)
S7_COLD_START.append(0x00)
S7_COLD_START.append(0x00)
S7_COLD_START.append(0x16)
S7_COLD_START.append(0x00)
S7_COLD_START.append(0x00)
S7_COLD_START.append(0x28)
S7_COLD_START.append(0x00)
S7_COLD_START.append(0x00)
S7_COLD_START.append(0x00)
S7_COLD_START.append(0x00)
S7_COLD_START.append(0x00)
S7_COLD_START.append(0x00)
S7_COLD_START.append(0xfd)
S7_COLD_START.append(0x00)
S7_COLD_START.append(0x02)
S7_COLD_START.append(0x43)
S7_COLD_START.append(0x20)
S7_COLD_START.append(0x09)
S7_COLD_START.append(0x50)
S7_COLD_START.append(0x5f)
S7_COLD_START.append(0x50)
S7_COLD_START.append(0x52)
S7_COLD_START.append(0x4f)
S7_COLD_START.append(0x47)
S7_COLD_START.append(0x52)
S7_COLD_START.append(0x41)
S7_COLD_START.append(0x4d)
pduStart = 0x28 # CPU start
pduStop = 0x29 # CPU stop
pduAlreadyStarted = 0x02 # CPU already in run mode
pduAlreadyStopped = 0x07 # CPU already in stop mode
# S7 Get PLC Status
S7_GET_STAT = bytearray()
# TPKT
S7_GET_STAT.append(0x03)
S7_GET_STAT.append(0x00)
S7_GET_STAT.append(0x00)
S7_GET_STAT.append(0x21)
# COTP
S7_GET_STAT.append(0x02)
S7_GET_STAT.append(0xf0)
S7_GET_STAT.append(0x80)
# S7 HDR
S7_GET_STAT.append(0x32)
S7_GET_STAT.append(0x07)
S7_GET_STAT.append(0x00)
S7_GET_STAT.append(0x00)
S7_GET_STAT.append(0x2c)
S7_GET_STAT.append(0x00)
S7_GET_STAT.append(0x00)
S7_GET_STAT.append(0x08)
S7_GET_STAT.append(0x00)
S7_GET_STAT.append(0x08)
# S7 FUN REQ
S7_GET_STAT.append(0x00)
S7_GET_STAT.append(0x01)
S7_GET_STAT.append(0x12)
S7_GET_STAT.append(0x04)
S7_GET_STAT.append(0x11)
# S7 FUN HDR
S7_GET_STAT.append(0x44)
S7_GET_STAT.append(0x01)
S7_GET_STAT.append(0x00)
S7_GET_STAT.append(0xff)
S7_GET_STAT.append(0x09)
S7_GET_STAT.append(0x00)
S7_GET_STAT.append(0x04)
S7_GET_STAT.append(0x04)
S7_GET_STAT.append(0x24)
S7_GET_STAT.append(0x00)
S7_GET_STAT.append(0x00)
# S7 Get Block Info Request Header (contains also ISO Header and COTP Header)
S7_BI = bytearray()
# TPKT HDR
S7_BI.append(0x03)
S7_BI.append(0x00)
S7_BI.append(0x00)
S7_BI.append(0x25)
# COPT DT HEADER
S7_BI.append(0x02)
S7_BI.append(0xf0)
S7_BI.append(0x80)
# S7 Header
S7_BI.append(0x32)
S7_BI.append(0x07)
S7_BI.append(0x00)
S7_BI.append(0x00)
S7_BI.append(0x05)
S7_BI.append(0x00)
S7_BI.append(0x00)
S7_BI.append(0x08) # Par Len
S7_BI.append(0x00)
S7_BI.append(0x0c) # Data Len
# Function Request Header
S7_BI.append(0x00) #Func
S7_BI.append(0x01) #Items
S7_BI.append(0x12) #Var_Spec
S7_BI.append(0x04) #Rem Bytes
S7_BI.append(0x11) #Syntax_id
#AreaTransferFunction Header
S7_BI.append(0x43)
S7_BI.append(0x03)
S7_BI.append(0x00)
S7_BI.append(0xff)
S7_BI.append(0x09)
S7_BI.append(0x00)
S7_BI.append(0x08)
S7_BI.append(0x30)
S7_BI.append(0x41) # Block Type
#AreaTransferFunction Params
S7_BI.append(0x30) #
S7_BI.append(0x30) #
S7_BI.append(0x30) #
S7_BI.append(0x30) #
S7_BI.append(0x30) # ASCII Block Number
S7_BI.append(0x41)