forked from PLC-lang/oscat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oscat_single_file.st
30045 lines (23791 loc) · 591 KB
/
oscat_single_file.st
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
(* @NESTEDCOMMENTS := 'Yes' *)
(* @PATH := '\/Buffer Management' *)
(* @OBJECTFLAGS := '0, 8' *)
(* @SYMFILEFLAGS := '2048' *)
@EXTERNAL
FUNCTION _BUFFER_CLEAR : BOOL
VAR_INPUT
PT : REF_TO BYTE;
SIZE : UINT;
END_VAR
VAR
ptw : REF_TO DWORD;
temp: DWORD;
end, end32 : DWORD;
END_VAR
(*
version 1.2 31. oct. 2008
programmer hugo
tested by oscat
this function will initialize a given array of byte with 0.
the function needs to be called: _buffer_clear(adr("array"),sizeof("array"));
this function will manipulate a given array.
the function manipulates the original array, it rerturnes true when finished.
because this function works with pointers its very time efficient and it needs no extra memory.
*)
(* @END_DECLARATION := '0' *)
(* this routine uses 32 bit access to gain speed *)
(* first access bytes till pointer is aligned for 32 bit access *)
temp := pt;
end := temp + UINT_TO_DWORD(size);
end32 := end - 3;
WHILE (pt < end) AND ((temp AND 16#00000003) > 0) DO
pt^ := 0;
pt := pt + 1;
temp := temp + 1;
END_WHILE;
(* pointer is aligned, now copy 32 bits at a time *)
ptw := pt;
WHILE ptw < end32 DO (* *)
ptw^ := 0;
ptw := ptw + 4;
END_WHILE;
(* copy the remaining bytes in byte mode *)
pt := ptw;
WHILE pt < end DO
pt^ := 0;
pt := pt + 1;
END_WHILE;
_BUFFER_CLEAR := TRUE;
(* revision History
hm 5. mar. 2008 rev 1.0
original version
hm 16. mar. 2008 rev 1.1
added type conversion to avoid warnings under codesys 30
chaged type of input size to uint
deleted unused variable i
hm 31. oct. 2008 rev 1.2
corrected an error while routine would write outside of arrays
*)
END_FUNCTION
(* @NESTEDCOMMENTS := 'Yes' *)
(* @PATH := '\/Buffer Management' *)
(* @OBJECTFLAGS := '0, 8' *)
(* @SYMFILEFLAGS := '2048' *)
@EXTERNAL
FUNCTION _BUFFER_INIT : BOOL
VAR_INPUT
PT : REF_TO BYTE;
SIZE : UINT;
INIT : BYTE;
END_VAR
VAR
ptw : REF_TO DWORD;
temp : DWORD;
end, end32 : DWORD;
END_VAR
(*
version 1.2 31. oct. 2008
programmer hugo
tested by oscat
this function will initialize a given array of byte with init.
the function needs to be called: _buffer_init(adr("array"),sizeof("array"),init);
this function will manipulate a given array.
the function manipulates the original array, it rerturnes true when finished.
because this function works with pointers its very time efficient and it needs no extra memory.
*)
(* @END_DECLARATION := '0' *)
(* this routine uses 32 bit access to gain speed *)
(* first access bytes till pointer is aligned for 32 bit access *)
temp := pt;
end := temp + UINT_TO_DWORD(size);
end32 := end - 3;
WHILE (pt < end) AND ((temp AND 16#00000003) > 0) DO
pt^ := init;
pt := pt + 1;
temp := temp + 1;
END_WHILE;
(* pointer is aligned, now copy 32 bits at a time *)
ptw := pt;
temp := SHL(BYTE_TO_DWORD(init),24) OR SHL(BYTE_TO_DWORD(init),16) OR SHL(BYTE_TO_DWORD(init),8) OR BYTE_TO_DWORD(init);
WHILE ptw < end32 DO
ptw^ := temp;
ptw := ptw + 4;
END_WHILE;
(* copy the remaining bytes in byte mode *)
pt := ptw;
WHILE pt < end DO
pt^ := init;
pt := pt + 1;
END_WHILE;
_BUFFER_INIT := TRUE;
(* revision History
hm 5. mar. 2008 rev 1.0
original version
hm 16. mar. 2008 rev 1.1
added type conversion to avoid warnings under codesys 3.0
chaged type of input size to uint.
hm 31. oct. 2008 rev 1.2
corrected an error while routine would write outside of arrays
*)
END_FUNCTION
(* @NESTEDCOMMENTS := 'Yes' *)
(* @PATH := '\/Buffer Management' *)
(* @OBJECTFLAGS := '0, 8' *)
(* @SYMFILEFLAGS := '2048' *)
FUNCTION _BUFFER_INSERT : INT
VAR_INPUT
STR : STRING[STRING_LENGTH];
POS : INT;
PT : REF_TO ARRAY[0..32767] OF BYTE;
SIZE : UINT;
END_VAR
VAR
end : INT;
lx: INT;
i: INT;
END_VAR
(*
version 1.5 2. jan. 2012
programmer hugo
tested by oscat
this function will insert a string at a given position in a buffer.
the function needs to be called: _buffer_init(adr("array"),sizeof("array"),init);
this function will manipulate a given array.
the function manipulates the original array, it returnes the next position after the input string when finished.
because this function works with pointers its very time efficient and it needs no extra memory.
*)
(* @END_DECLARATION := '0' *)
lx := LEN(str);
end := pos + lx;
(* first move the upper part of the buffer to make space for the string *)
FOR i := UINT_TO_INT(size) - 1 TO end BY -1 DO
pt^[i] := pt^[i-lx];
END_FOR;
(* copy the string *)
_BUFFER_INSERT := _STRING_TO_BUFFER(str, pos, PT, size);
(* revision History
hm 9. mar. 2008 rev 1.0
original version
hm 16. mar. 2008 rev 1.1
changed type of input size to uint
hm 13. may. 2008 rev 1.2
changed type of pointer to array[1..32767]
changed size of string to STRING_LENGTH
hm 23. mar. 2009 rev 1.3
avoid writing to input pos
hm 12. nov. 2009 rev 1.4
code optimized
hm 2. jan 2012 rev 1.5
function now returns the next position after the input string
*)
END_FUNCTION
(* @NESTEDCOMMENTS := 'Yes' *)
(* @PATH := '\/Buffer Management' *)
(* @OBJECTFLAGS := '0, 8' *)
(* @SYMFILEFLAGS := '2048' *)
FUNCTION _BUFFER_UPPERCASE : BOOL
VAR_INPUT
PT : REF_TO ARRAY[0..32000] OF BYTE;
SIZE : INT;
END_VAR
VAR
pos: INT;
END_VAR
(*
version 1.0 20. jan. 2011
programmer hugo
tested by oscat
this function will convert an array of byte into uppercase
the function needs to be called: _buffer_clear(adr("array"),sizeof("array"));
this function will manipulate a given array.
the function manipulates the original array, it rerturnes true when finished.
because this function works with pointers its very time efficient and it needs no extra memory.
*)
(* @END_DECLARATION := '0' *)
pos := 0;
WHILE pos < size DO
PT^[pos] := TO_UPPER(pt^[pos]);
pos := pos + 1;
END_WHILE;
_BUFFER_UPPERCASE := TRUE;
(* revision History
hm 20. jan. 2011 rev 1.0
original version
*)
END_FUNCTION
(* @NESTEDCOMMENTS := 'Yes' *)
(* @PATH := '\/Buffer Management' *)
(* @OBJECTFLAGS := '0, 8' *)
(* @SYMFILEFLAGS := '2048' *)
@EXTERNAL
FUNCTION _STRING_TO_BUFFER : INT
VAR_INPUT
STR : STRING[STRING_LENGTH];
POS : INT;
PT : REF_TO ARRAY[0..32767] OF BYTE;
SIZE : UINT;
END_VAR
VAR
ps : REF_TO BYTE;
i: INT;
end: INT;
END_VAR
(*
version 1.4 2. jan. 2012
programmer hugo
tested by oscat
this function will copy a string into an array of byte starting at position pos.
the function needs to be called: _String_To_buffer(str, pos, adr("array"),sizeof("array"));
this function will manipulate the array directly in memory and returns the position after the input string when finished.
because this function works with pointers its very time efficient and it needs no extra memory.
*)
(* @END_DECLARATION := '0' *)
ps := &(str);
end := MIN(pos + LEN(str), UINT_TO_INT(size));
IF end > 0 THEN end := end -1; END_IF;
FOR i := pos TO end DO
pt^[i] := ps^;
ps := ps + 1;
END_FOR;
_STRING_TO_BUFFER := i;
(* revision History
hm 5. mar. 2008 rev 1.0
original version
hm 16. mar. 2008 rev 1.1
changed type of input size to uint
hm 13. may. 2008 rev 1.2
changed type of pointer to array[1..32767]
changed size of string to STRING_LENGTH
hm 12. nov. 2009 rev 1.3
limit end to size - 1
hm 2. jan 2012 rev 1.4
return the position after the input string when finished
*)
END_FUNCTION
(* @NESTEDCOMMENTS := 'Yes' *)
(* @PATH := '\/Buffer Management' *)
(* @OBJECTFLAGS := '0, 8' *)
(* @SYMFILEFLAGS := '2048' *)
@EXTERNAL
FUNCTION BUFFER_COMP : INT
VAR_INPUT
PT1 : REF_TO ARRAY[0..32767] OF BYTE;
SIZE1 : INT;
PT2 : REF_TO ARRAY[0..32767] OF BYTE;
SIZE2 : INT;
START : INT;
END_VAR
VAR
i, j, end : INT;
firstbyte: BYTE;
END_VAR
(*
version 1.1 12. nov. 2009
programmer hugo
tested by oscat
*)
(* @END_DECLARATION := '0' *)
(* search for first character match *)
IF size2 <= size1 THEN
end := size1 - size2;
firstbyte := PT2^[0];
FOR i := START TO end DO
IF PT1^[i] = firstbyte THEN
(* first character matches, now compare rest of array *)
j := 1;
WHILE j < size2 DO
IF pt2^[j] <> pt1^[j+i] THEN EXIT; END_IF;
j := j + 1;
END_WHILE;
(* when J > size2 a match was found return the position i in buffer1 *)
IF j = size2 THEN
BUFFER_COMP := i;
RETURN;
END_IF;
END_IF;
END_FOR;
END_IF;
BUFFER_COMP := -1;
(*
hm 14. nov. 2008 rev 1.0
original version
hm 12. nov. 2009 rev 1.1
performance increase
*)
END_FUNCTION
(* @NESTEDCOMMENTS := 'Yes' *)
(* @PATH := '\/Buffer Management' *)
(* @OBJECTFLAGS := '0, 8' *)
(* @SYMFILEFLAGS := '2048' *)
@EXTERNAL
FUNCTION BUFFER_SEARCH : INT
VAR_INPUT
PT : REF_TO ARRAY[0..32767] OF BYTE;
SIZE : INT;
STR : STRING[STRING_LENGTH];
POS : INT;
IGN : BOOL;
END_VAR
VAR
ps : REF_TO ARRAY[0..STRING_LENGTH] OF BYTE;
chx : BYTE;
i: INT;
end: INT;
k: INT;
lx: INT;
END_VAR
(*
version 1.4 25. jan 2011
programmer hugo
tested by oscat
this function will search for a string STR in an array of byte starting at position pos.
the function needs to be called: buffer_search(adr("array"),sizeof("array"), STR, POS, IGN);
because this function works with pointers its very time efficient and it needs no extra memory.
The function returns the position of the first character of the string in the array if found.
a -1 is returned if the string is not found in the array.
when IGN = TRUE, STR must be in capital letters and the search is case insensitv.
*)
(* @END_DECLARATION := '0' *)
ps := &(STR);
lx := LEN(STR);
end := MIN(SIZE - lx, SIZE - 1);
lx := lx - 1;
FOR i := pos TO end DO
FOR k := 0 TO lx DO
IF IGN THEN chx := TO_UPPER(pt^[i+k]); ELSE chx := pt^[i+k]; END_IF;
IF ps^[k] <> chx THEN EXIT; END_IF;
END_FOR;
IF k > lx THEN
BUFFER_SEARCH := i;
RETURN;
END_IF;
END_FOR;
BUFFER_SEARCH := -1;
(* revision History
hm 5. mar. 2008 rev 1.0
original version
hm 16. mar. 2008 rev 1.1
chaged type of input size to uint
hm 13. may. 2008 rev 1.2
changed type of pointer to array[1..32767]
changed size of string to STRING_LENGTH
hm 12. nov. 2009 rev 1.3
limit end to array size
hm 25. jan. 2011 rev 1.4
ign = True will now ignore case
return -1 if nothing found
*)
END_FUNCTION
(* @NESTEDCOMMENTS := 'Yes' *)
(* @PATH := '\/Buffer Management' *)
(* @OBJECTFLAGS := '0, 8' *)
(* @SYMFILEFLAGS := '2048' *)
@EXTERNAL
FUNCTION BUFFER_TO_STRING : STRING[STRING_LENGTH]
VAR_INPUT
PT : REF_TO ARRAY[0..32767] OF BYTE;
SIZE : UINT;
START : UINT;
STOP : UINT;
END_VAR
VAR
ps : REF_TO BYTE;
i : UINT;
stp: UINT;
sta: UINT;
END_VAR
(*
version 1.5 12. nov. 2009
programmer hugo
tested by oscat
this function will retrieve a string from an array of byte starting at position start and stop at position stop.
the function needs to be called: buffer_TO_String(adr("array"),sizeof("array"), start, stop);
because this function works with pointers its very time efficient and it needs no extra memory.
*)
(* @END_DECLARATION := '0' *)
ps := &(BUFFER_TO_STRING);
IF size = 0 THEN RETURN; END_IF;
sta := MIN(start, size -1);
stp := MIN(stop, size -1);
(* check for maximum string_length *)
IF UINT_TO_INT(stp - sta + 1) >= STRING_LENGTH THEN
stp := sta + INT_TO_UINT(STRING_LENGTH) - 1;
END_IF;
FOR i := sta TO stp DO
ps^ := pt^[i];
ps := ps + 1;
END_FOR;
(* terminate the string *)
ps^ := 0;
(* revision History
hm 5. mar. 2008 rev 1.0
original version
hm 16. mar. 2008 rev 1.1
changed type of input size to uint
hm 13. may. 2008 rev 1.2
changed type of pointer to array[0..32767]
changed size of string to STRING_LENGTH
hm 12. jun. 2008 rev 1.3
check for pointer overrun
change input start and stop to uint
added type conversions to avoid warnings under codesys 3.0
hm 23. mar. 2009 rev 1.4
avoid writing to input stop
hm 12. nov. 2009 rev 1.5
limit start and stop to size -1
*)
END_FUNCTION
(* @NESTEDCOMMENTS := 'Yes' *)
(* @PATH := '\/Engineering\/automation' *)
(* @OBJECTFLAGS := '0, 8' *)
(* @SYMFILEFLAGS := '2048' *)
FUNCTION_BLOCK DRIVER_1
VAR_INPUT (* CONSTANT *)
Toggle_Mode : BOOL;
Timeout : TIME;
END_VAR
VAR_INPUT
SET : BOOL;
IN : BOOL;
RST : BOOL;
END_VAR
VAR_OUTPUT
Q : BOOL;
END_VAR
VAR
off : TON;
edge: BOOL;
END_VAR
(*
version 1.0 2 jan 2008
programmer hugo
tested by tobias
driver_1 is a multi purpose driver.
a rising edge on in sets the output high if toggle is flase. while toggle is true, a rising edge on in toggles the output Q.
if a timeout is specified the output q will be reset to false automatically after the timeout has elapsed.
a asynchronous reset and set will force the output high or low respectively.
*)
(* @END_DECLARATION := '0' *)
IF off.Q THEN Q := FALSE; END_IF;
IF rst THEN
Q := FALSE;
ELSIF set THEN
Q := TRUE;
ELSIF IN AND NOT edge THEN
IF toggle_mode THEN q := NOT Q; ELSE q := TRUE; END_IF;
END_IF;
edge := in;
IF timeout > t#0s THEN off(in := Q, PT := Timeout); END_IF;
(* revision history
hm 2. jan 2008 rev 1.0
original version
*)
END_FUNCTION_BLOCK
(* @NESTEDCOMMENTS := 'Yes' *)
(* @PATH := '\/Engineering\/automation' *)
(* @OBJECTFLAGS := '0, 8' *)
(* @SYMFILEFLAGS := '2048' *)
FUNCTION_BLOCK DRIVER_4
VAR_INPUT (* CONSTANT *)
Toggle_Mode : BOOL;
Timeout : TIME;
END_VAR
VAR_INPUT
SET : BOOL;
IN0, IN1, IN2, IN3 : BOOL;
RST : BOOL;
END_VAR
VAR_OUTPUT
Q0, Q1, Q2, Q3 : BOOL;
END_VAR
VAR
d0, d1, d2, d3 : DRIVER_1;
END_VAR
(*
version 1.0 2 jan 2008
programmer hugo
tested by tobias
driver_4 is a 4 channel multi purpose driver.
a rising edge on in? sets the output Q? high if toggle_mode is flase. while toggle_mode is true, a rising edge on in? toggles the output Q?.
if a timeout is specified the output Q? will be reset to false automatically after the timeout has elapsed.
a asynchronous reset and set will force the output high or low respectively.
an asynchronous set will force all outputs high simultaneously
*)
(* @END_DECLARATION := '0' *)
D0(Set:=set, in:=in0, rst:=rst, toggle_mode:=toggle_mode, timeout:=timeout);
D1(Set:=set, in:=in1, rst:=rst, toggle_mode:=toggle_mode, timeout:=timeout);
D2(Set:=set, in:=in2, rst:=rst, toggle_mode:=toggle_mode, timeout:=timeout);
D3(Set:=set, in:=in3, rst:=rst, toggle_mode:=toggle_mode, timeout:=timeout);
Q0 := D0.Q;
Q1 := D1.Q;
Q2 := D2.Q;
Q3 := D3.Q;
(* revision history
hm 2. jan 2008 rev 1.0
original version
*)
END_FUNCTION_BLOCK
(* @NESTEDCOMMENTS := 'Yes' *)
(* @PATH := '\/Engineering\/automation' *)
(* @OBJECTFLAGS := '0, 8' *)
(* @SYMFILEFLAGS := '2048' *)
FUNCTION_BLOCK DRIVER_4C
VAR_INPUT
IN : BOOL;
RST : BOOL;
END_VAR
VAR_INPUT (* CONSTANT *)
Timeout : TIME;
SX : ARRAY[1..7] OF BYTE := [1,3,7,15];
END_VAR
VAR_OUTPUT
SN : INT;
Q0 : BOOL;
Q1 : BOOL;
Q2 : BOOL;
Q3 : BOOL;
END_VAR
VAR
off : TON;
edge: BOOL;
END_VAR
(*
version 1.0 23. mar. 2009
programmer hugo
tested by tobias
driver_4C is a multi purpose driver.
a rising edge on in switches from S0 state S1 and the next edge to state S2 and so on.
in state S0 all outputs Q are FALSE.
The stet of the Outputs in any state S? is configurable with setup variables.
The variables S1..S5 define the states, while the sequence is terminated when a state Variable S? = 0.
The lower bits 0..3 of the state vars S? are corresponding to the Outputs Q0..Q3
*)
(* @END_DECLARATION := '0' *)
IF RST OR off.Q THEN
SN := 0;
ELSIF IN AND NOT edge THEN
SN := SN + 1;
IF SN > 7 OR SX[SN] = 0 THEN SN := 0; END_IF;
END_IF;
edge := in;
IF SN > 0 THEN
Q0 := SX[SN].0;
Q1 := SX[SN].1;
Q2 := SX[SN].2;
Q3 := SX[SN].3;
ELSE
Q0 := FALSE;
Q1 := FALSE;
Q2 := FALSE;
Q3 := FALSE;
END_IF;
(* maximaum timeout *)
IF timeout > t#0s THEN off(in := SN > 0, PT := Timeout); END_IF;
(* revision history
hm 23. mar. 2009 rev 1.0
original version
*)
END_FUNCTION_BLOCK
(* @NESTEDCOMMENTS := 'Yes' *)
(* @PATH := '\/Engineering\/automation' *)
(* @OBJECTFLAGS := '0, 8' *)
(* @SYMFILEFLAGS := '2048' *)
FUNCTION_BLOCK FLOW_CONTROL
VAR_INPUT
IN : BOOL;
REQ : BOOL;
ENQ : BOOL;
RST : BOOL;
END_VAR
VAR_INPUT (* CONSTANT *)
T_AUTO : TIME := T#1h;
T_DELAY : TIME := T#23h;
END_VAR
VAR_OUTPUT
Q : BOOL;
STATUS : BYTE;
END_VAR
VAR
timer : TP_1D;
END_VAR
(*
version 1.0 28. jun. 2008
programmer hugo
tested by oscat
FLOW_CONTROL switches a valves depending on the input in.
flow control also limits the maximum ontime of the valve and controls pressure on the output side.
*)
(* @END_DECLARATION := '0' *)
STATUS := 100;
IF RST THEN
Q := FALSE;
timer(rst := TRUE);
timer.RST := FALSE;
STATUS := 103;
ELSIF ENQ THEN
IF IN THEN
status := 101;
END_IF;
IF REQ THEN
(* timer will generate a timed pulse after TP goes high *)
timer.PT1 := T_AUTO;
timer.PTD := T_DELAY;
timer.IN := TRUE;
STATUS := 102;
END_IF;
END_IF;
(* set output and run timer *)
timer();
timer.IN := FALSE;
Q := (IN AND ENQ) OR timer.Q;
(* revision history
hm 28. jun. 2008 rev 1.0
original version
*)
END_FUNCTION_BLOCK
(* @NESTEDCOMMENTS := 'Yes' *)
(* @PATH := '\/Engineering\/automation' *)
(* @OBJECTFLAGS := '0, 8' *)
(* @SYMFILEFLAGS := '2048' *)
FUNCTION_BLOCK FT_Profile
VAR_INPUT
K : REAL := 1.0;
O : REAL;
M : REAL := 1.0;
E : BOOL;
END_VAR
VAR_INPUT (* CONSTANT *)
value_0 : REAL;
time_1 : TIME;
value_1 : REAL;
time_2 : TIME;
value_2 : REAL;
time_3 : TIME;
value_3 : REAL;
time_10 : TIME;
value_10 : REAL;
time_11 : TIME;
value_11 : REAL;
time_12 : TIME;
value_12 : REAL;
time_13 : TIME;
value_13 : REAL;
END_VAR
VAR_OUTPUT
Y : REAL;
RUN : BOOL;
ET : TIME;
END_VAR
VAR
tx : TIME;
edge : BOOL;
state: BYTE;
ta: TIME;
tb: TIME;
t0 : TIME;
temp: REAL;
va: REAL;
vb: REAL;
END_VAR
(*
version 1.1 15 sep 2007
programmer tobias
tested by hugo
FT_Profile generates an output signal which is defined by values over a time scale.
the different values are connected by ramps between the individual values.
a rising edge on E starts the output signal generation and E = True can delay time_3 / value_3 as long as it stays true.
an additional multiplier K can be used to multiply the output and an offset O can be added to the output dynamically.
*)
(* @END_DECLARATION := '0' *)
(* read system time *)
tx := DWORD_TO_TIME(T_PLC_MS());
(* determine start condition *)
IF E AND NOT edge THEN
RUN := TRUE;
ET := t#0s;
t0 := tx;
ta := tx;
tb := multime(time_1, M);
va := value_0;
vb := value_1;
temp := value_0;
state := 1;
END_IF;
edge := E;
(* generate startup profile *)
IF run THEN
CASE state OF
1: IF tx - ta >= tb THEN
ta := ta + tb;
tb := multime(time_2 - time_1, M);
va := value_1;
vb := value_2;
temp := value_1;
state := 2;
ELSE
temp := ((vb - va) * TIME_TO_REAL(tx - ta) / TIME_TO_REAL(tb) + va);
END_IF;
2: IF tx - ta >= tb THEN
ta := ta + tb;
tb := multime(time_3 - time_2, M);
va := value_2;
vb := value_3;
temp := value_2;
state := 3;
ELSE
temp := ((vb - va) * TIME_TO_REAL(tx - ta) / TIME_TO_REAL(tb) + va);
END_IF;
3: IF tx - ta >= tb THEN
ta := ta + tb;
tb := multime(time_10 - time_3, M);
va := value_3;
vb := value_10;
temp := value_3;
state := 4;
ELSE
temp := ((vb - va) * TIME_TO_REAL(tx - ta) / TIME_TO_REAL(tb) + va);
END_IF;
4 : IF tx - ta >= tb THEN
ta := ta + tb;
tb := multime(time_11 - time_10, M);
va := value_10;
vb := value_11;
temp := value_10;
IF E THEN state := 5; ELSE state := 6; END_IF;
ELSE
temp := ((vb - va) * TIME_TO_REAL(tx - ta) / TIME_TO_REAL(tb) + va);
END_IF;
5: (* extend the signal while E is true *)
IF E THEN
ta := tx;
ELSE
state := 6;
END_IF;
6: IF tx - ta >= tb THEN
ta := ta + tb;
tb := multime(time_12 - time_11, M);
va := value_11;
vb := value_12;
temp := value_11;
state := 7;
ELSE
temp := ((vb - va) * TIME_TO_REAL(tx - ta) / TIME_TO_REAL(tb) + va);
END_IF;
7: IF tx - ta >= tb THEN
ta := ta + tb;
tb := multime(time_13 - time_12, M);
va := value_12;
vb := value_13;
temp := value_12;
state := 8;
ELSE
temp := ((vb - va) * TIME_TO_REAL(tx - ta) / TIME_TO_REAL(tb) + va);
END_IF;
8: IF tx - ta >= tb THEN
temp := value_13;
run := FALSE;
ELSE
temp := ((vb - va) * TIME_TO_REAL(tx - ta) / TIME_TO_REAL(tb) + va);
END_IF;
END_CASE;
Y := temp * K + O;
ET := tx - t0;
END_IF;
(* revision history
hm 27 feb 2007 rev 1.0
original version
hm 15. sep2007 rev 1.1
replaced Time() with T_PLC_MS for compatibility and performance reasons
*)
END_FUNCTION_BLOCK
(* @NESTEDCOMMENTS := 'Yes' *)
(* @PATH := '\/Engineering\/automation' *)
(* @OBJECTFLAGS := '0, 8' *)
(* @SYMFILEFLAGS := '2048' *)
FUNCTION_BLOCK INC_DEC
VAR_INPUT
CHa : BOOL;
CHb : BOOL;
RST : BOOL;
END_VAR
VAR_OUTPUT
dir : BOOL;
cnt : INT;
END_VAR
VAR
edgea : BOOL;
clk: BOOL;
clka: BOOL;
clkb: BOOL;
edgeb: BOOL;
axb: BOOL;
END_VAR
(*
version 1.0 4 aug 2006
programmer oscat
tested BY oscat
incremental decoder with quadruple accuracy.
2 pulses for each channel are created for each directional pulse.
*)
(* @END_DECLARATION := '0' *)
axb := cha XOR chb;
(* create pulses for channel a *)
clka := cha XOR edgea;
edgea := cha;
clkb := chb XOR edgeb;
edgeb := chb;
(* create pulses for both channels *)
clk := clka OR clkb;
(* set the direction output *)
IF axb AND clka THEN dir := TRUE; END_IF;
IF axb AND clkb THEN dir := FALSE; END_IF;
(* increment or decrement the counter *)
IF clk AND dir THEN cnt := cnt + 1; END_IF;
IF clk AND NOT dir THEN cnt := cnt -1; END_IF;
(* reset the counter if rst active *)
IF rst THEN cnt := 0; END_IF;
END_FUNCTION_BLOCK
(* @NESTEDCOMMENTS := 'Yes' *)
(* @PATH := '\/Engineering\/automation' *)
(* @OBJECTFLAGS := '0, 8' *)
(* @SYMFILEFLAGS := '2048' *)