can someone help me with the following script, for me scripting is completely new, I have some tutorials followed but to make the first start I find difficult.
Two pumps with alternate operation according to hours of operation and according to fault / stop status.
If both pumps are OK, they alternate every 50 hours of operation. If one of the pumps is faulty / stopped, the other always starts.
30.07.2021, 08:11 (This post was last modified: 30.07.2021, 08:23 by streilkx.)
(29.07.2021, 13:47)admin Wrote: Which objects are available? Pump start/stop and fault status (both binary)?
Yes, objects are;
Pumps start/stop (5/0/0)
Pump A Start/Stop (5/0/1)
Pump B Start/Stop (5/0/2)
Pump A Fault/manual stop status (5/0/10)
Pump B Fault/manual stop status (5/0/20)
on_1 = grp.getvalue('5/0/1')
on_2 = grp.getvalue('5/0/2')
-- one of the pumps is onifon_1oron_2thenpump_time = storage.get('pump_time', 0)
pump_time = pump_time + 1-- try switching to another pumpifpump_time > 50thenstop_1 = grp.getvalue('5/0/10')
stop_2 = grp.getvalue('5/0/20')
-- first is on, second is not in stop stateifon_1andnotstop_2thengrp.write('5/0/1', false)
grp.write('5/0/2', true)
pump_time = 0-- second is on, first is not in stop stateelseifon_2andnotstop_1thengrp.write('5/0/2', false)
grp.write('5/0/1', true)
pump_time = 0endendelsepump_time = 0endstorage.set('pump_time', pump_time)
Event script for first pump fault (5/0/10):
Code:
1234567891011121314151617181920
on_1 = grp.getvalue('5/0/1')
on_2 = grp.getvalue('5/0/2')
stop_1 = event.getvalue()
stop_2 = grp.getvalue('5/0/20')
-- switch to the second pumpifstop_1thenifnotstop_2andnoton_2thengrp.write('5/0/1', false)
grp.write('5/0/2', true)
storage.set('pump_time', 0)
end-- fault is removed and no pump is runningelseifnoton_1andnoton_2thengrp.write('5/0/1', true)
storage.set('pump_time', 0)
end
Event script for second pump fault (5/0/20):
Code:
1234567891011121314151617181920
on_1 = grp.getvalue('5/0/1')
on_2 = grp.getvalue('5/0/2')
stop_1 = grp.getvalue('5/0/10')
stop_2 = event.getvalue()
-- switch to the first pump if it's not in a fault stateifstop_2thenifnotstop_1andnoton_1thengrp.write('5/0/2', false)
grp.write('5/0/1', true)
storage.set('pump_time', 0)
end-- fault is removed and no pump is runningelseifnoton_1andnoton_2thengrp.write('5/0/2', true)
storage.set('pump_time', 0)
end
on_1 = grp.getvalue('5/0/1')
on_2 = grp.getvalue('5/0/2')
-- one of the pumps is onifon_1oron_2thenpump_time = storage.get('pump_time', 0)
pump_time = pump_time + 1-- try switching to another pumpifpump_time > 50thenstop_1 = grp.getvalue('5/0/10')
stop_2 = grp.getvalue('5/0/20')
-- first is on, second is not in stop stateifon_1andnotstop_2thengrp.write('5/0/1', false)
grp.write('5/0/2', true)
pump_time = 0-- second is on, first is not in stop stateelseifon_2andnotstop_1thengrp.write('5/0/2', false)
grp.write('5/0/1', true)
pump_time = 0endendelsepump_time = 0endstorage.set('pump_time', pump_time)
Event script for first pump fault (5/0/10):
Code:
1234567891011121314151617181920
on_1 = grp.getvalue('5/0/1')
on_2 = grp.getvalue('5/0/2')
stop_1 = event.getvalue()
stop_2 = grp.getvalue('5/0/20')
-- switch to the second pumpifstop_1thenifnotstop_2andnoton_2thengrp.write('5/0/1', false)
grp.write('5/0/2', true)
storage.set('pump_time', 0)
end-- fault is removed and no pump is runningelseifnoton_1andnoton_2thengrp.write('5/0/1', true)
storage.set('pump_time', 0)
end
Event script for second pump fault (5/0/20):
Code:
1234567891011121314151617181920
on_1 = grp.getvalue('5/0/1')
on_2 = grp.getvalue('5/0/2')
stop_1 = grp.getvalue('5/0/10')
stop_2 = event.getvalue()
-- switch to the first pump if it's not in a fault stateifstop_2thenifnotstop_1andnoton_1thengrp.write('5/0/2', false)
grp.write('5/0/1', true)
storage.set('pump_time', 0)
end-- fault is removed and no pump is runningelseifnoton_1andnoton_2thengrp.write('5/0/2', true)
storage.set('pump_time', 0)
end
Thanks for help!
I have been testing the scripts.
I understand that I always give start order to pump 1, and if it is faulty or has more than 50 hours, pump 2 starts.
I have found the following problem, if pump 1 is running, pump 2 is faulty, if pump 1 breaks down and pump 2 is repaired, pump 2 does not start automatically
stop_1 = event.getvalue()
stop_2 = grp.getvalue('5/0/20')
on_1 = grp.getvalue('5/0/1') andnotstop_1on_2 = grp.getvalue('5/0/2') andnotstop_2-- switch to the second pumpifstop_1thenifnotstop_2andnoton_2thengrp.write('5/0/1', false)
grp.write('5/0/2', true)
storage.set('pump_time', 0)
end-- fault is removed and no pump is runningelseifnoton_1andnoton_2thengrp.write('5/0/1', true)
storage.set('pump_time', 0)
end
Code:
1234567891011121314151617181920
stop_1 = grp.getvalue('5/0/10')
stop_2 = event.getvalue()
on_1 = grp.getvalue('5/0/1') andnotstop_1on_2 = grp.getvalue('5/0/2') andnotstop_2-- switch to the first pump if it's not in a fault stateifstop_2thenifnotstop_1andnoton_1thengrp.write('5/0/2', false)
grp.write('5/0/1', true)
storage.set('pump_time', 0)
end-- fault is removed and no pump is runningelseifnoton_1andnoton_2thengrp.write('5/0/2', true)
storage.set('pump_time', 0)
end
This will send OFF command when a fault is detected:
Code:
123456789101112131415161718192021
stop_1 = event.getvalue()
stop_2 = grp.getvalue('5/0/20')
on_1 = grp.getvalue('5/0/1') andnotstop_1on_2 = grp.getvalue('5/0/2') andnotstop_2-- switch to the second pumpifstop_1thengrp.write('5/0/1', false)
ifnotstop_2andnoton_2thengrp.write('5/0/2', true)
storage.set('pump_time', 0)
end-- fault is removed and no pump is runningelseifnoton_1andnoton_2thengrp.write('5/0/1', true)
storage.set('pump_time', 0)
end
Code:
123456789101112131415161718192021
stop_1 = grp.getvalue('5/0/10')
stop_2 = event.getvalue()
on_1 = grp.getvalue('5/0/1') andnotstop_1on_2 = grp.getvalue('5/0/2') andnotstop_2-- switch to the first pump if it's not in a fault stateifstop_2thengrp.write('5/0/2', false)
ifnotstop_1andnoton_1thengrp.write('5/0/1', true)
storage.set('pump_time', 0)
end-- fault is removed and no pump is runningelseifnoton_1andnoton_2thengrp.write('5/0/2', true)
storage.set('pump_time', 0)
end