(* Sorting conveyor: reference solution in IEC 61131-3 Structured Text. *) VAR_GLOBAL Start_PB AT %IX0.0 : BOOL; (* Start pushbutton, normally open *) Stop_PB AT %IX0.1 : BOOL; (* Stop pushbutton, normally closed, 1 when healthy *) PE_Entry AT %IX0.2 : BOOL; (* Photo-eye at the feeder, 1 when a part is there *) PE_Pusher AT %IX0.3 : BOOL; (* Photo-eye at the pusher station, sees every part *) Metal_Sensor AT %IX0.4 : BOOL; (* Inductive sensor at the pusher station, sees metal parts only *) Belt AT %QX0.0 : BOOL; (* Conveyor motor contactor *) Pusher AT %QX0.1 : BOOL; (* Reject pusher solenoid valve, 1 extends *) END_VAR PROGRAM Main VAR arrived : R_TRIG; parts : UDINT; (* Parts seen at the entry since the last cold restart. *) END_VAR Belt := (Start_PB OR Belt) AND Stop_PB; (* A metal part at the pusher station is pushed off. *) Pusher := PE_Pusher AND Metal_Sensor; arrived(CLK := PE_Entry); IF arrived.Q THEN parts := parts + 1; END_IF; END_PROGRAM