Code for PLC Control