forked from paulscherrerinstitute/s7plc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
s7plc.html
1073 lines (1053 loc) · 34.5 KB
/
s7plc.html
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
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>S7plc EPICS driver</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch">
<style type="text/css">
<!--
.indent {text-indent:-4ex; margin-left:4ex; text-align:left;}
@media screen {
pre,code {color:green; }
}
@media print {
a {color:black; text-decoration:none; }
}
-->
</style>
</head>
<body>
<h1>S7plc EPICS driver documentation</h1>
<h2>Contents</h2>
<ol>
<li><a href="#intro">Introduction</a></li>
<li><a href="#theory">Theory of Operation</a></li>
<li><a href="#config">Driver Configuration</a></li>
<li><a href="#device">Device Support</a>
<ol>
<li><a href="#stat">Connection Status</a></li>
<li><a href="#ai">Analog Input</a></li>
<li><a href="#ao">Analog Output</a></li>
<li><a href="#bi">Binary Input</a></li>
<li><a href="#bo">Binary Output</a></li>
<li><a href="#mbbi">Multibit Binary Input</a></li>
<li><a href="#mbbo">Multibit Binary Output</a></li>
<li><a href="#mbbiDirect">Multibit Binary Input Direct</a></li>
<li><a href="#mbboDirect">Multibit Binary Output Direct</a></li>
<li><a href="#longin">Long Input</a></li>
<li><a href="#longout">Long Output</a></li>
<li><a href="#stringin">String Input</a></li>
<li><a href="#stringout">String Output</a></li>
<li><a href="#waveform">Waveform Input</a></li>
<li><a href="#calcout">Calculation Output</a></li>
</ol></li>
<li><a href="#driver">Driver Functions</a></li>
</ol>
<a name="intro"></a>
<h2>1 Introduction</h2>
<p>
This driver is intended to connect a Siemens S7 PLC (programmable
logic controller) via TCP/IP to an EPICS IOC, using the so called
"send/receive" protocol.
However, it can be used for any device sending and receiving blocks of
process variables (PVs) in the same way.
I highly recommend to connect to the PLC on a separate physical
network using a second network interface to avoid connection problems.
</p>
<p>
The driver was originally developped for SLS (Swiss Light Source) in 2000.
Later is has been modified by DESY (Deutsches Elektronen Synchrotron). The
current version has been completely rewritten for PPT (Puls-Plasmatechnik GmbH)
to run on a R3.14.6 PC based system, but it can also run on R3.13 vxWorks
system. Author of the current version is
<a href="mailto:Dirk Zimoch <dirk.zimoch@psi.ch>">Dirk
Zimoch <dirk.zimoch@psi.ch></a>.
</p>
<p>
In this document, it is assumed that the reader is familiar with EPICS, the
record concept and meanings of the fields of the standard records.
Recommended documentation: EPICS Record Refecrence Manual.
</p>
<a name="theory"></a>
<h2>2 Theory of Operation</h2>
<p>
The driver and the PLC periodically exchange data (process variables)
over the network.
For each direction (IOC to PLC and PLC to IOC), there is one fixed size
data block that bundles all process variables for this direction.
The process variables are identified by their bytes offset in the data
block.
</p>
<p>
Process variables can be 8, 16, or 32 bit wide signed or unsigned integers
or bit fields, single or double precision floating point values,
or arrays of these, as well as strings of single byte characters.
Both byte orders, big endian and little endian, are supported.
</p>
<p>
The IOC programmer typically connects one input record to each process
variable sent from the PLC to the IOC and one output record for each
process variable sent from the IOC to the PLC.
This requires that the programmer of the PLC and the programmer of the IOC
agree on the data block sizes and layouts.
The layout is not negotiated between IOC and PLC in any automated way.
</p>
<p>
When the IOC starts, the driver tries to connect to the PLC
which must run a TCP server.
If connection cannot be established (e.g. because the PLC is off)
the driver periodically retries to set up the connection.
Once connected, the driver waits for data blocks sent by the PLC.
The PLC must be set up to send its data periodically.
If the driver does not receive any data within a configurable timeout
(which should be 2 to 10 times the send period of the PLC) or the
data block does not have the correct size, the driver considers the
communication broken and closes the connection.
After a short time it tries to reconnect.
<p>
Upon reciving the data block, the driver copies the process variables
from this block into input records and then triggers processing of the
records.
To allow this triggering, the input records should use "I/O Intr" scanning
(or alternatively be processed by another record that uses "I/O Intr"
and is conencted to the same PLC).
All input records connected to the same PLC are triggered at the same time
after all input values have been updated.
The order of processing is undefined.
</p>
<p>
On the other hand, the driver periodically checks if any of the output
records connected to this PLC has processed since the last cycle.
If and only if this is the case, a data block containing all output
variables is sent to the PLC.
Sending output only starts after the "PINI" run at IOC startup.
This allows to initialize all output records before any data is sent
to the IOC.
Thus all output records should have the "PINI" field set to "YES" (or
alternatively be processed by another record that uses "PINI").
Any output that has not been processed before the data block is sent
to the PLC transfers only 0 bytes (usually meaning integer 0, floating
point 0.0, or empty string, depending on the data type).
<p>
Data blocks are always transfered completely.
That means all process variables in that block are transfered, even
if they have not changed since the last cycle.
There is no way to write or read only a sub-set of process variables.
In between two cycles, any number of process variables may have changed.
These changes are only transfered to the other communication partner
in the next cycle.
Thus, there is always a delay until the values update on the other side
of the connection.
Also if values change too quickly, faster than the transfer cycle,
intermediate values are lost.
</p>
<a name="config"></a>
<h2>3 Driver Configuration</h2>
<p>
In the IOC startup script, the s7plc driver needs to be configured:
</p>
<p class="indent">
<code>
s7plcConfigure (<i>PLCname</i>, <i>IPaddr</i>, <i>port</i>, <i>inSize</i>,
<i>outSize</i>, <i>bigEndian</i>, <i>recvTimeout</i>, <i>sendIntervall</i>)
</code>
</p>
<p>
<code><i>PLCname</i></code> is an arbitrary symbolic name for the PLC running
a server TCP socket on <code><i>IPaddr</i>:<i>port</i></code>.
The records reference the PLC with this name in their <code>INP</code> or
<code>OUT</code> link. <code><i>PLCname</i></code> must not contain the
slash character (<code>/</code>).
</p>
<p>
<code><i>inSize</i></code> and <code><i>outSize</i></code> are the data block
sizes in bytes read from and sent to the PLC, respectively. Any of them can
be <code>0</code>. Byte order is defined by <code><i>bigEndian</i></code>. If
this is <code>1</code>, the IOC expects the PLC to send and receive any
multibyte PV (word, float, etc) most significant byte first. If it is
<code>0</code>, the data is least significant byte first. This is independent
of the byte order of the IOC.
</p>
<p>
If the IOC does not receive new data from the PLC for
<code><i>recvTimeout</i></code> milliseconds, it closes the connection and
tries to reopen it after a few seconds. <code><i>recvTimeout</i></code>
should be 2 to 10 times the send intervall of the PLC.
</p>
<p>
The IOC checks for data to send every <code><i>sendIntervall</i></code>
milliseconds. If any output record has been processed in this time, the
complete buffer is sent to the PLC. If no new output is available, nothing
is sent.
</p>
<h4>Example:</h4>
<p class="indent">
<code>
s7plcConfigure ("vak-4", "192.168.0.10", 2000, 1024, 32, 1, 500, 100)
</code>
</p>
<p>
In the vxWorks target shell, <code><i>PLCname</i></code>, and
<code><i>IPaddr</i></code> must be quoted. In the iocsh, quotes are
optional.
</p>
<p>
The variable <code>s7plcDebug</code> can be set in the statup script or
at any time on the command line to change the amount or debug output.
The following levels are supported:
</p>
<p>
-1: fatal errors only<br>
0: errors only<br>
1: startup messages<br>
2:+ output record processing<br>
3:+ inputput record processing<br>
4:+ driver calls<br>
5:+ io printout<br>
</p>
<p>
Be careful using level>1 since many messages can introduce considerable
delays which may result in connection losses. Default level is 0.
</p>
<p>
On vxWorks, <code>s7plcDebug</code> can be set with
<code>s7plcDebug=<i>level</i></code>
</p>
<p>
In the iocsh use
<code>var s7plcDebug <i>level</i></code>
</p>
<a name="device"></a>
<h2>4 Device Support</h2>
<p>
The driver supports the standard record types <a href="#ai">ai</a>,
<a href="#ao">ao</a>, <a href="#bi">bi</a>, <a href="#bo">bo</a>,
<a href="#mbbi">mbbi</a>, <a href="#mbbo">mbbo</a>,
<a href="#mbbiDirect">mbbiDirect</a>, <a href="#mbboDirect">mbboDirect</a>,
<a href="#longin">longin</a>, <a href="#longout">longout</a>,
<a href="#stringin">stringin</a>, <a href="#stringout">stringout</a>,
and <a href="#waveform">waveform</a>. With EPICS R3.14,
<a href="#calcout">calcout</a> is supported, too.
The <code>DTYP</code> is <code>"S7plc"</code>. If the record processes when
the PLC is not connected (off, down, unreachable), the record raises an
alarm with <code>SEVR="INVALID"</code> and <code>STAT="CONN"</code>.
</p>
<p>
There is also a connection status support for <a href="#stat">bi</a>. The
<code>DTYP</code> is <code>"S7plc stat"</code>. This record does not
raise an alarm when the PLC is disconnected. It just changes to
<code>0</code> state in that case.
</p>
<p>
<code>SCAN="I/O Intr"</code> is supported. Whenever input data is received
from a PLC, all <code>"I/O Intr"</code> input records connected to this PLC
are processed. In each output cyle, all <code>"I/O Intr"</code> output
records are processed.
</p>
<p>
The general form of the <code>INP</code> or <code>OUT</code> link is
</p >
<p class="indent">
<code>
"@<i>PLCname</i>/<i>offset</i> T=<i>type</i> L=<i>low</i> H=<i>high</i> B=<i>bit</i>"
</code>
</p>
<p>
Not all parameters <code>T</code>, <code>L</code>, <code>H</code>, and
<code>B</code> are required for each record type and parameters equal to the
default value may be omitted. The default values depend on the record type.
</p>
<p>
<code><i>PLCname</i></code> is the PLC name as defined by
<code>s7plcConfigure</code> in the startup script.
</p>
<p>
<code><i>offset</i></code> is the byte offset of the PV relative to the
beginning of the input or output data block for this PLC. It must be an
integer number or a sum of integer numbers like <code>20+3+2</code>.
</p>
<p>
<code>T=<i>type</i></code> defines the data type for transmitting the PV
from or to the PLC. It is not case sensitive and has several aliases (see
table <a href="#type">below</a>).
The default is <code>T=INT16</code> for most record types.
<code>L=<i>low</i></code> and <code>H=<i>high</i></code> are used in analog
input and output records if <code>LINR</code> is set to <code>"LINEAR"</code>
to convert analog values to integer values and back. They define the raw
values which correspond to <code>EGUL</code> and <code>EGUF</code>,
respectively.
Analog output records will never write integer values lower than
<code>L</code> or higher than <code>H</code>. If necessary, the raw output
value is truncated to the nearest limit. The default values for
<code>L</code> and <code>H</code> depend on <code>T</code>.
</p>
<a name="type"></a>
<center>
<table border=1 cellpadding=5>
<tr>
<th>T=</th><th>Data Type</th><th>Default L=</th><th>Default H=</th>
</tr>
<tr>
<td><tt>INT8</tt>
</td><td>8 bit (1 byte) signed integer number</td>
<td><tt>-0x7F<br>-127</tt></td>
<td><tt>0x7F<br>127</tt></td>
</tr>
<tr>
<td><tt>UINT8<br>UNSIGN8<br>BYTE<br>CHAR</tt>
</td><td>8 bit (1 byte) unsigned integer number</td>
<td><tt>0x00<br>0</tt></td>
<td><tt>0xFF<br>255</tt></td>
</tr>
<tr>
<td><tt>INT16<br>SHORT</tt></td>
<td>16 bit (2 bytes) signed integer number</td>
<td><tt>-0x7FFF<br>-32767</tt></td>
<td><tt>0x7FFF<br>32767</tt></td>
</tr>
<tr>
<td><tt>UINT16<br>UNSIGN16<br>WORD</tt></td>
<td>16 bit (2 bytes) unsigned integer number</td>
<td><tt>0x0000<br>0</tt></td>
<td><tt>0xFFFF<br>65535</tt></td>
</tr>
<tr>
<td><tt>INT32<br>LONG</tt></td>
<td>32 bit (4 bytes) signed integer number</td>
<td><tt>-0x7FFFFFFF<br>-2147483647</tt></td>
<td><tt>0x7FFFFFFF<br>2147483647</tt></td>
</tr>
<tr>
<td><tt>UINT32<br>UNSIGN32<br>DWORD</tt></td>
<td>32 bit (4 bytes) unsigned integer number</td>
<td><tt>0x00000000<br>0</tt></td>
<td><tt>0xFFFFFFFF<br>4294967295</tt></td>
</tr>
<tr>
<td><tt>REAL32<br>FLOAT32<br>FLOAT</tt></td>
<td>32 bit (4 bytes) floating point number</td>
<td>N/A</td><td>N/A</td>
</tr>
<tr>
<td><tt>REAL64<br>FLOAT64<br>DOUBLE</tt></td>
<td>64 bit (8 bytes) floating point number</td>
<td>N/A</td><td>N/A</td>
</tr>
<tr>
<td><tt>STRING</tt></td>
<td>character array</td>
<td>40</td><td>N/A</td>
</tr>
</table>
</center>
<p>
If <code>T=STRING</code>, <code>L</code> means <i>length</i>, not <i>low</i>.
The default value is the length of the <code>VAL</code> field.
In the case of the stringin and stringout records, this is 40 (including
the terminating null byte).
</p>
<p>
<code>B=<i>bit</i></code> is only used for bi and bo records to define the
bit number within the data byte, word, or doubleword (depending on
<code>T</code>). Bit number 0 is the least significant bit.
Note that in big endian byte order (also known as motorola format) bit 0 is
in the last byte, while in little endian byte order (intel format) bit 0 is
in the first byte. If in doubt, use <code>T=BYTE</code> to avoid all
byte order problems when handling single bits.
</p>
<p>
Note that the output buffer is initialised with null bytes at startup and
any output record that has not been processed after reboot will send null
values to the PLC. The driver does not send anything before the global
variable <code>interruptAccept</code> has been set <code>TRUE</code> at the
end of <code>iocInit</code>. All records with <code>PINI</code> set to
<code>"YES"</code> have already been processed by that time. The driver
does not change the <code>VAL</code> field of any output record at
initialisation. Thus, auto save and restore can be used in combination with
<code>PINI="YES"</code>.
</p>
<a name="stat"></a>
<h3>4.1 Connection Status</h3>
<pre>
record (bi, "$(RECORDNAME)") {
field (DTYP, "S7plc stat")
field (INP, "@$(PLCNAME)")
field (SCAN, "I/O Intr")
}
</pre>
<p>
The record value is 1 if a connection to the PLC is established and 0 if not.
Disconnect does not raise an alarm.
</p>
<a name="ai"></a>
<h3>4.2 Analog Input</h3>
With conversion from integer data type:
<pre>
record (ai, "$(RECORDNAME)") {
field (DTYP, "S7plc")
field (INP, "@$(PLCNAME)/$(OFFSET) T=$(T) L=$(L) H=$(H)")
field (SCAN, "I/O Intr")
field (LINR, "Linear")
field (EGUL, "$(MINVAL)")
field (EGUF, "$(MAXVAL)")
}
</pre>
Using floating point data type:
<pre>
record (ai, "$(RECORDNAME)") {
field (DTYP, "S7plc")
field (INP, "@$(PLCNAME)/$(OFFSET) T=$(T)")
field (SCAN, "I/O Intr")
}
</pre>
<p>
Default type is <code>T=INT16</code>.
Defaults for <code>L</code> and <code>H</code> depend
on <code>T</code> (see table <a href="#type">above</a>).
</p>
<p>
If <code>T</code> is an integer type, the PV is read into
<code>RVAL</code>. If <code>LINR</code> is set to <code>"LINEAR"</code>,
then the record support converts <code>RVAL</code> to <code>VAL</code>
so that <code>RVAL=L</code> converts to <code>VAL=EGUL</code> and
<code>RVAL=H</code> converts to <code>VAL=EGUF</code>.
</p>
<p>
<code>VAL<sub>temp</sub>=(RVAL-L)*(EGUF-EGUL)/(H-L)+EGUL</code>
</p>
<p>
After this conversion, <code>VAL<sub>temp</sub></code> is still
subject to scaling and smoothing.
</p>
<p>
<code>VAL=(VAL<sub>temp</sub>*ASLO+AOFF)*(1-SMOO)+VAL<sub>old</sub>*SMOO</code>.
</p>
<p>
If <code>T=FLOAT</code> or <code>T=DOUBLE</code>,
the PV is read directly into <code>VAL</code> and <code>L</code>,
<code>H</code>, <code>EGUL</code> and <code>EGUF</code> are ignored.
The device support emulates scaling and smoothing which is otherwise done
by the record support during conversion.
</p>
<p>
<code>VAL=(<i>PV</i>*ASLO+AOFF)*(1-SMOO)+VAL<sub>old</sub>*SMOO</code>
</p>
<p>
<code>T=STRING</code> is not valid for ai records.
</p>
<a name="ao"></a>
<h3>4.3 Analog Output</h3>
With conversion to integer data type:
<pre>
record (ao, "$(RECORDNAME)") {
field (DTYP, "S7plc")
field (OUT, "@$(PLCNAME)/$(OFFSET) T=$(T) L=$(L) H=$(H)")
field (LINR, "Linear")
field (PINI, "YES")
field (EGUL, "$(MINVAL)")
field (EGUF, "$(MAXVAL)")
}
</pre>
Using floating point data type:
<pre>
record (ao, "$(RECORDNAME)") {
field (DTYP, "S7plc")
field (OUT, "@$(PLCNAME)/$(OFFSET) T=$(T)")
field (PINI, "YES")
}
</pre>
<p>
Default type is <code>T=INT16</code>.
Defaults for <code>L</code> and <code>H</code> depend
on <code>T</code> (see table <a href="#type">above</a>).
</p>
<p>
If <code>T</code> is an integer type, <code>RVAL</code> is
written to the PV. If <code>LINR</code> is set to <code>"LINEAR"</code>,
then the record support first scales <code>OVAL</code>.
</p>
<p>
<code>OVAL<sub>temp</sub>=(OVAL-AOFF)/ASLO</code>
</p>
<p>
After that, the value is converted to <code>RVAL</code> so that
<code>OVAL<sub>temp</sub>=EGUL</code> converts to <code>RVAL=L</code> and
<code>OVAL<sub>temp</sub>=EGUF</code> converts to <code>RVAL=H</code>.
</p>
<p>
<code>RVAL=(OVAL<sub>temp</sub>-EGUL)*(H-L)/(EGUF-EGUL)+L</code>
</p>
<p>
If <code>RVAL</code> is higher than <code>H</code> or lower than
<code>L</code>, the value is truncated to the nearest limit.
</p>
<p>
If <code>T=FLOAT</code> or <code>T=DOUBLE</code>,
<code>OVAL</code> is written directly to the PV. <code>L</code>,
<code>H</code>, <code>EGUL</code> and <code>EGUF</code> are ignored.
The device support emulates scaling which is otherwise done by the
record support during conversion.
</p>
<p>
<code><i>PV</i>=(OVAL-AOFF)/ASLO</code>
</p>
<p>
<code>T=STRING</code> is not valid for ao records.
</p>
<a name="bi"></a>
<h3>4.4 Binary Input</h3>
<pre>
record(bi, "$(NAME)") {
field (DTYP, "S7plc")
field (INP, "@$(PLCNAME)/$(OFFSET) T=$(T) B=$(B)")
field (SCAN, "I/O Intr")
}
</pre>
<p>
Default type is <code>T=INT16</code>. Default bit is <code>B=0</code>.
</p>
<p>
Depending on <code>T</code>, <code>B</code> can vary from 0 to 7, 15, or 31.
Bit 0 is the least significant bit. In little endian byte order, bit 0 is in
the first byte, in big endian byte order it is in the last byte of the PV.
If in doubt, use <code>T=BYTE</code> to avoid all byte order problems when
handling single bits.
</p>
<p>
The PV is read to <code>RVAL</code> and masked with
2<sup><code>B</code></sup>.
<code>VAL</code> is 1 if <code>RVAL</code> is not 0.
</p>
<p>
<code>RVAL=<i>PV</i>&(1<<B); VAL=(RVAL!=0)?1:0</code>
</p>
<p>
<code>T=STRING</code>, <code>T=FLOAT</code> or <code>T=DOUBLE</code> are not
valid for bo records. Signed and unsigned types are equivalent.
</p>
<a name="bo"></a>
<h3>4.5 Binary Output</h3>
<pre>
record(bo, "$(NAME)") {
field (DTYP, "S7plc")
field (OUT, "@$(PLCNAME)/$(OFFSET) T=$(T) B=<i>bit</i>")
field (PINI, "YES")
}
</pre>
<p>
Default type is <code>T=INT16</code>. Default bit is <code>B=0</code>.
</p>
<p>
Depending on <code>T</code>, <code>B</code> can vary from 0 to 7, 15, or 31.
Bit 0 is the least significant bit. In little endian byte order, bit 0 is in
the first byte, in big endian byte order it is in the last byte of the PV.
If in doubt, use <code>T=BYTE</code> to avoid all byte order problems when
handling single bits.
</p>
<p>
If <code>VAL</code> is not 0, then <code>RVAL</code> is set to
2<sup><code>B</code></sup>, else <code>RVAL</code> is set to 0.
Only the referenced bit of the PV is changed while all other bits remain
untouched. Thus, other output records can write to different bits of the
same PV.
<p>
<code>RVAL=(VAL!=0)?(1<<<i>bit</i>):0;
<i>PV</i>=(<i>PV</i><sub>old</sub>&~(1<<<i>bit</i>))|RVAL</code>
</p>
<p>
<code>T=STRING</code>, <code>T=FLOAT</code> or <code>T=DOUBLE</code> are not
valid for bo records. Signed and unsigned types are equivalent.
</p>
<a name="mbbi"></a>
<h3>4.6 Multibit Binary Input</h3>
<pre>
record(mbbi, "$(NAME)") {
field (DTYP, "S7plc")
field (INP, "@$(PLCNAME)/$(OFFSET) T=$(T)")
field (SCAN, "I/O Intr")
field (NOBT, "$(NUMBER_OF_BITS)")
field (SHFT, "$(RIGHT_SHIFT)")
}
</pre>
<p>
Default type is <code>T=INT16</code>.
</p>
<p>
The PV is read to <code>RVAL</code>, shifted right by <code>SHFT</code> bits
and masked with <code>NOBT</code> bits. Valid values for <code>NOBT</code>
and <code>SHFT</code> depend on <code>T</code>:
<code>NOBT</code>+<code>SHFT</code> must not exceed the number of bits of
the type.
</p>
<p>
Bit 0 is the least significant bit. In little endian byte order, bit 0 is in
the first byte, in big endian byte order it is in the last byte of the PV.
</p>
<p>
<b>Example:</b> Use bits 4 to 9 out of 16.
<code>T=INT16</code>, <code>NOBT=6</code>, <code>SHFT=4</code>
</p>
<table border=1 cellspacing=0>
<tr>
<td>PV</td>
<th bgcolor="#c0c0c0" width="5%">15</th>
<th bgcolor="#c0c0c0" width="5%">14</th>
<th bgcolor="#c0c0c0" width="5%">13</th>
<th bgcolor="#c0c0c0" width="5%">12</th>
<th bgcolor="#c0c0c0" width="5%">11</th>
<th bgcolor="#c0c0c0" width="5%">10</th>
<th width="5%">9</th>
<th width="5%">8</th>
<th width="5%">7</th>
<th width="5%">6</th>
<th width="5%">5</th>
<th width="5%">4</th>
<th bgcolor="#c0c0c0" width="5%">3</th>
<th bgcolor="#c0c0c0" width="5%">2</th>
<th bgcolor="#c0c0c0" width="5%">1</th>
<th bgcolor="#c0c0c0" width="5%">0</th>
</tr>
<tr>
<td>RVAL</td>
<th bgcolor="#c0c0c0"> </th>
<th bgcolor="#c0c0c0"> </th>
<th bgcolor="#c0c0c0"> </th>
<th bgcolor="#c0c0c0"> </th>
<th bgcolor="#c0c0c0"> </th>
<th bgcolor="#c0c0c0"> </th>
<th bgcolor="#c0c0c0"> </th>
<th bgcolor="#c0c0c0"> </th>
<th bgcolor="#c0c0c0"> </th>
<th bgcolor="#c0c0c0"> </th>
<th>9</th>
<th>8</th>
<th>7</th>
<th>6</th>
<th>5</th>
<th>4</th>
</tr>
</table>
<p>
<code>T=STRING</code>, <code>T=FLOAT</code> or <code>T=DOUBLE</code> are not
valid for mbbi records. Signed and unsigned types are equivalent.
</p>
<a name="mbbo"></a>
<h3>4.7 Multibit Binary Output</h3>
<pre>
record(mbbo, "$(NAME)") {
field (DTYP, "S7plc")
field (OUT, "@$(PLCNAME)/$(OFFSET) T=$(T)")
field (PINI, "YES")
field (NOBT, "$(NUMBER_OF_BITS)")
field (SHFT, "$(LEFT_SHIFT)")
}
</pre>
<p>
Default type is <code>T=INT16</code>.
</p>
<p>
RVAL is masked with <code>NOBT</code> bits, shifted left by
<code>SHFT</code> bits and written to the PV. Valid values for
<code>NOBT</code> and <code>SHFT</code> depend on <code>T</code>:
<code>NOBT</code>+<code>SHFT</code> must not exceed the number of bits of
the type.
</p>
<p>
Bit 0 is the least significant bit. In little endian byte order, bit 0 is in
the first byte, in big endian byte order it is in the last byte of the PV.
</p>
<p>
Only the referenced <code>NOBT</code> bits of the PV are changed. All other
bits remain untouched. Thus, other output records can write to different bits
of the same PV.
</p>
<p>
<b>Example:</b> Use bits 5 to 8 out of 16.
<code>T=INT16</code>, <code>NOBT=4</code>, <code>SHFT=5</code>
</p>
<table border=1 cellspacing=0>
<tr>
<td>RVAL</td>
<th bgcolor="#c0c0c0"> </th>
<th bgcolor="#c0c0c0"> </th>
<th bgcolor="#c0c0c0"> </th>
<th bgcolor="#c0c0c0"> </th>
<th bgcolor="#c0c0c0"> </th>
<th bgcolor="#c0c0c0"> </th>
<th bgcolor="#c0c0c0"> </th>
<th bgcolor="#c0c0c0"> </th>
<th bgcolor="#c0c0c0"> </th>
<th bgcolor="#c0c0c0"> </th>
<th bgcolor="#c0c0c0"> </th>
<th bgcolor="#c0c0c0"> </th>
<th>8</th>
<th>7</th>
<th>6</th>
<th>5</th>
</tr>
<tr>
<td>PV</td>
<th bgcolor="#c0c0c0" width="5%">15</th>
<th bgcolor="#c0c0c0" width="5%">14</th>
<th bgcolor="#c0c0c0" width="5%">13</th>
<th bgcolor="#c0c0c0" width="5%">12</th>
<th bgcolor="#c0c0c0" width="5%">11</th>
<th bgcolor="#c0c0c0" width="5%">10</th>
<th bgcolor="#c0c0c0" width="5%">9</th>
<th width="5%">8</th>
<th width="5%">7</th>
<th width="5%">6</th>
<th width="5%">5</th>
<th bgcolor="#c0c0c0" width="5%">4</th>
<th bgcolor="#c0c0c0" width="5%">3</th>
<th bgcolor="#c0c0c0" width="5%">2</th>
<th bgcolor="#c0c0c0" width="5%">1</th>
<th bgcolor="#c0c0c0" width="5%">0</th>
</tr>
</table>
<p>
<code>T=STRING</code>, <code>T=FLOAT</code> or <code>T=DOUBLE</code> are not
valid for mbbo records. Signed and unsigned types are equivalent.
</p>
<a name="mbbiDirect"></a>
<h3>4.8 Multibit Binary Input Direct</h3>
<pre>
record(mbbiDirect, "$(NAME)") {
field (DTYP, "S7plc")
field (INP, "@$(PLCNAME)/$(OFFSET) T=$(T)")
field (SCAN, "I/O Intr")
field (NOBT, "$(NUMBER_OF_BITS)")
field (SHFT, "$(RIGHT_SHIFT)")
}
</pre>
<p>
Default type is <code>T=INT16</code>.
</p>
<p>
The PV is read to <code>VAL</code>, shifted right by <code>SHFT</code>
bits and masked with <code>NOBT</code> bits (see <a href="#mbbi">mbbi</a>).
Valid values for <code>NOBT</code> and <code>SHFT</code> depend
on <code>T</code>: <code>NOBT</code>+<code>SHFT</code> must
not exceed the number of bits of the type.
</p>
<p>
Bit 0 is the least significant bit. In little endian byte order, bit 0 is in
the first byte, in big endian byte order it is in the last byte of the PV.
</p>
<p>
<code>T=STRING</code>, <code>T=FLOAT</code> or <code>T=DOUBLE</code> are not
valid for mbbiDirect records. Signed and unsigned types are equivalent.
</p>
<a name="mbboDirect"></a>
<h3>4.9 Multibit Binary Output Direct</h3>
<pre>
record(mbboDirect, "$(NAME)") {
field (DTYP, "S7plc")
field (OUT, "@$(PLCNAME)/$(OFFSET) T=$(T)")
field (PINI, "YES")
field (NOBT, "$(NUMBER_OF_BITS)")
field (SHFT, "$(LEFT_SHIFT)")
}
</pre>
<p>
Default type is <code>T=INT16</code>.
</p>
<p>
VAL is masked with <code>NOBT</code> bits, shifted left by <code>SHFT</code>
bits and written to the PV (see <a href="#mbbo">mbbo</a>). Valid values for
<code>NOBT</code> and <code>SHFT</code> depend on <code>T</code>:
<code>NOBT</code>+<code>SHFT</code> must not exceed the number of bits of
the type.
</p>
<p>
Bit 0 is the least significant bit. In little endian byte order, bit 0 is in
the first byte, in big endian byte order it is in the last byte of the PV.
</p>
<p>
Only the referenced <code>NOBT</code> bits of the PV are changed. All other
bits remain untouched. Thus, other output records can write to different bits
of the same PV.
</p>
<p>
<code>T=STRING</code>, <code>T=FLOAT</code> or <code>T=DOUBLE</code> are not
valid for mbboDirect records. Signed and unsigned types are equivalent.
</p>
<a name="longin"></a>
<h3>4.10 Long Input</h3>
<pre>
record(longin, "$(NAME)") {
field (DTYP, "S7plc")
field (INP, "@$(PLCNAME)/$(OFFSET) T=$(T)")
field (SCAN, "I/O Intr")
}
</pre>
<p>
Default type is <code>T=INT16</code>.
</p>
<p>
The PV is read to <code>VAL</code>. If the type has less than 32 bits, the
value is zero extended or sign extended depending on the signedness of
the type.
</p>
<p>
<code>T=STRING</code>, <code>T=FLOAT</code> or <code>T=DOUBLE</code> are not
valid for longin records.
</p>
<a name="longout"></a>
<h3>4.11 Long Output</h3>
<pre>
record(longout, "$(NAME)") {
field (DTYP, "S7plc")
field (OUT, "@$(PLCNAME)/$(OFFSET) T=$(T)")
field (PINI, "YES")
}
</pre>
<p>
Default type is <code>T=INT16</code>.
</p>
<p>
Depending on <code>T</code>, the least significant 8, 16, or 32 bytes
of <code>VAL</code> are written to the PV.
</p>
<p>
<code>T=STRING</code>, <code>T=FLOAT</code> or <code>T=DOUBLE</code> are not
valid for longout records.
</p>
<a name="stringin"></a>
<h3>4.12 String Input</h3>
<pre>
record(stringin, "$(NAME)") {
field (DTYP, "S7plc")
field (INP, "@$(PLCNAME)/$(OFFSET) L=$(LENGTH)")
field (SCAN, "I/O Intr")
}
</pre>
<p>
Default and only valid type is <code>T=STRING</code>.
Default (and maximum) length is <code>L=40</code>.
</p>
<p>
<code>L</code> bytes are read from the PV to <code>VAL</code> and null
terminated. Because the stringin record uses a fixed size, 40-byte long
buffer if <code>L<40</code>, the effective string length is <code>L</code>
bytes. If <code>L=40</code>, the effective string length is 39 bytes.
</p>
<a name="stringout"></a>
<h3>4.13 String Output</h3>
<pre>
record(stringout, "$(NAME)") {
field (DTYP, "S7plc")
field (OUT, "@$(PLCNAME)/$(OFFSET) L=$(LENGTH)")
field (PINI, "YES")
}
</pre>
<p>
Default and only valid type is <code>T=STRING</code>.
Default length is <code>L=40</code>.
</p>
<p>
<code>L</code> bytes are written from <code>VAL</code> to the PV.
If the actual string length of <code>VAL</code> is shorter than
<code>L</code>, the remaining space is filled with null bytes. If
it is longer than <code>L</code>, the string is truncated and not
null terminated
</p>
<a name="waveform"></a>
<h3>4.14 Waveform Input</h3>
<pre>
record(waveform, "$(NAME)") {
field (DTYP, "S7plc")
field (INP, "@$(PLCNAME)/$(OFFSET)")
field (SCAN, "I/O Intr")
field (NELM, "$(NUMBER_OF_ELEMENTS)")
field (FTVL, "$(DATATYPE)")
}
</pre>
<p>
<code>NELM</code> elements are read from the PV to <code>VAL</code>.
</p>
<p>
The default type depends on <code>FTVL</code>. For example
<code>FTVL=LONG</code> results in <code>T=INT32</code>.
<code>T</code> and <code>FTVL</code> must match but can differ
in signedness. In most cases, better just specify <code>FTVL</code> and
leave <code>T</code> to the default.
</p>
<p>
If <code>T=STRING</code>, <code>FTVL</code> must be <code>"CHAR"</code> or
<code>"UCHAR"</code>. <code>L=<i>length</i></code> can be specified but
defaults to and must not exceed <code>NELM</code>.
If <code>L</code> is less than <code>NELM</code>, the
remaining elements are left untouched.
</p>
<p>
<code>FTVL="STRING"</code> is not supported.
</p>
<p>
The special type <code>T=TIME</code> is supported for
waveforms records only. <code>FTVL</code> must be
<code>"CHAR"</code> or <code>"UCHAR"</code> and <code>NELM</code> should be
<code>"8"</code>. The input bytes are converted from BCD (binary coded decimal)
to integer values in the range from 0 to 99 each. This type is intended
to transfer BCD coded real time clock timestamps.
</p>
<p>
The Siemens "STEP 7" manual defines the 8 byte PLC timetamp as follows:
</p>
<table border=1 cellspacing=0>
<tr>
<th>0</th>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th>5</th>
<th>6</th>
<th>7</th>
</tr>
<tr>
<td>year</td>
<td>month</td>
<td>day</td>
<td>hour</td>
<td>minute</td>
<td>second</td>
<td>msec(hi)</td>
<td>msec(lo)*10+day of week</td>
</tr>
</table>
<p>
Years 90 to 99 mean 1990 to 1999, years 0 to 89 mean 2000 to 2089. Months
and days start with 1. Hour is 0 to 23, minute and second 0 to 59. Msec are
milliseconds in the range 0 to 999. The first two digits (0-99 hundredth of
a second) are in msec(hi). The last digit (0-9 thousandth of a second)
is multiplyed by 10 and added to the day of week (Sunday=1 to Saturday=7).
If you want to have the unconverted BCD bytes, do not use
<code>T=TIME</code>.
</p>
<a name="calcout"></a>
<h3>4.15 Calculation Output</h3>
<pre>
record(calcout, "$(NAME)") {
field (DTYP, "S7plc")
field (OUT, "@$(PLCNAME)/$(OFFSET) T=$(T) L=$(L) H=$(H)")
field (PINI, "YES")
}
</pre>
<p>
Default type is <code>T=INT16</code>.
Defaults for <code>L</code> and <code>H</code> depend
on <code>T</code> (see table <a href="#type">above</a>).
</p>
<p>
<code>OVAL</code> (the result of <code>CALC</code> or <code>OCAL</code>,
depending on <code>DOPT</code>) is written to the PV. If
<code>T</code> is an integer type, the value is truncated to an
integer and compared to <code>L</code> and <code>H</code>.
If <code>OVAL</code> is lower than <code>L</code> or higher than
<code>H</code>, it is truncated to the nearest limit.
</p>
<p>
If <code>T=FLOAT</code> or <code>T=DOUBLE</code>,
<code>OVAL</code> is written to the PV directly without any conversion.
</p>
<p>
<code>T=STRING</code> is not valid for calcout records.
</p>
<p>
To use this device support with calcout records, you need EPICS R3.14.
</p>
<a name="driver"></a>
<h2>5 Driver Functions</h2>
<p>
Device support for other record types can be written with calls to the
following driver functions:
</p>
<p>
<code>
s7plcStation* s7plcOpen (char* PLCname);
</code>
</p>
<p class="indent">
<code>
int s7plcRead (s7plcStation* station,
unsigned int offset, unsigned int dlen,
void* pdata);
</code>
</p>
<p class="indent">
<code>
int s7plcReadArray (s7plcStation* station,