-
Notifications
You must be signed in to change notification settings - Fork 22
/
main.plua
89 lines (77 loc) · 3.25 KB
/
main.plua
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
--Проект 'T1-PLCnext-Demo'
prg = require("prg") --Технологические объекты.
require( "sharedmodbus" ) --Межконтроллерный обмен
------------------------------------------------------------------------------
------------------------------------------------------------------------------
--Пользовательская функция инициализации, выполняемая однократно в PAC.
A5HL1_info = { lamp = A5HL1 }
A5HL2_info = { lamp = A5HL2 }
A5HL3_info = { lamp = A5HL3 }
A5HL4_info = { lamp = A5HL4 }
A5HL5_info = { lamp = A5HL5 }
A5HL6_info = { lamp = A5HL6 }
A5HL7_info = { lamp = A5HL7 }
A5HL8_info = { lamp = A5HL8 }
function user_init()
local delay = 5000
local delta = 200
A5HL1_info.start_time = get_millisec()
A5HL2_info.start_time = A5HL1_info.start_time - delta
A5HL3_info.start_time = A5HL2_info.start_time - delta
A5HL4_info.start_time = A5HL3_info.start_time - delta
A5HL5_info.start_time = A5HL4_info.start_time - delta
A5HL6_info.start_time = A5HL5_info.start_time - delta
A5HL7_info.start_time = A5HL6_info.start_time - delta
A5HL8_info.start_time = A5HL7_info.start_time - delta
end
function blink( info )
if get_delta_millisec( info.start_time ) > 2000 then
if info.lamp:get_state() == 1 then info.lamp:set_state( 0 ) else info.lamp:set_state( 1 ) end
info.start_time = get_millisec()
end
end
------------------------------------------------------------------------------
------------------------------------------------------------------------------
--Пользовательская функция, выполняемая каждый цикл в PAC.
function user_eval()
A2HL1:set_state( A2DI1:get_state() )
A2HL2:set_state( A2DI2:get_state() )
A2HL3:set_state( A2DI3:get_state() )
A2HL4:set_state( A2DI4:get_state() )
A2HL5:set_state( A2DI5:get_state() )
A2HL6:set_state( A2DI6:get_state() )
A2HL7:set_state( A2DI7:get_state() )
A2HL8:set_state( A2DI8:get_state() )
A3AO1:set_value( A3AI1:get_value() )
blink( A5HL1_info )
blink( A5HL2_info )
blink( A5HL3_info )
blink( A5HL4_info )
blink( A5HL5_info )
blink( A5HL6_info )
blink( A5HL7_info )
blink( A5HL8_info )
local GREEN_MIN = 0.3
local YELLOW_MIN = 3
local RED_MIN = 6
if A3AI1:get_value() < GREEN_MIN then
HLA1:off()
elseif A3AI1:get_value() >= GREEN_MIN and A3AI1:get_value() < YELLOW_MIN then
HLA1:turn_off_red()
HLA1:turn_off_yellow()
HLA1:normal_blink_green()
elseif A3AI1:get_value() >= YELLOW_MIN and A3AI1:get_value() < RED_MIN then
HLA1:off()
HLA1:turn_on_yellow()
elseif A3AI1:get_value() >= RED_MIN then
HLA1:off()
HLA1:turn_on_red()
end
end
------------------------------------------------------------------------------
------------------------------------------------------------------------------
--Функция инициализации параметров, выполняемая однократно в PAC.
function user_init_params()
end
------------------------------------------------------------------------------
------------------------------------------------------------------------------